|
|
|
@ -42,10 +42,10 @@ auto& player(manager.addEntity());
|
|
|
|
|
|
|
|
|
|
auto& enemy(manager.addEntity());
|
|
|
|
|
|
|
|
|
|
auto& scoreboard(manager.addEntity());
|
|
|
|
|
auto& uiInfo(manager.addEntity());
|
|
|
|
|
auto& background(manager.addEntity());
|
|
|
|
|
|
|
|
|
|
auto& tree(manager.addEntity());
|
|
|
|
|
// auto& scoreboard(manager.addEntity());
|
|
|
|
|
auto& uiInfo(manager.addEntity());
|
|
|
|
|
|
|
|
|
|
bool Game::debugCollisionBoxes = false;
|
|
|
|
|
|
|
|
|
@ -94,17 +94,14 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't initialize SDL audio mixer!, Error: %s", SDL_GetError());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assets->AddTexture("terrain", "assets/textures/tiles/GS-tiles2.png");
|
|
|
|
|
assets->AddTexture("terrain", "assets/textures/tiles/br-tiles.png");
|
|
|
|
|
assets->AddTexture("player", "assets/textures/actors/owl_anim.png");
|
|
|
|
|
assets->AddTexture("font", "assets/textures/ui/ui-font-tombstone-serif.png");
|
|
|
|
|
assets->AddTexture("textBox", "assets/textures/ui/ui-element-tombstone.png");
|
|
|
|
|
assets->AddTexture("tree","assets/textures/objects/tree.png");
|
|
|
|
|
assets->AddTexture("jewel","assets/textures/objects/jewel.png");
|
|
|
|
|
assets->AddTexture("daynighticon","assets/textures/ui/day-night-icon.png");
|
|
|
|
|
assets->AddTexture("robber","assets/textures/actors/robberrodent.png");
|
|
|
|
|
assets->AddTexture("font", "assets/textures/ui/ui-font-cloud-sans.png");
|
|
|
|
|
assets->AddTexture("textBox", "assets/textures/ui/ui-element-cloud.png");
|
|
|
|
|
assets->AddMusicTrack("simonZ","assets/audio/music/sailing16.ogg");
|
|
|
|
|
assets->AddSoundClip("bwoop","assets/audio/sfx/bwoop.wav");
|
|
|
|
|
|
|
|
|
|
assets->AddTexture("background","assets/textures/tiles/background-sky.png");
|
|
|
|
|
|
|
|
|
|
map = new Map("terrain",globalScale,16);
|
|
|
|
|
|
|
|
|
|
const char* myText = "Beagle Rescue";
|
|
|
|
@ -116,39 +113,11 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|
|
|
|
myDestRect.w = 140;
|
|
|
|
|
myDestRect.h = 40;
|
|
|
|
|
my9Slice = new UINineSlice("textBox");
|
|
|
|
|
my9Slice->MakeSlices("textBox",128,128,16,111,16,111,myDestRect,globalScale);
|
|
|
|
|
|
|
|
|
|
const char* sbText = "500";
|
|
|
|
|
scoreboardText = new UIText(sbText, "font", 0, 0, 8, 12, globalScale);
|
|
|
|
|
scoreboardText->ParseString(sbText, 190, 22, globalScale);
|
|
|
|
|
SDL_Rect scoreboardDestRect = SDL_Rect();
|
|
|
|
|
scoreboardDestRect.x = 164;
|
|
|
|
|
scoreboardDestRect.y = 8;
|
|
|
|
|
scoreboardDestRect.w = 140;
|
|
|
|
|
scoreboardDestRect.h = 40;
|
|
|
|
|
scoreboard9Slice = new UINineSlice("textBox");
|
|
|
|
|
SDL_Rect jewelSrcRect = SDL_Rect();
|
|
|
|
|
jewelSrcRect.x = 0;
|
|
|
|
|
jewelSrcRect.y = 0;
|
|
|
|
|
jewelSrcRect.w = 24;
|
|
|
|
|
jewelSrcRect.h = 22;
|
|
|
|
|
SDL_Rect jewelDestRect = SDL_Rect();
|
|
|
|
|
jewelDestRect.x = 0;
|
|
|
|
|
jewelDestRect.y = 0;
|
|
|
|
|
jewelDestRect.w = 24*globalScale;
|
|
|
|
|
jewelDestRect.h = 22*globalScale;
|
|
|
|
|
scoreboard9Slice->MakeSlices("textBox",128,128,16,111,16,111,scoreboardDestRect,globalScale);
|
|
|
|
|
scoreboard.addComponent<TransformComponent>(172*globalScale,16*globalScale,24,22,globalScale);
|
|
|
|
|
scoreboard.addComponent<SpriteComponent>("jewel", SpriteComponent::spriteUIL1, jewelSrcRect, jewelDestRect);
|
|
|
|
|
scoreboard.addGroup(groupUI_Layer1);
|
|
|
|
|
|
|
|
|
|
tree.addComponent<TransformComponent>(292*globalScale,168*globalScale,192,142,globalScale);
|
|
|
|
|
tree.addComponent<SpriteComponent>("tree",SpriteComponent::spriteObject);
|
|
|
|
|
tree.addGroup(groupObjects);
|
|
|
|
|
my9Slice->MakeSlices("textBox",32,32,14,17,14,17,myDestRect,globalScale);
|
|
|
|
|
|
|
|
|
|
//ecs implementation
|
|
|
|
|
|
|
|
|
|
map->LoadMap("assets/maps/GS-Night.txt",48,32, globalScale);
|
|
|
|
|
map->LoadMap("assets/maps/br-map.txt",60,25, globalScale);
|
|
|
|
|
|
|
|
|
|
player.addComponent<TransformComponent>(50*globalScale,50*globalScale,40,40,globalScale);
|
|
|
|
|
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/owl_anim.json");
|
|
|
|
@ -156,9 +125,13 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|
|
|
|
player.addComponent<ColliderComponent>("player");
|
|
|
|
|
player.addGroup(groupPlayers);
|
|
|
|
|
|
|
|
|
|
enemy.addComponent<TransformComponent>(180*globalScale,180*globalScale,32,32,globalScale);
|
|
|
|
|
enemy.addComponent<SpriteComponent>("robber", SpriteComponent::spriteAnimation, "assets/textures/actors/robberrodent.json");
|
|
|
|
|
enemy.addGroup(groupEnemies);
|
|
|
|
|
|
|
|
|
|
background.addComponent<TransformComponent>(0*globalScale,0*globalScale,320,240,globalScale);
|
|
|
|
|
background.addComponent<SpriteComponent>("background", SpriteComponent::spriteObject);
|
|
|
|
|
background.addGroup(groupObjects);
|
|
|
|
|
// enemy.addComponent<TransformComponent>(180*globalScale,180*globalScale,32,32,globalScale);
|
|
|
|
|
// enemy.addComponent<SpriteComponent>("robber", SpriteComponent::spriteAnimation, "assets/textures/actors/robberrodent.json");
|
|
|
|
|
// enemy.addGroup(groupEnemies);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError());
|
|
|
|
@ -176,6 +149,7 @@ auto& enemies(manager.getGroup(Game::groupEnemies));
|
|
|
|
|
// auto& projectiles(manager.getGroup(Game::groupProjectiles));
|
|
|
|
|
auto& gui(manager.getGroup(Game::groupUI_Layer0));
|
|
|
|
|
auto& uiText(manager.getGroup(Game::groupUI_Layer1));
|
|
|
|
|
auto& backgrounds(manager.getGroup(Game::groupBackground));
|
|
|
|
|
|
|
|
|
|
void Game::handleEvents()
|
|
|
|
|
{
|
|
|
|
@ -226,7 +200,6 @@ void Game::update()
|
|
|
|
|
camera.x = player.getComponent<TransformComponent>().position.x - camera.w/2;
|
|
|
|
|
camera.y = player.getComponent<TransformComponent>().position.y - camera.h/2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(camera.x < 0)
|
|
|
|
|
camera.x = 0;
|
|
|
|
|
if (camera.y < 0)
|
|
|
|
@ -241,7 +214,18 @@ void Game::update()
|
|
|
|
|
void Game::render()
|
|
|
|
|
{
|
|
|
|
|
SDL_RenderClear(renderer);
|
|
|
|
|
for (auto& t : tiles)
|
|
|
|
|
|
|
|
|
|
for (auto& b : backgrounds)
|
|
|
|
|
{
|
|
|
|
|
b->draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& o : objects)
|
|
|
|
|
{
|
|
|
|
|
o->draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& t : tiles)
|
|
|
|
|
{
|
|
|
|
|
t->draw();
|
|
|
|
|
}
|
|
|
|
@ -252,11 +236,6 @@ void Game::render()
|
|
|
|
|
c->draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& o : objects)
|
|
|
|
|
{
|
|
|
|
|
o->draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& e : enemies)
|
|
|
|
|
{
|
|
|
|
|