Commit c76096b0 authored by Derek Xu's avatar Derek Xu
Browse files

Who doesnt love some documentation, also added enemy functions

parent 1bc367cc
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -2,10 +2,56 @@ package com.example.a8_bitinvader;

public class Enemy extends Sprite{

    // this will need to vary no?
    /** Health of player */
    private int health = 1;

    // speed adjust
    /** Speed */
    public final int SPEED_MULTIPLIER = 3;

    //initialize the Xval,Yval. and inital position

    /**
     * Initialize an enemy with the given coordinates and initial velocity
     * @param xPos X point
     * @param yPos Y point
     * @param xVel X velocity
     * @param yVel Y velocity
     */
    public Enemy(int xPos, int yPos, int xVel, int yVel) {
        super(xPos, yPos, xVel, yVel);

    }

    /**
     * Checks if the given points are within the sprite and reduce the health if so
     * @param xx Other X point
     * @param yy Other Y point
     * @return True if input xx and yy are within the sprite
     */
    @Override //the return doesn't really mean anything all we need is that when any of the point hit within the hit box of player, call the loose health function.
    public boolean checkForCollision(int xx, int yy)
    {
        if( super.checkForCollision(xx,yy) ) {
            loseHealth();
            return true;
        } else {
            return false;
        }
    }

    /**
     * Decrease the health of the player
     */
    // when loseHealth drop the help to 0, call the destroy function. which we will override ltr
    private void loseHealth() {
        health -= 1;
        if (health == 0) {
            destroy();
        }
    }


    // will shoot bullets
    public void shootBullets(){
+16 −1
Original line number Diff line number Diff line
@@ -35,11 +35,23 @@ public class Player extends Sprite{
    //get input from the joystick, and change the location

    // tbh I think this is going to give us an error ltr, because we are going to call update and shoot constantly, I wonder what will happen if we write and deleting at the same time. We'll see tho

    /**
     * Update the position of the player based on joystick offset
     * @param joyStickInputX X input from joystick
     * @param joyStickInputY Y input from joystick
     */
    public void update(int joyStickInputX, int joyStickInputY){
        xPos += joyStickInputX;
        yPos += joyStickInputY;
    }

    /**
     * Checks if the given points are within the sprite and reduce the health if so
     * @param xx Other X point
     * @param yy Other Y point
     * @return True if input xx and yy are within the sprite
     */
    @Override //the return doesn't really mean anything all we need is that when any of the point hit within the hit box of player, call the loose health function.
    public boolean checkForCollision(int xx, int yy)
    {
@@ -51,8 +63,11 @@ public class Player extends Sprite{
        }
    }

    /**
     * Decrease the health of the player
     */
    // when loseHealth drop the help to 0, call the destroy function. which we will override ltr
    public void loseHealth() {
    private void loseHealth() {
        health -= 1;
        if (health == 0) {
            destroy();
+13 −0
Original line number Diff line number Diff line
@@ -9,9 +9,16 @@ public class Sprite {
    // xPos and yPos represent top left corner of Sprite hit box
    // xVel and yVel represent x and y velocity respectively
    // image is the Bitmap of the Sprite object
    /** X and Y position of the sprite */
    int xPos, yPos;

    /** X and Y velocity of the sprite */
    int xVel, yVel;

    /** Screen size */
    int screenWidth, screenHeight;

    /** Image of the sprite */
    Bitmap spriteImage;

    //private properties
@@ -66,10 +73,16 @@ public class Sprite {
        return false;
    }

    /**
     * Function to destory the sprite and delete the object
     */
    public void destroy() {
        //this should call the animation, and delete the object
    }

    /**
     * Updates the sprite to move according to a given velocity
     */
    public void update() {
        xPos += xVel;
        yPos += yVel;