diff --git a/.idea/misc.xml b/.idea/misc.xml index 1ce6e7f..d15472f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/out/production/final/GamePanel.class b/out/production/final/GamePanel.class index 0cd9913..c4d26fa 100644 Binary files a/out/production/final/GamePanel.class and b/out/production/final/GamePanel.class differ diff --git a/out/production/final/GenericSprite.class b/out/production/final/GenericSprite.class index 499fc0c..859f6df 100644 Binary files a/out/production/final/GenericSprite.class and b/out/production/final/GenericSprite.class differ diff --git a/src/GamePanel.java b/src/GamePanel.java index a089809..fb75c80 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -50,6 +50,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ } player = new Player(GAME_WIDTH/2, GAME_HEIGHT/2, 'W', 'A', 'S', 'D', spriteArray); //create a player controlled player, set start location to middle of screen map.add(new Tile(1000, 700)); + map.add(new Tile(700, 600)); + map.add(new Tile(1000, 500)); + map.add(new Tile(700, 400)); + map.add(new Tile(1000, 300)); + map.add(new Tile(700, 200)); this.setFocusable(true); //make everything in this class appear on the screen this.addKeyListener(this); //start listening for keyboard input @@ -96,31 +101,28 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ player.isGrounded = false; for (Tile i : map) { - + i.collide(player); } //force player to remain on screen if (player.y <= 0) { player.y = 0; } if (player.y >= GAME_HEIGHT - Player.PLAYER_HEIGHT) { - player.y = GAME_HEIGHT - Player.PLAYER_HEIGHT; - if (player.y >= GAME_HEIGHT - Player.PLAYER_HEIGHT) { player.y = GAME_HEIGHT - Player.PLAYER_HEIGHT; player.yVelocity = 0; player.isGrounded = true; } if (player.x <= 0) { player.x = 0; - + } if (player.x <= 0) { player.x = 0; } - } if (player.x + Player.PLAYER_WIDTH >= GAME_WIDTH) { player.x = GAME_WIDTH - Player.PLAYER_WIDTH; } } - } + //run() method is what makes the game continue running without end. It calls other methods to move objects, check for collision, and update the screen public void run(){ diff --git a/src/GenericSprite.java b/src/GenericSprite.java index 6a7cbae..00c2b4b 100644 --- a/src/GenericSprite.java +++ b/src/GenericSprite.java @@ -12,9 +12,9 @@ public class GenericSprite extends Rectangle{ public double yVelocity; public double xVelocity; public final double SPEED = 20; //movement speed of ball - public final double speedCap = 7; //Speed cap of ball - public static final int WIDTH = 20; //size of ball - public static final int HEIGHT = 20; //size of ball + public final double speedCap = 5; //Speed cap of ball + public int WIDTH = 20; //size of ball + public int HEIGHT = 20; //size of ball public boolean rightPressed = false; public boolean leftPressed = false; public boolean upPressed= false; @@ -22,7 +22,7 @@ public class GenericSprite extends Rectangle{ public boolean isGrounded = false; //constructor creates ball at given location with given dimensions public GenericSprite(int x, int y, int height, int width){ - super(x, y, height, width); + super(x, y, height, width);WIDTH = width; HEIGHT = height; } //called from GamePanel when any keyboard input is detected diff --git a/src/Tile.java b/src/Tile.java index 06b7153..62e667f 100644 --- a/src/Tile.java +++ b/src/Tile.java @@ -9,6 +9,21 @@ public class Tile { this.y = y; } + //Actions when tile interacts with sprites + public void collide(GenericSprite s){ + if(s.x+s.WIDTH>x&&s.x=y&&s.y<=y+length){ + if(s.x+s.WIDTH>x+20&&s.xx+length-length/2){ + s.x = x+length; + } + } + } public void draw(Graphics g){ g.setColor(Color.black); g.fillRect(x, y, length, length);