Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Map/Map.cpp
- Revision:
- 6:39bda45efeed
- Parent:
- 5:12c179da4788
- Child:
- 7:cd3cafda3dd4
--- a/Map/Map.cpp Tue Mar 26 09:16:35 2019 +0000
+++ b/Map/Map.cpp Mon Apr 08 09:14:33 2019 +0000
@@ -1,13 +1,11 @@
#include "Map.h"
-#include <vector>
-using namespace std;
+#include "Ball.h"
-Centerpoints center;
-vector <Centerpoints> point;
// Constructor
Map::Map()
{
+
}
// Destructor
@@ -16,28 +14,82 @@
}
-void Map::setCenterpoints()
+void Map::initBricks()
{
- center.y = -1;
- for (int i = 0; i < 15; i++)
+ int w = 5;
+ int h = 1;
+ int gap = 1;
+
+ int y = 0;
+
+ for (int j = 0; j < 15; ++j) {
+ int x = 0;
+ for (int i = 0; i < 14; ++i) {
+ Brick b;
+ b.x = x;
+ b.y = y;
+ b.w = w;
+ b.h = h;
+ bricks.push_back(b);
+
+ x += w + gap;
+ }
+ y += h + gap;
+ }
+}
+
+void Map::drawMap(N5110 &lcd)
+{
+ vector<Brick>::size_type end = bricks.size();
+ for (int i = 0; i < end; i++)
{
- center.y = center.y + 2;
- for (int j = 0; j < 14; j++)
- {
- center.x = j * 6 + 1;//1,7,13,19,25,31,37,43,49,55,61,67,73,79 and 5 to the right
- point.push_back(center);
+ const Brick& b = bricks[i];
+ lcd.drawRect(b.x,b.y,b.w,b.h,FILL_BLACK);
+ }
+}
+
+//Taken from a forum, took me a bit to understand/main collision detection
+bool isIntersect(
+ int Ax, int Ay, int Aw, int Ah,
+ float Bx, float By, float Bw, float Bh)
+{
+ return
+ Bx + Bw > Ax &&
+ By + Bh > Ay &&
+ Ax + Aw > Bx &&
+ Ay + Ah > By;
+}
+
+void Map::checkCollision(GameObject &obj)
+{
+ vector<Brick>::size_type end = bricks.size();
+ for (int i = 0; i < end; i++)
+ {
+ const Brick& b = bricks[i];
+ if (isIntersect(b.x, b.y, b.w, b.h,
+ obj.getballPos().x, obj.getballPos().y, obj.getW(), obj.getH())) {
+ bricks.erase(bricks.begin() + i);
+ break;
}
}
}
-void Map::drawMap(N5110 &lcd)
+void Map::destroyMap(N5110 &lcd, Gamepad &pad, Ball &ball)
{
+/*
+ Vector2D posBall = ball.get_ballPos(pad);
vector<Centerpoints>::size_type end = point.size();
for (int i = 0; i < end; i++)
{
for (int j = 0; j < 5; j++)
{
- lcd.setPixel(point[i].x+j,point[i].y,true);
+ if (posBall.x == point[i].x+j)
+ {
+ point.at(i).x = 70;
+ point.at(i).y = 40;
+ printf("collided\n");
+ }
}
}
+ */
}
\ No newline at end of file