Shots are defined on XML files. Each Shot have a name, a return speed and a movement. The movement is a set of moves with a start, a horizontal speed and a vertical speed.

Attributes:

    • name: just for information purposes
    • returnSpeed: the speed after the shot is hit
    • start: when the move will start (percentage of the screen, starts with 100)
    • speedX: horizontal speed
    • speedY: vertical speed

Example 1:

This is a simple shot that has a constant speed of 5.

Example 2:

This shot starts with a speed of 5 and on the middle of the screen (start=”50″) it increases its speed to 10.

Example 3:

This shot starts with a speed of 10 during the first quarter of the screen, then it decreases its speed to 5 and starts to move vertically with a speed of 10. On the middle of the screen it changes its vertical speed to -10. On the last quarter, it stops moving vertically and increases its horizontal speed to 10.

Shot.java

This was my first game and it was done on early 2010. Now I can see a lot of improvements opportunities, so feel free to modify it and use the best coding practices! =)

All the Shots are defined on a single class. The resources are stored on static variables to improve performance and make them resusable by all instances.

Shots have type, movement, state, coordinates, direction and picture. This class is responsible to load Shot resources and to handle all Shot actions. More info about these methods on future lessons!

shot_001.xml

If you need more info, use the comment section below!

SVN Project:

PingPong Madness Tutorial – Part 02 SVN

APK:

PingPong Madness Tutorial – Part 02.apk

Tutorial: