diff --git a/SantaRules/Game/config.xml b/SantaRules/Game/config.xml index ba6ba00..eefad5c 100644 --- a/SantaRules/Game/config.xml +++ b/SantaRules/Game/config.xml @@ -1,8 +1,8 @@ - - Santa Rules + + Game Development Testbed UPC @@ -31,12 +31,11 @@ - - + + - @@ -54,12 +53,18 @@ + + + + + + + + + + + + + - - - - - - - \ No newline at end of file diff --git a/SantaRules/Game/maps/map_1.tmx b/SantaRules/Game/maps/map_1.tmx index 17160f3..c5ee7d6 100644 --- a/SantaRules/Game/maps/map_1.tmx +++ b/SantaRules/Game/maps/map_1.tmx @@ -1,12 +1,12 @@ - + - + @@ -1550,6 +1550,7 @@ + @@ -1557,7 +1558,6 @@ - @@ -1700,14 +1700,14 @@ + + - - @@ -1849,13 +1849,13 @@ - - - + + + @@ -1995,15 +1995,15 @@ + - - + @@ -2145,14 +2145,13 @@ + - - @@ -2160,6 +2159,7 @@ + @@ -2301,16 +2301,16 @@ - - - + + + @@ -2451,10 +2451,10 @@ + - - + @@ -3215,8 +3215,8 @@ + - @@ -4862,9 +4862,9 @@ - - - + + + @@ -5310,7 +5310,6 @@ - @@ -5324,6 +5323,7 @@ + diff --git a/SantaRules/Game/maps/map_2.tmx b/SantaRules/Game/maps/map_2.tmx index 70033df..9006af6 100644 --- a/SantaRules/Game/maps/map_2.tmx +++ b/SantaRules/Game/maps/map_2.tmx @@ -1,6 +1,8 @@ - - + + + + diff --git a/SantaRules/Game/maps/metadata.tmx b/SantaRules/Game/maps/metadata.tmx new file mode 100644 index 0000000..8ebbac1 --- /dev/null +++ b/SantaRules/Game/maps/metadata.tmx @@ -0,0 +1,1517 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SantaRules/Game/maps/platformer_map_0.tmx b/SantaRules/Game/maps/platformer_map_0.tmx new file mode 100644 index 0000000..bd39a2c --- /dev/null +++ b/SantaRules/Game/maps/platformer_map_0.tmx @@ -0,0 +1,1518 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/SantaRules/Game/maps/tama\303\261obackground.tmx" "b/SantaRules/Game/maps/tama\303\261obackground.tmx" new file mode 100644 index 0000000..2880129 --- /dev/null +++ "b/SantaRules/Game/maps/tama\303\261obackground.tmx" @@ -0,0 +1,2269 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SantaRules/Game/save_game.xml b/SantaRules/Game/save_game.xml deleted file mode 100644 index a6be327..0000000 --- a/SantaRules/Game/save_game.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - diff --git a/SantaRules/Motor2D/J1EntityMovable.cpp b/SantaRules/Motor2D/J1EntityMovable.cpp index 924c7c1..93d8a4e 100644 --- a/SantaRules/Motor2D/J1EntityMovable.cpp +++ b/SantaRules/Motor2D/J1EntityMovable.cpp @@ -19,10 +19,12 @@ j1EntityMovable::j1EntityMovable(iPoint pos, ENTITY_TYPE type) : j1Entity(pos, t EntityState = Current_State::ST_IDLE; EntityRect = { CurrentPosition.x, CurrentPosition.y, Size.x, Size.y }; + } bool j1EntityMovable::Awake() { + EntityCollider->callback = this; return true; } bool j1EntityMovable::Update(float dt, bool doLogic) @@ -40,7 +42,7 @@ bool j1EntityMovable::CleanUp() { LOG("Unloading Entity"); - App->tex->UnLoad(Graphics); + App->tex->UnLoad(EntityTexture); return true; } diff --git a/SantaRules/Motor2D/J1EntityMovable.h b/SantaRules/Motor2D/J1EntityMovable.h index 6ea1d77..8d8e5ba 100644 --- a/SantaRules/Motor2D/J1EntityMovable.h +++ b/SantaRules/Motor2D/J1EntityMovable.h @@ -24,7 +24,6 @@ class j1EntityMovable : public j1Entity ST_RIGHT_W, ST_RIGHT_R, ST_JUMPING, - ST_FALLING, ST_SLIDING, ST_CLIMBING, ST_DYING, @@ -61,17 +60,13 @@ class j1EntityMovable : public j1Entity //Position / Movement iPoint CurrentPosition; float velocity; - SDL_Texture* Graphics = nullptr; + //SDL_Texture Graphics; Entity inherited property -- EntityTexture //Animation - Animation* EntityAnimation; + Animation* current_animation; SDL_Rect rotating_animation; bool flipped = false; - //Texture - SDL_Texture* tex; - SDL_Rect* tex_rect; - }; diff --git a/SantaRules/Motor2D/Motor2D.vcxproj b/SantaRules/Motor2D/Motor2D.vcxproj index 06496b2..54ec96c 100644 --- a/SantaRules/Motor2D/Motor2D.vcxproj +++ b/SantaRules/Motor2D/Motor2D.vcxproj @@ -13,8 +13,8 @@ {2AF9969B-F202-497B-AF30-7BEF9CE8005E} programacio_2 - Santa_realm - 10.0.17763.0 + Development - Class 7 + 10.0.17134.0 @@ -88,9 +88,7 @@ - - @@ -108,12 +106,10 @@ - - diff --git a/SantaRules/Motor2D/Motor2D.vcxproj.filters b/SantaRules/Motor2D/Motor2D.vcxproj.filters index e8ce4a1..6f6d8b6 100644 --- a/SantaRules/Motor2D/Motor2D.vcxproj.filters +++ b/SantaRules/Motor2D/Motor2D.vcxproj.filters @@ -61,12 +61,6 @@ Desenvolupament ========\entity structure\Movable\Movable_Ground - - Desenvolupament ========\Tools - - - Desenvolupament ========\Tools - @@ -150,12 +144,6 @@ Desenvolupament ========\entity structure\Movable\Movable_Ground - - Desenvolupament ========\Tools - - - Desenvolupament ========\Tools - diff --git a/SantaRules/Motor2D/j1App.cpp b/SantaRules/Motor2D/j1App.cpp index 0f417e9..bd189b8 100644 --- a/SantaRules/Motor2D/j1App.cpp +++ b/SantaRules/Motor2D/j1App.cpp @@ -37,7 +37,7 @@ j1App::j1App(int argc, char* args[]) : argc(argc), args(args) //player = new j1Player(); pathfinding = new j1PathFinding(); manager = new j1EntityManager(); - fade = new j1FadeToBlack(); + //fade = new j1FadeToBlack(); // Ordered for awake / Start / Update // Reverse order of CleanUp @@ -50,9 +50,9 @@ j1App::j1App(int argc, char* args[]) : argc(argc), args(args) AddModule(pathfinding); AddModule(manager); AddModule(scene); - AddModule(fade); //AddModule(player); + //AddModule(fade); // render last to swap buffer AddModule(render); @@ -86,11 +86,6 @@ bool j1App::Awake() pugi::xml_node config; pugi::xml_node app_config; - save_game = "save_file"; - load_game = "save_file"; - - frame_cap = 30; - bool ret = false; config = LoadConfig(config_file); @@ -102,8 +97,6 @@ bool j1App::Awake() app_config = config.child("app"); title.create(app_config.child("title").child_value()); organization.create(app_config.child("organization").child_value()); - VSyncActive = config.child("vsync").attribute("value").as_bool(true); - frame_cap = config.child("app").attribute("framerate_cap").as_uint(); } if (ret == true) @@ -140,7 +133,6 @@ bool j1App::Start() // Called each loop iteration bool j1App::Update() {BROFILER_CATEGORY("UpdateApp", Profiler::Color::MediumSpringGreen) - bool ret = true; PrepareUpdate(); @@ -188,67 +180,11 @@ void j1App::FinishUpdate() if (want_to_load == true) LoadGameNow(); - - // Framerate operations - if (last_second_timer.ReadMs() > 1000) - { - last_second_timer.Start(); - prev_sec_frames = frames_last_second; - frames_last_second = 0; - } - - float frame_cap_ms = 1000 / frame_cap; - float current_frame_ms = frame_timer.Read(); - float avg_fps = frame_count / startup_timer.ReadSec(); - float seconds_since_startup = startup_timer.ReadSec(); - uint32 last_frame_ms = frame_timer.Read(); - uint32 frames_on_last_update = prev_sec_frames; - - if (FramesCaped == true) - { - if (current_frame_ms < frame_cap_ms) - { - true_delay_timer.Start(); - - SDL_Delay(frame_cap_ms - current_frame_ms); - - int intended_delay = frame_cap_ms - current_frame_ms; - - LOG("Waited for %d milliseconds to go back in %f", intended_delay, true_delay_timer.ReadMs()); - } - } - - if (FramesCaped == true) - { - TitleIndicator_frame_cap = "On"; - } - else - { - TitleIndicator_frame_cap = "Off"; - } - - if (VSyncActive == true) - { - TitleIndicator_vsync = "On"; - } - else - { - TitleIndicator_vsync = "Off"; - } - - //Title text - static char title[256]; - - sprintf_s(title, 256, "Av.FPS: %.2f / Last Frame Ms: %02u / Last sec frames: %i / Last dt: %.3f / Time since startup: %.3f / Frame Count: %lu / Vsync: %s / Frame cap: %s", - avg_fps, last_frame_ms, frames_on_last_update, dt, seconds_since_startup, frame_count, TitleIndicator_vsync, TitleIndicator_frame_cap); - - App->win->SetTitle(title); } // Call modules before each loop iteration bool j1App::PreUpdate() {BROFILER_CATEGORY("PreUpdateApp", Profiler::Color::DarkRed) - bool ret = true; p2List_item* item; item = modules.start; @@ -271,7 +207,6 @@ bool j1App::PreUpdate() // Call modules on each loop iteration bool j1App::DoUpdate() {BROFILER_CATEGORY("DoUpdateApp", Profiler::Color::Blue) - bool ret = true; p2List_item* item; item = modules.start; @@ -293,8 +228,7 @@ bool j1App::DoUpdate() // Call modules after each loop iteration bool j1App::PostUpdate() -{BROFILER_CATEGORY("PostUpdateApp", Profiler::Color::GreenYellow) - +{ bool ret = true; p2List_item* item; j1Module* pModule = NULL; @@ -356,17 +290,13 @@ const char* j1App::GetOrganization() const return organization.GetString(); } -float j1App::Getdt() -{ - LOG("dt is: %f", dt); - return dt; -} - // Load / Save void j1App::LoadGame(const char* file) { - // Check if it exists in the p2list + // we should be checking if that file actually exist + // from the "GetSaveGames" list want_to_load = true; + //load_game.create("%s%s", fs->GetSaveDirectory(), file); } // --------------------------------------- @@ -376,7 +306,7 @@ void j1App::SaveGame(const char* file) const // from the "GetSaveGames" list ... should we overwrite ? want_to_save = true; - save_game.create(file); + //save_game.create(file); } // --------------------------------------- @@ -426,8 +356,6 @@ bool j1App::SavegameNow() const { bool ret = true; - save_game.create("save_game.xml"); - LOG("Saving Game State to %s...", save_game.GetString()); // xml object were we will store all data @@ -446,7 +374,11 @@ bool j1App::SavegameNow() const if (ret == true) { - data.save_file(save_game.GetString()); + std::stringstream stream; + data.save(stream); + + // we are done, so write data to disk + //fs->Save(save_game.GetString(), stream.str().c_str(), stream.str().length()); LOG("... finished saving", save_game.GetString()); } else diff --git a/SantaRules/Motor2D/j1App.h b/SantaRules/Motor2D/j1App.h index 468980e..1cd0ea6 100644 --- a/SantaRules/Motor2D/j1App.h +++ b/SantaRules/Motor2D/j1App.h @@ -4,8 +4,6 @@ #include "p2List.h" #include "j1Module.h" #include "PugiXml\src\pugixml.hpp" -#include "j1Timer.h" -#include "j1PerfTimer.h" // Modules class j1Window; @@ -16,10 +14,10 @@ class j1Audio; class j1Scene; class j1Map; class j1Collision; -class j1Player; +//class j1Player; class j1PathFinding; class j1EntityManager; -class j1FadeToBlack; +//class j1FadeToBlack; class j1App { @@ -56,8 +54,6 @@ class j1App void SaveGame(const char* file) const; void GetSaveGames(p2List& list_to_fill) const; - float Getdt(); - private: // Load config file @@ -93,15 +89,10 @@ class j1App j1Scene* scene; j1Map* map; j1Collision* coll; - j1Player* player; +// j1Player* player; j1PathFinding* pathfinding; j1EntityManager* manager; - j1FadeToBlack* fade; - - - //Framerate / VSync - bool FramesCaped; - bool VSyncActive; + //j1FadeToBlack fade; private: @@ -111,7 +102,6 @@ class j1App int argc; char** args; - p2SString title; p2SString organization; @@ -119,23 +109,8 @@ class j1App bool want_to_load; p2SString load_game; mutable p2SString save_game; - - //Framerate - uint64 frame_count; //Calcultes the amount of frames per second. frames++ after each Update() loop. - j1Timer startup_timer; //Creates a pointer to j1Timer tool. Gives acces to j1Timer's elements. Used to keep track of time since app start. - j1Timer frame_timer; //Keeps track of everything time related in the span of a frame. - j1PerfTimer perf_timer; //Creates a pointer to j1PerfTimer tool. Gives access to j1PerfTimer's elements. Used to keep track of time since app start. - j1PerfTimer last_second_timer; //Creates a pointer to j1PerfTimer tool. Used to calculate variables in spans of one second. - uint32 last_update_ms; //Calculates the amount of milliseconds that the last update spent running. - uint32 frames_last_second; //Calculates the amount of frames that where processed the last second. - uint32 prev_sec_frames; //Stores the number of frames processed last second. - - j1PerfTimer true_delay_timer; //Timer that will be used to see the actual amount of time that was delayed to cap the framerate. - uint frame_cap; //Stores the frames per second cap to be applied. - char* TitleIndicator_frame_cap; //Show i the top text - char* TitleIndicator_vsync; //Show in the top text }; -extern j1App* App; +extern j1App* App; //needed? #endif \ No newline at end of file diff --git a/SantaRules/Motor2D/j1Collision.cpp b/SantaRules/Motor2D/j1Collision.cpp index fd38937..880b7c4 100644 --- a/SantaRules/Motor2D/j1Collision.cpp +++ b/SantaRules/Motor2D/j1Collision.cpp @@ -102,11 +102,29 @@ bool j1Collision::PostUpdate() //BIG ERROR HERE, CALLBACK ACCESSES WEIRD PLACES c2 = colliders[k]; - if (c1->CheckCollision(c2->rect) == true && matrix[c2->type][c1->type] && App->manager->Player->God_Mode != true) + if (c1->CheckCollision(c2->rect) == true && matrix[c2->type][c1->type]) { - App->manager->OnCollision(c1, c2); + if ((c1->type == PLAYER && c2->type == ENEMY) && (c1->type == ENEMY && c2->type == PLAYER)) + { + if (App->manager->Player->God_Mode == false) + { + App->manager->OnCollision(c1, c2); + } + } + + else if ((c1->type == ENEMY )|| (c2->type == ENEMY)) + { + App->manager->OnCollision(c1, c2); + } + + else if (c1->type == PLAYER || c2->type == PLAYER) + { + if (App->manager->Player->God_Mode == false) + { + App->manager->OnCollision(c1, c2); + } + } } - } } @@ -154,6 +172,10 @@ void j1Collision::DebugDraw() case BONUS: // yellow App->render->DrawQuad(colliders[i]->rect, 255, 255, 0, alpha); break; + + case ENEMY: // pink + App->render->DrawQuad(colliders[i]->rect, 255, 0, 255, alpha); + break; } } @@ -248,7 +270,7 @@ bool j1Collision::CleanUp() } -Collider* j1Collision::AddCollider(SDL_Rect rect, COLLIDER_TYPE type, j1Module* callback) +Collider* j1Collision::AddCollider(SDL_Rect rect, COLLIDER_TYPE type, j1Entity* callback) { Collider* ret = nullptr; diff --git a/SantaRules/Motor2D/j1Collision.h b/SantaRules/Motor2D/j1Collision.h index 56109b1..d09bb0d 100644 --- a/SantaRules/Motor2D/j1Collision.h +++ b/SantaRules/Motor2D/j1Collision.h @@ -8,6 +8,7 @@ #pragma comment( lib, "SDL/libx86/SDL2main.lib" ) #include "j1Module.h" +#include "j1Entity.h" enum COLLIDER_TYPE { @@ -26,9 +27,9 @@ struct Collider SDL_Rect rect; bool to_delete = false; COLLIDER_TYPE type; - j1Module* callback = nullptr; + j1Entity* callback = nullptr; - Collider(SDL_Rect rectangle, COLLIDER_TYPE type, j1Module* calback = nullptr) : + Collider(SDL_Rect rectangle, COLLIDER_TYPE type, j1Entity* calback = nullptr) : rect(rectangle), type(type), callback(callback) @@ -45,9 +46,6 @@ struct Collider rect.h = h; } bool CheckCollision(const SDL_Rect& r) const; - - - }; class j1Collision : public j1Module { @@ -70,7 +68,7 @@ class j1Collision : public j1Module // Called before quitting bool CleanUp(); - Collider* AddCollider(SDL_Rect rect, COLLIDER_TYPE type, j1Module* callback = nullptr); + Collider* AddCollider(SDL_Rect rect, COLLIDER_TYPE type, j1Entity* callback = nullptr); void DebugDraw(); //--Check if collision from sides is possible--// diff --git a/SantaRules/Motor2D/j1Entity.cpp b/SantaRules/Motor2D/j1Entity.cpp index 0ba02d8..3858c60 100644 --- a/SantaRules/Motor2D/j1Entity.cpp +++ b/SantaRules/Motor2D/j1Entity.cpp @@ -28,49 +28,37 @@ bool j1Entity::Update(float dt, bool doLogic) return true; } -bool j1Entity::PostUpdate() +bool j1Entity::Start() { + flipped = false; return true; } -bool j1Entity::CleanUp() +bool j1Entity::Draw() { - return true; + bool ret = false; + + if (ret = App->render->Blit(EntityTexture, StartingPosition.x, StartingPosition.y, &EntityRect, flipped) == 0) + { + LOG("Blit error: Entity Texture"); + } + + return ret; } -bool j1Entity::Save(pugi::xml_node &)const +bool j1Entity::PostUpdate() { return true; } -bool j1Entity::Load(pugi::xml_node &) +bool j1Entity::CleanUp() { return true; } -//bool j1Entity::Draw(iPoint pos, SDL_Rect rect, bool flip) -//{ -// bool ret = false; -// -// if (ret = App->render->Blit(EntityTexture, pos.x, pos.y, &rect, flip) == 0) -// { -// LOG("Blit error: Entity Texture"); -// } -// -// return ret; -//} +//save? -void j1Entity::BlitEntities(SDL_Rect r, bool flip, float x, float y) -{ - if (flip == false) - { - App->render->Blit(EntityTexture, x, y, &r, flip); - } - else - { - App->render->Blit(EntityTexture, x, y, &r, flip); - } -} +//load? void j1Entity::OnCollision(Collider* c1, Collider* c2) //collisions must be managed from the Entity manager { diff --git a/SantaRules/Motor2D/j1Entity.h b/SantaRules/Motor2D/j1Entity.h index 173a9ed..9fc9df9 100644 --- a/SantaRules/Motor2D/j1Entity.h +++ b/SantaRules/Motor2D/j1Entity.h @@ -3,9 +3,8 @@ #include "j1Module.h" #include "p2Point.h" -#include "Animation.h" +#include "SDL/include/SDL.h" -struct SDL_Rect; struct Collider; struct SDL_Texture; @@ -22,6 +21,8 @@ class j1Entity : public j1Module public: j1Entity(iPoint pos, ENTITY_TYPE type); + virtual bool Start(); + virtual bool PreUpdate(); virtual bool Update(float dt, bool doLogic); @@ -30,12 +31,11 @@ class j1Entity : public j1Module virtual bool CleanUp(); - virtual bool Save(pugi::xml_node&) const; - - virtual bool Load(pugi::xml_node&); + //save? + + //load? - //virtual bool Draw(iPoint pos, SDL_Rect rect, bool flip); - virtual void BlitEntities(SDL_Rect r, bool flip = false, float x = 0, float y = 0); + virtual bool Draw(); virtual void OnCollision(Collider* c1, Collider* c2); @@ -54,14 +54,14 @@ class j1Entity : public j1Module EntityTexture = texture; } - -public: - iPoint StartingPosition; +protected: ENTITY_TYPE Type; Collider* EntityCollider; + iPoint StartingPosition; SDL_Texture* EntityTexture; - Animation* EntityAnimation; + SDL_Rect EntityRect; iPoint sprite_size; + bool flipped; friend class j1EntityManager; }; diff --git a/SantaRules/Motor2D/j1EntityManager.cpp b/SantaRules/Motor2D/j1EntityManager.cpp index ab102ab..85fdbc3 100644 --- a/SantaRules/Motor2D/j1EntityManager.cpp +++ b/SantaRules/Motor2D/j1EntityManager.cpp @@ -21,10 +21,9 @@ j1EntityManager::~j1EntityManager() bool j1EntityManager::Awake(pugi::xml_node& node) { - Player = (j1EntityPlayer*)App->manager->CreateEntity(ENTITY_TYPE::PLAYER, App->manager->Init_playerPos); - - + + TestEnemy = (j1EntityMovable_ground*)App->manager->CreateEntity(ENTITY_TYPE::WALKING_ENEMY, App->manager->Init_playerPos); for (p2List_item* item = entities.start; item != nullptr; item = item->next) { item->data->Awake(node); @@ -33,6 +32,16 @@ bool j1EntityManager::Awake(pugi::xml_node& node) return true; } +bool j1EntityManager::Start() +{ + for (p2List_item* item = entities.start; item != nullptr; item = item->next) + { + item->data->Start(); + } + + return true; +} + bool j1EntityManager::PreUpdate() { for (p2List_item* item = entities.start; item != nullptr; item = item->next) @@ -76,6 +85,16 @@ bool j1EntityManager::PostUpdate() { EntityIterator->data->PostUpdate(); } + DrawEntity(); + return true; +} + +bool j1EntityManager::DrawEntity() +{ + for (p2List_item* EntityIterator = entities.start; EntityIterator != nullptr; EntityIterator = EntityIterator->next) + { + EntityIterator->data->Draw(); + } return true; } @@ -138,7 +157,7 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) return ret; } */ - if (c1->type == PLAYER) + if (c1->type == PLAYER || c1->type == ENEMY) { iPoint wall_position = App->map->WorldToMap(c2->rect.x, c2->rect.y); uint tileid = App->map->Metadata->GetLayerPositon(wall_position.x, wall_position.y); @@ -150,7 +169,8 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) { if(c2->type == WALL || c2->type == CLIMB_WALL) { - Player->CurrentPosition.y = c2->rect.y - c1->rect.h; + j1EntityMovable* callback = (j1EntityMovable*)c1->callback; + callback->CurrentPosition.y = c2->rect.y - c1->rect.h; } if(c2->type == BONUS) @@ -175,7 +195,8 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) { if (c2->type == WALL || c2->type == CLIMB_WALL) { - Player->CurrentPosition.y = c2->rect.y + c2->rect.h; + j1EntityMovable* callback = (j1EntityMovable*)c1->callback; + callback->CurrentPosition.y = c2->rect.y + c2->rect.h; } if (c2->type == BONUS) @@ -199,7 +220,8 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) { if (App->coll->canCollide_right(tileid)) { - Player->CurrentPosition.x = c2->rect.x + c2->rect.w; + j1EntityMovable* callback = (j1EntityMovable*)c1->callback; + callback->CurrentPosition.x = c2->rect.x + c2->rect.w; } } @@ -208,12 +230,13 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) { if (App->coll->canCollide_left(tileid)) { - Player->CurrentPosition.x = c2->rect.x - c1->rect.w; + j1EntityMovable* callback = (j1EntityMovable*)c1->callback; + callback->CurrentPosition.x = c2->rect.x - c1->rect.w; } } } - if (c2->type == PLAYER) + if (c2->type == PLAYER || c2->type == ENEMY) { iPoint wall_position = App->map->WorldToMap(c2->rect.x, c2->rect.y); uint tileid = App->map->Metadata->GetLayerPositon(wall_position.x, wall_position.y); @@ -223,7 +246,8 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) { if (App->coll->canCollide_top(tileid)) { - Player->CurrentPosition.y = c1->rect.y - c2->rect.h; + j1EntityMovable* callback = (j1EntityMovable*)c2->callback; + callback->CurrentPosition.y = c1->rect.y - c2->rect.h; } } @@ -232,7 +256,8 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) { if (App->coll->canCollide_bottom(tileid)) { - Player->CurrentPosition.y = c1->rect.y + c1->rect.h; + j1EntityMovable* callback = (j1EntityMovable*)c2->callback; + callback->CurrentPosition.y = c1->rect.y + c1->rect.h; } } @@ -241,7 +266,8 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) { if (App->coll->canCollide_right(tileid)) { - Player->CurrentPosition.x = c1->rect.x + c1->rect.w; + j1EntityMovable* callback = (j1EntityMovable*)c2->callback; + callback->CurrentPosition.x = c1->rect.x + c1->rect.w; } } @@ -250,7 +276,8 @@ void j1EntityManager::OnCollision(Collider* c1, Collider* c2) { if (App->coll->canCollide_left(tileid)) { - Player->CurrentPosition.x = c1->rect.x - c2->rect.w; + j1EntityMovable* callback = (j1EntityMovable*)c2->callback; + callback->CurrentPosition.x = c1->rect.x - c2->rect.w; } } } diff --git a/SantaRules/Motor2D/j1EntityManager.h b/SantaRules/Motor2D/j1EntityManager.h index 22b37cd..02a3f58 100644 --- a/SantaRules/Motor2D/j1EntityManager.h +++ b/SantaRules/Motor2D/j1EntityManager.h @@ -20,12 +20,16 @@ class j1EntityManager : public j1Module bool Awake(pugi::xml_node&); + bool Start(); + bool PreUpdate(); bool Update(float dt); bool PostUpdate(); + bool DrawEntity(); + bool CleanUp(); public: @@ -33,24 +37,27 @@ class j1EntityManager : public j1Module j1Entity* CreateEntity(ENTITY_TYPE type, iPoint initPos); bool DestroyEntity(j1Entity* entity); void OnCollision(Collider* c1, Collider* c2); - + public: + //SDL_Texture PlayerTexture; //Entity list - p2List entities; - j1EntityPlayer* Player; + p2List entities; + j1EntityPlayer* Player; + j1EntityMovable_ground* TestEnemy; //Entities Initial position - iPoint Init_playerPos; - iPoint Init_groundEnemyPos; - iPoint Init_flyingEnemyPos; - + iPoint Init_playerPos; + iPoint Init_groundEnemyPos; + iPoint Init_flyingEnemyPos; + //Time management/logic--- - float udate_ms_cycle = 10.0f; //just to put some temporary value here - float accumulated_time = 0; - bool doLogic = false; + float udate_ms_cycle = 10.0f; //just to put some temporary value here + float accumulated_time = 0; + bool doLogic = false; //config file--- - pugi::xml_node config; + pugi::xml_node config; + }; diff --git a/SantaRules/Motor2D/j1EntityMovable_Ground.cpp b/SantaRules/Motor2D/j1EntityMovable_Ground.cpp index b28ecee..89bda72 100644 --- a/SantaRules/Motor2D/j1EntityMovable_Ground.cpp +++ b/SantaRules/Motor2D/j1EntityMovable_Ground.cpp @@ -1,16 +1,23 @@ #ifndef __j1ENTITYMOVABLE_GROUND_CPP__ #define __j1ENTITYMOVABLE_GROUND_CPP__ -#include "j1EntityMovable_Ground.h" +#define cBotMaxPositionError 20 +#define cMaxStuckFrames 20 + +#include "j1Entity.h" #include "J1EntityMovable.h" -#include "j1Module.h" +#include "j1EntityMovable_Ground.h" +#include "j1EntityManager.h" #include "p2Point.h" -#include "j1Entity.h" -#include "Animation.h" #include "p2Log.h" +#include "j1Module.h" +#include "Animation.h" #include "j1Textures.h" #include "j1Collision.h" #include "j1Render.h" +#include "j1Map.h" +#include "j1Input.h" +#include "j1Pathfinding.h" j1EntityMovable_ground::j1EntityMovable_ground(iPoint pos, ENTITY_TYPE type) : j1EntityMovable(pos, type) { @@ -24,25 +31,154 @@ j1EntityMovable_ground::j1EntityMovable_ground(iPoint pos, ENTITY_TYPE type) : j EntityRect = { CurrentPosition.x, CurrentPosition.y, Size.x, Size.y }; } +bool j1EntityMovable_ground::Awake(pugi::xml_node& node) +{ + //set inputs to false--- + mInputs[(int)mKeyInput::GoRight] = false; + mInputs[(int)mKeyInput::GoLeft] = false; + mInputs[(int)mKeyInput::Jump] = false; + mInputs[(int)mKeyInput::GoDown] = false; + mInputs[(int)mKeyInput::Dying] = false; + + //Player loaded from xml (LOS NOMBRES DE LAS VARIABLES YA ESTÁN BIEN PUESTOS) + pugi::xml_node colliders = node.child("player").child("colliders"); + pugi::xml_node Entity_stats = node.child("enemy").child("enemy_stats"); + pugi::xml_node player_stats = node.child("player").child("player_stats"); + + Size.x = Entity_stats.child("charachter_width").attribute("value").as_uint(); + Size.y = Entity_stats.child("character_height").attribute("value").as_uint(); + StartingPosition.x = Entity_stats.child("InitialPos_x").attribute("value").as_uint(); + StartingPosition.y = Entity_stats.child("InitialPos_y").attribute("value").as_uint(); + CurrentPosition.x = StartingPosition.x; + CurrentPosition.y = StartingPosition.y; + velocity = Entity_stats.child("PlayerVel_w").attribute("value").as_uint(); + Gravity = Entity_stats.child("Gravity").attribute("value").as_float(); + falling_velocity = Entity_stats.child("falling_velocity").attribute("value").as_float(); + + //--- main_Collider creation + EntityRect.w = player_stats.child("character_width").attribute("value").as_uint(); + EntityRect.h = player_stats.child("character_height").attribute("value").as_uint(); + EntityRect.x = player_stats.child("InitialPos_x").attribute("value").as_uint(); + EntityRect.y = player_stats.child("InitialPos_y").attribute("value").as_uint(); + EntityCollider = App->coll->AddCollider(EntityRect, COLLIDER_TYPE::ENEMY); + + EntityCollider->callback = this; + return true; +} + bool j1EntityMovable_ground::PreUpdate() { - //some kind of state machine that, instead of input keys, - //works with the pathfinder ins some way I still have to think of + CurrentPosition.y += Gravity; + pathCount = pathList.count(); + //------ + static iPoint origin; + static bool origin_selected = false; + + int x, y; + App->input->GetMousePosition(x, y); + iPoint p = App->render->ScreenToWorld(x, y); + p = App->map->WorldToMap(p.x, p.y); + pathPosition = App->map->WorldToMap((CurrentPosition.x + EntityCollider->rect.w * 0.5f), + (CurrentPosition.y + EntityCollider->rect.h * 0.6f)); + + + if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN) + { + if (origin_selected == true) + { + while (!App->map->isGround(p.x, p.y)) + { + p.y++; //Here I force the destination to be at the ground + } + App->pathfinding->CreatePath(pathPosition, p); + App->pathfinding->CopyPathList(&pathList); + //if path is not null copy the path into another array. + if (pathList.count() > 0) + { + mCurrentNodeId = 1; + ChangeState(BotState::MoveTo); + } + origin_selected = false; + } + else + { + origin = pathPosition; + origin_selected = true; + } + } + + if (App->map->isGround(pathPosition.x, pathPosition.y)) + mOnGround = true; + else + mOnGround = false; + + return true; + } bool j1EntityMovable_ground::Update(float dt, bool doLogic) { - //TODO: state machine of the bat + switch (mCurrentBotState) + { + case BotState::None: + break; //no need to do anything + + case BotState::MoveTo: + + if (&pathList[mCurrentNodeId - 1] != nullptr) + { + prevDest = pathList[mCurrentNodeId - 1]; + } + else + { + prevDest.x = 0; prevDest.y = 0; + } + + currentDest = pathList[mCurrentNodeId]; + nextDest = pathList[mCurrentNodeId + 1]; + + GetContext(prevDest, currentDest, nextDest, destOnGround, reachedX, reachedY); + + if (!mOnGround || (reachedX && !destOnGround) || (mOnGround && destOnGround)) + { + mInputs[(int)mKeyInput::Jump] = true; + } + + if (reachedX && reachedY) + { + mCurrentNodeId++; + + if (mCurrentNodeId >= pathList.count()) + { + mCurrentNodeId = -1; + ChangeState(BotState::None); + } + + } + else if (!reachedX || !reachedY && App->map->isGround(nextDest.x, nextDest.y)) + { + currentDest = App->map->MapToWorld(currentDest.x, currentDest.y); + pathPosition = App->map->MapToWorld(pathPosition.x, pathPosition.y); + if (currentDest.x - pathPosition.x > cBotMaxPositionError) + mInputs[(int)mKeyInput::GoRight] = true; + else if (pathPosition.x - currentDest.x > cBotMaxPositionError) + mInputs[(int)mKeyInput::GoLeft] = true; + } - //PLAYER - EntityRect = { CurrentPosition.x, CurrentPosition.y, Size.x, Size.y }; - EntityCollider->SetPos(CurrentPosition.x, CurrentPosition.y); - ////ANIMATIONS - //rotating_animation = EntityAnimation->GetCurrentFrame(); - //App->render->Blit(Graphics, CurrentPosition.x, CurrentPosition.y, &rotating_animation, flipped); + if (pathPosition == currentDest) + { + ++mStuckFrames; + if (mStuckFrames > cMaxStuckFrames) + (pathList[pathCount - 1]); + } + else + mStuckFrames = 0; + break; + } + CharacterUpdate(); return true; } @@ -50,5 +186,134 @@ void j1EntityMovable_ground::OnCollision(Collider* c1, Collider* c2) { // TODO: Launch dead animation if hit from top // TODO: Go a few tiles backwards after hitting the player before trying to attack again + LOG("collision"); +} + +void j1EntityMovable_ground::CharacterUpdate() +{ + bool ret = true; + + //MOVEMENT THROUGH STATES + + if (mCurrentBotState == BotState::None) + { + LOG("IDLE"); + current_animation = &idle; + } + + if (mInputs[(int)mKeyInput::GoLeft] == true) + { + LOG("WALKING LEFT"); + flipped = true; + CurrentPosition.x -= velocity; + current_animation = &walking; + } + + if (mInputs[(int)mKeyInput::GoRight] == true) + { + LOG("WALKING RIGHT"); + flipped = false; + CurrentPosition.x += velocity; + current_animation = &walking; + } + + if (mInputs[(int)mKeyInput::Jump] == true) + { + LOG("JUMPING"); + current_animation = &jumping; + //FALTA + } + + if (mInputs[(int)mKeyInput::Dying] == true) + { + LOG("DYING"); + current_animation = &dying; + } + + //PLAYER + EntityRect = { CurrentPosition.x, CurrentPosition.y, Size.x, Size.y }; + EntityCollider->SetPos(CurrentPosition.x, CurrentPosition.y); +} + +void j1EntityMovable_ground::ChangeState(BotState newState) +{ + mCurrentBotState = newState; +} + +void j1EntityMovable_ground::GetContext(iPoint prevDest, iPoint currentDest, iPoint nextDest, bool destOnGround, bool reachedX, bool reachedY) +{ + if (App->map->isGround(pathPosition.x, pathPosition.y)) + mOnGround = true; + else + mOnGround = false; + //set inputs to false--- + mInputs[(int)mKeyInput::GoRight] = false; + mInputs[(int)mKeyInput::GoLeft] = false; + mInputs[(int)mKeyInput::Jump] = false; + mInputs[(int)mKeyInput::GoDown] = false; + mInputs[(int)mKeyInput::Dying] = false; + + //calculate the x and y coincidence of the current position with the next destination coordinates--- + prevDest = App->map->MapToWorld(prevDest.x, prevDest.y); + currentDest = App->map->MapToWorld(currentDest.x, currentDest.y); + + if (pathCount > mCurrentNodeId + 1) + { + nextDest = App->map->MapToWorld(nextDest.x, nextDest.y); + } + reachedX = ReachedNodeOnXAxis(pathPosition, prevDest, currentDest); + + reachedY = ReachedNodeOnYAxis(pathPosition, prevDest, currentDest); + + if (destOnGround && !mOnGround) + { + reachedY = false; + } + +} +//int j1EntityMovable_ground::GetJumpFramesForNode(int prevNodeId) +//{ +// if (pathList[mCurrentNodeId].y - pathList[prevNodeId].y > 0 && mOnGround) +// { +// int jumpHeight = 1; +// +// for (int i = mCurrentNodeId; i < pathList.count; ++i) +// { +// if (pathList[i].y - pathList[prevNodeId].y >= jumpHeight && App->map->isGround(pathList[i].x, pathList[i].y - 1)) +// } +// } +//} +bool j1EntityMovable_ground::ReachedNodeOnXAxis(iPoint pathPosition, iPoint prevDest, iPoint currentDest) +{ + uint absX = 0; + if ((pathPosition.x - currentDest.x) < 0) + absX = (pathPosition.x - currentDest.x) * (-1); + else + absX = (pathPosition.x - currentDest.x); + + return (prevDest.x <= currentDest.x && pathPosition.x >= currentDest.x) + || (prevDest.x >= currentDest.x && pathPosition.x <= currentDest.x) + || absX <= cBotMaxPositionError; +} + +bool j1EntityMovable_ground::ReachedNodeOnYAxis(iPoint pathPosition, iPoint prevDest, iPoint currentDest) +{ + uint absY = 0; + if ((pathPosition.y - currentDest.y) < 0) + absY = (pathPosition.y - currentDest.y) * (-1); + else + absY = (pathPosition.y - currentDest.y); + + return (prevDest.y <= currentDest.y && pathPosition.y >= currentDest.y) + || (prevDest.y >= currentDest.y && pathPosition.y <= currentDest.y) + || (absY <= cBotMaxPositionError); +} + +void j1EntityMovable_ground::MoveTo(iPoint destination) +{ + mStuckFrames = 0; + + App->pathfinding->CreatePath(pathPosition, destination); + App->pathfinding->CopyPathList(&pathList); } #endif __j1ENTITYMOVABLE_GROUND_CPP__ \ No newline at end of file diff --git a/SantaRules/Motor2D/j1EntityMovable_Ground.h b/SantaRules/Motor2D/j1EntityMovable_Ground.h index 1f758ad..0c7feb0 100644 --- a/SantaRules/Motor2D/j1EntityMovable_Ground.h +++ b/SantaRules/Motor2D/j1EntityMovable_Ground.h @@ -8,17 +8,72 @@ #include "Animation.h" +enum BotState +{ + None = 0, + MoveTo, +}; +enum mKeyInput +{ + GoLeft = 0, + GoRight, + GoDown, + Jump, + Dying, + Count +}; class j1EntityMovable_ground : public j1EntityMovable { public: j1EntityMovable_ground(iPoint pos, ENTITY_TYPE type); + virtual bool Awake(pugi::xml_node& node); + virtual bool PreUpdate(); virtual bool Update(float dt, bool doLogic); virtual void OnCollision(Collider* c1, Collider* c2); +public://ground bot functions + + void CharacterUpdate(); + + void ChangeState(BotState newState); + + void GetContext(iPoint prevDest, iPoint currentDest, iPoint nextDest, bool destOnGround, bool reachedX, bool reachedY); + + void MoveTo(iPoint destination); + + bool ReachedNodeOnXAxis(iPoint pathPosition, iPoint prevDest, iPoint currentDest); + + bool ReachedNodeOnYAxis(iPoint pathPosition, iPoint prevDest, iPoint currentDest); + +public: + BotState mCurrentBotState; + uint mCurrentNodeId; + iPoint pathPosition; + p2List pathList; + bool mOnGround; + uint pathCount; + float Gravity; + float falling_velocity; + + //Inputs array + bool mInputs[6]; + + //Update vars--- + iPoint prevDest, currentDest, nextDest; + bool destOnGround, reachedY, reachedX; + + //Repath vars--- + int mStuckFrames; + + //Animations--- + Animation jumping; + + + }; #endif __j1ENTITYMOVABLE_GROUND_H__ diff --git a/SantaRules/Motor2D/j1EntityPlayer.cpp b/SantaRules/Motor2D/j1EntityPlayer.cpp index 31ed543..46cfbbc 100644 --- a/SantaRules/Motor2D/j1EntityPlayer.cpp +++ b/SantaRules/Motor2D/j1EntityPlayer.cpp @@ -21,9 +21,6 @@ j1EntityPlayer::j1EntityPlayer(iPoint pos, ENTITY_TYPE type) : j1EntityMovable_g { name.create("player"); - LOG("Loading player textures"); - EntityTexture = App->tex->Load("Spritesheets/Santa.png"); - //IDLE idle.PushBack({ 5,1,48,75 }); idle.PushBack({ 135,1,48,75 }); @@ -83,7 +80,7 @@ j1EntityPlayer::j1EntityPlayer(iPoint pos, ENTITY_TYPE type) : j1EntityMovable_g //JUMPING jumping.PushBack({ 23,663,48,75 }); jumping.PushBack({ 157,663,48,75 }); - /*jumping.PushBack({ 287,663,48,75 }); + jumping.PushBack({ 287,663,48,75 }); jumping.PushBack({ 412,663,48,75 }); jumping.PushBack({ 543,663,48,75 }); jumping.PushBack({ 659,663,48,75 }); @@ -97,7 +94,7 @@ j1EntityPlayer::j1EntityPlayer(iPoint pos, ENTITY_TYPE type) : j1EntityMovable_g jumping.PushBack({ 275,749,48,75 }); jumping.PushBack({ 411,749,48,75 }); jumping.PushBack({ 542,749,48,75 }); - jumping.PushBack({ 674,749,48,75 });*/ + jumping.PushBack({ 674,749,48,75 }); jumping.speed = 0.1f; @@ -139,7 +136,7 @@ j1EntityPlayer::j1EntityPlayer(iPoint pos, ENTITY_TYPE type) : j1EntityMovable_g dying.speed = 0.1f; - + God_Mode = false; } bool j1EntityPlayer::Awake(pugi::xml_node& node) @@ -156,9 +153,8 @@ bool j1EntityPlayer::Awake(pugi::xml_node& node) CurrentPosition.y = StartingPosition.y; velocity = player_stats.child("PlayerVel_w").attribute("value").as_uint(); PlayerVel_r = player_stats.child("PlayerVel_r").attribute("value").as_uint(); - PlayerVel_Y = player_stats.child("PlayerVel_Y").attribute("value").as_uint(); Gravity = player_stats.child("Gravity").attribute("value").as_float(); - FallingVel = player_stats.child("falling_velocity").attribute("value").as_float(); + falling_velocity = player_stats.child("falling_velocity").attribute("value").as_float(); Slide_distance = player_stats.child("slide_distance").attribute("value").as_uint(); //--- main_Collider creation @@ -173,34 +169,23 @@ bool j1EntityPlayer::Awake(pugi::xml_node& node) CLIMB_WALL_id = colliders.child("tile_types").child("CLIMB_WALL").attribute("value").as_uint(); BONUS_id = colliders.child("tile_types").child("BONUS").attribute("value").as_uint(); + EntityCollider->callback = this; + return true; +} - +bool j1EntityPlayer::Start() +{ + LOG("Loading player textures"); + EntityTexture = App->tex->Load("Spritesheets/Santa.png"); EntityState = Current_State::ST_IDLE; EntityRect = { CurrentPosition.x, CurrentPosition.y, Size.x, Size.y }; - - God_Mode = false; - - - return true; } - bool j1EntityPlayer::PreUpdate() { - On_Ground; - if (On_Ground == false) { - - Falling = true; - } - - if (Falling == true) - { - - CurrentPosition.y += Gravity; - } bool ret = true; //SHORTCUTS INPUTS--- PlayerInput.F1_enabled = App->input->keyboard[SDL_SCANCODE_F1] == KEY_DOWN; @@ -211,6 +196,14 @@ bool j1EntityPlayer::PreUpdate() PlayerInput.F7_enabled = App->input->keyboard[SDL_SCANCODE_F7] == KEY_DOWN; PlayerInput.F8_enabled = App->input->keyboard[SDL_SCANCODE_F8] == KEY_DOWN; + //RESET CURRENT LEVEL--- + if (PlayerInput.F3_enabled) + { + CurrentPosition.x = StartingPosition.x; + CurrentPosition.y = StartingPosition.y; + //FALTA CAMERA RESET + } + //GODMODE--- if (God_Mode == false && PlayerInput.F8_enabled) { @@ -248,6 +241,7 @@ bool j1EntityPlayer::PreUpdate() { if (PlayerInput.A_enabled) { + LOG("A pressed"); EntityState = Current_State::ST_LEFT_W; } if (PlayerInput.D_enabled) @@ -256,21 +250,7 @@ bool j1EntityPlayer::PreUpdate() } if (PlayerInput.Space_enabled) { - EntityState = Current_State::ST_JUMPING; - - if (On_Ground == false) { - EntityState = Current_State::ST_FALLING; - LOG("JUMP NOT AVAILABLE"); - } - } - if (PlayerInput.Space_enabled) { - - On_Ground = false; - CanJump = false; - PlayerVel_Y = 50; - EntityState = Current_State::ST_JUMPING; - } } if (EntityState == Current_State::ST_LEFT_W) @@ -287,9 +267,8 @@ bool j1EntityPlayer::PreUpdate() { EntityState = Current_State::ST_RIGHT_W; } - if (PlayerInput.Space_enabled && CanJump == true) + if (PlayerInput.Space_enabled && jump_available) { - On_Ground = false; EntityState = Current_State::ST_JUMPING; } } @@ -307,7 +286,7 @@ bool j1EntityPlayer::PreUpdate() { EntityState = Current_State::ST_RIGHT_W; } - if (PlayerInput.Space_enabled && CanJump == true) + if (PlayerInput.Space_enabled && jump_available) { EntityState = Current_State::ST_JUMPING; } @@ -330,7 +309,7 @@ bool j1EntityPlayer::PreUpdate() { EntityState = Current_State::ST_LEFT_W; } - if (PlayerInput.Space_enabled && CanJump == true) + if (PlayerInput.Space_enabled && jump_available) { EntityState = Current_State::ST_JUMPING; } @@ -349,7 +328,7 @@ bool j1EntityPlayer::PreUpdate() { EntityState = Current_State::ST_RIGHT_W; } - if (PlayerInput.Space_enabled && CanJump == true) + if (PlayerInput.Space_enabled && jump_available) { EntityState = Current_State::ST_JUMPING; } @@ -360,14 +339,10 @@ bool j1EntityPlayer::PreUpdate() } if (EntityState == Current_State::ST_JUMPING) { - /*if (PlayerInput.W_enabled) + if (PlayerInput.W_enabled) { EntityState = Current_State::ST_CLIMBING; - }*/ - } - if (EntityState == Current_State::ST_FALLING) - { - + } } if (EntityState == Current_State::ST_SLIDING) { @@ -375,7 +350,7 @@ bool j1EntityPlayer::PreUpdate() { EntityState = Current_State::ST_IDLE; } - if (PlayerInput.Space_enabled && CanJump == true) + if (PlayerInput.Space_enabled && jump_available) { EntityState = Current_State::ST_JUMPING; } @@ -386,7 +361,7 @@ bool j1EntityPlayer::PreUpdate() { EntityState = Current_State::ST_IDLE; } - if (PlayerInput.Space_enabled && CanJump == true) + if (PlayerInput.Space_enabled && jump_available) { EntityState = Current_State::ST_JUMPING; } @@ -423,89 +398,63 @@ bool j1EntityPlayer::PreUpdate() bool j1EntityPlayer::Update(float dt, bool doLogic) { bool ret = true; - ActualizedPosition = CurrentPosition; - + //MOVEMENT THROUGH STATES switch (EntityState) { case Current_State::ST_IDLE: LOG("IDLE"); - if (EndJump == true) { - EntityAnimation = &idle; - } - else { - EntityAnimation = &jumping; - } - JumpTicks = true; + current_animation = &idle; break; case Current_State::ST_LEFT_W: LOG("WALKING LEFT"); flipped = true; - Movement(); - EntityAnimation = &walking; + CurrentPosition.x -= velocity; + current_animation = &walking; break; case Current_State::ST_LEFT_R: LOG("RUNNING LEFT"); flipped = true; - Movement(); - EntityAnimation = &running; + CurrentPosition.x -= PlayerVel_r; + current_animation = &running; break; case Current_State::ST_RIGHT_W: LOG("WALKING RIGHT"); flipped = false; - Movement(); - EntityAnimation = &walking; + CurrentPosition.x += velocity; + current_animation = &walking; break; case Current_State::ST_RIGHT_R: LOG("RUNNING RIGHT"); flipped = false; - Movement(); - EntityAnimation = &running; + CurrentPosition.x += PlayerVel_r; + current_animation = &running; break; case Current_State::ST_JUMPING: LOG("JUMPING"); - - EntityAnimation = &jumping; - - EndJump = false; - On_The_Ground(); - - if (Jump_Ready == true) { - MidAirUP = true; - - Jumping(); - } - if (EndJump == true) { - Current_State::ST_FALLING; - EntityAnimation = &jumping; - } - break; - - case Current_State::ST_FALLING: - LOG("FALLING"); - TouchingCollider = false; - EntityAnimation = &jumping; + current_animation = &jumping; + //FALTA break; case Current_State::ST_SLIDING: LOG("SLIDING"); - EntityAnimation = &sliding; + current_animation = &sliding; break; case Current_State::ST_CLIMBING: LOG("CLIMBING"); - EntityAnimation = &climbing; + current_animation = &climbing; break; case Current_State::ST_DYING: LOG("DYING"); - EntityAnimation = &dying; + current_animation = &dying; break; } @@ -513,153 +462,74 @@ bool j1EntityPlayer::Update(float dt, bool doLogic) EntityRect = { CurrentPosition.x, CurrentPosition.y, Size.x, Size.y }; EntityCollider->SetPos(CurrentPosition.x, CurrentPosition.y); - //ANIMATIONS - rotating_animation = EntityAnimation->GetCurrentFrame(); - //App->render->Blit(Graphics, CurrentPosition.x, CurrentPosition.y, &rotating_animation, flipped); - if (flipped == false) - { - BlitEntities(rotating_animation, flipped, CurrentPosition.x, CurrentPosition.y); - } - else - { - BlitEntities(rotating_animation, flipped, CurrentPosition.x, CurrentPosition.y); - } - - return true; } -void j1EntityPlayer::On_The_Ground() +bool j1EntityPlayer::Draw() { - //CHECK COLLISION - CanJump = false; - if (On_Ground == true) { - - Jump_Ready = true; - - LOG("ON GROUND TRUE"); + bool ret = true; + //ANIMATIONS + rotating_animation = current_animation->GetCurrentFrame(); + if ((ret = App->render->Blit(EntityTexture, CurrentPosition.x, CurrentPosition.y, &rotating_animation, flipped) == 0)) + { + LOG("Blit error in Player"); } - else if (On_Ground == false) { - - Jump_Ready = false; - LOG("ON GROUND FALSE"); - } + return ret; } -void j1EntityPlayer::Jumping() +void j1EntityPlayer::grounded() { - CanJump = false; - - if (MidAirUP == true) { - LOG("MID AIR TRUE"); - PlayerVel_Y -= Gravity * 0.75; - - if (PlayerInput.A_enabled) - { - CurrentPosition.x -= 1.5*velocity; - } - - if (PlayerInput.D_enabled) { - CurrentPosition.x += 1.5*velocity; - - LOG("GOING RIGHT INSIDE JUMP"); - } - - if (PlayerVel_Y <= 0) { - height = CurrentPosition.y; - LOG("VELOCITY REACHED 0 at %f", height); - MidAirUP = false; - } - - CurrentPosition.y -= PlayerVel_Y / 2; - } - - if (MidAirUP == false) { - LOG("MID AIR UP == FALSE"); - - - if (PlayerInput.D_enabled) { - FallLeft = true; - FallRight = false; - - } - if (PlayerInput.A_enabled) { - FallRight = true; - FallLeft = false; - } - - if (On_Ground == true) { - LOG("TO IDLE FROM JUMP"); - EndJump = true; - PlayerVel_Y = TempVelY; - } - - else { - LOG("FALLING"); - CurrentPosition.y += PlayerVel_Y; - ++FallingVel; - LOG("TIMES = %d", FallingVel); - } - } -} - -void j1EntityPlayer::On_The_Air() { - - CanJump = false; - if (On_Ground == true) { - Jump_Ready = false; + jump_available = false; + if (in_land == true) + { + jump_available = true; } - else if (On_Ground == false) { - Jump_Ready = true; + else + { + jump_available = false; } - } -void j1EntityPlayer::Movement() { +void j1EntityPlayer::jump() +{ + if (mid_air) + { + falling_velocity -= Gravity; - if (PlayerInput.A_enabled && !TouchingCollider) { - if (!PlayerInput.Shift_enabled) + if (PlayerInput.A_enabled) { CurrentPosition.x -= velocity; } - else if (PlayerInput.Shift_enabled) + else if (PlayerInput.A_enabled && PlayerInput.Shift_enabled) { CurrentPosition.x -= PlayerVel_r; } - } - - if (PlayerInput.D_enabled && !TouchingCollider) { - if (!PlayerInput.Shift_enabled) + else if (PlayerInput.D_enabled) { CurrentPosition.x += velocity; } - else if (PlayerInput.Shift_enabled) + else if (PlayerInput.D_enabled && PlayerInput.Shift_enabled) { - CurrentPosition.x += PlayerVel_r; + CurrentPosition.x -= PlayerVel_r; } - } - -} - -bool j1EntityPlayer::Load(pugi::xml_node& data) -{ - - CurrentPosition.x = data.child("scene1").child("playerPos").attribute("x").as_float(); - CurrentPosition.y = data.child("scene1").child("playerPos").attribute("y").as_float(); + CurrentPosition.y -= Gravity; - return true; -} - -bool j1EntityPlayer::Save(pugi::xml_node& data) const -{ - pugi::xml_node player = data.append_child("playerPos"); - - player.append_attribute("x") = CurrentPosition.x; - player.append_attribute("y") = CurrentPosition.y; - - return true; + } + else if (!mid_air) + { + falling_velocity += Gravity; + if (in_land) + { + jump_ended = true; + EntityState = Current_State::ST_IDLE; + } + else if (!in_land) + { + CurrentPosition.y += falling_velocity; + } + } } void j1EntityPlayer::OnCollision(Collider* c1, Collider* c2) diff --git a/SantaRules/Motor2D/j1EntityPlayer.h b/SantaRules/Motor2D/j1EntityPlayer.h index 842107d..d12802f 100644 --- a/SantaRules/Motor2D/j1EntityPlayer.h +++ b/SantaRules/Motor2D/j1EntityPlayer.h @@ -39,15 +39,16 @@ class j1EntityPlayer : public j1EntityMovable_ground j1EntityPlayer(iPoint pos, ENTITY_TYPE type); bool Awake(pugi::xml_node& node); - + bool PreUpdate(); bool Update(float dt, bool doLogic); - void OnCollision(Collider* c1, Collider* c2); + bool Start(); - bool Load(pugi::xml_node&); - bool Save(pugi::xml_node&) const; + bool Draw(); + + void OnCollision(Collider* c1, Collider* c2); public: @@ -63,13 +64,11 @@ class j1EntityPlayer : public j1EntityMovable_ground iPoint ActualizedPosition; //Needed in EntityMovable? //float PlayerVel_w; EntityMovable inherited property -- velocity float PlayerVel_r; - float PlayerVel_Y; - //SDL_Texture* Graphics = nullptr; EntityMovable inherited property -- Graphics (also set to nullptr) - + //SDL_Texture* Graphics = nullptr; Entity inherited property -- EntityTexture (also set to nullptr) //ANIMATION //Draw diferents animations - //Animation* EntityAnimation; EntityMovable inherited property -- EntityAnimation + //Animation* current_animation; EntityMovable inherited property -- current_animation //SDL_Rect rotating_animation; EntityMovable inherited property -- rotating_animation //bool flipped = false; EntityMovable inherited property -- flipped (also set to false) //Idle--- @@ -85,32 +84,17 @@ class j1EntityPlayer : public j1EntityMovable_ground Animation climbing; //Dying--- //Animation dying; EntityMovable inherited property -- dying - void Movement(); - //Jumping--- Animation jumping; - float TempVelY; - float FallingVel; - float height; - bool On_Ground; - float Gravity; //10 - float GravitySave; - bool Jump_Ready; - bool MidAirUP; - bool Falling; - bool EndJump; - bool CanJump = true; - bool TouchingCollider; - bool JumpTicks; - bool FallLeft; - bool FallRight; - - void On_The_Air(); - void On_The_Ground(); - void Jumping(); - - - + float Gravity; + float falling_velocity; + bool in_land; + bool falling; + bool jump_available; + bool mid_air; + bool jump_ended; + void grounded(); + void jump(); //SHORTCUTS bool God_Mode = false; diff --git a/SantaRules/Motor2D/j1FadeToBlack.cpp b/SantaRules/Motor2D/j1FadeToBlack.cpp index 8cdaef9..cca1029 100644 --- a/SantaRules/Motor2D/j1FadeToBlack.cpp +++ b/SantaRules/Motor2D/j1FadeToBlack.cpp @@ -1,101 +1,25 @@ -#include "p2Point.h" -#include "p2Log.h" -#include "j1App.h" -#include "j1Textures.h" -#include "j1Render.h" -#include "j1Input.h" -#include "j1Audio.h" -#include "j1Collision.h" -#include "j1FadeToBlack.h" -#include "j1Window.h" -#include "j1Map.h" - - -#include "SDL\include\SDL_render.h" -#include "SDL\include\SDL_timer.h" - -j1FadeToBlack::j1FadeToBlack() -{ - -} - -j1FadeToBlack:: ~j1FadeToBlack() -{ - -} - -bool j1FadeToBlack::Awake(pugi::xml_node&) -{ - screen = { 0, 0, App->win->width*App->win->scale, App->win->height*App->win->scale }; - return true; -} - -bool j1FadeToBlack::Start() -{ - LOG("Preparing FadeToBlack"); - SDL_SetRenderDrawBlendMode(App->render->renderer, SDL_BLENDMODE_BLEND); - return true; -} - -bool j1FadeToBlack::Update(float dt) -{ - if (current_step == fade_step::none) - { - return true; - } - - uint now = SDL_GetTicks() - start_time; - float normalized = 1.0f < ((float)now / (float)total_time) ? 1.0f : ((float)now / (float)total_time); - - - switch (current_step) - { - case fade_step::fade_to_black: - { - if (now >= total_time) //Point where the screen is totally black, and the new map is loaded. - { - App->map->ChangeMap(map_name); //Here the map is changed - - total_time += total_time; - start_time = SDL_GetTicks(); - fading = false; - current_step = fade_step::fade_from_black; - } - } - break; - - case fade_step::fade_from_black: - { - normalized = 1.0f - normalized; - - if (now >= total_time) - { - current_step = fade_step::none; - } - - } - break; - } - - SDL_SetRenderDrawColor(App->render->renderer, 0, 0, 0, (Uint8)(normalized * 255.0f)); - SDL_RenderFillRect(App->render->renderer, &screen); - - return true; -} - -bool j1FadeToBlack::Fade_To_Black(const char* mapname, float time) -{ - bool ret = false; - - map_name = mapname; - - if (current_step == fade_step::none) - { - current_step = fade_step::fade_to_black; - start_time = SDL_GetTicks(); - total_time = (Uint32)(time * 0.5f * 1000.0f); - ret = true; - } - - return ret; -} \ No newline at end of file +//#include "p2Point.h" +//#include "p2Log.h" +//#include "j1Module.h" +//#include "j1App.h" +//#include "j1Textures.h" +//#include "j1Render.h" +//#include "j1Input.h" +//#include "Animation.h" +//#include "j1Player.h" +//#include "j1Audio.h" +//#include "j1Collision.h" +//#include "j1FadeToBlack.h" +// +//#include "SDL\include\SDL_render.h" +//#include "SDL\include\SDL_timer.h" +// +//j1FadeToBlack::j1FadeToBlack(){} +// +//j1FadeToBlack:: ~j1FadeToBlack() {} +// +//bool j1FadeToBlack::Awake(pugi::xml_node&) +//{ +// screen = {0,0,App->win->width*App->win->scale,} +// return true; +//} diff --git a/SantaRules/Motor2D/j1FadeToBlack.h b/SantaRules/Motor2D/j1FadeToBlack.h index a320b12..0107bb6 100644 --- a/SantaRules/Motor2D/j1FadeToBlack.h +++ b/SantaRules/Motor2D/j1FadeToBlack.h @@ -1,45 +1,47 @@ -#ifndef __j1FADETOBLACK_H__ -#define __j1FADETOBLACK_H__ - -#include "j1Module.h" -#include "SDL\include\SDL_rect.h" - - -class j1FadeToBlack : public j1Module -{ -public: - j1FadeToBlack(); - - virtual ~j1FadeToBlack(); - - // Called before render is available - bool Awake(pugi::xml_node&); - - // Called before the first frame - bool Start(); - - // Called each loop iteration - bool Update(float dt); - - bool Fade_To_Black(const char* mapname, float time); - - bool fading = false; - -private: - enum fade_step - { - none, - fade_to_black, - fade_from_black - } current_step = fade_step::none; - - Uint32 start_time = 0; - Uint32 total_time = 0; - SDL_Rect screen; - const char* map_name; - int nextMap; - - -}; - -#endif // __j1FADETOBLACK_H__ \ No newline at end of file +//#ifndef __j1FADETOBLACK_H__ +//#define __j1FADETOBLACK_H__ +// +//#include "j1Module.h" +//#include "SDL\include\SDL_rect.h" + +// +//class j1FadeToBlack : public j1Module +//{ +//public: +// j1FadeToBlack(); +// +// virtual ~j1FadeToBlack(); +// +// // Called before render is available +// bool Awake(pugi::xml_node&); +// +// // Called before the first frame +// bool Start(); +// +// // Called each loop iteration +// bool Update(); +// +// // Called before quitting +// bool CleanUp(); +// +// bool Change_Map(const char* nextMap); +// +// bool Fade_To_Black(const char* map, float time = 1.5f); +// +// +//private: +// enum fade_step +// { +// none, +// fade_to_black, +// fade_from_black +// } current_step = fade_step::none; +// +// Uint32 start_time = 0; +// Uint32 total_time = 0; +// SDL_Rect screen; +// const char* map_name; +// +//}; +// +//#endif // __j1FADETOBLACK_H__ \ No newline at end of file diff --git a/SantaRules/Motor2D/j1Input.cpp b/SantaRules/Motor2D/j1Input.cpp index 4b10fb0..d671348 100644 --- a/SantaRules/Motor2D/j1Input.cpp +++ b/SantaRules/Motor2D/j1Input.cpp @@ -34,6 +34,7 @@ bool j1Input::Awake(pugi::xml_node& config) LOG("SDL_EVENTS could not initialize! SDL_Error: %s\n", SDL_GetError()); ret = false; } + return ret; } diff --git a/SantaRules/Motor2D/j1Map.cpp b/SantaRules/Motor2D/j1Map.cpp index b9212e7..e5bbdb3 100644 --- a/SantaRules/Motor2D/j1Map.cpp +++ b/SantaRules/Motor2D/j1Map.cpp @@ -573,55 +573,12 @@ bool j1Map::CreateWalkabilityMap(int& width, int& height, uchar** buffer) const return ret; } -bool j1Map::SwitchMaps(p2SString* new_map) // switch map function that passes the number of map defined in config.xml +bool j1Map::isGround(uint x, uint y) { - CleanUp(); - App->scene->to_end = false; - Load(new_map->GetString()); + uint tileid = Metadata->GetLayerPositon(x, y); + if (Metadata->data[tileid + App->map->Metadata->width] != NULL) + uint groundTileid = Metadata->data[tileid + App->map->Metadata->width]; - return true; -} - -bool j1Map::ChangeMap(const char* newMap) -{ - bool ret = true; - - App->scene->CleanUp(); - - App->map->Load(newMap); - //Load Collisions - - if (newMap == "map_1.tmx") - { - App->scene->Map_1 = true; - App->scene->Map_2 = false; - - //This needs to be changed somewhere else. Here it works but probably this is not it's place. - int w, h; - uchar* data = NULL; - if (App->map->CreateWalkabilityMap(w, h, &data)) //If CreatewalkabilityMap() returns true. It means that the walkability map could be created. - { - App->pathfinding->SetMap(w, h, data); //Sets a new walkability map with the map passed by CreateWalkabilityMap(). - } - - RELEASE_ARRAY(data); - } - if (newMap == "map_2.tmx") - { - App->scene->Map_1 = false; - App->scene->Map_2 = true; - - int w, h; - uchar* data = NULL; - if (App->map->CreateWalkabilityMap(w, h, &data)) //If CreatewalkabilityMap() returns true. It means that the walkability map could be created. - { - App->pathfinding->SetMap(w, h, data); //Sets a new walkability map with the map passed by CreateWalkabilityMap(). - } - - RELEASE_ARRAY(data); - } - - App->manager->Player->Start(); //Load / Reset P1 //REVISE THIS HERE. Should players be loaded like this? - - return ret; + else + return false; } \ No newline at end of file diff --git a/SantaRules/Motor2D/j1Map.h b/SantaRules/Motor2D/j1Map.h index 4aba6a2..1db1413 100644 --- a/SantaRules/Motor2D/j1Map.h +++ b/SantaRules/Motor2D/j1Map.h @@ -7,6 +7,9 @@ #include "j1Module.h" #include "SDL_image/include/SDL_image.h" +// TODO 5: Create a generic structure to hold properties +// TODO 7: Our custom properties should have one method +// to ask for the value of a custom property // ---------------------------------------------------- struct Properties { @@ -130,11 +133,7 @@ class j1Map : public j1Module iPoint MapToWorld(int x, int y) const; iPoint WorldToMap(int x, int y) const; bool CreateWalkabilityMap(int& width, int& height, uchar** buffer) const; - - bool SwitchMaps(p2SString* new_map); - bool ChangeMap(const char* newMap); //Change map with a fade time - - + bool isGround(uint x, uint y); private: bool LoadMap(); @@ -154,8 +153,6 @@ class j1Map : public j1Module uint win_height = 0; bool drawLayer; - int tile_index; //Will store the tile's index - private: diff --git a/SantaRules/Motor2D/j1Pathfinding.cpp b/SantaRules/Motor2D/j1Pathfinding.cpp index c7c0655..fad5567 100644 --- a/SantaRules/Motor2D/j1Pathfinding.cpp +++ b/SantaRules/Motor2D/j1Pathfinding.cpp @@ -2,6 +2,8 @@ #include "p2Log.h" #include "j1App.h" #include "j1PathFinding.h" +#include "p2Point.h" +#include "j1Map.h" j1PathFinding::j1PathFinding() : j1Module(), map(NULL), last_path(DEFAULT_PATH_LENGTH), width(0), height(0) { @@ -61,7 +63,16 @@ uchar j1PathFinding::GetTileAt(const iPoint& pos) const // To request all tiles involved in the last generated path const p2DynArray* j1PathFinding::GetLastPath() const { - return &last_path; + return &last_path; +} + +void j1PathFinding::CopyPathList(p2List* empty_list) +{ + empty_list->clear(); + for (p2List_item* item = path_list.start; item != nullptr; item = item->next) + { + empty_list->add(item->data); + } } // PathList ------------------------------------------------------------------------ @@ -191,13 +202,28 @@ int j1PathFinding::CreatePath(const iPoint& origin, const iPoint& destination) // TODO 4: If we just added the destination, we are done! if (current->data.pos == destination) { + path_list.clear(); last_path.Clear(); // Backtrack to create the final path for (const PathNode* node = ¤t->data; node != NULL; node = node->parent) + { last_path.PushBack(node->pos); + path_list.add(node->pos); + } + // Use the Pathnode::parent and Flip() the path when you are finish last_path.Flip(); + + p2List last_path_flipped; + for (p2List_item* item = path_list.start; item != nullptr; item = item->next) + { + last_path_flipped.add(item->data); + } + + path_list.clear(); + path_list += last_path_flipped; + LOG("Distance to destinaton of: %d", last_path.Count()); ret = last_path.Count(); break; diff --git a/SantaRules/Motor2D/j1Pathfinding.h b/SantaRules/Motor2D/j1Pathfinding.h index 288991f..f6be6e9 100644 --- a/SantaRules/Motor2D/j1Pathfinding.h +++ b/SantaRules/Motor2D/j1Pathfinding.h @@ -44,6 +44,8 @@ class j1PathFinding : public j1Module // Utility: return the walkability value of a tile uchar GetTileAt(const iPoint& pos) const; + void CopyPathList(p2List* given_list); + private: // size of the map @@ -53,6 +55,8 @@ class j1PathFinding : public j1Module uchar* map; // we store the created path here p2DynArray last_path; + + p2List path_list; }; // forward declaration diff --git a/SantaRules/Motor2D/j1PerfTimer.cpp b/SantaRules/Motor2D/j1PerfTimer.cpp deleted file mode 100644 index f33f345..0000000 --- a/SantaRules/Motor2D/j1PerfTimer.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// ---------------------------------------------------- -// j1PerfTimer.cpp -// Slow timer with microsecond precision -// ---------------------------------------------------- - -#include "j1PerfTimer.h" -#include "SDL\include\SDL_timer.h" - -uint64 j1PerfTimer::frequency = 0; - -// --------------------------------------------- -j1PerfTimer::j1PerfTimer() -{ - if (frequency == 0) - { - frequency = SDL_GetPerformanceFrequency(); // Frequency into cycles of seconds (from microsenconds). - } - - Start(); -} - -// --------------------------------------------- -void j1PerfTimer::Start() -{ - started_at = SDL_GetPerformanceCounter(); //Initializes the timer in microseconds. -} - -// --------------------------------------------- -double j1PerfTimer::ReadMs() const -{ - return ((SDL_GetPerformanceCounter() - started_at)) / (frequency / 1000.0f); //Miliseconds since timer started (Start()). The first part is in microseconds and the second one is in seconds, needed to be translated. -} - -// --------------------------------------------- -uint64 j1PerfTimer::ReadTicks() const -{ - return SDL_GetPerformanceCounter() - started_at; //Checks how many ticks (in microseconds) have passed since the timer started (Start()). -} \ No newline at end of file diff --git a/SantaRules/Motor2D/j1PerfTimer.h b/SantaRules/Motor2D/j1PerfTimer.h deleted file mode 100644 index 6dc798b..0000000 --- a/SantaRules/Motor2D/j1PerfTimer.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __j1PERFTIMER_H__ -#define __j1PERFTIMER_H__ - -#include "p2Defs.h" - -class j1PerfTimer -{ -public: - - // Constructor - j1PerfTimer(); - - void Start(); - double ReadMs() const; - uint64 ReadTicks() const; - -private: - uint64 started_at; - static uint64 frequency; //As frequency will be the same across all timers, we declare it as static. That way, when frequency is initialized, the variable will carry its values through function calls instead of being reset to 0. -}; - -#endif //__j1PERFTIMER_H__ \ No newline at end of file diff --git a/SantaRules/Motor2D/j1Player.cpp b/SantaRules/Motor2D/j1Player.cpp index 093fcde..3d4a2c9 100644 --- a/SantaRules/Motor2D/j1Player.cpp +++ b/SantaRules/Motor2D/j1Player.cpp @@ -409,57 +409,57 @@ // { // case ST_IDLE: // LOG("IDLE"); -// EntityAnimation = &idle; +// current_animation = &idle; // break; // // case ST_LEFT_W: // LOG("WALKING LEFT"); // flipped = true; // CurrentPosition.x -= PlayerVel_w; -// EntityAnimation = &walking; +// current_animation = &walking; // break; // // case ST_LEFT_R: // LOG("RUNNING LEFT"); // flipped = true; // CurrentPosition.x -= PlayerVel_r; -// EntityAnimation = &running; +// current_animation = &running; // break; // // case ST_RIGHT_W: // LOG("WALKING RIGHT"); // flipped = false; // CurrentPosition.x += PlayerVel_w; -// EntityAnimation = &walking; +// current_animation = &walking; // break; // // case ST_RIGHT_R: // LOG("RUNNING RIGHT"); // flipped = false; // CurrentPosition.x += PlayerVel_r; -// EntityAnimation = &running; +// current_animation = &running; // break; // // case ST_JUMPING: // LOG("JUMPING"); // -// EntityAnimation = &jumping; +// current_animation = &jumping; // //FALTA // break; // // case ST_SLIDING: // LOG("SLIDING"); -// EntityAnimation = &sliding; +// current_animation = &sliding; // break; // // case ST_CLIMBING: // LOG("CLIMBING"); -// EntityAnimation = &climbing; +// current_animation = &climbing; // break; // // case ST_DYING: // LOG("DYING"); -// EntityAnimation = &dying; +// current_animation = &dying; // break; // } // @@ -469,7 +469,7 @@ // // // //ANIMATIONS -// rotating_animation = EntityAnimation->GetCurrentFrame(); +// rotating_animation = current_animation->GetCurrentFrame(); // App->render->Blit(Graphics, CurrentPosition.x, CurrentPosition.y, &rotating_animation, flipped); // // diff --git a/SantaRules/Motor2D/j1Player.h b/SantaRules/Motor2D/j1Player.h index af84bbd..a07f6e8 100644 --- a/SantaRules/Motor2D/j1Player.h +++ b/SantaRules/Motor2D/j1Player.h @@ -7,8 +7,6 @@ //#include "p2Point.h" //#include "Animation.h" // -// -// //struct SDL_Texture; //struct Animation; //struct Collider; @@ -59,13 +57,10 @@ // iPoint Initial_Pos; //player exclusive // //public: -// //AUDIO -// // // //SHORTCUTS // bool God_Mode = false; // player only // -// // //TESTING - TEMPORAL // float Floor = CurrentPosition.y; //Movement // @@ -106,7 +101,7 @@ // // //ANIMATION // //Draw diferents animations -// Animation* EntityAnimation; +// Animation* current_animation; // SDL_Rect rotating_animation; // bool flipped = false; // //Idle diff --git a/SantaRules/Motor2D/j1Scene.cpp b/SantaRules/Motor2D/j1Scene.cpp index 61d309c..820137e 100644 --- a/SantaRules/Motor2D/j1Scene.cpp +++ b/SantaRules/Motor2D/j1Scene.cpp @@ -13,7 +13,7 @@ #include "j1Pathfinding.h" #include "j1EntityManager.h" #include "j1EntityPlayer.h" -#include "j1FadeToBlack.h" +#include "p2DynArray.h" j1Scene::j1Scene() : j1Module() { @@ -25,45 +25,23 @@ j1Scene::~j1Scene() {} // Called before render is available -bool j1Scene::Awake(pugi::xml_node& config) +bool j1Scene::Awake() { LOG("Loading Scene"); bool ret = true; - transition_time = config.child("transition_time").attribute("value").as_float(); - - for (pugi::xml_node map = config.child("map_name"); map; map = map.next_sibling("map_name")) - { - p2SString* data = new p2SString; - - data->create(map.attribute("name").as_string()); - map_names.add(data); - } - return ret; } // Called before the first frame bool j1Scene::Start() { - bool ret; - - to_end = false; - Map_1 = true; - Map_2 = false; - - ret = App->map->Load(map_names.start->data->GetString()); - LOG("Currenmt Level: %s", map_names.start->data->GetString()); - - - if (App->map->Load(map_names.start->data->GetString()) == true) + App->map->Load("map_1.tmx"); { int w, h; uchar* data = NULL; if (App->map->CreateWalkabilityMap(w, h, &data)) - { App->pathfinding->SetMap(w, h, data); - } RELEASE_ARRAY(data); } @@ -75,83 +53,31 @@ bool j1Scene::Start() // Called each loop iteration bool j1Scene::PreUpdate() -{ - // debug pathfing ------------------ - static iPoint origin; - static bool origin_selected = false; - - int x, y; - App->input->GetMousePosition(x, y); - iPoint p = App->render->ScreenToWorld(x, y); - p = App->map->WorldToMap(p.x, p.y); - iPoint Player_pos = App->map->WorldToMap(App->manager->Player->CurrentPosition.x, App->manager->Player->CurrentPosition.y); - - if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN) - { - if (origin_selected == true) - { - App->pathfinding->CreatePath(origin, p); - origin_selected = false; - } - else - { - origin = Player_pos; - origin_selected = true; - } - } - - /*if (App->input->GetKey(SDL_SCANCODE_U) == KEY_DOWN) - { - App->pathfinding->CreatePath((iPoint(0,0), iPoint(camera)); - }*/ +{ return true; } // Called each loop iteration bool j1Scene::Update(float dt) { - //camera movement with keys - if (App->input->GetKey(SDL_SCANCODE_LEFT) == KEY_REPEAT) - { - App->render->camera.x += ceil(camera_speed_debugg * dt); //As the value is multiplied by dt, camera movement will be adjusted to the framerate. (100 * 0.033s (30fps), 100 * 0.066s (60fps)...) - } - if (App->input->GetKey(SDL_SCANCODE_RIGHT) == KEY_REPEAT) - { - App->render->camera.x -= ceil(camera_speed_debugg * dt); //Ceil rounds up all the decimal values, returning the smallest integral value not less than the given value. - } - if (App->input->GetKey(SDL_SCANCODE_UP) == KEY_REPEAT) - { - App->render->camera.y += ceil(camera_speed_debugg * dt); - } - if (App->input->GetKey(SDL_SCANCODE_DOWN) == KEY_REPEAT) - { - App->render->camera.y -= ceil(camera_speed_debugg * dt); - } + if(App->input->GetKey(SDL_SCANCODE_L) == KEY_DOWN) + App->LoadGame("save_game.xml"); - //Debugg keys - if (App->manager->Player->PlayerInput.F1_enabled) //Load First Level - { - App->fade->Fade_To_Black("map_1.tmx", transition_time); - } - if (App->manager->Player->PlayerInput.F2_enabled) //Load Second Level - { - App->fade->Fade_To_Black("map_2.tmx",transition_time); - } - if (App->manager->Player->PlayerInput.F3_enabled) //Restart Key - { - App->manager->Player->CurrentPosition.x = App->manager->Player->StartingPosition.x; - App->manager->Player->CurrentPosition.y = App->manager->Player->StartingPosition.y; - } - if (App->manager->Player->PlayerInput.F5_enabled) //Save Game Key - { + if(App->input->GetKey(SDL_SCANCODE_F5) == KEY_DOWN) App->SaveGame("save_game.xml"); - } - if (App->manager->Player->PlayerInput.F6_enabled) //Load Game Key - { - App->LoadGame("save_game.xml"); - } + if(App->input->GetKey(SDL_SCANCODE_UP) == KEY_REPEAT) + App->render->camera.y += 1; + + if(App->input->GetKey(SDL_SCANCODE_DOWN) == KEY_REPEAT) + App->render->camera.y -= 1; + + if(App->input->GetKey(SDL_SCANCODE_LEFT) == KEY_REPEAT) + App->render->camera.x += 1; + if(App->input->GetKey(SDL_SCANCODE_RIGHT) == KEY_REPEAT) + App->render->camera.x -= 1; + uint win_height = 0; uint win_width = 0; App->win->GetWindowSize(win_width, win_height); @@ -161,21 +87,16 @@ bool j1Scene::Update(float dt) App->map->Draw(); App->coll->DebugDraw(); - //------------------------------------------------------------------- - //Uncomment to show coordinates on title for debugg functions - int x, y; App->input->GetMousePosition(x, y); iPoint map_coordinates = App->map->WorldToMap(x - App->render->camera.x, y - App->render->camera.y); - /*p2SString title("Map:%dx%d Tiles:%dx%d Tilesets:%d Tile:%d,%d", + p2SString title("Map:%dx%d Tiles:%dx%d Tilesets:%d Tile:%d,%d", App->map->data.width, App->map->data.height, App->map->data.tile_width, App->map->data.tile_height, App->map->data.tilesets.count(), map_coordinates.x, map_coordinates.y); - App->win->SetTitle(title.GetString());*/ - - //------------------------------------------------------------------- + App->win->SetTitle(title.GetString()); // Debug pathfinding ------------------------------ //int x, y; @@ -195,7 +116,7 @@ bool j1Scene::Update(float dt) App->render->Blit(debug_tex, pos.x, pos.y); } - if (i == 100 && j < path->Count()) + if (i == 10 && j < path->Count()) { iPoint pos = App->map->MapToWorld(path->At(j)->x, path->At(j)->y); App->manager->Player->CurrentPosition = pos; @@ -210,10 +131,8 @@ bool j1Scene::PostUpdate() { bool ret = true; - if (App->input->GetKey(SDL_SCANCODE_ESCAPE) == KEY_DOWN) - { + if(App->input->GetKey(SDL_SCANCODE_ESCAPE) == KEY_DOWN) ret = false; - } return ret; } @@ -223,31 +142,5 @@ bool j1Scene::CleanUp() { LOG("Freeing scene"); - App->coll->CleanUp(); - //App->manager->DestroyEntity(fffffffffff); //all entities destroyed - App->map->CleanUp(); - if (App->manager->Player != nullptr) - { - App->manager->Player->CleanUp(); - } - return true; -} - -bool j1Scene::Save(pugi::xml_node& data) const -{ - data.append_child("currentMap").append_attribute("num") = currentMap; return true; } - -bool j1Scene::Load(pugi::xml_node& data) -{ - - if (currentMap != data.child("currentMap").attribute("num").as_int()) - { - LOG("Calling switch maps"); - currentMap = data.child("currentMap").attribute("num").as_int(); - App->map->SwitchMaps(map_names[data.child("currentMap").attribute("num").as_int()]); - - } - return true; -} \ No newline at end of file diff --git a/SantaRules/Motor2D/j1Scene.h b/SantaRules/Motor2D/j1Scene.h index a9fb3e3..018da21 100644 --- a/SantaRules/Motor2D/j1Scene.h +++ b/SantaRules/Motor2D/j1Scene.h @@ -7,12 +7,6 @@ struct SDL_Texture; -enum ListOfMapNames -{ - FirstLevel, - SecondLevel -}; - class j1Scene : public j1Module { public: @@ -23,7 +17,7 @@ class j1Scene : public j1Module virtual ~j1Scene(); // Called before render is available - bool Awake(pugi::xml_node&); + bool Awake(); // Called before the first frame bool Start(); @@ -40,21 +34,8 @@ class j1Scene : public j1Module // Called before quitting bool CleanUp(); - bool Load(pugi::xml_node& data); - bool Save(pugi::xml_node& data) const; - -public: - p2List map_names; - int currentMap; - float transition_time; - - bool to_end; - bool Map_1; - bool Map_2; - private: - SDL_Texture* debug_tex; - float camera_speed_debugg; + SDL_Texture* debug_tex; uint i = 0; // PF test uint j = 0; // PF test }; diff --git a/SantaRules/Motor2D/j1Timer.cpp b/SantaRules/Motor2D/j1Timer.cpp deleted file mode 100644 index 32906b4..0000000 --- a/SantaRules/Motor2D/j1Timer.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// ---------------------------------------------------- -// j1Timer.cpp -// Fast timer with milisecons precision -// ---------------------------------------------------- - -#include "j1Timer.h" -#include "SDL\include\SDL_timer.h" - -// --------------------------------------------- -j1Timer::j1Timer() -{ - Start(); -} - -// --------------------------------------------- -void j1Timer::Start() //Velocity rather than precision, SDL_GetTicks() instead of SDL_GetPerformanceCounter. -{ - started_at = SDL_GetTicks(); //Amount of ticks (in milliseconds) whenever the function is called. Used to set the start of the timer. -} - -// --------------------------------------------- -uint32 j1Timer::Read() const -{ - return SDL_GetTicks() - started_at; //Time (in milliseconds) since Start() function call. -} - -// --------------------------------------------- -float j1Timer::ReadSec() const -{ - return (SDL_GetTicks() - started_at) / 1000.0f; //Time passed from Start method call until this method's call. ms converted to seconds. -} \ No newline at end of file diff --git a/SantaRules/Motor2D/j1Timer.h b/SantaRules/Motor2D/j1Timer.h deleted file mode 100644 index fc967a5..0000000 --- a/SantaRules/Motor2D/j1Timer.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __j1TIMER_H__ -#define __j1TIMER_H__ - -#include "p2Defs.h" - -class j1Timer -{ -public: - - // Constructor - j1Timer(); - - void Start(); - uint32 Read() const; - float ReadSec() const; - -private: - uint32 started_at; -}; - -#endif //__j1TIMER_H__ diff --git a/SantaRules/Motor2D/j1Window.h b/SantaRules/Motor2D/j1Window.h index 8540cd6..c724310 100644 --- a/SantaRules/Motor2D/j1Window.h +++ b/SantaRules/Motor2D/j1Window.h @@ -40,11 +40,11 @@ class j1Window : public j1Module //The surface contained by the window SDL_Surface* screen_surface; -public: +private: p2SString title; - int width; - int height; - int scale; + uint width; + uint height; + uint scale; }; #endif // __j1WINDOW_H__ \ No newline at end of file diff --git a/SantaRules/Motor2D/p2Defs.h b/SantaRules/Motor2D/p2Defs.h index da657a3..8229a10 100644 --- a/SantaRules/Motor2D/p2Defs.h +++ b/SantaRules/Motor2D/p2Defs.h @@ -38,8 +38,6 @@ typedef unsigned int uint; typedef unsigned char uchar; -typedef unsigned __int32 uint32; -typedef unsigned __int64 uint64; template void SWAP(VALUE_TYPE& a, VALUE_TYPE& b) { diff --git a/SantaRules/Motor2D/p2DynArray.h b/SantaRules/Motor2D/p2DynArray.h index e6e856c..272cff2 100644 --- a/SantaRules/Motor2D/p2DynArray.h +++ b/SantaRules/Motor2D/p2DynArray.h @@ -61,6 +61,11 @@ class p2DynArray return(*this); } + const VALUE& getElementAt(uint index) + { + return data[index]; + } + // Data Management void PushBack(const VALUE& element) { @@ -244,6 +249,13 @@ class p2DynArray SWAP(*start++, *end--); } + const void CopyData(p2DynArray dataPointer) + { + dataPointer.num_elements = num_elements; + dataPointer.mem_capacity = mem_capacity; + dataPointer.data = data; + } + private: // Private Utils diff --git a/SantaRules/Santa_Rules.sln b/SantaRules/upc_videojocs.sln similarity index 100% rename from SantaRules/Santa_Rules.sln rename to SantaRules/upc_videojocs.sln diff --git a/Tileset documents/map_2.tmx b/Tileset documents/map_2.tmx index 70033df..3df3737 100644 --- a/Tileset documents/map_2.tmx +++ b/Tileset documents/map_2.tmx @@ -1,6 +1,8 @@ - - + + + +