-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathYASC.java
82 lines (66 loc) · 1.94 KB
/
YASC.java
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
package ie.dit;
import java.util.ArrayList;
import processing.core.PApplet;
public class YASC extends PApplet
{
boolean[] keys = new boolean[1024];
public ArrayList<GameObject> gameObjects = new ArrayList<GameObject>();
AIShip aiShip;
Ship ship;
public void keyPressed()
{
keys[keyCode] = true;
}
public void keyReleased()
{
keys[keyCode] = false;
}
public boolean checkKey(int c)
{
return keys[c] || keys [Character.toUpperCase(c)];
}
public void settings()
{
size(500, 500);
}
public void setup()
{
ship = new Ship(this, width / 2, height / 2, 5, 50);
gameObjects.add(ship);
aiShip = new AIShip(this, 100, 100, 5, 50);
gameObjects.add(aiShip);
gameObjects.add(new AmmoPowerup(this));
gameObjects.add(new AmmoPowerup(this));
String s = "Hello";
System.out.println(s.substring(2));
System.out.println(s.substring(2, 4));
System.out.println(s.indexOf("ll"));
System.out.println(s.startsWith("Hel"));
System.out.println(s.endsWith("x"));
}
public float timeDelta;
private float last;
public void draw()
{
float now = millis();
timeDelta = (now - last) / 1000.0f;
last = now;
background(255);
fill(0);
text("GameObjects: " + gameObjects.size(), 50, 100);
for(int i= gameObjects.size() - 1; i >= 0; i--)
{
GameObject b = gameObjects.get(i);
b.render();
b.update();
if (b instanceof Powerup)
{
if (dist(b.pos.x, b.pos.y, ship.pos.x, ship.pos.y) < 50)
{
((Powerup)b).applyTo(ship);
gameObjects.remove(b);
}
}
}
}
}