Moving Blocks ProtoType
parent
17d49895f7
commit
1c3ae30225
Binary file not shown.
After Width: | Height: | Size: 618 B |
|
@ -13,6 +13,6 @@ sssssssssssssssssd asd a
|
||||||
sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv
|
sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv
|
||||||
sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv
|
sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv
|
||||||
sssssssssssssssssdlllllad qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv
|
sssssssssssssssssdlllllad qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv
|
||||||
sssssssssssssssssdlllllad qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv
|
sssssssssssssssssdlllllad bbb qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv
|
||||||
sssssssssssssssssdllllladbb qwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv +
|
sssssssssssssssssdllllladbb ooqwwrssssllssssstwe !!! qwe vvvvvvvvvvvvvvvvvvvvv +
|
||||||
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3
|
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3
|
|
@ -121,8 +121,14 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
||||||
//add the MousePressed method from the MouseAdapter - by doing this we can listen for mouse input. We do this differently from the KeyListener because MouseAdapter has SEVEN mandatory methods - we only need one of them, and we don't want to make 6 empty methods
|
//add the MousePressed method from the MouseAdapter - by doing this we can listen for mouse input. We do this differently from the KeyListener because MouseAdapter has SEVEN mandatory methods - we only need one of them, and we don't want to make 6 empty methods
|
||||||
addMouseListener(new MouseAdapter() {
|
addMouseListener(new MouseAdapter() {
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
player.mousePressed(e);
|
try {
|
||||||
}
|
player.mousePressed(e);
|
||||||
|
} catch (SpriteException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
player.mouseReleased(e);
|
player.mouseReleased(e);
|
||||||
}
|
}
|
||||||
|
@ -203,8 +209,8 @@ 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+" "+((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) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class GenericSprite extends Rectangle{
|
||||||
|
|
||||||
//called from GamePanel whenever a mouse click is detected
|
//called from GamePanel whenever a mouse click is detected
|
||||||
//changes the current location of the ball to be wherever the mouse is located on the screen
|
//changes the current location of the ball to be wherever the mouse is located on the screen
|
||||||
public void mousePressed(MouseEvent e){
|
public void mousePressed(MouseEvent e) throws SpriteException, IOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
import javax.sound.sampled.LineUnavailableException;
|
import javax.sound.sampled.LineUnavailableException;
|
||||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class MapReader {
|
public class MapReader {
|
||||||
private static int x = 0;
|
private static int x = 0;
|
||||||
private static int y = 0;
|
private static int y = 0;
|
||||||
private static int TileX = 0;
|
public static int TileX = 0;
|
||||||
private static int TileY = 0;
|
public static int TileY = 0;
|
||||||
//Input game map
|
//Input game map
|
||||||
/*
|
/*
|
||||||
1: Normal Grass
|
1: Normal Grass
|
||||||
|
@ -23,6 +21,7 @@ public class MapReader {
|
||||||
v= background
|
v= background
|
||||||
Grass:
|
Grass:
|
||||||
*/
|
*/
|
||||||
|
//o = steel
|
||||||
|
|
||||||
public static void inputMap(String filePath) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
|
public static void inputMap(String filePath) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
@ -95,6 +94,9 @@ public class MapReader {
|
||||||
if(y>0&&GamePanel.map[x][y-1]==null) {
|
if(y>0&&GamePanel.map[x][y-1]==null) {
|
||||||
GamePanel.particleTiles.add(GamePanel.map[x][y]);
|
GamePanel.particleTiles.add(GamePanel.map[x][y]);
|
||||||
}
|
}
|
||||||
|
} else if(file.charAt(i)=='o'){
|
||||||
|
newTile("img/tiles/boxes/steel.png");
|
||||||
|
GamePanel.map[x][y].movable = true;
|
||||||
}
|
}
|
||||||
x+=1;
|
x+=1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,8 @@ public class NonPlayer extends GenericSprite {
|
||||||
}
|
}
|
||||||
public void move(){
|
public void move(){
|
||||||
if (isDead) {
|
if (isDead) {
|
||||||
// preemptively end move function if enemy is dead
|
xVelocity = 0;
|
||||||
return;
|
// return;
|
||||||
}
|
}
|
||||||
if(!canUpdate(xVelocity, 0)){
|
if(!canUpdate(xVelocity, 0)){
|
||||||
xVelocity*=-1;
|
xVelocity*=-1;
|
||||||
|
|
|
@ -27,6 +27,9 @@ public class Player extends GenericSprite {
|
||||||
|
|
||||||
public boolean leftMouseDown;
|
public boolean leftMouseDown;
|
||||||
|
|
||||||
|
public boolean rightMouseDown;
|
||||||
|
boolean holdingSteel;
|
||||||
|
|
||||||
|
|
||||||
// sA[0] is -x, -y
|
// sA[0] is -x, -y
|
||||||
// sA[1] is x, -y
|
// sA[1] is x, -y
|
||||||
|
@ -44,6 +47,7 @@ public class Player extends GenericSprite {
|
||||||
alive = true;
|
alive = true;
|
||||||
isPlayer = true;
|
isPlayer = true;
|
||||||
leftMouseDown = false;
|
leftMouseDown = false;
|
||||||
|
holdingSteel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,14 +214,31 @@ public class Player extends GenericSprite {
|
||||||
y = LevelManager.ySpawn;
|
y = LevelManager.ySpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) throws SpriteException, IOException {
|
||||||
mouseX = e.getX();
|
mouseX = e.getX();
|
||||||
mouseY = e.getY();
|
mouseY = e.getY();
|
||||||
if(e.getButton()==MouseEvent.BUTTON1) {
|
if(e.getButton()==MouseEvent.BUTTON1) {
|
||||||
leftMouseDown = true;
|
leftMouseDown = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(e.getButton()==MouseEvent.BUTTON3) {
|
||||||
|
int x = (mouseX + GamePanel.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length;
|
||||||
|
int y = (mouseY / Tile.length);
|
||||||
|
if (GamePanel.map[x][y] != null) {
|
||||||
|
if (!holdingSteel) {
|
||||||
|
rightMouseDown = true;
|
||||||
|
if (GamePanel.map[x][y].movable) {
|
||||||
|
holdingSteel = true;
|
||||||
|
GamePanel.map[x][y] = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
holdingSteel = false;
|
||||||
|
MapReader.TileX = x;
|
||||||
|
MapReader.TileY = y;
|
||||||
|
MapReader.newTile("img/tiles/boxes/steel.png");
|
||||||
|
GamePanel.map[x][y].movable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
@ -236,6 +257,9 @@ public class Player extends GenericSprite {
|
||||||
(mouseX - GamePanel.player.x) / 20, (mouseY - GamePanel.player.y) / 10, GamePanel.bomb, GamePanel.explosionArray));
|
(mouseX - GamePanel.player.x) / 20, (mouseY - GamePanel.player.y) / 10, GamePanel.bomb, GamePanel.explosionArray));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(e.getButton()==MouseEvent.BUTTON3){
|
||||||
|
rightMouseDown = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void addParticle(int x) throws IOException {
|
public void addParticle(int x) throws IOException {
|
||||||
if(GlobalState.randInt(1,3)==3) {
|
if(GlobalState.randInt(1,3)==3) {
|
||||||
|
@ -246,6 +270,9 @@ 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);
|
//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;
|
||||||
|
|
|
@ -106,6 +106,11 @@ public class StickyBomb extends GenericSprite{
|
||||||
explode();
|
explode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(canUpdate(1,1)&&canUpdate(-1,1)&&canUpdate(0,-1)&&isMove == false&&fuse>0){
|
||||||
|
isMove = true;
|
||||||
|
xVelocity = 0;
|
||||||
|
yVelocity = 0;
|
||||||
|
}
|
||||||
if(isMove) {
|
if(isMove) {
|
||||||
if(canUpdate(xVelocity, 0)&&canUpdate(0, yVelocity)&&!canUpdate(xVelocity, yVelocity)){
|
if(canUpdate(xVelocity, 0)&&canUpdate(0, yVelocity)&&!canUpdate(xVelocity, yVelocity)){
|
||||||
checked = true;
|
checked = true;
|
||||||
|
|
|
@ -13,6 +13,8 @@ public class Tile {
|
||||||
public boolean kills;
|
public boolean kills;
|
||||||
|
|
||||||
public boolean breakable;
|
public boolean breakable;
|
||||||
|
|
||||||
|
public boolean movable;
|
||||||
public int realX;
|
public int realX;
|
||||||
public static final int length = 35;
|
public static final int length = 35;
|
||||||
public Tile(int x, int y){
|
public Tile(int x, int y){
|
||||||
|
@ -23,6 +25,7 @@ public class Tile {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
nonBombCollide = false;
|
nonBombCollide = false;
|
||||||
breakable = false;
|
breakable = false;
|
||||||
|
movable = false;
|
||||||
}
|
}
|
||||||
public void update(){
|
public void update(){
|
||||||
realX = x-GamePanel.camera.x;
|
realX = x-GamePanel.camera.x;
|
||||||
|
|
Loading…
Reference in New Issue