Game apps for smartphones and tablets |
|
Research project PHBern |
|
![]() |
|
|
In order to understand the program code, it is recommended to develop the application in 4 steps:
Step 1: Create randomly chosen fruits at a determined position
Since all fruit actors act the same way, it would be a good idea to determine the characteristics of these actors in an abstract class Fruit.java and derive all fruit actors from that class. In a first step, in the method act() of the Fruit class only the turn around the own axis is implemented.
|
![]() |
Step 2: Fruits move on a trajectory parabola
The coordinates x, y of the moving fruits are calculated in physical terms with the the method act() of the class Fruit (horizontal shot)
|
![]() |
Edit this example in the Online Editor
Step 3: Implementing touch events
The fruits are "cut" with a sword by touching the fruit sprite with your finger. Since we work with pixel coordinates, we have to use a precise collision identification. We implement a GGTouchListener. In the callback method touchEvent(), the x- and y-coordinate of the point of contact are captured and the sword is set to this position. When letting go, the sword is positioned outside the game window, so that it is not in the way of the game mechanics. In the class fruit, we've implemented a GGAcctorCollisionListener that registers in the method collide() the collisions of the fruit actor and the sword. |
Schritt 4: Evaluation of the game
In the final step, only number variables are introduced and the results are displayed continuously. |
Edit this example in the Online Editor