Skip to content

Commit 2eab35f

Browse files
committed
Added boundaries to edge of screen
1 parent 8f11c52 commit 2eab35f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/main/java/com/dinosaur/dinosaurexploder/model/PlayerComponent.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,41 @@
33
import com.almasb.fxgl.core.math.Vec2;
44
import com.almasb.fxgl.entity.SpawnData;
55
import com.almasb.fxgl.entity.component.Component;
6+
import com.dinosaur.dinosaurexploder.view.DinosaurGUI;
67
import javafx.geometry.Point2D;
78
import javafx.scene.image.Image;
89

9-
import static com.almasb.fxgl.dsl.FXGLForKtKt.spawn;
10+
import static com.almasb.fxgl.dsl.FXGLForKtKt.*;
1011

1112
public class PlayerComponent extends Component implements Player{
1213
int movementSpeed = 8;
1314
//entity is not initialized anywhere because it is linked in the factory
1415
public void moveUp(){
16+
if(entity.getY() < 0) {
17+
System.out.println("Out of bounds");
18+
return;
19+
}
1520
entity.translateY(-movementSpeed);
1621
}
1722
public void moveDown(){
23+
if(!(entity.getY() < DinosaurGUI.HEIGHT - entity.getHeight())) {
24+
System.out.println("Out of bounds");
25+
return;
26+
}
1827
entity.translateY(movementSpeed);
1928
}
2029
public void moveRight(){
30+
if(!(entity.getX() < DinosaurGUI.WIDTH - entity.getWidth())) {
31+
System.out.println("Out of bounds");
32+
return;
33+
}
2134
entity.translateX(movementSpeed);
2235
}
2336
public void moveLeft(){
37+
if(entity.getX() < 0) {
38+
System.out.println("Out of bounds");
39+
return;
40+
}
2441
entity.translateX(-movementSpeed);
2542
}
2643

@@ -31,7 +48,7 @@ public void shoot(){
3148
Image spcshpImg = new Image("assets/textures/spaceship.png");
3249
spawn("basicProjectile",
3350
new SpawnData(center.getX() - (projImg.getWidth()/2) +3, center.getY() - spcshpImg.getHeight()/2)
34-
.put("direction", direction.toPoint2D() )
51+
.put("direction", direction.toPoint2D() )
3552
);
3653
}
3754
}

0 commit comments

Comments
 (0)