Added Breakable Blocks
parent
f7b071b624
commit
17d49895f7
|
@ -3,16 +3,16 @@ sssssssssssssssssd
|
|||
sssssssssssssssssd 1
|
||||
sssssssssssssssssd
|
||||
sssssssssssssssssd
|
||||
sssssssssssssssssd 1 1 1 1 1
|
||||
sssssssssssssssssd 1 1lllllllll1 1 1
|
||||
sssssssssssssssssd 1
|
||||
sssssssssssssssssd
|
||||
sssssssssssssssssd qe qe
|
||||
sssssssssssssssssd ad ! ad
|
||||
sssssssssssssssssd b ! qe qe
|
||||
sssssssssssssssssd bbbbb ad ! ad
|
||||
sssssssssssssssssd qwe qwe atwwwrd qwwwwwwellllqwwwwwwwe
|
||||
sssssssssssssssssd asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc
|
||||
sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv
|
||||
sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv
|
||||
sssssssssssssssssdlllllad qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv
|
||||
sssssssssssssssssdlllllad qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv
|
||||
sssssssssssssssssdlllllad qwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv +
|
||||
sssssssssssssssssdllllladbb qwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv +
|
||||
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
|
|
@ -4,6 +4,8 @@ import java.awt.image.BufferedImage;
|
|||
public class BombDirectionShow extends StickyBomb{
|
||||
public BombDirectionShow(int x, int y, int xVelocity, int yVelocity) {
|
||||
super(x, y, xVelocity, yVelocity, null, null);
|
||||
WIDTH = 25;
|
||||
HEIGHT = 25;
|
||||
}
|
||||
|
||||
public void draw(Graphics g){
|
||||
|
|
|
@ -50,7 +50,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
|
||||
public static ArrayList<Tile>particleTiles = new ArrayList<Tile>();
|
||||
public static ArrayList<NonPlayer>enemy = new ArrayList<NonPlayer>();
|
||||
|
||||
public static ArrayList<StickyBomb>bombs = new ArrayList<>();
|
||||
public BombDirectionShow bombDir = null;
|
||||
public static ArrayList<Particle>particles = new ArrayList<Particle>();
|
||||
|
@ -204,8 +203,10 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
(player.mouseX - GamePanel.player.x) / 20, (player.mouseY - GamePanel.player.y) / 10);
|
||||
bombDir.draw(g);
|
||||
}
|
||||
g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length)+" "+player.leftMouseDown,100,100);
|
||||
// g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length)+" "+player.leftMouseDown,100,100);
|
||||
|
||||
g.drawImage(bomb,20,20,35,35,null);
|
||||
g.drawString("X"+LevelManager.bombs,60,40);
|
||||
if (isPaused) {
|
||||
g.setColor(new Color(255, 255, 255, 100));
|
||||
g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
|
||||
|
|
|
@ -8,20 +8,27 @@ public class LevelManager {
|
|||
public static int ySpawn = 600;
|
||||
|
||||
public static String filePath;
|
||||
|
||||
public static int bombs;
|
||||
public static void setLevel(int level){
|
||||
GamePanel.player.yVelocity = 0;
|
||||
GamePanel.player.xVelocity = 0;
|
||||
LevelManager.level = level;
|
||||
if(level == 1){
|
||||
xSpawn = 0;
|
||||
ySpawn = 300;
|
||||
filePath = "saves/Level1.txt";
|
||||
bombs = 99999;
|
||||
} else if(level == 2){
|
||||
xSpawn = 200;
|
||||
ySpawn = 0;
|
||||
filePath = "saves/Level2.txt";
|
||||
bombs = 2;
|
||||
} else if(level == 3){
|
||||
xSpawn = 200;
|
||||
ySpawn = 0;
|
||||
filePath = "saves/Level3.txt";
|
||||
bombs = 99329;
|
||||
}
|
||||
try {
|
||||
MapReader.inputMap(filePath);
|
||||
|
@ -32,7 +39,7 @@ public class LevelManager {
|
|||
} catch (LineUnavailableException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
GamePanel.player.reset();
|
||||
//GamePanel.player.reset();
|
||||
}
|
||||
public static void nextLevel(){
|
||||
setLevel(level+1);
|
||||
|
|
|
@ -59,7 +59,6 @@ public class MapReader {
|
|||
newTile("img/tiles/terrain/grassMiddleLeft.png");
|
||||
} else if(file.charAt(i)=='s'){
|
||||
newTile("img/tiles/terrain/grassCenter.png");
|
||||
GamePanel.map[x][y].collision = false;
|
||||
} else if(file.charAt(i)=='d'){
|
||||
newTile("img/tiles/terrain/grassMiddleRight.png");
|
||||
} else if(file.charAt(i)=='z'){
|
||||
|
@ -78,7 +77,7 @@ public class MapReader {
|
|||
newTile("img/tiles/terrain/cornerBottomRight.png");
|
||||
} else if(file.charAt(i)=='b'){
|
||||
newTile("img/tiles/boxes/box.png");
|
||||
GamePanel.map[x][y].collision = false;
|
||||
GamePanel.map[x][y].breakable = true;
|
||||
} else if(file.charAt(i)=='!'){
|
||||
GamePanel.enemy.add(new NonPlayer(TileX, TileY, GamePanel.slimeSpriteArray, 50, 28, 100));
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ public class Player extends GenericSprite {
|
|||
if (collide(GamePanel.map[i][j], this.x + x, this.y + y)) {
|
||||
if (GamePanel.map[i][j].isFinish) {
|
||||
LevelManager.nextLevel();
|
||||
GamePanel.player.reset();
|
||||
return true;
|
||||
}
|
||||
if (GamePanel.map[i][j].kills) {
|
||||
|
@ -204,6 +205,7 @@ public class Player extends GenericSprite {
|
|||
}
|
||||
|
||||
public void reset(){
|
||||
LevelManager.setLevel(LevelManager.level);
|
||||
GamePanel.camera.x = LevelManager.xSpawn;
|
||||
y = LevelManager.ySpawn;
|
||||
}
|
||||
|
@ -228,7 +230,8 @@ public class Player extends GenericSprite {
|
|||
mouseY = e.getY();
|
||||
if(e.getButton()==MouseEvent.BUTTON1) {
|
||||
leftMouseDown = false;
|
||||
if (GamePanel.bombs.size() < 3) {
|
||||
if (GamePanel.bombs.size() < 3 && LevelManager.bombs>0) {
|
||||
LevelManager.bombs--;
|
||||
GamePanel.bombs.add(new StickyBomb(GamePanel.player.x + GamePanel.camera.x + WIDTH/2, GamePanel.player.y+HEIGHT/2,
|
||||
(mouseX - GamePanel.player.x) / 20, (mouseY - GamePanel.player.y) / 10, GamePanel.bomb, GamePanel.explosionArray));
|
||||
}
|
||||
|
@ -241,7 +244,7 @@ public class Player extends GenericSprite {
|
|||
}
|
||||
}
|
||||
public int draw(Graphics g, int frame) {
|
||||
g.drawString(mouseX+" "+mouseY, 300, 300);
|
||||
//g.drawString(mouseX+" "+mouseY, 300, 300);
|
||||
frame %= spriteArray[0][0].length;
|
||||
if (!upPressed && !downPressed && !leftPressed && !rightPressed) {
|
||||
g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x-10, y, null);
|
||||
|
|
|
@ -66,6 +66,23 @@ public class StickyBomb extends GenericSprite{
|
|||
}
|
||||
|
||||
}
|
||||
int lowX = Math.max(0, ((x+GamePanel.GAME_WIDTH)/Tile.length)-4);
|
||||
int highX = Math.min(lowX + 8, GamePanel.map.length);
|
||||
int lowY = Math.max(0,(this.y/Tile.length)-6);
|
||||
int highY = Math.min(lowY + 12, GamePanel.map[0].length);
|
||||
for(int i=0; i<100; i++) {
|
||||
for (int j = lowY; j < highY; j++) {
|
||||
if (GamePanel.map[i][j] != null && GamePanel.map[i][j].breakable) {
|
||||
double disX = (x + WIDTH / 2) - (GamePanel.map[i][j].x + Tile.length / 2);
|
||||
double disY = (y + HEIGHT / 2) - (GamePanel.map[i][j].y + Tile.length / 2);
|
||||
if (Math.sqrt(disX * disX + disY * disY) < Tile.length * 5) {
|
||||
GamePanel.map[i][j] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean collide(Tile tile, double x, double y){
|
||||
|
|
|
@ -11,6 +11,8 @@ public class Tile {
|
|||
public boolean isFinish;
|
||||
|
||||
public boolean kills;
|
||||
|
||||
public boolean breakable;
|
||||
public int realX;
|
||||
public static final int length = 35;
|
||||
public Tile(int x, int y){
|
||||
|
@ -20,6 +22,7 @@ public class Tile {
|
|||
this.x = x;
|
||||
this.y = y;
|
||||
nonBombCollide = false;
|
||||
breakable = false;
|
||||
}
|
||||
public void update(){
|
||||
realX = x-GamePanel.camera.x;
|
||||
|
|
Loading…
Reference in New Issue