Commit 9e1f3f98 authored by Anish Sinha's avatar Anish Sinha
Browse files

Merge branch 'Sprites' of https://agile.bu.edu/gitlab/ec327_projects/group5project into Sprites

parents ffdcafc4 38b37279
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);
    }

+7 −29
Original line number Diff line number Diff line
@@ -9,57 +9,38 @@ 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);
    }

    //get input from the joystick, and change the location

    // tbh I think this is goingto give us an error ltr, becuase 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
    // 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
    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;
    }