Commit 56c81985 authored by Thomas Poimenidis's avatar Thomas Poimenidis
Browse files

updated Player class. still needs work

parent a2f764b4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class GameView extends SurfaceView implements Runnable{
        if(background2.yPos > screenHeight) {
            background2.yPos = -screenHeight;
        }
        p1.updateLocation();
        p1.update();
        joystick.update(joystick);
    }

+6 −28
Original line number Diff line number Diff line
@@ -9,29 +9,13 @@ import android.util.Log;


public class Player extends Sprite{
    public class Bullet{
        private final int  speed = 5;  //this can be changed ltr;
        private final int X;
        private int Y;
        public Bullet(int xx, int yy){
            X = xx;
            Y = yy;
        }
        public void goUp(){
            Y += speed;
        }
        public int[] getLocation() {
            return new int[]{X, Y};
        }
    }

    private int health = 3;
    private Queue<Bullet> Bullets = new LinkedList<>(); // max on the screen at the same time, can be change ltr;

    public Player(int xPos, int yPos, int xVel, int yVel, Resources res) {
        super(xPos,yPos,xVel,yVel);
        this.xPos = xPos;  //haven't implement it yet
        this.yPos = yPos; //haven't implement it yet
        this.xPos = xPos;
        this.yPos = yPos;
        spriteImage = BitmapFactory.decodeResource(res, R.drawable.green64);
        spriteImage = Bitmap.createScaledBitmap(spriteImage, getSpriteWidth(), getSpriteHeight(), false);
    }
@@ -42,24 +26,21 @@ public class Player extends Sprite{
    public void update(int joyStickInputX, int joyStickInputY){
        xPos += joyStickInputX;
        yPos += joyStickInputY;
        for(Bullet ii : Bullets) {
            ii.goUp();
        }
    }

    @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) ) {
            looseHealth();
            loseHealth();
            return true;
        } else {
            return false;
        }
    }

    // when looseHealth drop the help to 0, call the destroy function. which we will override ltr
    public void looseHealth() {
    // when loseHealth drop the help to 0, call the destroy function. which we will override ltr
    public void loseHealth() {
        health -= 1;
        if (health == 0) {
            destroy();
@@ -68,10 +49,7 @@ public class Player extends Sprite{


    public void shoot() {
        Bullets.add(new Bullet(xPos,yPos));
        if(Bullets.size() == 5){
            Bullets.remove();   // this should remove the first one that go into the list. it is a Que, so first in first out.
        }

    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class Sprite {
        //this should call the animation, and delete the object
    }

    public void updateLocation() {
    public void update() {
        xPos += xVel;
        yPos += yVel;
    }