33import com .almasb .fxgl .core .math .Vec2 ;
44import com .almasb .fxgl .entity .SpawnData ;
55import com .almasb .fxgl .entity .component .Component ;
6+ import com .dinosaur .dinosaurexploder .view .DinosaurGUI ;
67import javafx .geometry .Point2D ;
78import javafx .scene .image .Image ;
89
9- import static com .almasb .fxgl .dsl .FXGLForKtKt .spawn ;
10+ import static com .almasb .fxgl .dsl .FXGLForKtKt .* ;
1011
1112public 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