demo map
This commit is contained in:
@@ -15,7 +15,6 @@ namespace Demo {
|
||||
enum IntroStateType {
|
||||
STATE_PS2DEV,
|
||||
STATE_TYRA,
|
||||
STATE_WAR_INFO,
|
||||
STATE_PRESS_KEY,
|
||||
STATE_INTRO_END
|
||||
};
|
||||
|
||||
+14
-5
@@ -18,13 +18,14 @@
|
||||
using Tyra::Sprite;
|
||||
using Tyra::Texture;
|
||||
using Tyra::Timer;
|
||||
using Tyra::Vec2;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
class IntroWarInfoState : public State<IntroStateType> {
|
||||
class IntroPressKeyState : public State<IntroStateType> {
|
||||
public:
|
||||
IntroWarInfoState(Engine* t_engine);
|
||||
~IntroWarInfoState();
|
||||
IntroPressKeyState(Engine* t_engine);
|
||||
~IntroPressKeyState();
|
||||
|
||||
const IntroStateType& getState() const { return state; }
|
||||
|
||||
@@ -38,12 +39,20 @@ class IntroWarInfoState : public State<IntroStateType> {
|
||||
IntroStateType onFinish();
|
||||
|
||||
private:
|
||||
void updateMap();
|
||||
|
||||
IntroStateType state;
|
||||
bool _wantFinish;
|
||||
bool initialized;
|
||||
|
||||
Texture* warInfoTexture;
|
||||
Sprite* warInfoSprite;
|
||||
const static u8 mapRows = 3;
|
||||
const static u8 mapCols = 3;
|
||||
|
||||
Vec2 mapPosition;
|
||||
u8 mapDirection;
|
||||
|
||||
Texture* mapTextures[mapRows][mapCols];
|
||||
Sprite* mapSprites[mapRows][mapCols];
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -14,14 +14,14 @@
|
||||
|
||||
#include "states/intro/states/intro_ps2dev_state.hpp"
|
||||
#include "states/intro/states/intro_tyra_state.hpp"
|
||||
#include "states/intro/states/intro_war_info_state.hpp"
|
||||
#include "states/intro/states/intro_press_key_state.hpp"
|
||||
|
||||
using Tyra::FileUtils;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
IntroState::IntroState(Engine* t_engine)
|
||||
: State(t_engine), stateManager(STATE_WAR_INFO) {
|
||||
: State(t_engine), stateManager(STATE_PRESS_KEY) {
|
||||
state = STATE_INTRO;
|
||||
_wantFinish = false;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ void IntroState::onStart() {
|
||||
|
||||
stateManager.add(new IntroPs2DevState(engine));
|
||||
stateManager.add(new IntroTyraState(engine));
|
||||
stateManager.add(new IntroWarInfoState(engine));
|
||||
stateManager.add(new IntroPressKeyState(engine));
|
||||
}
|
||||
|
||||
void IntroState::update() { stateManager.update(); }
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "states/intro/states/intro_press_key_state.hpp"
|
||||
#include "loaders/texture/png_loader.hpp"
|
||||
#include "file/file_utils.hpp"
|
||||
#include "debug/debug.hpp"
|
||||
#include <string>
|
||||
#include "thread/threading.hpp"
|
||||
#include "math/math.hpp"
|
||||
|
||||
using Tyra::FileUtils;
|
||||
using Tyra::Math;
|
||||
using Tyra::PngLoader;
|
||||
using Tyra::Threading;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
IntroPressKeyState::IntroPressKeyState(Engine* t_engine)
|
||||
: State(t_engine), mapPosition(0.0F, 0.0F) {
|
||||
state = STATE_PRESS_KEY;
|
||||
mapDirection = 0;
|
||||
_wantFinish = false;
|
||||
}
|
||||
|
||||
IntroPressKeyState::~IntroPressKeyState() {
|
||||
if (!initialized) return;
|
||||
|
||||
for (u8 i = 0; i < mapRows; i++)
|
||||
for (u8 j = 0; j < mapCols; j++) {
|
||||
engine->renderer.core.texture.repository.free(mapTextures[i][j]->getId());
|
||||
delete mapSprites[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
void IntroPressKeyState::onStart() {
|
||||
for (u8 i = 0; i < mapRows; i++) {
|
||||
for (u8 j = 0; j < mapCols; j++) {
|
||||
mapSprites[i][j] = new Sprite;
|
||||
mapSprites[i][j]->size.set(512.0F, 512.0F);
|
||||
mapSprites[i][j]->position.set(i * 512.0F, j * 512.0F);
|
||||
|
||||
std::string filename =
|
||||
"map-" + std::to_string(i) + "-" + std::to_string(j);
|
||||
std::string path = "intro/map/" + filename + ".png";
|
||||
|
||||
mapTextures[i][j] = engine->renderer.core.texture.repository.add(
|
||||
FileUtils::fromCwd(path));
|
||||
mapTextures[i][j]->addLink(mapSprites[i][j]->getId());
|
||||
}
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void IntroPressKeyState::update() {
|
||||
engine->renderer.beginFrame();
|
||||
|
||||
if (mapDirection == 0 && mapPosition.x >= 512.0F * (mapRows - 1) &&
|
||||
mapPosition.y >= 512.0F * (mapCols - 1)) {
|
||||
mapDirection = 1;
|
||||
} else if (mapDirection == 1 && mapPosition.x <= 0.0F &&
|
||||
mapPosition.y <= 0.0F) {
|
||||
mapDirection = 0;
|
||||
}
|
||||
|
||||
if (mapDirection == 0) {
|
||||
mapPosition += .5F;
|
||||
} else if (mapDirection == 1) {
|
||||
mapPosition -= .5F;
|
||||
}
|
||||
|
||||
updateMap();
|
||||
Threading::switchThread();
|
||||
|
||||
for (u8 i = 0; i < mapRows; i++)
|
||||
for (u8 j = 0; j < mapCols; j++)
|
||||
engine->renderer.renderer2D.render(mapSprites[i][j]);
|
||||
|
||||
engine->renderer.endFrame();
|
||||
}
|
||||
|
||||
IntroStateType IntroPressKeyState::onFinish() { return STATE_INTRO_END; }
|
||||
|
||||
void IntroPressKeyState::updateMap() {
|
||||
for (u8 i = 0; i < mapRows; i++)
|
||||
for (u8 j = 0; j < mapCols; j++) {
|
||||
mapSprites[i][j]->position.x = i * 512.0F - mapPosition.x;
|
||||
mapSprites[i][j]->position.y = j * 512.0F - mapPosition.y;
|
||||
}
|
||||
}
|
||||
} // namespace Demo
|
||||
@@ -170,6 +170,6 @@ void IntroTyraState::renderFillers() {
|
||||
engine->renderer.renderer2D.render(fillerSprite);
|
||||
}
|
||||
|
||||
IntroStateType IntroTyraState::onFinish() { return STATE_WAR_INFO; }
|
||||
IntroStateType IntroTyraState::onFinish() { return STATE_PRESS_KEY; }
|
||||
|
||||
} // namespace Demo
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "states/intro/states/intro_war_info_state.hpp"
|
||||
#include "loaders/texture/png_loader.hpp"
|
||||
#include "file/file_utils.hpp"
|
||||
#include "debug/debug.hpp"
|
||||
#include "thread/threading.hpp"
|
||||
#include "math/math.hpp"
|
||||
|
||||
using Tyra::FileUtils;
|
||||
using Tyra::Math;
|
||||
using Tyra::PngLoader;
|
||||
using Tyra::Threading;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
IntroWarInfoState::IntroWarInfoState(Engine* t_engine) : State(t_engine) {
|
||||
state = STATE_WAR_INFO;
|
||||
_wantFinish = false;
|
||||
}
|
||||
|
||||
IntroWarInfoState::~IntroWarInfoState() {
|
||||
if (!initialized) return;
|
||||
}
|
||||
|
||||
void IntroWarInfoState::onStart() {
|
||||
warInfoSprite = new Sprite;
|
||||
warInfoSprite->size.set(512.0F, 512.0F);
|
||||
warInfoSprite->position.set(0.0F, 0.0F);
|
||||
|
||||
warInfoTexture = engine->renderer.core.texture.repository.add(
|
||||
FileUtils::fromCwd("intro/war_info.png"));
|
||||
warInfoTexture->addLink(warInfoSprite->getId());
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void IntroWarInfoState::update() {
|
||||
engine->renderer.beginFrame();
|
||||
|
||||
Threading::switchThread();
|
||||
|
||||
engine->renderer.renderer2D.render(warInfoSprite);
|
||||
|
||||
engine->renderer.endFrame();
|
||||
}
|
||||
IntroStateType IntroWarInfoState::onFinish() { return STATE_PRESS_KEY; }
|
||||
|
||||
} // namespace Demo
|
||||
Reference in New Issue
Block a user