-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
99 lines (84 loc) · 2.15 KB
/
main.c
File metadata and controls
99 lines (84 loc) · 2.15 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
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
#define FORTUNA true
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#if !FORTUNA
# include "src/graphics.h"
#else
# include "src/graphicsF.h"
#endif
#include "src/physics.h"
#include "rios.h"
#include "ruota.h"
const int MIN_X = 0;
const int MIN_Y = 0;
const int MAX_X = 318;
const int MAX_Y = 238;
int buttonForce = 100;
void check_switches();
void init(void) {
initPhysics(MIN_X, MIN_Y, MAX_X, MAX_Y);
initGraphics();
srand(time(NULL));
os_init_scheduler();
os_init_ruota();
}
int main(void) {
init();
os_led_brightness(0);
os_add_task(check_switches, 50, 1);
// main physics loop
float dt = 0;
Particle oldParticles[NUM_PARTICLES];
while (true) {
// store old particles so we can remove them later
memcpy(oldParticles, particles, sizeof(oldParticles));
waitForNextFrame();
// apply collisions
for (int i=0; i<1; i++) {
applyCollisions();
for (int p=0; p<NUM_PARTICLES; ++p) {
Particle *particle = &particles[p];
applyContainerForce(particle);
}
}
// apply forces and draw
for (int i=0; i<NUM_PARTICLES; ++i) {
dt = getDT();
Particle *particle = &particles[i];
applyGravity(particle, dt);
particle->position.x += particle->velocity.x * dt;
particle->position.y += particle->velocity.y * dt;
}
redrawParticles(oldParticles, particles, NUM_PARTICLES);
drawForce(buttonForce);
}
return 0;
}
void check_switches() {
if (get_switch_press(_BV(SWN))) {
for (int i=0; i<NUM_PARTICLES; ++i) {
particles[i].velocity.y -= buttonForce;
}
}
if (get_switch_press(_BV(SWS))) {
for (int i=0; i<NUM_PARTICLES; ++i) {
particles[i].velocity.y += buttonForce;
}
}
if (get_switch_press(_BV(SWE))) {
for (int i=0; i<NUM_PARTICLES; ++i) {
particles[i].velocity.x += buttonForce;
}
}
if (get_switch_press(_BV(SWW))) {
for (int i=0; i<NUM_PARTICLES; ++i) {
particles[i].velocity.x -= buttonForce;
}
}
buttonForce += os_enc_delta() * 5;
}