-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerCar.java
More file actions
38 lines (29 loc) · 1018 Bytes
/
PlayerCar.java
File metadata and controls
38 lines (29 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.javarush.games.racer;
import com.javarush.games.racer.road.RoadManager;
public class PlayerCar extends GameObject {
private static int playerCarHeight = ShapeMatrix.PLAYER.length;
public int speed = 1;
private Direction direction;
public PlayerCar() {
super(RacerGame.WIDTH / 2 + 2, RacerGame.HEIGHT - playerCarHeight - 1, ShapeMatrix.PLAYER);
}
public void setDirection(Direction direction) {
this.direction = direction;
}
public Direction getDirection() {
return this.direction;
}
public void move() {
if (direction == Direction.LEFT)
x -= 1;
else if (direction == Direction.RIGHT)
x += 1;
if (x < RoadManager.LEFT_BORDER)
x = RoadManager.LEFT_BORDER;
if (x > RoadManager.RIGHT_BORDER - width)
x = RoadManager.RIGHT_BORDER - width;
}
public void stop() {
matrix = ShapeMatrix.PLAYER_DEAD;
}
}