-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloot.cpp
More file actions
72 lines (61 loc) · 2.08 KB
/
loot.cpp
File metadata and controls
72 lines (61 loc) · 2.08 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
70
71
#include <stdio.h>
#include <math.h>
#include "sdl_compat.h"
#include "object.h"
#include "loot.h"
#include "geom.h"
#include "physics_world.h"
Loot::Loot(float x, float y, float width, float height, GameColor color, LootType type)
:Object(x, y, width, height), color(color), type(type){
}
void Loot::initPhysics(PhysicsWorld& world) {
physicsBody = world.createBody(this, PhysicsBodyType::SENSOR, 0.0f, 0.0f, 0.0f);
}
void applyRot(Point *p, float theta){
float x = p->x*cos(theta) - p->y*sin(theta);
float y = p->x*sin(theta) + p->y*cos(theta);
p->x = x;
p->y = y;
}
void Loot::draw(void){
switch(type){
case FUEL:
draw_rounded_rect(
rect.tl.x, rect.tl.y, rect.br.x, rect.br.y,
4, 4, color, 4
);
draw_line(rect.tl.x, rect.tl.y, rect.br.x, rect.br.y, color, 2);
draw_line(rect.br.x, rect.tl.y, rect.tl.x, rect.br.y, color, 2);
draw_line(rect.tl.x, rect.tl.y, rect.tl.x-4, rect.tl.y-4, color, 3);
draw_line(rect.tl.x-4, rect.tl.y-4, rect.tl.x-10, rect.tl.y-4, color, 3);
break;
case BOOST: {
Point p1, p2, p3;
float d = 0.5*width2;
float deg2rad = M_PI/180;
float a = d*cos(54*deg2rad);
float b = d*sin(54*deg2rad);
float c, g, theta = 2*M_PI/5.0;
p1.x = 0;
p1.y = -height2;
p2.x = a;
p2.y = -b;
c = sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y));
g = c + a;
p3.x = g;
p3.y = -g*tan(18*deg2rad);
for (int i=0; i < 5; i++) {
applyRot(&p1, theta);
applyRot(&p2, theta);
applyRot(&p3, theta);
draw_line(pos.x + p1.x, pos.y + p1.y,
pos.x + p2.x, pos.y + p2.y, color, 4);
draw_line(pos.x + p2.x, pos.y + p2.y,
pos.x + p3.x, pos.y + p3.y, color, 4);
}
break;
}
case NUM_LOOT:
break;
}
}