diff --git a/build/BeagleRescue b/build/BeagleRescue index ded2cda..dc75b77 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/config/config.json b/src/config/config.json index 7185755..13ad7ad 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -1,7 +1,7 @@ { "GameName":"Beagle Rescue", "WindowName":"Beagle Rescue", -"WindowSize":{"w":320,"h":240}, +"WindowSize":{"w":320,"h":200}, "WindowFullScreen": 0, -"GlobalScale": 1 +"GlobalScale": 4 } diff --git a/src/ecs/KeyboardController.h b/src/ecs/KeyboardController.h index da056fb..74d9a26 100644 --- a/src/ecs/KeyboardController.h +++ b/src/ecs/KeyboardController.h @@ -14,6 +14,7 @@ #include "PlayerController.h" #include "../assetmgr/AssetManager.h" #include "ColliderComponent.h" +#include // #include "../game/Vector2D.h" class KeyboardController : public Component @@ -79,19 +80,25 @@ public: // printf("lastSafePos .x: %g .y: %g \n",transform->lastSafePos.x,transform->lastSafePos.y); // Game::pTileX // if(transform->position.x>0){ -// ====== For Each Row ==== -// for (int r=Game::pTileY-1;r<=Game::pTileY+1;r++){ -// ====== For Each Tile (Column) ===== -// for (int c=Game::pTileX;c>Game::pTileX-Game::camera.w;c--){ -// -// -// } -// } - transform->velocity.x = -1; -// if(Game::playerIsGrounded){ + + int *borders; + borders = Game::predictCollisions(); + int max = borders[0]; + for (int b=0;b<3;b++){ + if (borders[b]>max){ + max = borders[b]; + } + } + int desiredMovement = std::abs(-1*transform->speed*transform->scale); + int difference = transform->velocity.x-max*transform->scale; +// if(difference>desiredMovement){ + transform->velocity.x = -1; sprite->Play("Walk"); -// } - sprite->spriteFlip = SDL_FLIP_NONE; + sprite->spriteFlip = SDL_FLIP_NONE; +// }else{ +// // transform->velocity.x = -difference/desiredMovement; +// sprite->Play("Walk"); +// sprite->spriteFlip = SDL_FLIP_NONE; // } } break; diff --git a/src/ecs/TransformComponent.h b/src/ecs/TransformComponent.h index cc44bd7..b44e7f4 100644 --- a/src/ecs/TransformComponent.h +++ b/src/ecs/TransformComponent.h @@ -24,7 +24,7 @@ public: int height = 40; int width = 30; int scale = 1; - int speed = 2; + int speed = 1; TransformComponent() { @@ -54,6 +54,16 @@ public: speed = speed*sc; } + TransformComponent(int x, int y, int w, int h, int sc, int spd) + { + position.x = x; + position.y = y; + width = w; + height = h; + scale = sc; + speed = spd*sc; + } + void init() override { velocity.Zero(); diff --git a/src/game/Game.cpp b/src/game/Game.cpp index ebcc3c0..76c9382 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -21,6 +21,7 @@ // #include "../ui/UIText.h" #include "../ui/UINineSlice.h" #include "../cjson/cJSON.h" +#include // tmxparser::TmxMap map; Manager manager; @@ -185,7 +186,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g uiInfo.addComponent(camera.w/gScale-94,10,72*gScale,96*gScale,gScale); // uiInfo.addComponent("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1); - uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : Bnd1: Bnd2: Bnd3:", 8, 12, gScale); + uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : dMvX: diff: bMax:", 8, 12, gScale); uiInfo.addGroup(groupUI_Layer3); uiCamXInfo.addComponent(camera.w/gScale-48,23,40*gScale,12*gScale,gScale); @@ -233,7 +234,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g //ecs implementation // player.addComponent(860*globalScale,640*globalScale,22,42,globalScale); - player.addComponent(150*gScale,100*gScale,22,42,globalScale); // 180,120 + player.addComponent(150*gScale,100*gScale,22,42,globalScale,3); // 180,120 player.addComponent("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json"); // player.addComponent(0.0,0.0,false,false,Vector2D().Zero()); @@ -363,9 +364,21 @@ void Game::update() uiPlayerYInfo.getComponent().updateString(std::to_string(playerY)); int * foundBoundaries = predictCollisions(); - uiBoundary1Info.getComponent().updateString(std::to_string((int)foundBoundaries[0])); - uiBoundary2Info.getComponent().updateString(std::to_string((int)foundBoundaries[1])); - uiBoundary3Info.getComponent().updateString(std::to_string((int)foundBoundaries[2])); + int max = foundBoundaries[0]; + for (int b=0;b<3;b++){ + if (foundBoundaries[b]>max){ + max = foundBoundaries[b]; + } + } + int desiredMovementX = std::abs(-1*player.getComponent().speed*player.getComponent().scale); +// int desiredMovementY = player.getComponent().velocity.y*player.getComponent().speed*player.getComponent().scale; +// uiBoundary1Info.getComponent().updateString(std::to_string((int)foundBoundaries[0])); + uiBoundary1Info.getComponent().updateString(std::to_string((int)desiredMovementX)); +// uiBoundary2Info.getComponent().updateString(std::to_string((int)foundBoundaries[1])); + int difference = player.getComponent().position.x-max; + uiBoundary2Info.getComponent().updateString(std::to_string((int)difference)); + uiBoundary3Info.getComponent().updateString(std::to_string((int)max)); +// uiBoundary3Info.getComponent().updateString(std::to_string((int)foundBoundaries[2])); playerPosition.x = playerX; playerPosition.y = playerY; diff --git a/src/game/Main.cpp b/src/game/Main.cpp index 1da0b1d..791169b 100644 --- a/src/game/Main.cpp +++ b/src/game/Main.cpp @@ -19,7 +19,7 @@ int main(int argc, const char * argv[]) const int FPS = 60; const int frameDelay = 1000 / FPS; - Uint32 frameStart; + Uint64 frameStart; int frameTime; // ============================= @@ -58,13 +58,13 @@ int main(int argc, const char * argv[]) while (game->running()) { - frameStart = SDL_GetTicks(); + frameStart = SDL_GetTicks64(); game->handleEvents(); game->update(); game->render(); - frameTime = SDL_GetTicks() - frameStart; + frameTime = SDL_GetTicks64() - frameStart; if(frameDelay > frameTime) {