summaryrefslogtreecommitdiffstats
path: root/balls.h
blob: 7b68ea157ef122806c8a98576c3a24414d9feefe (plain) (blame)
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
#include <u.h>
#include <libc.h>
#include <stdio.h>
#include <draw.h>
#include <cursor.h>

typedef struct {
	double x, y;
} Vec;

typedef struct {
	Point p1, p2;
} Line;

typedef struct {
	Point p; /* position [pixels] */
	Vec v; /* velocity [m/s] */
	uint r; /* radius [pixels] */
	double m; /* mass [kg] */
} Ball;

Vec vsub(Vec v1, Vec v2);
Vec vmuls(Vec v, double a);
Vec vdivs(Vec v, double a);
double vdot(Vec v1, Vec v2);
double vlen(Vec v);
Vec unitnorm(Vec v);
Point ptaddv(Point p, Vec v);
Vec V(double x, double y);
Vec Vpt(Point p, Point q);

void drawbg(Image *walls, Image *bg);
Image *alloccircle(int fg, int bg, uint radius);
void drawcircle(Image *m, Point pos);

int iscollision(Point p1, uint r1, Point p2, uint r2);
void collideball(Ball *b1, const Ball *b2);
void collidewall(Ball *b, Rectangle wall);