ECE 2036 Project

Revision:
2:2042f29de6b7
Parent:
0:cf4396614a79
--- a/wall.cpp	Wed Nov 08 21:01:43 2017 +0000
+++ b/wall.cpp	Thu Nov 21 16:10:57 2019 +0000
@@ -9,19 +9,19 @@
{
// Alocate memory for wall
Wall* wall = (Wall*) malloc(sizeof(Wall));
-
+
// Initialize type info.
// Always draw on the first frame
wall->type = WALL;
wall->should_draw = 1;
-
+
// Set user parameters
wall->direction = direction;
wall->x = x;
wall->y = y;
wall->length = length;
wall->bounce = bounce;
-
+
return wall;
}

@@ -29,56 +29,55 @@
{
// Debug info
//    pc.printf("wall: %d %d %d %d\r\n", wall->direction, wall->x, wall->y, wall->length);
-
+

-    if (wall->direction == VERTICAL)
-    {
+    if (wall->direction == VERTICAL) {

// Step 1: Compute percent of motion before bounce
percent = (adj - curr->px) / (curr->vx*delta);
-
+
// Negative percent means we're moving away from the wall
// >=100% means we don't need to bounce yet
-        if (percent >= 0.0 && percent < 1.0)
-        {
+        if (percent >= 0.0 && percent < 1.0) {
// Compute the bounce location
contact = curr->py + curr->vy*percent*delta;
-            if (in_range(contact, wall->y, wall->y + wall->length))
-            {
-
+            if (in_range(contact, wall->y, wall->y + wall->length)) {
+                // SGFX
+                redLED = 1;
+                speaker.PlayNote(100, 0.01, sound);
+                redLED = 0;
+
// Reverse velocity and slow down
next->vx = -wall->bounce*curr->vx;

-                // This dampens the integration based on how far the ball had
+                // This dampens the integration based on how far the ball had
// to travel before reflecting.
}
// Draw the wall if we're close by
wall->should_draw = 1;
}
-
+
// Make sure we aren't inside the wall
-             && in_range((int)curr->py, wall->y, wall->y + wall->length))
-        {
+                && in_range((int)curr->py, wall->y, wall->y + wall->length)) {
next->px = wall->x + sgn(curr->px - wall->x)*(radius+1);
wall->should_draw = 1;
}
-    }
-    else //direction == HORIZONTAL
-    {
+    } else { //direction == HORIZONTAL
// Same as vertical case, but swap x/y
percent = (adj - curr->py) / (curr->vy*delta);
-        if (percent >= 0.0 && percent < 1.0)
-        {
+        if (percent >= 0.0 && percent < 1.0) {
contact = curr->px + curr->vx*percent*delta;
-            if (in_range(contact, wall->x, wall->x + wall->length))
-            {
+            if (in_range(contact, wall->x, wall->x + wall->length)) {
+                redLED = 1;
+                speaker.PlayNote(100, 0.01, sound);
+                redLED = 0;
next->vy = -wall->bounce*curr->vy;
}
@@ -86,8 +85,7 @@
wall->should_draw = 1;
}
-         && in_range((int)curr->px, wall->x, wall->x + wall->length))
-        {
+                && in_range((int)curr->px, wall->x, wall->x + wall->length)) {
next->py = wall->y + sgn(curr->py - wall->y)*(radius+1);
wall->should_draw = 1;
}
@@ -96,16 +94,15 @@

void draw_wall(Wall* wall)
{
-    if (wall->should_draw)
-    {
+    if (wall->should_draw) {
int wx1, wx2, wy1, wy2;
wx1 = wall->x;
wy1 = wall->y;
wx2 = wx1 + ((wall->direction == HORIZONTAL) ? wall->length : 0);
wy2 = wy1 + ((wall->direction == VERTICAL) ? wall->length : 0);
uLCD.line(wx1, wy1, wx2, wy2, WHITE);
-
+
// Don't draw again unless requested
wall->should_draw = 0;
}
-}
\ No newline at end of file
+}
\ No newline at end of file