Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Android Game Programming By Example
  • Table Of Contents Toc
  • Feedback & Rating feedback
Android Game Programming By Example

Android Game Programming By Example

By : John Horton
4.4 (9)
close
close
Android Game Programming By Example

Android Game Programming By Example

4.4 (9)
By: John Horton

Overview of this book

The book is best suited for existing Android or Java programmers who want to adapt their skills to make exciting Android games. The book is also for determined readers who might have no Android, game programming or even Java experience, but a reasonable understanding of object oriented programming knowledge is assumed.
Table of Contents (13 chapters)
close
close
7
7. Platformer – Guns, Life, Money, and the Enemy
chevron up
12
Index

Ready aim fire


Now, we can give our hero a gun, and later, we can give him enemies to shoot at. We will create a MachineGun class to do all the work and a Bullet class to represent the projectiles that it fires. The Player class will control the MachineGun class, and the MachineGun class will control and keep track of all the Bullet objects that it fires.

Create a new Java class and call it Bullet. Bullets are not complicated. Ours will need a x and y location, a horizontal velocity, and a direction to help calculate the velocity.

This implies the following simple class, constructor, and a bunch of getters and setters:

public class Bullet  {

    private float x;
    private float y;
    private float xVelocity;
    private int direction;

    Bullet(float x, float y, int speed, int direction){
        this.direction = direction;
        this.x = x;
        this.y = y;
        this.xVelocity = speed * direction;
    }

    public int getDirection(){
        return direction;
    }

    public...
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Android Game Programming By Example
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon