Skip to content

Commit f3bf8ba

Browse files
committed
feat: adicionado limite para o teto e chao do jogo
1 parent bfe0d33 commit f3bf8ba

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

src/main/java/com/gustavolr/game_entities/Ball.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,25 @@ public void invertDX() {
2424
dx *= -1;
2525
}
2626

27+
public void increaseSpeed() {
28+
this.speed += 1;
29+
}
30+
31+
public int getSpeed() {
32+
return speed;
33+
}
34+
35+
public void setSpeed(int speed) {
36+
this.speed = speed;
37+
}
38+
2739
@Override
2840
public void update() {
2941

3042
position.x += dx * speed;
3143
position.y += dy * speed;
3244

33-
if(position.y < 0 || position.y > GameWindow.getWindowHeight())
45+
if(position.y < 0 || position.y > GameWindow.getWindowHeight() - this.height)
3446
dy *= -1;
3547
}
3648

src/main/java/com/gustavolr/game_entities/Player.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.awt.Color;
66

77
import com.gustavolr.engine.input.GameInput;
8+
import com.gustavolr.engine.window.GameWindow;
89
import com.gustavolr.engine.entity.Entity;
910
import com.gustavolr.engine.entity.Vector;
1011

@@ -22,10 +23,10 @@ public void update() {
2223

2324
Vector direction = new Vector();
2425

25-
if (GameInput.isKeyPressed(KeyEvent.VK_UP)) {
26+
if (GameInput.isKeyPressed(KeyEvent.VK_UP) && position.y > 0) {
2627
direction.y -= speed;
2728
}
28-
else if (GameInput.isKeyPressed(KeyEvent.VK_DOWN)) {
29+
else if (GameInput.isKeyPressed(KeyEvent.VK_DOWN) && position.y < GameWindow.getWindowHeight() - this.height) {
2930
direction.y += speed;
3031
}
3132

src/main/java/com/gustavolr/game_scenes/MainScene.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import com.gustavolr.engine.window.GameWindow;
1313
import com.gustavolr.game_entities.*;
1414

15+
import static com.gustavolr.game_scenes.MainSceneConstants.ENEMY_START_POSITION;
16+
import static com.gustavolr.game_scenes.MainSceneConstants.PLAYER_START_POSITION;
17+
import static com.gustavolr.game_scenes.MainSceneConstants.BALL_START_POSITION;
18+
1519
public final class MainScene implements Scene {
1620

1721
private Player p;
@@ -27,9 +31,9 @@ public final class MainScene implements Scene {
2731
private final List<Entity> entities;
2832

2933
public MainScene() {
30-
p = new Player(MainSceneConstants.PLAYER_START_POSITION.clone(), 10, 50);
31-
e = new Enemy(MainSceneConstants.ENEMY_START_POSITION.clone(), 10, 50);
32-
b = new Ball(MainSceneConstants.BALL_START_POSITION.clone(),7,7);
34+
p = new Player(PLAYER_START_POSITION.clone(), 5, 25);
35+
e = new Enemy(ENEMY_START_POSITION.clone(), 5, 25);
36+
b = new Ball(BALL_START_POSITION.clone(),7,7);
3337

3438
this.enemyScore = 0;
3539
int enemyScorePositionX = (int)(GameWindow.getWindowWidth() - (GameWindow.getWindowWidth()*0.15));
@@ -94,7 +98,8 @@ public boolean enemyScored(int ball_x) {
9498
}
9599

96100
public void updateBallPosition() {
97-
b.setPosition(MainSceneConstants.BALL_START_POSITION.clone());
101+
b.setPosition(BALL_START_POSITION.clone());
102+
b.setSpeed(1);
98103
b.invertDX();
99104
}
100105

src/main/java/com/gustavolr/game_scenes/MainSceneConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public final class MainSceneConstants {
77

8-
public static final Vector PLAYER_START_POSITION = new Vector(0,GameWindow.getWindowHeight()/2);
8+
public static final Vector PLAYER_START_POSITION = new Vector(5,GameWindow.getWindowHeight()/2);
99
public static final Vector ENEMY_START_POSITION = new Vector(GameWindow.getWindowWidth()-10,0);
1010
public static final Vector BALL_START_POSITION = new Vector(GameWindow.getWindowWidth()/2-3,GameWindow.getWindowHeight()/2-3);
1111
}

0 commit comments

Comments
 (0)