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
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "scene.h"
#include "sdl_wrapper.h"
#include "state.h"
const double WEDGE_ANGLE = M_PI / 3; // angle of pacman's mouth
const double INCREMENT_ANGLE = 0.1; // angle between points on pacman shape
const double PACMAN_RADIUS = 60;
const double BALL_RADIUS = 10; // radius of balls (pacman's food)
const size_t CIRC_NPOINTS = 20; // points to draw circle
struct state {
scene_t *scene;
// TODO: Add any other fields in state you need for your demo
};
/** Make a circle-shaped body object.
*
* @param center a vector representing the center of the body.
* @param radius the radius of the circle
* @param mass the mass of the body
* @param color the color of the circle
* @return pointer to the circle-shaped body
*/
body_t *make_circle(vector_t center, double radius, double mass,
color_t color) {
list_t *c = list_init(CIRC_NPOINTS, free);
for (size_t i = 0; i < CIRC_NPOINTS; i++) {
double angle = 2 * M_PI * i / CIRC_NPOINTS;
vector_t *v = malloc(sizeof(*v));
assert(v);
vector_t unit = {cos(angle), sin(angle)};
*v = vec_add(vec_multiply(radius, unit), center);
list_add(c, v);
}
return body_init(c, mass, color);
}
/** Return a list of points representing the pacman shape.
*
* @param center a vector representing the center of the pacman
* @return list of vectors representing points of pacman object.
*/
list_t *make_pacman(vector_t center) {
list_t *points = list_init(1, free);
vector_t *vec = malloc(sizeof(vector_t));
assert(vec);
for (double i = (WEDGE_ANGLE / 2); i <= (2 * M_PI) - (WEDGE_ANGLE / 2);
i += INCREMENT_ANGLE) {
vector_t *new_vec = malloc(sizeof(vector_t));
assert(new_vec);
vector_t angle = {cos(i), sin(i)};
*new_vec = vec_add(vec_multiply(PACMAN_RADIUS, angle), center);
list_add(points, new_vec);
}
vector_t *new_vec = malloc(sizeof(vector_t));
assert(new_vec);
*new_vec = center;
list_add(points, new_vec);
return points;
}
state_t *emscripten_init() {
// TODO: Initialize the state
}
void emscripten_main(state_t *state) {
// TODO: Implement the main loop
}
void emscripten_free(state_t *state) {
// TODO: Free the state
}