Working on moving block
parent
a6e1ffe98c
commit
e698273bfa
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -6,7 +6,7 @@ sssssssssssssssssd
|
||||||
sssssssssssssssssd 1 1lllllllll1 1 1
|
sssssssssssssssssd 1 1lllllllll1 1 1
|
||||||
sssssssssssssssssd 1
|
sssssssssssssssssd 1
|
||||||
sssssssssssssssssd
|
sssssssssssssssssd
|
||||||
sssssssssssssssssd b ! qe qe
|
sssssssssssssssssd ! b qe qe
|
||||||
sssssssssssssssssd bbbbb ad ! ad
|
sssssssssssssssssd bbbbb ad ! ad
|
||||||
sssssssssssssssssd qwe qwe atwwwrd qwwwwwwellllqwwwwwwwe
|
sssssssssssssssssd qwe qwe atwwwrd qwwwwwwellllqwwwwwwwe
|
||||||
sssssssssssssssssd asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc
|
sssssssssssssssssd asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc
|
||||||
|
|
|
@ -140,7 +140,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
player.mouseDragged(e);
|
player.mouseDragged(e);
|
||||||
}
|
}
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
player.mouseMoved(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT));
|
this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT));
|
||||||
|
|
||||||
|
@ -156,13 +158,17 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
||||||
//we are using "double buffering here" - if we draw images directly onto the screen, it takes time and the human eye can actually notice flashes of lag as each pixel on the screen is drawn one at a time. Instead, we are going to draw images OFF the screen, then simply move the image on screen as needed.
|
//we are using "double buffering here" - if we draw images directly onto the screen, it takes time and the human eye can actually notice flashes of lag as each pixel on the screen is drawn one at a time. Instead, we are going to draw images OFF the screen, then simply move the image on screen as needed.
|
||||||
image = createImage(GAME_WIDTH, GAME_HEIGHT); //draw off screen
|
image = createImage(GAME_WIDTH, GAME_HEIGHT); //draw off screen
|
||||||
graphics = image.getGraphics();
|
graphics = image.getGraphics();
|
||||||
|
try {
|
||||||
draw(graphics, playerFrame, enemyFrame);//update the positions of everything on the screen
|
draw(graphics, playerFrame, enemyFrame);//update the positions of everything on the screen
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
g.drawImage(image, 0, 0, this); //move the image on the screen
|
g.drawImage(image, 0, 0, this); //move the image on the screen
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//call the draw methods in each class to update positions as things move
|
//call the draw methods in each class to update positions as things move
|
||||||
public void draw(Graphics g, int playerFrame, int enemyFrame){
|
public void draw(Graphics g, int playerFrame, int enemyFrame) throws IOException {
|
||||||
background.draw(g);
|
background.draw(g);
|
||||||
if (isPaused) {
|
if (isPaused) {
|
||||||
// set player frame to 0 to prevent frame from changing when player moves
|
// set player frame to 0 to prevent frame from changing when player moves
|
||||||
|
@ -209,8 +215,21 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
||||||
(player.mouseX - GamePanel.player.x) / 20, (player.mouseY - GamePanel.player.y) / 10);
|
(player.mouseX - GamePanel.player.x) / 20, (player.mouseY - GamePanel.player.y) / 10);
|
||||||
bombDir.draw(g);
|
bombDir.draw(g);
|
||||||
}
|
}
|
||||||
g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length)+" "+player.leftMouseDown,100,100);
|
|
||||||
g.drawString(camera.x+" "+((player.mouseX+camera.x+GAME_WIDTH/2)/Tile.length)+" "+player.leftMouseDown,100,200);
|
if(player.holdingSteel){
|
||||||
|
String filePath = "";
|
||||||
|
if(player.canPlaceSteel){
|
||||||
|
filePath = "img/tiles/boxes/greenSteel.png";
|
||||||
|
} else {
|
||||||
|
filePath = "img/tiles/boxes/redSteel.png";
|
||||||
|
}
|
||||||
|
double x = ((player.mouseX+camera.x) / Tile.length)*Tile.length;
|
||||||
|
double y = ((player.mouseY / Tile.length))*Tile.length;
|
||||||
|
g.drawImage(getImage(filePath),(int)x-camera.x+Tile.length/2+1,(int)y,Tile.length,Tile.length,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length)+" "+player.leftMouseDown,100,100);
|
||||||
|
// g.drawString(camera.x+" "+((player.mouseX+camera.x+GAME_WIDTH/2)/Tile.length)+" "+player.leftMouseDown,100,200);
|
||||||
g.drawImage(bomb,20,20,35,35,null);
|
g.drawImage(bomb,20,20,35,35,null);
|
||||||
g.drawString("X"+LevelManager.bombs,60,40);
|
g.drawString("X"+LevelManager.bombs,60,40);
|
||||||
if (isPaused) {
|
if (isPaused) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class Player extends GenericSprite {
|
||||||
public boolean rightMouseDown;
|
public boolean rightMouseDown;
|
||||||
boolean holdingSteel;
|
boolean holdingSteel;
|
||||||
|
|
||||||
|
boolean canPlaceSteel;
|
||||||
|
|
||||||
// sA[0] is -x, -y
|
// sA[0] is -x, -y
|
||||||
// sA[1] is x, -y
|
// sA[1] is x, -y
|
||||||
|
@ -48,6 +49,7 @@ public class Player extends GenericSprite {
|
||||||
isPlayer = true;
|
isPlayer = true;
|
||||||
leftMouseDown = false;
|
leftMouseDown = false;
|
||||||
holdingSteel = false;
|
holdingSteel = false;
|
||||||
|
canPlaceSteel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,17 +225,16 @@ public class Player extends GenericSprite {
|
||||||
if(e.getButton()==MouseEvent.BUTTON3) {
|
if(e.getButton()==MouseEvent.BUTTON3) {
|
||||||
int x = (mouseX + GamePanel.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length;
|
int x = (mouseX + GamePanel.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length;
|
||||||
int y = (mouseY / Tile.length);
|
int y = (mouseY / Tile.length);
|
||||||
|
|
||||||
if (!holdingSteel&&GamePanel.map[x][y] != null) {
|
|
||||||
rightMouseDown = true;
|
rightMouseDown = true;
|
||||||
if (GamePanel.map[x][y].movable) {
|
if (!holdingSteel) {
|
||||||
|
if (GamePanel.map[x][y] != null&&GamePanel.map[x][y].movable) {
|
||||||
holdingSteel = true;
|
holdingSteel = true;
|
||||||
GamePanel.map[x][y] = null;
|
GamePanel.map[x][y] = null;
|
||||||
}
|
}
|
||||||
} else if(GamePanel.map[x][y] == null){
|
} else if(GamePanel.map[x][y] == null){
|
||||||
holdingSteel = false;
|
|
||||||
GamePanel.map[x][y] = new SingleTile(x*Tile.length - (GamePanel.GAME_WIDTH/2), y*Tile.length, GamePanel.getImage("img/tiles/boxes/steel.png"));
|
GamePanel.map[x][y] = new SingleTile(x*Tile.length - (GamePanel.GAME_WIDTH/2), y*Tile.length, GamePanel.getImage("img/tiles/boxes/steel.png"));
|
||||||
GamePanel.map[x][y].movable = true;
|
GamePanel.map[x][y].movable = true;
|
||||||
|
holdingSteel = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,6 +245,12 @@ public class Player extends GenericSprite {
|
||||||
mouseX = e.getX();
|
mouseX = e.getX();
|
||||||
mouseY = e.getY();
|
mouseY = e.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
|
||||||
|
mouseX = e.getX();
|
||||||
|
mouseY = e.getY();
|
||||||
|
}
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
mouseX = e.getX();
|
mouseX = e.getX();
|
||||||
mouseY = e.getY();
|
mouseY = e.getY();
|
||||||
|
@ -266,11 +273,7 @@ public class Player extends GenericSprite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int draw(Graphics g, int frame) {
|
public int draw(Graphics g, int frame) {
|
||||||
//g.drawString(mouseX+" "+mouseY, 300, 300);
|
|
||||||
frame %= spriteArray[0][0].length;
|
frame %= spriteArray[0][0].length;
|
||||||
if(rightMouseDown){
|
|
||||||
g.drawRect(mouseX,mouseY,35,35);
|
|
||||||
}
|
|
||||||
if (!upPressed && !downPressed && !leftPressed && !rightPressed) {
|
if (!upPressed && !downPressed && !leftPressed && !rightPressed) {
|
||||||
g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x-10, y, null);
|
g.drawImage(spriteArray[lastXDirection][lastYDirection][0], x-10, y, null);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue