-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbody.cpp
More file actions
57 lines (49 loc) · 1.74 KB
/
body.cpp
File metadata and controls
57 lines (49 loc) · 1.74 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
#include <stdio.h>
#include "sdl_compat.h"
#include "object.h"
#include "body.h"
#include "physics_world.h"
Body::Body(float x, float y, float width, float height, GameColor color, bool filled)
:Object(x, y, width, height), color(color), filled(filled){
round = rand() % 20 + 1;
density = (100 + rand() % 100) / 100.0;
thick = rand() % 8 + 2;
gravityStrength = 0.0f;
isGravityWell = false;
}
void Body::initPhysics(PhysicsWorld& world) {
physicsBody = world.createBody(this, PhysicsBodyType::STATIC, 0.0f, 0.3f, 0.1f);
}
void Body::draw(void){
if (isGravityWell) {
// Draw gravity well with a purple/blue swirl effect
float cx = pos.x;
float cy = pos.y;
float maxRadius = (width2 + height2) / 2;
// Draw multiple rings with decreasing opacity for "swirl" effect
for (int i = 5; i >= 1; i--) {
float radius = maxRadius * (i / 5.0f);
// Purple to blue gradient
float t = i / 5.0f;
GameColor ringColor = map_rgb(
(int)(100 + 80 * t), // R: purple component
(int)(20 + 30 * t), // G: dark
(int)(180 + 75 * t) // B: blue/purple
);
draw_ellipse(cx, cy, radius, radius, ringColor, 2.0f + i);
}
// Draw center core
GameColor coreColor = map_rgb(50, 0, 100);
draw_filled_ellipse(cx, cy, maxRadius * 0.2f, maxRadius * 0.2f, coreColor);
} else if (!filled){
draw_rounded_rect(
rect.tl.x, rect.tl.y, rect.br.x, rect.br.y,
round, round, color, thick
);
} else {
draw_filled_rounded_rect(
rect.tl.x, rect.tl.y, rect.br.x, rect.br.y,
round, round, color
);
}
}