Greenfoot Workshop Bobby Snake www devoxx 4 kids
Greenfoot Workshop Bobby - Snake www. devoxx 4 kids. com
Greenfoot • Development Environment based on the Java programming language. • Mainly designed to ease the Java language learning • Allow to easily create 2 D games • Greenfoot is freely available on Microsoft Windows, Mac OS X, and Linux. • http: //www. greenfoot. org/ www. devoxx 4 kids. com
The Java language • « Object Oriented » Language • One of the World’s most used programming language • Allow to develop applications running on multiple systems – Windows, Mac, Linux, Android, … www. devoxx 4 kids. com
« Object Oriented » • Java applications are made of « Objects » • Each Object is composed of two main parts: – A set of internal properties – its « behavior » , the actions it can do www. devoxx 4 kids. com
Classes and Objects • To describe an object, we will define a class. • A class is a kind of « model » allowing to build the objects – We also say that the objects are « instances » of the class www. devoxx 4 kids. com
A Java Class sample public class Game. Element { private int x; private int y; public Game. Element(int init. X, int init. Y) { x = init. X; y = init. Y; } public int get. X() { return x; } public int get. Y() { return y; } public void move(int x. Move, int y. Move) { x = x + x. Move; y = y + y. Move; } } www. devoxx 4 kids. com
Bobby-Snake www. devoxx 4 kids. com 7
New scenario www. devoxx 4 kids. com 8
World creation www. devoxx 4 kids. com 9
Snake World www. devoxx 4 kids. com 10
Snake. World code www. devoxx 4 kids. com 11
Inspect World www. devoxx 4 kids. com 12
Change the code • We will use blocks of 32 x 32 pixels • The game size will be 25 x 20 blocks www. devoxx 4 kids. com 13
Create a Block www. devoxx 4 kids. com 14
Create the Border www. devoxx 4 kids. com 15
Coordinates (0, 0) (1, 0) (2, 0) … (24, 0) (0, 1) (1, 1) (2, 1) … (24, 1) (0, 2) (1, 2) (2, 2) … (24, 2) … … … (0, 19) (1, 19) (2, 19) … (24, 19) www. devoxx 4 kids. com 16
Display the borders www. devoxx 4 kids. com 17
for loops for ( initialization ; test ; post-processing ) { body ; } www. devoxx 4 kids. com 18
The game borders www. devoxx 4 kids. com 19
Class Snake. Body www. devoxx 4 kids. com 20
Snake. World changes www. devoxx 4 kids. com 21
Movement www. devoxx 4 kids. com 22
If Statement www. devoxx 4 kids. com 23
Limit the Snake size www. devoxx 4 kids. com 24
Change of direction www. devoxx 4 kids. com 25
Manage collisions (1) www. devoxx 4 kids. com 26
Manage collisions (2) www. devoxx 4 kids. com 27
Add Apples (1) www. devoxx 4 kids. com 28
Add Apples (2) www. devoxx 4 kids. com 29
Collision with an apple www. devoxx 4 kids. com 30
Add sounds www. devoxx 4 kids. com 31
Congratulations! • You have completed your first Greenfoot game! • You can now start to add new features in your game or start creating new games ! www. devoxx 4 kids. com 32
- Slides: 32