-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSScene.pde
82 lines (60 loc) · 2.7 KB
/
SSScene.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
class SSScene extends PhysicsScene {
int rockScale = 4;
Player player;
int FOREGROUND_LAYER = 1, PLAYER_LAYER = 0, BACKGROUND_LAYER = -1;
Camera camera;
RockGenerator rg;
public SSScene() {
rg = new RockGenerator(0, 0, width/rockScale, height/rockScale, 5, rockScale);
addAABB(new AABB(1000, 800, 1200, 150, this));
player = new Player(new PVector(900, -200), this);
camera = new Camera(player);
layers.add(PLAYER_LAYER, player);
input.register(new SingleKey('W', KeyMethod.HELD), UP);
input.register(new SingleKey(UP, KeyMethod.HELD), UP);
input.register(new SingleKey('A', KeyMethod.HELD), LEFT);
input.register(new SingleKey(LEFT, KeyMethod.HELD), LEFT);
input.register(new SingleKey('S', KeyMethod.HELD), DOWN);
input.register(new SingleKey(DOWN, KeyMethod.HELD), DOWN);
input.register(new SingleKey('D', KeyMethod.HELD), RIGHT);
input.register(new SingleKey(RIGHT, KeyMethod.HELD), RIGHT);
input.register(new SingleKey(SHIFT, KeyMethod.HELD), CROUCH);
PROJECTILECREATE = input.register(new SingleKey(LMB, KeyMethod.PRESSED));
PROJECTILEDESTROY = input.register(new SingleKey(LMB, KeyMethod.RELEASED));
RESET = input.register(new SingleKey('R', KeyMethod.PRESSED));
SWITCHSCENE = input.register(new SingleKey('Y', KeyMethod.PRESSED));
input.register(new SingleKey(SHIFT, KeyMethod.HELD), CROUCH);
}
public void addAABB(AABB r) {
layers.add(0, r);
AABB scaled = new AABB(r.x / rockScale, r.y / rockScale, r.w / rockScale, r.h / rockScale, null);
rg.updateTexture(scaled);
r.sprite = generateResized(scaled.sprite, rockScale);
//rg.images.add(r.sprite);
}
public void update(float s) {
super.update(s);
if (input.check(RESET)) sm.changeScene(new SSScene());
if (input.check(SWITCHSCENE)) {
println("SWITCH");
sm.changeScene(new TestScene());
}
camera.checkPos(s);
}
@Override
public void draw(float s, PGraphics pg) {
pg.translate(-camera.currentPoint.x, -camera.currentPoint.y);
super.draw(s, pg);
//for (PImage img : rg.images) {
// pg.image(img, 0, 0);
//}
//if (rg.resized == null) {
// rg.generateResized();
//}
//player.draw(s, pg);
pg.translate(camera.currentPoint.x, camera.currentPoint.y);
//PImage newImage = rg.resized.get((int) camera.currentPoint.x, (int) camera.currentPoint.y, width, height);
//pg.image(newImage, 0, 0, width, height);
//pg.image(rocks, 0, 0, width, height, (int) camera.currentPoint.x, (int) camera.currentPoint.y, width, height);
}
}