Loading app/src/main/java/com/example/a8_bitinvader/Bullet.java +2 −2 Original line number Diff line number Diff line Loading @@ -10,8 +10,8 @@ public class Bullet extends Sprite { /** * Creates Bullet object using Sprite constructor */ public Bullet(int xPos, int yPos, int xVel, int yVel, Resources res) { super(xPos, yPos, xVel, yVel); public Bullet(int xPos, int yPos, int xVel, int yVel, int screenWidth, int screenHeight, Resources res) { super(xPos, yPos, xVel, yVel, screenWidth, screenHeight); spriteImage = BitmapFactory.decodeResource(res, R.drawable.red); spriteImage = Bitmap.createScaledBitmap(spriteImage, screenWidth, screenHeight, false); } Loading app/src/main/java/com/example/a8_bitinvader/Enemy.java +2 −2 Original line number Diff line number Diff line Loading @@ -19,8 +19,8 @@ public class Enemy extends Sprite{ * @param xVel X velocity * @param yVel Y velocity */ public Enemy(int xPos, int yPos, int xVel, int yVel) { super(xPos, yPos, xVel, yVel); public Enemy(int xPos, int yPos, int xVel, int yVel, int screenWidth, int screenHeight) { super(xPos, yPos, xVel, yVel, screenWidth, screenWidth); } Loading app/src/main/java/com/example/a8_bitinvader/GameView.java +4 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,6 @@ public class GameView extends SurfaceView implements Runnable{ */ public GameView(Context context, int screenWidth, int screenHeight) { super(context); joystick = new Joystick(screenWidth/2,screenHeight*9/10,130,40); p1 = new Player(screenWidth/2,screenHeight*7/10,0,0, getResources()); this.screenWidth = screenWidth; this.screenHeight = screenHeight; Loading @@ -42,6 +40,9 @@ public class GameView extends SurfaceView implements Runnable{ background2.yPos = -screenHeight; paint = new Paint(); joystick = new Joystick(screenWidth/2,screenHeight*9/10,130,40); p1 = new Player(screenWidth/2,screenHeight*7/10,0,0, screenWidth, screenHeight, getResources()); } /* Loading Loading @@ -84,6 +85,7 @@ public class GameView extends SurfaceView implements Runnable{ if(background2.yPos > screenHeight) { background2.yPos = -screenHeight; } p1.update((int)joystick.XVelocity, (int)joystick.YVelocity); joystick.update(joystick); } Loading app/src/main/java/com/example/a8_bitinvader/Player.java +16 −6 Original line number Diff line number Diff line package com.example.a8_bitinvader; import java.util.LinkedList; import java.util.Queue; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; public class Player extends Sprite{ Loading @@ -24,8 +20,8 @@ public class Player extends Sprite{ * @param yVel Y velocity of player * @param res Resource object */ public Player(int xPos, int yPos, int xVel, int yVel, Resources res) { super(xPos,yPos,xVel,yVel); public Player(int xPos, int yPos, int xVel, int yVel, int screenWidth, int screenHeight, Resources res) { super(xPos,yPos,xVel,yVel, screenWidth, screenHeight); this.xPos = xPos; this.yPos = yPos; spriteImage = BitmapFactory.decodeResource(res, R.drawable.player); Loading @@ -45,8 +41,22 @@ public class Player extends Sprite{ xVel = joyStickInputX * SPEED_MULTIPLIER; yVel = joyStickInputY * SPEED_MULTIPLIER; // calls Sprite update(). Updates xPos and yPos. update(); // checks if Player is offscreen. If so, repositions them within the screen. if(xPos < 0){ xPos = 5; } else if(xPos + getSpriteWidth() > screenWidth){ xPos = screenWidth - getSpriteWidth() - 5; } if(yPos < 0){ yPos = 5; } else if(yPos + getSpriteHeight() > screenHeight){ yPos = screenHeight - getSpriteHeight() - 5; } } /** Loading app/src/main/java/com/example/a8_bitinvader/Sprite.java +5 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ public class Sprite { Bitmap spriteImage; //private properties private final int spriteHeight = 160, spriteWidth = 160; private final int spriteHeight = 128, spriteWidth = 128; //private properties Loading @@ -32,12 +32,15 @@ public class Sprite { * @param xVel initial x velocity of Sprite * @param yVel initial y velocity of Sprite */ public Sprite(int xPos, int yPos, int xVel, int yVel) public Sprite(int xPos, int yPos, int xVel, int yVel, int screenWidth, int screenHeight) { this.xPos = xPos; this.yPos = yPos; this.xVel = xVel; this.yVel = yVel; this.screenWidth = screenWidth; this.screenHeight = screenHeight; } /** Loading Loading
app/src/main/java/com/example/a8_bitinvader/Bullet.java +2 −2 Original line number Diff line number Diff line Loading @@ -10,8 +10,8 @@ public class Bullet extends Sprite { /** * Creates Bullet object using Sprite constructor */ public Bullet(int xPos, int yPos, int xVel, int yVel, Resources res) { super(xPos, yPos, xVel, yVel); public Bullet(int xPos, int yPos, int xVel, int yVel, int screenWidth, int screenHeight, Resources res) { super(xPos, yPos, xVel, yVel, screenWidth, screenHeight); spriteImage = BitmapFactory.decodeResource(res, R.drawable.red); spriteImage = Bitmap.createScaledBitmap(spriteImage, screenWidth, screenHeight, false); } Loading
app/src/main/java/com/example/a8_bitinvader/Enemy.java +2 −2 Original line number Diff line number Diff line Loading @@ -19,8 +19,8 @@ public class Enemy extends Sprite{ * @param xVel X velocity * @param yVel Y velocity */ public Enemy(int xPos, int yPos, int xVel, int yVel) { super(xPos, yPos, xVel, yVel); public Enemy(int xPos, int yPos, int xVel, int yVel, int screenWidth, int screenHeight) { super(xPos, yPos, xVel, yVel, screenWidth, screenWidth); } Loading
app/src/main/java/com/example/a8_bitinvader/GameView.java +4 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,6 @@ public class GameView extends SurfaceView implements Runnable{ */ public GameView(Context context, int screenWidth, int screenHeight) { super(context); joystick = new Joystick(screenWidth/2,screenHeight*9/10,130,40); p1 = new Player(screenWidth/2,screenHeight*7/10,0,0, getResources()); this.screenWidth = screenWidth; this.screenHeight = screenHeight; Loading @@ -42,6 +40,9 @@ public class GameView extends SurfaceView implements Runnable{ background2.yPos = -screenHeight; paint = new Paint(); joystick = new Joystick(screenWidth/2,screenHeight*9/10,130,40); p1 = new Player(screenWidth/2,screenHeight*7/10,0,0, screenWidth, screenHeight, getResources()); } /* Loading Loading @@ -84,6 +85,7 @@ public class GameView extends SurfaceView implements Runnable{ if(background2.yPos > screenHeight) { background2.yPos = -screenHeight; } p1.update((int)joystick.XVelocity, (int)joystick.YVelocity); joystick.update(joystick); } Loading
app/src/main/java/com/example/a8_bitinvader/Player.java +16 −6 Original line number Diff line number Diff line package com.example.a8_bitinvader; import java.util.LinkedList; import java.util.Queue; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; public class Player extends Sprite{ Loading @@ -24,8 +20,8 @@ public class Player extends Sprite{ * @param yVel Y velocity of player * @param res Resource object */ public Player(int xPos, int yPos, int xVel, int yVel, Resources res) { super(xPos,yPos,xVel,yVel); public Player(int xPos, int yPos, int xVel, int yVel, int screenWidth, int screenHeight, Resources res) { super(xPos,yPos,xVel,yVel, screenWidth, screenHeight); this.xPos = xPos; this.yPos = yPos; spriteImage = BitmapFactory.decodeResource(res, R.drawable.player); Loading @@ -45,8 +41,22 @@ public class Player extends Sprite{ xVel = joyStickInputX * SPEED_MULTIPLIER; yVel = joyStickInputY * SPEED_MULTIPLIER; // calls Sprite update(). Updates xPos and yPos. update(); // checks if Player is offscreen. If so, repositions them within the screen. if(xPos < 0){ xPos = 5; } else if(xPos + getSpriteWidth() > screenWidth){ xPos = screenWidth - getSpriteWidth() - 5; } if(yPos < 0){ yPos = 5; } else if(yPos + getSpriteHeight() > screenHeight){ yPos = screenHeight - getSpriteHeight() - 5; } } /** Loading
app/src/main/java/com/example/a8_bitinvader/Sprite.java +5 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ public class Sprite { Bitmap spriteImage; //private properties private final int spriteHeight = 160, spriteWidth = 160; private final int spriteHeight = 128, spriteWidth = 128; //private properties Loading @@ -32,12 +32,15 @@ public class Sprite { * @param xVel initial x velocity of Sprite * @param yVel initial y velocity of Sprite */ public Sprite(int xPos, int yPos, int xVel, int yVel) public Sprite(int xPos, int yPos, int xVel, int yVel, int screenWidth, int screenHeight) { this.xPos = xPos; this.yPos = yPos; this.xVel = xVel; this.yVel = yVel; this.screenWidth = screenWidth; this.screenHeight = screenHeight; } /** Loading