diff --git a/img/tiles/terrain/GrassMiddleLeft.png b/img/tiles/terrain/GrassMiddleLeft.png new file mode 100644 index 0000000..dd23cfe Binary files /dev/null and b/img/tiles/terrain/GrassMiddleLeft.png differ diff --git a/img/tiles/terrain/cornerBottomLeft.png b/img/tiles/terrain/cornerBottomLeft.png new file mode 100644 index 0000000..de29d78 Binary files /dev/null and b/img/tiles/terrain/cornerBottomLeft.png differ diff --git a/img/tiles/terrain/cornerBottomRight.png b/img/tiles/terrain/cornerBottomRight.png new file mode 100644 index 0000000..e26e83d Binary files /dev/null and b/img/tiles/terrain/cornerBottomRight.png differ diff --git a/img/tiles/terrain/cornerTopLeft.png b/img/tiles/terrain/cornerTopLeft.png new file mode 100644 index 0000000..1cdd1e2 Binary files /dev/null and b/img/tiles/terrain/cornerTopLeft.png differ diff --git a/img/tiles/terrain/cornerTopRight.png b/img/tiles/terrain/cornerTopRight.png new file mode 100644 index 0000000..404530a Binary files /dev/null and b/img/tiles/terrain/cornerTopRight.png differ diff --git a/img/tiles/terrain/grassBottomLeft.png b/img/tiles/terrain/grassBottomLeft.png new file mode 100644 index 0000000..44ce95b Binary files /dev/null and b/img/tiles/terrain/grassBottomLeft.png differ diff --git a/img/tiles/terrain/grassBottomMiddle.png b/img/tiles/terrain/grassBottomMiddle.png new file mode 100644 index 0000000..7a32547 Binary files /dev/null and b/img/tiles/terrain/grassBottomMiddle.png differ diff --git a/img/tiles/terrain/grassBottomRight.png b/img/tiles/terrain/grassBottomRight.png new file mode 100644 index 0000000..b89bec3 Binary files /dev/null and b/img/tiles/terrain/grassBottomRight.png differ diff --git a/img/tiles/terrain/grassCenter.png b/img/tiles/terrain/grassCenter.png new file mode 100644 index 0000000..abe9429 Binary files /dev/null and b/img/tiles/terrain/grassCenter.png differ diff --git a/img/tiles/terrain/grassMiddleRight.png b/img/tiles/terrain/grassMiddleRight.png new file mode 100644 index 0000000..c6b987d Binary files /dev/null and b/img/tiles/terrain/grassMiddleRight.png differ diff --git a/img/tiles/terrain/grassTopLeft.png b/img/tiles/terrain/grassTopLeft.png new file mode 100644 index 0000000..57eeab8 Binary files /dev/null and b/img/tiles/terrain/grassTopLeft.png differ diff --git a/img/tiles/terrain/grassTopRight.png b/img/tiles/terrain/grassTopRight.png new file mode 100644 index 0000000..f1be1f7 Binary files /dev/null and b/img/tiles/terrain/grassTopRight.png differ diff --git a/saves/Level1.txt b/saves/Level1.txt index 27d0633..ee931e3 100644 --- a/saves/Level1.txt +++ b/saves/Level1.txt @@ -1,18 +1,18 @@ -10000000 -01101101 -00000000 -00000000 -00010000 -00010000 -00010000 -00010100 -00000000 -00000000 -10000001 -0000000011000100000000000101010100110100 -0000000000000000000000000000000000000000000101000000111111111111111111111 -100000000000000000000000000000000000000000011000001000000000000000000000 -100000000000000000000000000000000000000000011000001000000000000000000000 -10000000000000000000010000bb00001000000000010000000000000000000000000 -10000000000000000000000000b000000000000000010000000000000011111111111111111 -2333333333333333333333333333333333333333333333341111111111 \ No newline at end of file +2wwwwwwwwwwwwwwwwe +sssssssssssssssssd +sssssssssssssssssd 1 +sssssssssssssssssd +sssssssssssssssssd +sssssssssssssssssd 1 1 1 1 1 +sssssssssssssssssd 1 +sssssssssssssssssd +sssssssssssssssssd +sssssssssssssssssd +sssssssssssssssssd qwe qwe +sssssssssssssssssd asd asd +sssssssssssssssssd 1 zxc zxc +sssssssssssssssssd +sssssssssssssssssd qwwwwwwwwe +sssssssssssssssssd qrsssssssstwe +sssssssssssssssssd qwwrssssssssssstwe qwe +ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwww3 \ No newline at end of file diff --git a/saves/Level2.txt b/saves/Level2.txt new file mode 100644 index 0000000..982508d --- /dev/null +++ b/saves/Level2.txt @@ -0,0 +1,18 @@ +2wwwwwwwwwwwwwwwwe +sssssssssssssssssd +sssssssssssssssssd 1 +sssssssssssssssssd +sssssssssssssssssd +sssssssssssssssssd 1 1 1 1 1 +sssssssssssssssssd 1 +sssssssssssssssssd +sssssssssssssssssd +sssssssssssssssssd +sssssssssssssssssd qwe qwe +sssssssssssssssssd asd asd +sssssssssssssssssd bbb 1 zxc zxc +sssssssssssssssssdbbbbbbbbbbbbbbbbbbbbbbb +sssssssssssssssssd qwwwwwwwwe +sssssssssssssssssd qrsssssssstwe +sssssssssssssssssd bbb qwwrssssssssssstwe qwe +ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwww3 \ No newline at end of file diff --git a/src/GamePanel.java b/src/GamePanel.java index 084429a..217436e 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -138,10 +138,8 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ for (Tile i : map) { i.update(); } - //force player to remain on screen - if (player.y <= 0) { - player.y = 0; - } + //force player to remain on screen (For the most part) + if (player.y >= GAME_HEIGHT - Player.PLAYER_HEIGHT) { player.y = GAME_HEIGHT - Player.PLAYER_HEIGHT; player.yVelocity = 0; @@ -165,6 +163,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{ //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(){ + LevelManager.setLevel(1); try { MapReader.inputMap(map, "saves/Level1.txt"); } catch (IOException | SpriteException e) { diff --git a/src/LevelManager.java b/src/LevelManager.java new file mode 100644 index 0000000..664e934 --- /dev/null +++ b/src/LevelManager.java @@ -0,0 +1,19 @@ +public class LevelManager { + public static int level = 1; + public static int xSpawn = 0; + public static int ySpawn = 600; + + public static String filePath; + public static void setLevel(int level){ + LevelManager.level = level; + if(level == 1){ + xSpawn = 0; + ySpawn = 600; + filePath = "saves/Level1.txt"; + } else if(level == 2){ + xSpawn = 0; + ySpawn = 600; + filePath = "saves/Level2.txt"; + } + } +} diff --git a/src/MapReader.java b/src/MapReader.java index f5e503b..e76808f 100644 --- a/src/MapReader.java +++ b/src/MapReader.java @@ -6,27 +6,56 @@ public class MapReader { //Input game map /* 1: Normal Grass - 2: Left Grass - 3: Middle Grass - 4: Right Grass + 2: Left Grass: + 3: Right Grass: + Grass Tiling: + qwe + asd + zxc + !: Slime + Grass: */ public static void inputMap(ArrayList map, String filePath) throws IOException, SpriteException { - String file = FileManager.readFile(filePath); - int x = -GamePanel.WIDTH*Tile.length; + String file = FileManager.readFile(LevelManager.filePath); + int x = -GamePanel.GAME_WIDTH/2 + Tile.length; int y = 0; for(int i=0; itile.x&&x0){ + while(canUpdate(0,1)){ + y+=1; + } + isGrounded = true; + } else if(yVelocity<0){ + while(canUpdate(0,-1)){ + y-=1; + } + } + yVelocity = 0; + } + if(canUpdate(0, yVelocity)) { + y = y + (int) yVelocity; + x = x + (int) xVelocity; + } + if(!isGrounded) { + yVelocity += 0.3; + } capSpeed(); } diff --git a/src/Player.java b/src/Player.java index 5bef996..4888e4f 100644 --- a/src/Player.java +++ b/src/Player.java @@ -12,8 +12,8 @@ import java.io.IOException; public class Player extends GenericSprite { public final int SPEED = 5; - public static final int PLAYER_WIDTH = 72; - public static final int PLAYER_HEIGHT = 97; + public static final int PLAYER_WIDTH = 64; + public static final int PLAYER_HEIGHT = 94; public int lastXDirection, lastYDirection, lastFrame; public int upKey, downKey, rightKey, leftKey; @@ -72,11 +72,6 @@ public class Player extends GenericSprite { } private boolean collide(Tile tile, double x, double y){ -// if(tile.realX-x>PLAYER_WIDTH&&x-tile.realX0){ @@ -113,13 +111,14 @@ public class Player extends GenericSprite { GamePanel.camera.x+=updateAmount+1; } xVelocity = 0; - } if(!canUpdate(0, yVelocity)){ + } + if(!canUpdate(0, yVelocity)){ if(yVelocity>0){ while(canUpdate(0,1)){ y+=1; } isGrounded = true; - } else if(yVelocity>0){ + } else if(yVelocity<0){ while(canUpdate(0,-1)){ y-=1; } @@ -148,6 +147,9 @@ public class Player extends GenericSprite { xVelocity*=0.9; if(!isGrounded) { yVelocity += 0.3; + if(downPressed){ + yVelocity+=1; + } } capSpeed(); } @@ -155,13 +157,13 @@ public class Player extends GenericSprite { public int draw(Graphics g, int frame) { frame %= spriteArray[0][0].length; if (!upPressed && !downPressed && !leftPressed && !rightPressed) { - g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x, y, null); + g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x-6, y, null); return 0; } else { lastXDirection = (int)(Math.signum(xVelocity) + 1) / 2; lastYDirection = (int)(Math.signum(yVelocity) + 1) / 2; lastFrame = frame; - g.drawImage(spriteArray[lastXDirection][lastYDirection][frame], x, y, null); + g.drawImage(spriteArray[lastXDirection][lastYDirection][frame], x-6, y, null); return 1; } }