-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRectangleInverted.java
More file actions
70 lines (53 loc) · 1 KB
/
GRectangleInverted.java
File metadata and controls
70 lines (53 loc) · 1 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.awt.Rectangle;
import java.awt.*;
import java.awt.event.*;
public class GRectangleInverted extends Rectangle {
// public int x, y, WIDTH, HEIGHT;
int x, y, w, h;
int dx, dy;
boolean goUp;
boolean goDown;
int JUMP_HEIGHT = 90;
int GROUND_LEVEL;
public GRectangleInverted(int x, int y, int w, int h) {
super(x, y, w, h);
this.x = x;
this.y = y;
this.w = w;
this.h = h;
GROUND_LEVEL = y;
dx = 2;
dy = 3;
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
jump(key);
}
public void keyReleased(KeyEvent e) {
}
public void draw(Graphics g) {
if (goDown) {
y += dy;
}
if (goUp) {
y -= dy;
}
//g.clearRect(0, 0, 640, 480);
g.setColor(Color.BLUE);
g.fillRect(x, y, w, h);
if (y - GROUND_LEVEL >= JUMP_HEIGHT) {
goDown = false;
goUp = true;
}
if ( y <= GROUND_LEVEL) {
goUp = false;
}
}
void jump(int key) {
if (!goUp && !goDown) {
if (key == KeyEvent.VK_DOWN) {
goDown = true;
}
}
}
}