diff --git a/1/Game/Maps/Lvl_1.tmx b/1/Game/Maps/Lvl_1.tmx
index 6686adb..3c9a9f3 100644
--- a/1/Game/Maps/Lvl_1.tmx
+++ b/1/Game/Maps/Lvl_1.tmx
@@ -1,5 +1,5 @@
-
@@ -78,7 +88,27 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -123,6 +153,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/1/Motor2D/Coin.cpp b/1/Motor2D/Coin.cpp
new file mode 100644
index 0000000..492b023
--- /dev/null
+++ b/1/Motor2D/Coin.cpp
@@ -0,0 +1,57 @@
+#include "Coin.h"
+#include "j1App.h"
+#include "EntityManager.h"
+#include "j1Player.h"
+
+bool Coin::Start()
+{
+ bool ret = true;
+
+ current_animation = FindAnimByName(idle);
+ state = idle;
+
+ collision_box = App->collisions->AddCollider(*coll_rect, (COLLIDER_TYPE)(type + COLLIDER_PLAYER), App->entities);
+ delete coll_rect;
+
+ return ret;
+}
+
+void Coin::CopySpecifics(Entity* template_entity)
+{
+
+}
+
+void Coin::Draw(float dt)
+{
+ if (this != nullptr) {
+ current_animation = FindAnimByName(state);
+
+ collision_box->rect.x = position.x;
+ collision_box->rect.y = position.y;
+
+ App->render->Blit(*graphics,
+ position.x - current_animation->offset_x,
+ position.y - current_animation->offset_y,
+ ¤t_animation->frames[current_animation->GetAnimationFrame(dt, current_animation->frames.Count())],
+ current_animation->speed,
+ 0.0,
+ render_scale,
+ flip);
+ }
+ App->collisions->LookColl(this, dt);
+}
+
+void Coin::OnCollision(Collider* c1, Collider* c2, SDL_Rect& check)
+{
+ if (c2->type == COLLIDER_PLAYER)
+ {
+ j1Player* temp = (j1Player*)App->entities->GetPlayer();
+ temp->AddCoin(1);
+ temp->AddScore(1 * 500);
+
+ temp = nullptr;
+
+ App->entities->DestroyEntity(App->entities->FindEntities(type, entity_id));
+ }
+
+}
\ No newline at end of file
diff --git a/1/Motor2D/Coin.h b/1/Motor2D/Coin.h
new file mode 100644
index 0000000..f502601
--- /dev/null
+++ b/1/Motor2D/Coin.h
@@ -0,0 +1,23 @@
+#ifndef _Coin_H_
+#define _Coin_H_
+
+#include "Entity.h"
+
+class Coin : public Entity {
+public:
+ Coin(const uint& type, const uint& eid) { this->type = type; this->entity_id = eid; }
+
+ Coin(const uint& eid, Coin* template_coin) { CopyFromTE(template_coin); entity_id = eid; };
+
+ bool Start();
+
+ void CopySpecifics(Entity* template_entity);
+
+ virtual void Draw(float dt);
+
+ void OnCollision(Collider* c1, Collider* c2, SDL_Rect& check);
+};
+
+
+
+#endif //_Coin_H_
\ No newline at end of file
diff --git a/1/Motor2D/Continue.h b/1/Motor2D/Continue.h
index 37d037d..6b9246e 100644
--- a/1/Motor2D/Continue.h
+++ b/1/Motor2D/Continue.h
@@ -3,6 +3,7 @@
#include "Button.h"
#include "j1Gui.h"
+#include "j1Audio.h"
class Continue : public Button
{
@@ -13,6 +14,7 @@ class Continue : public Button
{
App->Trigger_Load();
App->gui->Set_ActiveSet((int)ingame);
+ App->audio->SetPlayMusic();
}
};
diff --git a/1/Motor2D/Counter.h b/1/Motor2D/Counter.h
new file mode 100644
index 0000000..1d2d355
--- /dev/null
+++ b/1/Motor2D/Counter.h
@@ -0,0 +1,71 @@
+#ifndef _Counter_H_
+#define _Counter_H_
+
+#include "UI_Elements.h"
+#include "Label.h"
+
+class Counter : public UI_Element {
+public:
+ Counter() {}
+
+ Counter(SDL_Rect& rect, float size) { image_rect = rect; scale = size; }
+
+ bool Start();
+ bool SpecificPostUpdate();
+ bool Draw();
+ bool CleanUp();
+
+public:
+ int* counter = nullptr;
+ Label content;
+};
+
+bool Counter::Start()
+{
+ bool ret = true;
+
+ content.scale = scale;
+
+ return ret;
+}
+
+bool Counter::SpecificPostUpdate()
+{
+ bool ret = true;
+
+ position = { -App->render->camera.x + image_rect.x, -App->render->camera.y + image_rect.y };
+
+ if (counter != nullptr)
+ {
+ content.content.Clear();
+ content.content.create("%i", *counter);
+
+ ret = Draw();
+ }
+
+ counter = nullptr;
+
+ return ret;
+}
+
+bool Counter::Draw()
+{
+ bool ret = true;
+
+ content.Draw(position);
+
+ return ret;
+}
+
+bool Counter::CleanUp()
+{
+ bool ret = true;
+
+ counter = nullptr;
+
+ ret = content.CleanUp();
+
+ return ret;
+}
+
+#endif //_Counter_H_
\ No newline at end of file
diff --git a/1/Motor2D/Crawler.cpp b/1/Motor2D/Crawler.cpp
index efbc8fa..234d3fd 100644
--- a/1/Motor2D/Crawler.cpp
+++ b/1/Motor2D/Crawler.cpp
@@ -5,6 +5,7 @@
#include "j1Render.h"
#include "j1Scene.h"
#include "EntityManager.h"
+#include "j1Player.h"
bool Crawler::Start()
{
@@ -67,12 +68,16 @@ void Crawler::OnCollision(Collider* c1, Collider* c2, SDL_Rect& check)
}
else if (c2->type == COLLIDER_PLAYER)
{
- if (c2->rect.y + c2->rect.h < c1->rect.y + 3) {
+ if (c2->rect.y + c2->rect.h < c1->rect.y + 3)
+ {
App->entities->FindByColl(c2)->stats.speed *= { 1.1f, -1.2f };
collision_box->active = false;
App->entities->DestroyEntity(App->entities->FindEntities(type, entity_id));
+ j1Player* temp = (j1Player*)App->entities->GetPlayer();
+ temp->AddScore(100);
}
- else if(App->entities->FindByColl(c2)->HIT_TIMER.ReadSec() >= 5) {
+ else if(App->entities->FindByColl(c2)->HIT_TIMER.ReadSec() >= 5 && !App->scene->god_mode)
+ {
if (App->entities->FindByColl(c2)->stats.hp > 0)
App->entities->FindByColl(c2)->stats.hp -= 1;
App->entities->FindByColl(c2)->stats.speed *= {-1.0f, -1.0f};
diff --git a/1/Motor2D/Entity.cpp b/1/Motor2D/Entity.cpp
index fdc923d..f52ec3d 100644
--- a/1/Motor2D/Entity.cpp
+++ b/1/Motor2D/Entity.cpp
@@ -3,6 +3,8 @@
#include "j1Map.h"
#include "j1Collisions.h"
#include "EntityManager.h"
+#include "j1Player.h"
+#include "j1Gui.h"
bool Entity::Start() {
@@ -208,6 +210,16 @@ bool Entity::Load(const pugi::xml_node& savegame)
LoadSprites(temp_sprite);
+ if (type == 0)
+ {
+ j1Player* temp = (j1Player*)App->entities->GetPlayer();
+ stats.hp = savegame.child("life").attribute("value").as_int();
+ temp->score = savegame.child("score").attribute("value").as_int();
+ temp->coins = savegame.child("coins").attribute("value").as_int();
+ App->gui->LinkCounter(&temp->score);
+ App->gui->LinkCounter(&temp->coins);
+ }
+
this->Start();
return ret;
@@ -248,7 +260,12 @@ bool Entity::Save(pugi::xml_node& savegame)
temp_node.append_child("render_scale").append_attribute("value") = render_scale;
if (type == 0)
+ {
+ j1Player* temp = (j1Player*)App->entities->GetPlayer();
temp_node.append_child("life").append_attribute("value") = App->entities->GetPlayer()->stats.hp;
+ temp_node.append_child("score").append_attribute("value") = temp->score;
+ temp_node.append_child("coins").append_attribute("value") = temp->coins;
+ }
return ret;
}
\ No newline at end of file
diff --git a/1/Motor2D/EntityManager.cpp b/1/Motor2D/EntityManager.cpp
index 268def5..e8cc18d 100644
--- a/1/Motor2D/EntityManager.cpp
+++ b/1/Motor2D/EntityManager.cpp
@@ -6,6 +6,8 @@
#include "Crawler.h"
#include "Flyer.h"
#include "Brofiler\Brofiler.h"
+#include "j1Gui.h"
+#include "Coin.h"
EntityManager::EntityManager()
{
@@ -54,6 +56,10 @@ int EntityManager::AddTEntity(const uint& name)
template_entities.add(new Flyer(name, (uint)NULL));
return (int)flyer;
}
+ else if (name == (uint)coin) {
+ template_entities.add(new Coin(name, (uint)NULL));
+ return (int)coin;
+ }
return none;
}
@@ -75,6 +81,11 @@ int EntityManager::AddEntity(const uint& name, const uint& eid, Entity* template
entities.end->data->Start();
return (int)flyer;
}
+ else if (name == (uint)coin) {
+ entities.add(new Coin(eid, (Coin*)template_ent));
+ entities.end->data->Start();
+ return (int)coin;
+ }
return none;
}
@@ -210,6 +221,7 @@ bool EntityManager::Load(const pugi::xml_node& savegame)
temp = temp.next_sibling("entity");
}
+ App->gui->SetTimer(savegame.attribute("time").as_uint());
return ret;
}
@@ -226,6 +238,8 @@ bool EntityManager::Save(pugi::xml_node& savegame)
item = item->next;
}
+ savegame.append_attribute("time") = App->gui->GetTime();
+
return ret;
}
diff --git a/1/Motor2D/EntityManager.h b/1/Motor2D/EntityManager.h
index 6066dc8..7b344af 100644
--- a/1/Motor2D/EntityManager.h
+++ b/1/Motor2D/EntityManager.h
@@ -14,6 +14,7 @@ enum entity_type {
crawler,
jumper,
flyer,
+ coin,
max_
};
diff --git a/1/Motor2D/Flyer.cpp b/1/Motor2D/Flyer.cpp
index 0bfa310..d9bc441 100644
--- a/1/Motor2D/Flyer.cpp
+++ b/1/Motor2D/Flyer.cpp
@@ -6,6 +6,7 @@
#include "j1Scene.h"
#include "EntityManager.h"
#include "j1Pathfinding.h"
+#include "j1Player.h"
bool Flyer::Start()
{
@@ -72,8 +73,10 @@ void Flyer::OnCollision(Collider* c1, Collider* c2, SDL_Rect& check)
App->entities->FindByColl(c2)->stats.speed *= { 1.1f, -1.2f };
collision_box->active = false;
App->entities->DestroyEntity(App->entities->FindEntities(type, entity_id));
+ j1Player* temp = (j1Player*)App->entities->GetPlayer();
+ temp->AddScore(200);
}
- else if (App->entities->FindByColl(c2)->HIT_TIMER.ReadSec() >= 5) {
+ else if (App->entities->FindByColl(c2)->HIT_TIMER.ReadSec() >= 5 && !App->scene->god_mode) {
if (App->entities->FindByColl(c2)->stats.hp > 0)
App->entities->FindByColl(c2)->stats.hp -= 1;
App->entities->FindByColl(c2)->stats.speed *= {-1.0f, -1.0f};
diff --git a/1/Motor2D/Jumper.cpp b/1/Motor2D/Jumper.cpp
index 199a47c..07cbe27 100644
--- a/1/Motor2D/Jumper.cpp
+++ b/1/Motor2D/Jumper.cpp
@@ -72,7 +72,7 @@ void Jumper::OnCollision(Collider* c1, Collider* c2, SDL_Rect& check)
App->entities->FindByColl(c2)->stats.speed *= { 1.1f, -1.2f };
collision_box->active = false;
}
- else if (App->entities->FindByColl(c2)->HIT_TIMER.ReadSec() >= 5) {
+ else if (App->entities->FindByColl(c2)->HIT_TIMER.ReadSec() >= 5 && !App->scene->god_mode) {
if (App->entities->FindByColl(c2)->stats.hp > 0)
App->entities->FindByColl(c2)->stats.hp -= 1;
App->entities->FindByColl(c2)->stats.speed *= {-1.0f, -1.0f};
diff --git a/1/Motor2D/Label.h b/1/Motor2D/Label.h
index dc7dbd9..d4fa9a7 100644
--- a/1/Motor2D/Label.h
+++ b/1/Motor2D/Label.h
@@ -41,20 +41,20 @@ bool Label::Awake(const pugi::xml_node& config)
bool Label::Start()
{
- position.x -= App->render->camera.x;
- position.y -= App->render->camera.y;
+ position = { -App->render->camera.x + image_rect.x, -App->render->camera.y + image_rect.y };
return true;
}
bool Label::SpecificPreUpdate()
{
-
+
return true;
}
bool Label::SpecificPostUpdate()
{
+ position = { -App->render->camera.x + image_rect.x, -App->render->camera.y + image_rect.y };
Draw(position);
return true;
}
@@ -67,7 +67,7 @@ bool Label::Draw(const iPoint& pos)
blit = App->font->Print(content.GetString());
- App->render->Blit(blit, pos.x, pos.y);
+ App->render->BlitF(blit, pos.x, pos.y,scale);
return true;
}
diff --git a/1/Motor2D/Motor2D.vcxproj b/1/Motor2D/Motor2D.vcxproj
index 799c469..4dc8829 100644
--- a/1/Motor2D/Motor2D.vcxproj
+++ b/1/Motor2D/Motor2D.vcxproj
@@ -102,18 +102,22 @@
+
+
+
+
diff --git a/1/Motor2D/Motor2D.vcxproj.filters b/1/Motor2D/Motor2D.vcxproj.filters
index 67dad47..a7615d4 100644
--- a/1/Motor2D/Motor2D.vcxproj.filters
+++ b/1/Motor2D/Motor2D.vcxproj.filters
@@ -70,6 +70,9 @@
Desenvolupament ========\Modules\UI
+
+ Desenvolupament ========\Modules\Entities\Collectibles
+
Desenvolupament ========\Modules\UI\UI Elements\Interactables
@@ -215,12 +218,21 @@
Desenvolupament ========\Modules\UI\UI Elements\Interactables\Buttons
-
+
Desenvolupament ========\Modules\UI\UI Elements\Interactables\Buttons
Desenvolupament ========\Modules\UI\UI Elements\Interactables\Buttons
+
+
+ Desenvolupament ========\Modules\UI\UI Elements\Non-Interactables
+
+
+ Desenvolupament ========\Modules\Entities\Collectibles
+
+
+ Desenvolupament ========\Modules\UI\UI Elements\Non-Interactables
@@ -269,6 +281,9 @@
{2102a1b9-aaf9-4276-8b26-5adc7769cebf}
+
+ {513f04d9-1e8b-422e-beb9-06b503913197}
+
diff --git a/1/Motor2D/Start_b.h b/1/Motor2D/Start_b.h
index 6d2f125..5aac86b 100644
--- a/1/Motor2D/Start_b.h
+++ b/1/Motor2D/Start_b.h
@@ -4,6 +4,8 @@
#include "Button.h"
#include "j1Scene.h"
#include "j1Gui.h"
+#include "Timer.h"
+#include "j1Audio.h"
class Start_b : public Button
{
@@ -15,6 +17,8 @@ class Start_b : public Button
App->scene->curr_map = 0;
App->scene->LoadMap(App->scene->curr_map);
App->gui->Set_ActiveSet((int)ingame);
+ App->gui->game_timer->timer.Start();
+ App->audio->SetPlayMusic();
}
};
diff --git a/1/Motor2D/Timer.h b/1/Motor2D/Timer.h
new file mode 100644
index 0000000..cff94ca
--- /dev/null
+++ b/1/Motor2D/Timer.h
@@ -0,0 +1,95 @@
+#ifndef _Timer_H_
+#define _Timer_H_
+
+#include "UI_Elements.h"
+#include "Label.h"
+#include "j1Timer.h"
+
+class Timer : public UI_Element {
+public:
+ Timer() {}
+
+ Timer(SDL_Rect& rect, float size) { image_rect = rect; scale = size; }
+
+ ~Timer() {}
+
+public:
+ bool Awake(const pugi::xml_node& config);
+ bool Start();
+ bool SpecificPreUpdate();
+ bool SpecificPostUpdate();
+ bool Draw();
+ bool CleanUp();
+
+public:
+ int max_time;
+ Label content;
+ j1Timer timer;
+};
+
+bool Timer::Awake(const pugi::xml_node& config)
+{
+ max_time = config.attribute("max_time").as_int();
+ content.content.create("%i", max_time);
+ position = { config.attribute("posx").as_int(), config.attribute("posy").as_int() };
+
+ content.scale = scale;
+
+ group = (ui_set)config.attribute("group").as_int();
+
+ return true;
+}
+
+bool Timer::Start()
+{
+ position.x = -App->render->camera.x + image_rect.x;
+ position.y = -App->render->camera.y + image_rect.y;
+
+ timer.Start();
+
+ return true;
+}
+
+bool Timer::SpecificPreUpdate()
+{
+ content.content.Clear();
+
+ if ((max_time - (int)timer.ReadSec() / 1) > 0)
+ content.content.create("%i", max_time - (int)timer.ReadSec() / 1);
+ else
+ content.content.create("%i", 0);
+
+
+ position.x = -App->render->camera.x + image_rect.x;
+ position.y = -App->render->camera.y + image_rect.y;
+
+ return true;
+}
+
+bool Timer::SpecificPostUpdate()
+{
+ Draw();
+
+ if (App->entities->GetPlayer() != nullptr) {
+ if (App->entities->GetPlayer()->stats.hp <= 0)
+ timer.Start();
+ }
+
+ return true;
+}
+
+bool Timer::Draw()
+{
+ content.Draw(position);
+
+ return true;
+}
+
+bool Timer::CleanUp()
+{
+ content.CleanUp();
+
+ return true;
+}
+
+#endif //_Timer_H_
\ No newline at end of file
diff --git a/1/Motor2D/UI_Elements.h b/1/Motor2D/UI_Elements.h
index e073e38..9e3872a 100644
--- a/1/Motor2D/UI_Elements.h
+++ b/1/Motor2D/UI_Elements.h
@@ -43,7 +43,7 @@ class UI_Element {
iPoint position = { 0,0 };
ui_set group;
-
+ int type;
SDL_Texture* point_atlas;
};
diff --git a/1/Motor2D/j1App.cpp b/1/Motor2D/j1App.cpp
index 2f4a920..a79490b 100644
--- a/1/Motor2D/j1App.cpp
+++ b/1/Motor2D/j1App.cpp
@@ -198,8 +198,8 @@ void j1App::PrepareUpdate()
dt = frame_time.ReadMs() / 1000.0f;
frame_time.Start();
- if(dt > 5.0f / (float)fps_cap)
- dt = 5.0f / (float)fps_cap;
+ if(dt > 2.0f / (float)fps_cap)
+ dt = 2.0f / (float)fps_cap;
dt *= EXPECTED;
diff --git a/1/Motor2D/j1Audio.h b/1/Motor2D/j1Audio.h
index 8a4882b..4ada92d 100644
--- a/1/Motor2D/j1Audio.h
+++ b/1/Motor2D/j1Audio.h
@@ -75,6 +75,9 @@ class j1Audio : public j1Module
}
void SetMaster(int volume) { master_volume = volume; }
+
+ void SetMenuMusic() { PlayMusic("audio/music/menu_music.ogg"); }
+ void SetPlayMusic() { PlayMusic("audio/music/music_sadpiano.ogg"); }
};
#endif // __j1AUDIO_H__
\ No newline at end of file
diff --git a/1/Motor2D/j1Collisions.cpp b/1/Motor2D/j1Collisions.cpp
index 0ab4354..04dfc09 100644
--- a/1/Motor2D/j1Collisions.cpp
+++ b/1/Motor2D/j1Collisions.cpp
@@ -13,30 +13,33 @@ j1Collision::j1Collision() : j1Module()
for (int j = 0; j < COLLIDER_MAX; j++)
matrix[i][j] = false;
- matrix[COLLIDER_PLAYER][COLLIDER_GROUND] = true;
- matrix[COLLIDER_PLAYER][COLLIDER_CRAWLER] = true;
- matrix[COLLIDER_PLAYER][COLLIDER_DIE] = true;
- matrix[COLLIDER_PLAYER][COLLIDER_END] = true;
- matrix[COLLIDER_PLAYER][COLLIDER_FLYER] = true;
+ matrix[COLLIDER_PLAYER][COLLIDER_GROUND] = true;
+ matrix[COLLIDER_PLAYER][COLLIDER_CRAWLER] = true;
+ matrix[COLLIDER_PLAYER][COLLIDER_DIE] = true;
+ matrix[COLLIDER_PLAYER][COLLIDER_END] = true;
+ matrix[COLLIDER_PLAYER][COLLIDER_FLYER] = true;
+ matrix[COLLIDER_PLAYER][COLLIDER_COIN] = true;
- matrix[COLLIDER_CRAWLER][COLLIDER_GROUND] = true;
- matrix[COLLIDER_CRAWLER][COLLIDER_PLAYER] = true;
- matrix[COLLIDER_CRAWLER][COLLIDER_DIE] = true;
- matrix[COLLIDER_CRAWLER][COLLIDER_CRAWL_NAV] = true;
+ matrix[COLLIDER_CRAWLER][COLLIDER_GROUND] = true;
+ matrix[COLLIDER_CRAWLER][COLLIDER_PLAYER] = true;
+ matrix[COLLIDER_CRAWLER][COLLIDER_DIE] = true;
+ matrix[COLLIDER_CRAWLER][COLLIDER_CRAWL_NAV] = true;
- matrix[COLLIDER_FLYER][COLLIDER_PLAYER] = true;
- matrix[COLLIDER_FLYER][COLLIDER_FLYER] = true;
+ matrix[COLLIDER_FLYER][COLLIDER_PLAYER] = true;
+ matrix[COLLIDER_FLYER][COLLIDER_FLYER] = true;
- matrix[COLLIDER_GROUND][COLLIDER_PLAYER] = true;
- matrix[COLLIDER_GROUND][COLLIDER_CRAWLER] = true;
- matrix[COLLIDER_GROUND][COLLIDER_FLYER] = true;
+ matrix[COLLIDER_GROUND][COLLIDER_PLAYER] = true;
+ matrix[COLLIDER_GROUND][COLLIDER_CRAWLER] = true;
+ matrix[COLLIDER_GROUND][COLLIDER_FLYER] = true;
- matrix[COLLIDER_DIE][COLLIDER_PLAYER] = true;
- matrix[COLLIDER_DIE][COLLIDER_CRAWLER] = true;
+ matrix[COLLIDER_DIE][COLLIDER_PLAYER] = true;
+ matrix[COLLIDER_DIE][COLLIDER_CRAWLER] = true;
- matrix[COLLIDER_END][COLLIDER_PLAYER] = true;
+ matrix[COLLIDER_END][COLLIDER_PLAYER] = true;
- matrix[COLLIDER_CRAWL_NAV][COLLIDER_CRAWLER] = true;
+ matrix[COLLIDER_CRAWL_NAV][COLLIDER_CRAWLER] = true;
+
+ matrix[COLLIDER_COIN][COLLIDER_PLAYER] = true;
}
j1Collision::~j1Collision()
@@ -170,7 +173,7 @@ void j1Collision::DebugDraw()
if (App->map->debug_draw == false)
return;
- Uint8 alpha = 80;
+ Uint8 alpha = 100;
for (uint i = 0; i < colliders.count(); ++i)
{
if (colliders[i] == nullptr)
@@ -179,21 +182,21 @@ void j1Collision::DebugDraw()
switch (colliders[i]->type)
{
case COLLIDER_NONE: // white
- App->render->DrawQuad(colliders[i]->rect, 255, 255, 255, alpha);
+ App->render->DrawQuad(colliders.At(i)->data->rect, 255, 255, 255, alpha);
break;
case COLLIDER_PLAYER: // green
- App->render->DrawQuad(colliders[i]->rect, 0, 255, 0, alpha);
+ App->render->DrawQuad(colliders.At(i)->data->rect, 0, 255, 0, alpha);
break;
case COLLIDER_GROUND: // Purple
- App->render->DrawQuad(colliders[i]->rect, 204, 0, 204, alpha);
+ App->render->DrawQuad(colliders.At(i)->data->rect, 204, 0, 204, alpha);
break;
case COLLIDER_DIE:
- App->render->DrawQuad(colliders[i]->rect, 204, 0, 204, alpha);
+ App->render->DrawQuad(colliders.At(i)->data->rect, 204, 0, 204, alpha);
break;
case COLLIDER_END:
break;
- case COLLIDER_CRAWLER:
- App->render->DrawQuad(colliders[i]->rect, 0, 0, 255, alpha);
+ default:
+ App->render->DrawQuad(colliders.At(i)->data->rect, 0, 0, 255, alpha);
break;
diff --git a/1/Motor2D/j1Collisions.h b/1/Motor2D/j1Collisions.h
index 5ab0126..231523f 100644
--- a/1/Motor2D/j1Collisions.h
+++ b/1/Motor2D/j1Collisions.h
@@ -22,8 +22,10 @@ enum COLLIDER_TYPE
COLLIDER_FLY_NAV,
COLLIDER_PLAYER,
COLLIDER_CRAWLER,
+ COLLIDER_JUMPER,
COLLIDER_FLYER,
-
+ COLLIDER_COIN,
+
COLLIDER_MAX
};
diff --git a/1/Motor2D/j1Gui.cpp b/1/Motor2D/j1Gui.cpp
index 4991921..8476534 100644
--- a/1/Motor2D/j1Gui.cpp
+++ b/1/Motor2D/j1Gui.cpp
@@ -16,6 +16,8 @@
#include "Start_b.h"
#include "VolumeUp.h"
#include "VolumeDown.h"
+#include "Timer.h"
+#include "Counter.h"
j1Gui::j1Gui() : j1Module()
{
@@ -49,6 +51,8 @@ bool j1Gui::Awake(const pugi::xml_node& config)
object_node.attribute("size").as_float(),
object_node.attribute("type").as_int()));
+ objects.end->data->type = object_node.attribute("type").as_int();
+
objects.end->data->Awake(object_node);
object_node = object_node.next_sibling("obj");
@@ -179,11 +183,44 @@ UI_Element* j1Gui::CreateElement(SDL_Rect& rect, float size, int type)
return (new VolumeUp(rect, size));
case (int)volume_down:
return (new VolumeDown(rect, size));
+ case (int)timer:
+ game_timer = new Timer(rect, size);
+ return game_timer;
+ case (int)counter:
+ return (new Counter(rect, size));
default:
return nullptr;
}
return nullptr;
}
+
+uint32 j1Gui::GetTime() {
+ return game_timer->timer.Read() - game_timer->timer.GetStartedAt();
+}
+
+void j1Gui::SetTimer(uint32 start_at) {
+ game_timer->timer.Start();
+ game_timer->timer.StartAt(start_at);
+}
+
+void j1Gui::LinkCounter(int* count)
+{
+ p2List_item* item = objects.start;
+ Counter* temp;
+
+ while (item != NULL)
+ {
+ temp = (Counter*)item->data;
+ if (item->data->type == (int)counter && temp->counter == nullptr) {
+ temp->counter = count;
+ break;
+ }
+
+ item = item->next;
+
+ }
+
+}
// class Gui ---------------------------------------------------
diff --git a/1/Motor2D/j1Gui.h b/1/Motor2D/j1Gui.h
index 09e08be..a206af3 100644
--- a/1/Motor2D/j1Gui.h
+++ b/1/Motor2D/j1Gui.h
@@ -4,6 +4,7 @@
#include "j1Module.h"
#include "UI_Elements.h"
+
class Label;
class Image;
class TextBox;
@@ -18,6 +19,9 @@ class Exit;
class Settings;
class Start_b;
+class Timer;
+class Counter;
+
#define CURSOR_WIDTH 2
// TODO 1: Create your structure of classes
@@ -38,6 +42,9 @@ enum element_type {
volume_up,
volume_down,
+ timer,
+ counter,
+
element_max = INT_MAX
};
@@ -93,8 +100,15 @@ class j1Gui : public j1Module
return active_set;
}
+ uint32 GetTime();
+ void SetTimer(uint32 start_at);
+
+ void LinkCounter(int* count);
+
public:
bool not_end = true;
+ Timer* game_timer = nullptr;
+
private:
diff --git a/1/Motor2D/j1Player.cpp b/1/Motor2D/j1Player.cpp
index dfabfd6..6070f2c 100644
--- a/1/Motor2D/j1Player.cpp
+++ b/1/Motor2D/j1Player.cpp
@@ -5,6 +5,7 @@
#include "j1Render.h"
#include "j1Scene.h"
#include "EntityManager.h"
+#include "j1Gui.h"
void j1Player::CopySpecifics(Entity* template_ent) {
@@ -48,6 +49,9 @@ bool j1Player::UpdateTick(float dt)
App->test_ticks++;
+ App->gui->LinkCounter(&score);
+ App->gui->LinkCounter(&coins);
+
return ret;
}
@@ -124,6 +128,7 @@ void j1Player::OnCollision(Collider* c1, Collider* c2, SDL_Rect& check)
App->entities->DestroyEntity(App->entities->FindEntities(App->entities->FindByColl(c2)->type, App->entities->FindByColl(c2)->entity_id));
c2->active = false;
stats.speed *= { 1.1f, -1.2f };
+ AddScore(100);
}
}
else if(HIT_TIMER.ReadSec() >= 1){
@@ -140,6 +145,7 @@ void j1Player::OnCollision(Collider* c1, Collider* c2, SDL_Rect& check)
App->entities->DestroyEntity(App->entities->FindEntities(App->entities->FindByColl(c2)->type, App->entities->FindByColl(c2)->entity_id));
c2->active = false;
stats.speed *= { 1.1f, -1.2f };
+ AddScore(200);
}
else if (HIT_TIMER.ReadSec() >= 1) {
if (stats.hp > 0 && App->scene->god_mode == false)
@@ -158,6 +164,7 @@ void j1Player::OnCollision(Collider* c1, Collider* c2, SDL_Rect& check)
void j1Player::Movement(float dt) {
+
if (App->input->GetKey(SDL_SCANCODE_A) == KEY_REPEAT) {
MoveLeft(dt);
}
@@ -171,17 +178,28 @@ void j1Player::Movement(float dt) {
}
+ if (!App->scene->god_mode)
+ {
+ if ((App->input->GetKey(SDL_SCANCODE_SPACE) == (KEY_REPEAT || KEY_DOWN) || App->input->GetKey(SDL_SCANCODE_SPACE) == KEY_DOWN) && can_jump == true) {
+ DoJump(dt);
+ }
- if ((App->input->GetKey(SDL_SCANCODE_SPACE) == (KEY_REPEAT || KEY_DOWN) || App->input->GetKey(SDL_SCANCODE_SPACE) == KEY_DOWN) && can_jump == true) {
- DoJump(dt);
+ else if (is_jumping == true)
+ {
+ can_jump = false;
+ is_jumping = false;
+ }
}
- else if (is_jumping == true)
+ else
{
- can_jump = false;
- is_jumping = false;
-
-
+ if (App->input->GetKey(SDL_SCANCODE_W) == KEY_REPEAT) {
+ MoveDown(dt);
+ }
+ else if (App->input->GetKey(SDL_SCANCODE_S) == KEY_REPEAT)
+ {
+ MoveUp(dt);
+ }
}
}
@@ -198,6 +216,27 @@ void j1Player::MoveLeft(float dt){
can_jump = true;
}
+void j1Player::MoveUp(float dt)
+{
+
+ if (abs(stats.speed.x) + stats.accel.x * dt <= stats.max_speed.y)
+ stats.speed.y += stats.accel.y * dt;
+ else if (stats.speed.x >= 0)
+ stats.speed.y += stats.accel.y * 2 * dt;
+ else
+ stats.speed.y = stats.max_speed.x;
+}
+
+void j1Player::MoveDown(float dt)
+{
+ if (abs(stats.speed.x) + stats.accel.x * dt <= stats.max_speed.y && stats.speed.y < 0)
+ stats.speed.y -= stats.accel.y * dt;
+ else if (stats.speed.x >= 0)
+ stats.speed.y -= stats.accel.y * 2 * dt;
+ else
+ stats.speed.y = -stats.max_speed.x;
+}
+
void j1Player::MoveRight(float dt) {
if (abs(stats.speed.x) + stats.accel.x * dt <= stats.max_speed.x)
stats.speed.x += stats.accel.x * dt;
diff --git a/1/Motor2D/j1Player.h b/1/Motor2D/j1Player.h
index ab527ea..7db4732 100644
--- a/1/Motor2D/j1Player.h
+++ b/1/Motor2D/j1Player.h
@@ -34,6 +34,8 @@ class j1Player : public Entity
void MoveRight(float dt);
void MoveLeft(float dt);
+ void MoveUp(float dt);
+ void MoveDown(float dt);
void DoJump(float dt);
void NoMove(float dt);
@@ -54,11 +56,17 @@ class j1Player : public Entity
return ret;
}
+ void AddScore(int plus) { score += plus; }
+ void AddCoin(int plus) { coins += plus; }
+
public:
bool can_jump = true;
bool is_jumping = false;
+ int coins;
+ int score;
+
private:
SDL_Texture* player_life = nullptr;
p2SString health_source;
diff --git a/1/Motor2D/j1Render.cpp b/1/Motor2D/j1Render.cpp
index fdcc27f..600612c 100644
--- a/1/Motor2D/j1Render.cpp
+++ b/1/Motor2D/j1Render.cpp
@@ -176,6 +176,56 @@ bool j1Render::Blit(SDL_Texture* texture, int x, int y, const SDL_Rect* section,
return ret;
}
+// Blit to screen
+bool j1Render::BlitF(SDL_Texture* texture, int x, int y, float render_scale, const SDL_Rect* section, float speed, double angle, bool flip, int pivot_x, int pivot_y) const
+{
+ bool ret = true;
+ uint scale = App->win->GetScale();
+
+ SDL_Rect rect;
+ rect.x = (int)(camera.x) + x * scale;
+ rect.y = (int)(camera.y) + y * scale;
+
+ if (section != NULL)
+ {
+ rect.w = section->w;
+ rect.h = section->h;
+ }
+ else
+ {
+ SDL_QueryTexture(texture, NULL, NULL, &rect.w, &rect.h);
+ }
+
+ rect.x += (rect.w - rect.w * render_scale) * 0.5f;
+ rect.y += (rect.h - rect.h * render_scale) * 0.5f;
+ rect.w *= render_scale;
+ rect.h *= render_scale;
+
+
+ SDL_Point* p = NULL;
+ SDL_Point pivot;
+
+ if (pivot_x != INT_MAX && pivot_y != INT_MAX)
+ {
+ pivot.x = pivot_x;
+ pivot.y = pivot_y;
+ p = &pivot;
+ }
+
+ if (!flip && SDL_RenderCopyEx(renderer, texture, section, &rect, angle, p, SDL_FLIP_NONE) != 0)
+ {
+ LOG("Cannot blit to screen. SDL_RenderCopy error: %s", SDL_GetError());
+ ret = false;
+ }
+ else if (flip && SDL_RenderCopyEx(renderer, texture, section, &rect, angle, p, SDL_FLIP_HORIZONTAL) != 0)
+ {
+ LOG("Cannot blit to screen. SDL_RenderCopy error: %s", SDL_GetError());
+ ret = false;
+ }
+
+ return ret;
+}
+
bool j1Render::DrawQuad(const SDL_Rect& rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool filled, bool use_camera) const
{
bool ret = true;
diff --git a/1/Motor2D/j1Render.h b/1/Motor2D/j1Render.h
index 142056f..0050ee3 100644
--- a/1/Motor2D/j1Render.h
+++ b/1/Motor2D/j1Render.h
@@ -40,6 +40,7 @@ class j1Render : public j1Module
void SetViewPort(const SDL_Rect& rect);
void ResetViewPort();
bool Blit(SDL_Texture* texture, int x, int y, const SDL_Rect* section = NULL, float speed = 1.0f, double angle = 0, float render_scale = 1, bool flip = false, int pivot_x = INT_MAX, int pivot_y = INT_MAX) const;
+ bool BlitF(SDL_Texture* texture, int x, int y, float render_scale = 1, const SDL_Rect* section = NULL, float speed = 1.0f, double angle = 0, bool flip = false, int pivot_x = INT_MAX, int pivot_y = INT_MAX) const;
bool DrawQuad(const SDL_Rect& rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255, bool filled = true, bool use_camera = true) const;
bool DrawLine(int x1, int y1, int x2, int y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255, bool use_camera = true) const;
bool DrawCircle(int x1, int y1, int redius, Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255, bool use_camera = true) const;
diff --git a/1/Motor2D/j1Scene.cpp b/1/Motor2D/j1Scene.cpp
index b3bf023..81c33ac 100644
--- a/1/Motor2D/j1Scene.cpp
+++ b/1/Motor2D/j1Scene.cpp
@@ -11,6 +11,7 @@
#include "EntityManager.h"
#include "j1Scene.h"
#include "j1Gui.h"
+#include "j1Player.h"
j1Scene::j1Scene() : j1Module()
{
@@ -36,6 +37,7 @@ bool j1Scene::Awake(const pugi::xml_node& config)
}
click_id = App->audio->LoadFx("audio/fx/click.ogx");
+
return ret;
}
@@ -47,7 +49,8 @@ bool j1Scene::Start()
// LOAD MAPS AND MUSIC HERE
/*if (ret == true) ret = App->map->LoadMap(Map_list.start->data->GetString());
curr_map = 0;*/
- if (ret == true) ret = App->audio->PlayMusic("audio/music/music_sadpiano.ogg");
+
+ App->audio->PlayMusic("audio/music/menu_music.ogg");
return ret;
}
@@ -107,14 +110,16 @@ bool j1Scene::Update(float dt)
//App->win->SetTitle(title.GetString());
- if (App->input->GetKey(SDL_SCANCODE_F9) == KEY_DOWN) {
- App->map->debug_draw = !App->map->debug_draw;
- App->collisions->debug = !App->collisions->debug;
- }
+ if (App->gui->Get_ActiveSet() == (int)ingame) {
+ if (App->input->GetKey(SDL_SCANCODE_F9) == KEY_DOWN) {
+ App->map->debug_draw = !App->map->debug_draw;
+ App->collisions->debug = !App->collisions->debug;
+ }
- if (App->input->GetKey(SDL_SCANCODE_F11) == KEY_DOWN) {
- App->ChangeCap();
- App->CapFps(App->GetFpsCap());
+ if (App->input->GetKey(SDL_SCANCODE_F11) == KEY_DOWN) {
+ App->ChangeCap();
+ App->CapFps(App->GetFpsCap());
+ }
}
return true;
@@ -134,6 +139,7 @@ bool j1Scene::PostUpdate(float dt)
App->entities->CleanEntities();
App->pathfinding->ResetNav();
App->collisions->CleanColliders();
+ App->audio->SetMenuMusic();
}
App->gui->Set_ActiveSet((int)menu);
App->render->camera.x = 0;
@@ -153,6 +159,11 @@ bool j1Scene::CleanUp()
void j1Scene::LoadNextMap()
{
+ j1Player* temp = (j1Player*)App->entities->GetPlayer();
+
+ int temp_score = temp->score;
+ int temp_coins = temp->coins;
+
App->map->EraseMap();
App->entities->CleanEntities();
App->pathfinding->ResetNav();
@@ -170,6 +181,10 @@ void j1Scene::LoadNextMap()
App->map->first_loop = true;
}
+ temp = (j1Player*)App->entities->GetPlayer();
+ temp->score = temp_score;
+ temp->coins = temp_coins;
+
//App->entities->LoadEntities();
}
@@ -211,26 +226,31 @@ void j1Scene::GodMode(float dt)
void j1Scene::NotGodMode(float dt)
{
// TODO 2.5: Call load / save methods when pressing l/s
+ if (App->gui->Get_ActiveSet() == (int)ingame) {
+ if (App->input->GetKey(SDL_SCANCODE_F1) == KEY_DOWN)
+ {
+ curr_map = 0;
+ LoadMap(curr_map);
+ App->gui->Set_ActiveSet((int)ingame);
+ }
+ if (App->input->GetKey(SDL_SCANCODE_F2) == KEY_DOWN) {
+ LoadMap(curr_map);
+ App->gui->Set_ActiveSet((int)ingame);
+ }
- if (App->input->GetKey(SDL_SCANCODE_F1) == KEY_DOWN)
- {
- curr_map = 0;
- LoadMap(curr_map);
- App->gui->Set_ActiveSet((int)ingame);
- }
- if (App->input->GetKey(SDL_SCANCODE_F2) == KEY_DOWN) {
- LoadMap(curr_map);
- App->gui->Set_ActiveSet((int)ingame);
- }
-
- if (App->input->GetKey(SDL_SCANCODE_F6) == KEY_DOWN || (App->entities->GetPlayer() != nullptr && App->entities->GetPlayer()->stats.hp == 0)) {
- App->Trigger_Load();
- App->gui->Set_ActiveSet((int)ingame);
- }
+ if (App->input->GetKey(SDL_SCANCODE_F5) == KEY_DOWN)
+ App->Trigger_Save();
- if (App->input->GetKey(SDL_SCANCODE_F5) == KEY_DOWN)
- App->Trigger_Save();
+ if (App->input->GetKey(SDL_SCANCODE_F6) == KEY_DOWN || (App->entities->GetPlayer() != nullptr && App->entities->GetPlayer()->stats.hp == 0)) {
+ App->Trigger_Load();
+ App->gui->Set_ActiveSet((int)ingame);
+ }
+ if (App->input->GetKey(SDL_SCANCODE_F7) == KEY_DOWN || change_map == true) {
+ change_map = false;
+ LoadNextMap();
+ }
+ }
// TODO 2.Homework Allow for change in volume
@@ -242,8 +262,4 @@ void j1Scene::NotGodMode(float dt)
App->audio->Decrease_Master();
}
- if (App->input->GetKey(SDL_SCANCODE_F7) == KEY_DOWN || change_map == true) {
- change_map = false;
- LoadNextMap();
- }
}
\ No newline at end of file
diff --git a/1/Motor2D/j1Timer.h b/1/Motor2D/j1Timer.h
index db5c5d2..75ed7d7 100644
--- a/1/Motor2D/j1Timer.h
+++ b/1/Motor2D/j1Timer.h
@@ -14,6 +14,8 @@ class j1Timer
uint32 Read() const;
float ReadSec() const;
+ void StartAt(uint32& start_at) { started_at -= start_at; }
+ uint32 GetStartedAt() { return started_at; }
private:
uint32 started_at;
};