forked from choupeishuan/assign1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assign1.pde
87 lines (71 loc) · 1.79 KB
/
assign1.pde
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* please implement your assign1 code in this file. */
// positions
int bg1RX;
int bg2RX;
int enemyX;
int enemyY;
int fighterX;
int fighterY;
int hpX;
int hpY;
int hpRedX;
int hpRedY;
int hpRedLength;
int treasureX;
int treasureY;
int backgroundSpeed;
int enemySpeed;
// images
PImage bg1;
PImage bg2;
PImage enemy;
PImage fighter;
PImage hp;
PImage treasure;
void setup () {
size(640,480) ; // must use this size.
// your code
bg1RX = width; // bg1 right side position
bg2RX = width * 2; // bg2 right side position
// load images
bg1 = loadImage("img/bg1.png");
bg2 = loadImage("img/bg2.png");
enemy = loadImage("img/enemy.png");
fighter = loadImage("img/fighter.png");
hp = loadImage("img/hp.png");
treasure = loadImage("img/treasure.png");
// get random start position
// hp image size = 210x30
hpX = floor(random(width-210));
hpY = floor(random(height-30));
hpRedX = hpX+5;
hpRedY = hpY;
hpRedLength = floor(random(195));
// enemy image size = 60x60
enemyX = floor(random(width-60));
enemyY = floor(random(height-60));
// fighter image size = 50x50
fighterX = floor(random(width-50));
fighterY = floor(random(height-50));
// treasure image size = 40x40
treasureX = floor(random(width-40));
treasureY = floor(random(height-40));
// speed
backgroundSpeed = 2;
enemySpeed = 3;
}
void draw() {
// your code
bg1RX = (bg1RX + backgroundSpeed) % (width * 2);
bg2RX = (bg2RX + backgroundSpeed) % (width * 2);
image(bg1, bg1RX-width, 0);
image(bg2, bg2RX-width, 0);
println(bg1RX, bg2RX);
// hpRed shoud draw before hp
fill(#FF0000);
rect(hpRedX, hpRedY, hpRedLength, 30);
image(hp, hpX, hpY);
image(fighter, fighterX, fighterY);
image(treasure, treasureX, treasureY);
image(enemy, (enemyX+=enemySpeed)%width, enemyY);
}