Skip to content

Commit d3e89e4

Browse files
committed
added movement and check for keeping player on map only
1 parent 3a73924 commit d3e89e4

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

Ham Blaster/src/javagame/Menu.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public void update(GameContainer gc, StateBasedGame sbg,int delta) throws SlickE
7272

7373

7474
//check for cursor position if it is inside the circle
75-
if( (xpos>100&&xpos<311) && (ypos>209 && ypos<260) ){
75+
//if( (xpos>100&&xpos<311) && (ypos>209 && ypos<260) ){
7676
// check for cick 0 is left click and 1 is right click
77-
if(input.isMouseButtonDown(0)){
78-
sbg.enterState(1);
79-
}
80-
}
77+
//if(input.isMouseButtonDown(0)){
78+
//sbg.enterState(1);
79+
//}
80+
//}
8181

8282

8383
if( (xpos>100&&xpos<311) && (ypos>109 && ypos<160) ){

Ham Blaster/src/javagame/Play.java

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Play extends BasicGameState{
1818

1919
// shift map not the player
2020
float shiftX = buckyPositionX+320;
21-
float shiftY = buckyPositionY+320;
21+
float shiftY = buckyPositionY+160;
2222

2323

2424
//constructor
@@ -29,10 +29,10 @@ public Play(int state){
2929
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
3030
worldMap = new Image("res/world.png");
3131
//image array for animation
32-
Image[] walkUp = {new Image("res/buckysBack.png"),new Image("res/bucksBack.png") };
33-
Image[] walkDown = {new Image("res/buckysFront.png"),new Image("res/bucksFront.png") };
34-
Image[] walkLeft = {new Image("res/buckysLeft.png"),new Image("res/bucksLeft.png") };
35-
Image[] walkRight = {new Image("res/buckysRight.png"),new Image("res/bucksRight.png") };
32+
Image[] walkUp = {new Image("res/buckysBack.png"),new Image("res/buckysBack.png") };
33+
Image[] walkDown = {new Image("res/buckysFront.png"),new Image("res/buckysFront.png") };
34+
Image[] walkLeft = {new Image("res/buckysLeft.png"),new Image("res/buckysLeft.png") };
35+
Image[] walkRight = {new Image("res/buckysRight.png"),new Image("res/buckysRight.png") };
3636

3737
//Animation what images we want to use how long each image will last autoupdating
3838
movingUp = new Animation(walkUp,duration,false);
@@ -62,6 +62,44 @@ public void render(GameContainer gc, StateBasedGame sbg,Graphics g) throws Slick
6262

6363
//updates the images on screen
6464
public void update(GameContainer gc, StateBasedGame sbg,int delta) throws SlickException{
65+
66+
Input input = gc.getInput();
67+
//UP
68+
if (input.isKeyDown(Input.KEY_UP)){
69+
bucky=movingUp;
70+
buckyPositionY += delta * .1f;
71+
if(buckyPositionY>162){
72+
buckyPositionY -= delta * .1f;
73+
}
74+
75+
}
76+
77+
//Down
78+
if (input.isKeyDown(Input.KEY_DOWN)){
79+
bucky=movingDown;
80+
buckyPositionY -= delta * .1f;
81+
if(buckyPositionY<-600){
82+
buckyPositionY += delta * .1f;
83+
}
84+
}
85+
86+
//Left
87+
if (input.isKeyDown(Input.KEY_LEFT)){
88+
bucky=movingLeft;
89+
buckyPositionX += delta * .1f;
90+
if(buckyPositionX>324){
91+
buckyPositionX -= delta * .1f;
92+
}
93+
}
94+
95+
//Right
96+
if (input.isKeyDown(Input.KEY_RIGHT)){
97+
bucky=movingRight;
98+
buckyPositionX -= delta * .1f;
99+
if(buckyPositionX<-840){
100+
buckyPositionX += delta * .1f;
101+
}
102+
}
65103

66104
}
67105

0 commit comments

Comments
 (0)