Continued work on tilemaps/debug
This commit is contained in:
parent
2331110c71
commit
bc4262d552
6
Makefile
6
Makefile
@ -21,7 +21,7 @@ LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_mixer -lxml2 -ltmxparser
|
|||||||
|
|
||||||
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
|
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
|
||||||
# $(CC) $(OBJS) -o $@ $(LDFLAGS)
|
# $(CC) $(OBJS) -o $@ $(LDFLAGS)
|
||||||
LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(OBJS) $(LINKER_FLAGS) -o $@
|
$(CXX) $(OBJS) $(LINKER_FLAGS) -o $@
|
||||||
|
|
||||||
# assembly
|
# assembly
|
||||||
$(BUILD_DIR)/%.s.o: %.s
|
$(BUILD_DIR)/%.s.o: %.s
|
||||||
@ -31,12 +31,12 @@ $(BUILD_DIR)/%.s.o: %.s
|
|||||||
# c source
|
# c source
|
||||||
$(BUILD_DIR)/%.c.o: %.c
|
$(BUILD_DIR)/%.c.o: %.c
|
||||||
$(MKDIR_P) $(dir $@)
|
$(MKDIR_P) $(dir $@)
|
||||||
LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(CPPFLAGS) $(CFLAGS) $(LINKER_FLAGS) -c $< -o $@
|
$(CXX) $(CPPFLAGS) $(CFLAGS) $(LINKER_FLAGS) -c $< -o $@
|
||||||
|
|
||||||
# c++ source
|
# c++ source
|
||||||
$(BUILD_DIR)/%.cpp.o: %.cpp
|
$(BUILD_DIR)/%.cpp.o: %.cpp
|
||||||
$(MKDIR_P) $(dir $@)
|
$(MKDIR_P) $(dir $@)
|
||||||
LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINKER_FLAGS) -c $< -o $@
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINKER_FLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
Binary file not shown.
@ -91,11 +91,17 @@ public:
|
|||||||
void update() override
|
void update() override
|
||||||
{
|
{
|
||||||
if (Game::gsm->currentState == GameStateManager::ST_COREGAME){
|
if (Game::gsm->currentState == GameStateManager::ST_COREGAME){
|
||||||
|
|
||||||
for (int i=0;i<destRects.size()-1;i++){
|
for (int i=0;i<destRects.size()-1;i++){
|
||||||
if (Game::camera.x >= 352)
|
if (Game::pVel.x > 0)
|
||||||
destRects[i].x = destRects[i].x - Game::camera.x*0.01f;
|
destRects[i].x = destRects[i].x - Game::pVel.x;
|
||||||
if (Game::camera.y >= 432)
|
if (Game::pVel.y > 0)
|
||||||
destRects[i].y = destRects[i].y - Game::camera.y*0.01f;
|
destRects[i].y = destRects[i].y - Game::pVel.y;
|
||||||
|
if (Game::pVel.x < 0)
|
||||||
|
destRects[i].x = destRects[i].x - Game::pVel.x;
|
||||||
|
if (Game::pVel.y < 0)
|
||||||
|
destRects[i].y = destRects[i].y - Game::pVel.y;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,8 @@ bool Game::isRunning = false;
|
|||||||
bool Game::debugMenu = false;
|
bool Game::debugMenu = false;
|
||||||
|
|
||||||
auto& player(manager.addEntity());
|
auto& player(manager.addEntity());
|
||||||
|
Vector2D Game::playerPosition;
|
||||||
|
Vector2D Game::pVel;
|
||||||
|
|
||||||
// auto& enemy(manager.addEntity());
|
// auto& enemy(manager.addEntity());
|
||||||
auto& puppy(manager.addEntity());
|
auto& puppy(manager.addEntity());
|
||||||
@ -53,6 +55,8 @@ auto& uiInfo(manager.addEntity());
|
|||||||
auto& uiJumpInfo(manager.addEntity());
|
auto& uiJumpInfo(manager.addEntity());
|
||||||
auto& uiCamXInfo(manager.addEntity());
|
auto& uiCamXInfo(manager.addEntity());
|
||||||
auto& uiCamYInfo(manager.addEntity());
|
auto& uiCamYInfo(manager.addEntity());
|
||||||
|
auto& uiPlayerXInfo(manager.addEntity());
|
||||||
|
auto& uiPlayerYInfo(manager.addEntity());
|
||||||
auto& uiTextInstructions(manager.addEntity());
|
auto& uiTextInstructions(manager.addEntity());
|
||||||
|
|
||||||
auto& gameScene(manager.addEntity());
|
auto& gameScene(manager.addEntity());
|
||||||
@ -99,6 +103,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
|
if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
|
||||||
{
|
{
|
||||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
|
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
|
||||||
|
SDL_SetWindowBordered(window,SDL_FALSE);
|
||||||
if(!window)
|
if(!window)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Couldn't create window: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Couldn't create window: %s", SDL_GetError());
|
||||||
@ -176,7 +181,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
|
|
||||||
uiInfo.addComponent<TransformComponent>(camera.w-94,10,72,96,gScale);
|
uiInfo.addComponent<TransformComponent>(camera.w-94,10,72,96,gScale);
|
||||||
// uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
|
// uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
|
||||||
uiInfo.addComponent<UITextComponent>("font", "Camera CamX: CamY: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
|
uiInfo.addComponent<UITextComponent>("font", "Camera CamX: CamY: P.x: P.y : P.dy: YVec: ", 8, 12, gScale);
|
||||||
uiInfo.addGroup(groupUI_Layer3);
|
uiInfo.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
uiCamXInfo.addComponent<TransformComponent>(camera.w-48,24,40,12,gScale);
|
uiCamXInfo.addComponent<TransformComponent>(camera.w-48,24,40,12,gScale);
|
||||||
@ -187,9 +192,17 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
uiCamYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
|
uiCamYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
|
||||||
uiCamYInfo.addGroup(groupUI_Layer3);
|
uiCamYInfo.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
uiJumpInfo.addComponent<TransformComponent>(camera.w-48,48,40,12,gScale);
|
uiPlayerXInfo.addComponent<TransformComponent>(camera.w-48,48,40,12,gScale);
|
||||||
uiJumpInfo.addComponent<UITextComponent>("font", "false", 8, 12, 1);
|
uiPlayerXInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
|
||||||
uiJumpInfo.addGroup(groupUI_Layer3);
|
uiPlayerXInfo.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
|
uiPlayerYInfo.addComponent<TransformComponent>(camera.w-48,60,40,12,gScale);
|
||||||
|
uiPlayerYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
|
||||||
|
uiPlayerYInfo.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
|
// uiJumpInfo.addComponent<TransformComponent>(camera.w-48,48,40,12,gScale);
|
||||||
|
// uiJumpInfo.addComponent<UITextComponent>("font", "false", 8, 12, 1);
|
||||||
|
// uiJumpInfo.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
// debug UI box
|
// debug UI box
|
||||||
SDL_Rect debugBoxRect = SDL_Rect();
|
SDL_Rect debugBoxRect = SDL_Rect();
|
||||||
@ -203,7 +216,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
//ecs implementation
|
//ecs implementation
|
||||||
|
|
||||||
// player.addComponent<TransformComponent>(860*globalScale,640*globalScale,22,42,globalScale);
|
// player.addComponent<TransformComponent>(860*globalScale,640*globalScale,22,42,globalScale);
|
||||||
player.addComponent<TransformComponent>(180*globalScale,120*globalScale,22,42,globalScale);
|
player.addComponent<TransformComponent>(150*globalScale,100*globalScale,22,42,globalScale); // 180,120
|
||||||
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
|
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
|
||||||
|
|
||||||
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
|
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
|
||||||
@ -211,6 +224,9 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
player.addComponent<KeyboardController>();
|
player.addComponent<KeyboardController>();
|
||||||
player.addGroup(groupPlayers);
|
player.addGroup(groupPlayers);
|
||||||
|
|
||||||
|
playerPosition = Vector2D().Zero();
|
||||||
|
pVel = Vector2D().Zero();
|
||||||
|
|
||||||
puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
|
puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
|
||||||
puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
|
puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
|
||||||
puppy.addGroup(groupObjects);
|
puppy.addGroup(groupObjects);
|
||||||
@ -308,10 +324,20 @@ void Game::update()
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
camera.x = player.getComponent<TransformComponent>().position.x - camera.w/2;
|
camera.x = player.getComponent<TransformComponent>().position.x - camera.w/2 + player.getComponent<TransformComponent>().width/2;
|
||||||
camera.y = player.getComponent<TransformComponent>().position.y - camera.h/2;
|
camera.y = player.getComponent<TransformComponent>().position.y - camera.h/2 + player.getComponent<TransformComponent>().height/2;
|
||||||
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string(camera.x));
|
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string(camera.x));
|
||||||
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string(camera.y));
|
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string(camera.y));
|
||||||
|
int playerX = player.getComponent<TransformComponent>().position.x;
|
||||||
|
int playerY = player.getComponent<TransformComponent>().position.y;
|
||||||
|
uiPlayerXInfo.getComponent<UITextComponent>().updateString(std::to_string(playerX));
|
||||||
|
uiPlayerYInfo.getComponent<UITextComponent>().updateString(std::to_string(playerY));
|
||||||
|
|
||||||
|
playerPosition.x = playerX;
|
||||||
|
playerPosition.y = playerY;
|
||||||
|
|
||||||
|
pVel.x = player.getComponent<TransformComponent>().velocity.x;
|
||||||
|
pVel.y = player.getComponent<TransformComponent>().velocity.y;
|
||||||
|
|
||||||
if(camera.x < 0)
|
if(camera.x < 0)
|
||||||
camera.x = 0;
|
camera.x = 0;
|
||||||
|
@ -42,6 +42,8 @@ public:
|
|||||||
static bool gravityOnPlayer;
|
static bool gravityOnPlayer;
|
||||||
static bool playerIsGrounded;
|
static bool playerIsGrounded;
|
||||||
static bool playerIsJumping;
|
static bool playerIsJumping;
|
||||||
|
static Vector2D playerPosition;
|
||||||
|
static Vector2D pVel;
|
||||||
static SDL_Rect camera;
|
static SDL_Rect camera;
|
||||||
static AssetManager* assets;
|
static AssetManager* assets;
|
||||||
static GameStateManager* gsm;
|
static GameStateManager* gsm;
|
||||||
|
Loading…
Reference in New Issue
Block a user