summaryrefslogtreecommitdiffstats
path: root/balls.h
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-09-19 17:54:19 -0400
committerSam Anthony <sam@samanthony.xyz>2024-09-19 17:54:19 -0400
commit9da5009cdcabdc162d84e43853439cee78467f23 (patch)
tree7178ed979df4486499c609b90e4f3d9af61104f6 /balls.h
parentb35fe74ccc8711e3a81aa7078fe74ebc14217513 (diff)
downloadballs-9da5009cdcabdc162d84e43853439cee78467f23.zip
better collisions
Diffstat (limited to 'balls.h')
-rw-r--r--balls.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/balls.h b/balls.h
new file mode 100644
index 0000000..0fa93a7
--- /dev/null
+++ b/balls.h
@@ -0,0 +1,34 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <cursor.h>
+
+enum {
+ RADIUS = 20,
+};
+
+typedef struct {
+ int x, y;
+} Vec;
+
+typedef struct {
+ Point p1, p2;
+} Line;
+
+typedef struct {
+ Point p; /* position */
+ Vec v; /* velocity */
+ int m; /* mass */
+} Ball;
+
+Vec vsub(Vec v1, Vec v2);
+Vec vmuls(Vec v, int a);
+Vec vdivs(Vec v, int a);
+int vdot(Vec v1, Vec v2);
+int vlen(Vec v);
+Vec unitnorm(Vec v);
+Point ptaddv(Point p, Vec v);
+Vec V(int x, int y);
+Vec Vpt(Point p, Point q);
+
+int iscollision(Point p, Point q); \ No newline at end of file