Loading app/src/main/java/com/example/a8_bitinvader/Enemy.java +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ public class Enemy extends Sprite{ @Override public void destroy() { //call the distroy functions, then delete this. //call the destroy functions, then delete this. } } app/src/main/java/com/example/a8_bitinvader/Player.java +3 −3 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ public class Player extends Sprite{ xPos = screenWidth/2; //haven't implement it yet yPos = 9 * screenHeight/10; //haven't implement it yet playerImg = BitmapFactory.decodeResource(res, R.drawable.green64); playerImg = Bitmap.createScaledBitmap(playerImg, getWidth(), getHeight(), false); playerImg = Bitmap.createScaledBitmap(playerImg, getSpriteWidth(), getSpriteHeight(), false); } Loading @@ -50,9 +50,9 @@ public class Player extends 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 touching(int xx, int yy) public boolean checkForCollision(int xx, int yy) { if( super.touching(xx,yy) ) { if( super.checkForCollision(xx,yy) ) { looseHealth(); return true; } else { Loading app/src/main/java/com/example/a8_bitinvader/Sprite.java +16 −15 Original line number Diff line number Diff line Loading @@ -6,16 +6,17 @@ import android.graphics.BitmapFactory; public class Sprite { // public fields // xPos and yPos are represent top left corner of Sprite hit box // 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 int xPos, yPos; int xVel, yVel; int screenWidth, screenHeight; Bitmap image; //private properties //FIXME THIS FORMULA IS WRONG, ONLY RETURNS 0 private final int height = 128;//displayMetrics.heightPixels/100; private final int width = 128;//displayMetrics.widthPixels/100; private final int spriteHeight = 64; private final int spriteWidth = 64; //private properties Loading @@ -30,21 +31,19 @@ public class Sprite { } /** * * @return Height of the sprite * @return height of the sprite */ public int getHeight() public int getSpriteHeight() { return height; return spriteHeight; } /** * * @return Width of the sprite * @return width of the sprite */ public int getWidth() public int getSpriteWidth() { return width; return spriteWidth; } /** Loading @@ -53,10 +52,10 @@ public class Sprite { * @param yy * @return True if xx and yy are in the current sprite */ public boolean touching(int xx, int yy) public boolean checkForCollision(int xx, int yy) { //implement if((xx < (xPos+width) && xx > xPos) && (yy < (yPos+height) && yy > yPos)) if((xx < (xPos+spriteWidth) && xx > xPos) && (yy < (yPos+spriteHeight) && yy > yPos)) { return true; } Loading @@ -67,6 +66,8 @@ public class Sprite { //this should call the animation, and delete the object } void updateLocation() {} //other classes will override this function public void updateLocation() { //other classes will override this function } } Loading
app/src/main/java/com/example/a8_bitinvader/Enemy.java +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ public class Enemy extends Sprite{ @Override public void destroy() { //call the distroy functions, then delete this. //call the destroy functions, then delete this. } }
app/src/main/java/com/example/a8_bitinvader/Player.java +3 −3 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ public class Player extends Sprite{ xPos = screenWidth/2; //haven't implement it yet yPos = 9 * screenHeight/10; //haven't implement it yet playerImg = BitmapFactory.decodeResource(res, R.drawable.green64); playerImg = Bitmap.createScaledBitmap(playerImg, getWidth(), getHeight(), false); playerImg = Bitmap.createScaledBitmap(playerImg, getSpriteWidth(), getSpriteHeight(), false); } Loading @@ -50,9 +50,9 @@ public class Player extends 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 touching(int xx, int yy) public boolean checkForCollision(int xx, int yy) { if( super.touching(xx,yy) ) { if( super.checkForCollision(xx,yy) ) { looseHealth(); return true; } else { Loading
app/src/main/java/com/example/a8_bitinvader/Sprite.java +16 −15 Original line number Diff line number Diff line Loading @@ -6,16 +6,17 @@ import android.graphics.BitmapFactory; public class Sprite { // public fields // xPos and yPos are represent top left corner of Sprite hit box // 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 int xPos, yPos; int xVel, yVel; int screenWidth, screenHeight; Bitmap image; //private properties //FIXME THIS FORMULA IS WRONG, ONLY RETURNS 0 private final int height = 128;//displayMetrics.heightPixels/100; private final int width = 128;//displayMetrics.widthPixels/100; private final int spriteHeight = 64; private final int spriteWidth = 64; //private properties Loading @@ -30,21 +31,19 @@ public class Sprite { } /** * * @return Height of the sprite * @return height of the sprite */ public int getHeight() public int getSpriteHeight() { return height; return spriteHeight; } /** * * @return Width of the sprite * @return width of the sprite */ public int getWidth() public int getSpriteWidth() { return width; return spriteWidth; } /** Loading @@ -53,10 +52,10 @@ public class Sprite { * @param yy * @return True if xx and yy are in the current sprite */ public boolean touching(int xx, int yy) public boolean checkForCollision(int xx, int yy) { //implement if((xx < (xPos+width) && xx > xPos) && (yy < (yPos+height) && yy > yPos)) if((xx < (xPos+spriteWidth) && xx > xPos) && (yy < (yPos+spriteHeight) && yy > yPos)) { return true; } Loading @@ -67,6 +66,8 @@ public class Sprite { //this should call the animation, and delete the object } void updateLocation() {} //other classes will override this function public void updateLocation() { //other classes will override this function } }