![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test 1 doc
Diff: Engine/Engine.cpp
- Revision:
- 7:530ca713d2b2
- Parent:
- 6:00d20886e4f8
- Child:
- 8:d19b30a6cd69
--- a/Engine/Engine.cpp Mon May 25 16:17:58 2020 +0000 +++ b/Engine/Engine.cpp Tue May 26 01:45:20 2020 +0000 @@ -1,5 +1,25 @@ #include "Engine.h" +Platform maps[5] = {Platform(0, 15, 20, 3), Platform(64, 15, 20, 3), Platform(0, 40, 20, 3), Platform(64, 40, 20, 3), Platform(20, 30, 30, 3)}; +int mapSize = sizeof(maps)/sizeof(*maps); + + +////////////////////// DRAW MAP ////////////////////////// +void drawMap(N5110 &lcd) +{ + for (int i = 0; i < mapSize; i++) { + maps[i].draw(lcd); + + //debugs + //coords = maps[i].get_pos(); + //printf("x: %i, y: %i,w: %i,h: %i \n",coords.x, coords.y, coords.width, coords.height); + } + //debugs + //printf("-----------------------------------------\n"); +} + + + Engine::Engine() { } @@ -13,11 +33,16 @@ { //init coord _px = WIDTH / 2; - _py = 10; + _py = 5; //init call _p.init(_px, _py); + + //physics parameters + _Ypos = 0; + _fall = true; + _collide = false; } @@ -28,28 +53,40 @@ { _d = pad.get_direction(); _mag = pad.get_mag(); + _jump = pad.A_held(); } + + + + ////////////////////// DRAW /////////////////////////// //draw both player and map void Engine::draw(N5110 &lcd) { - + + drawMap(lcd); + // player _p.draw(lcd); - drawMap(lcd); - + } + + + ////////////////////// UPDATE ////////////////////////// //provide the player file with necessary Joystick values void Engine::update(Gamepad &pad) { - _p.update(_d,_mag); + + floorCollide(); + _p.update(_d,_mag, _Ypos, _fall, _jump); } + /* - floorCollide(); + if (_collision == true) { @@ -64,20 +101,38 @@ } */ -/* + ////////////////////// FLOOR COLLISION ////////////////////////// -bool Engine::floorCollide() +void Engine::floorCollide() { + //player.x + 8 >= coords[j].x && player.x +1 <= coords[j].x + coords[j].width && player.y +9 >= coords[j].y && player.y+9 <= coords[j].y + coords[j].height + _collide = false; + int a; Vector2D player = _p.get_pos(); - _collision = false; + Vector4 coords[mapSize]; + + for(int i = 0; i<mapSize; i++) { + coords[i] = maps[i].get_pos(); + } + - if ( player.x +1 >= plat.x && player.x +1 <= plat.x + plat.width ) { - _collision = true; - } else { - _collision = false; + if(_collide == false) { + _fall = true; + for(int j=0; j < mapSize; j++) { + if(player.x + 8 >= coords[j].x && player.x +1 <= coords[j].x + coords[j].width && player.y +9 >= coords[j].y && player.y+9 <= coords[j].y + coords[j].height) { + a = j; + _collide = true; + //printf("%i, %i\n", player.x, player.y ); + } + } } - return _collision; + + if(_collide == true){ + _Ypos = coords[a].y - 8; + _fall = false; + _collide = false; + } + } -*/ \ No newline at end of file