udpated SDL_GetTicks() to SDL_GetTicks64()
This commit is contained in:
parent
4aa7fe1692
commit
70402c5382
Binary file not shown.
@ -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
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "PlayerController.h"
|
||||
#include "../assetmgr/AssetManager.h"
|
||||
#include "ColliderComponent.h"
|
||||
#include <cmath>
|
||||
// #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--){
|
||||
//
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
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;
|
||||
// if(Game::playerIsGrounded){
|
||||
sprite->Play("Walk");
|
||||
// }
|
||||
sprite->spriteFlip = SDL_FLIP_NONE;
|
||||
// }else{
|
||||
// // transform->velocity.x = -difference/desiredMovement;
|
||||
// sprite->Play("Walk");
|
||||
// sprite->spriteFlip = SDL_FLIP_NONE;
|
||||
// }
|
||||
}
|
||||
break;
|
||||
|
@ -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();
|
||||
|
@ -21,6 +21,7 @@
|
||||
// #include "../ui/UIText.h"
|
||||
#include "../ui/UINineSlice.h"
|
||||
#include "../cjson/cJSON.h"
|
||||
#include <cmath>
|
||||
|
||||
// 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<TransformComponent>(camera.w/gScale-94,10,72*gScale,96*gScale,gScale);
|
||||
// uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
|
||||
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : Bnd1: Bnd2: Bnd3:", 8, 12, gScale);
|
||||
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : dMvX: diff: bMax:", 8, 12, gScale);
|
||||
uiInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
uiCamXInfo.addComponent<TransformComponent>(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<TransformComponent>(860*globalScale,640*globalScale,22,42,globalScale);
|
||||
player.addComponent<TransformComponent>(150*gScale,100*gScale,22,42,globalScale); // 180,120
|
||||
player.addComponent<TransformComponent>(150*gScale,100*gScale,22,42,globalScale,3); // 180,120
|
||||
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
|
||||
|
||||
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
|
||||
@ -363,9 +364,21 @@ void Game::update()
|
||||
uiPlayerYInfo.getComponent<UITextComponent>().updateString(std::to_string(playerY));
|
||||
|
||||
int * foundBoundaries = predictCollisions();
|
||||
uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[0]));
|
||||
uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[1]));
|
||||
uiBoundary3Info.getComponent<UITextComponent>().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<TransformComponent>().speed*player.getComponent<TransformComponent>().scale);
|
||||
// int desiredMovementY = player.getComponent<TransformComponent>().velocity.y*player.getComponent<TransformComponent>().speed*player.getComponent<TransformComponent>().scale;
|
||||
// uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[0]));
|
||||
uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((int)desiredMovementX));
|
||||
// uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[1]));
|
||||
int difference = player.getComponent<TransformComponent>().position.x-max;
|
||||
uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)difference));
|
||||
uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)max));
|
||||
// uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[2]));
|
||||
|
||||
playerPosition.x = playerX;
|
||||
playerPosition.y = playerY;
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user