-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTile.pde
119 lines (103 loc) · 2.42 KB
/
Tile.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class Collider {
PShape obj;
int type;
float scale;
PShape borders;
Collider(int type, float w, float h) {
this.type = type;
switch (type) {
case 0: //Tree, bitch
scale = 16;
break;
case 1: //Those buildy things
scale = 50;
break;
case 2: //Ding Dong the clunk has sung
scale = 100;
break;
default: //If u were dumm and didn't pass the write thing
scale = 20;
break;
}
borders = createShape(
RECT,
-w/4,
-h/4,
w/2,
h/2
);
borders.setFill(false);
borders.setStroke(false);
}
void display() {
//draw the obstacle itself (model, obj)
pushMatrix();
scale(scale);
rotateX(HALF_PI);
shape(obst[type], 0, 0);
popMatrix();
}
PVector[] getPoints() {
shape(borders);
int a = borders.getVertexCount();
PVector[] pts = new PVector[a];
for (int i = 0; i < a; i++) {
pts[i] = new PVector(borders.getVertex(i).x, borders.getVertex(i).y);
}
return pts;
}
}
int BLANK = 0;
int ROAD = 1;
float noiseScale = 0.06;
class Tile {
PVector pos, displaypos;
float w, h;
int type = 0;
Collider obstacle;
//type of grass or road (replaces grassType)
int tileType;
//probably temporary
boolean hastree = false;
Tile(float x, float y, float z, float w, float h) {
pos = new PVector(x, y, z);
displaypos = new PVector(x, y, z);
this.w = w;
this.h = h;
//generate grass patches using perlin noise
float noiseVal = noise(x*noiseScale, y*noiseScale);
tileType = int(map(noiseVal, 0, 1, 0, 3)); //grass based on noise
}
void addCollider(int type)
{
obstacle = new Collider(type, w, h);
}
void update(PVector tracked) {
/* tracked is the position (normally of the player) that
* this object will move on-screen relative to
*/
displaypos.x = -tracked.x + pos.x;
displaypos.y = -tracked.y + pos.y;
}
void display() {
pushMatrix();
{
translate(this.displaypos.x, this.displaypos.y, this.displaypos.z);
rectMode(CENTER);
imageMode(CENTER);
fill(200);
stroke(10);
strokeWeight(1);
//Draw ground sprite
if (type == ROAD) {
image(roads[tileType], 0, 0, this.w, this.h);
} else {
image(grass[tileType], 0, 0, this.w, this.h);
}
if (this.obstacle != null) {
obstacle.display();
}
popMatrix();
}
}
}