-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
51 lines (41 loc) · 944 Bytes
/
Player.java
File metadata and controls
51 lines (41 loc) · 944 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
39
40
41
42
43
44
45
46
47
48
49
50
51
package pong;
import static pong.Game.SCALE;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Scrollbar;
public class Player {
public boolean up = false,down = false;
public int x,y,speed = 3;
public static final int WIDTH_P = 10;
public static final int HEIGHT_P = 40;
public Player(int x, int y){
//this.x = (((WIDTH/2)-((10/SCALE)/2))/SCALE)-10; --meio
//this.y = (HEIGHT/2)-((40/SCALE)/2); --meio
this.x = x;
this.y = y;
}
public void tick() {
if(up){
if(speed > 0){
y = y-speed;
}else{
y--;
}
}else if(down){
if(speed > 0){
y = y+speed;
}else{
y++;
}
}
if(y+(HEIGHT_P/SCALE) > Game.HEIGHT){
y = Game.HEIGHT - (HEIGHT_P/SCALE);
}else if(y <= 0){
y = 0;
}
}
public void render(Graphics g) {
g.setColor(Color.BLUE);
g.fillRect(x,y, WIDTH_P/SCALE, HEIGHT_P/SCALE);
}
}