finished demo intro
This commit is contained in:
@@ -39,12 +39,19 @@ class IntroPressKeyState : public State<IntroStateType> {
|
|||||||
IntroStateType onFinish();
|
IntroStateType onFinish();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void renderFiller();
|
||||||
void updateMap();
|
void updateMap();
|
||||||
|
|
||||||
IntroStateType state;
|
IntroStateType state;
|
||||||
bool _wantFinish;
|
bool _wantFinish;
|
||||||
bool initialized;
|
bool initialized;
|
||||||
|
bool mapFadeIn;
|
||||||
|
bool fillerFadeIn;
|
||||||
|
bool showPressKey;
|
||||||
|
bool pressKeyAlphaToggle;
|
||||||
|
u8 pressKeyAlphaDelayer;
|
||||||
|
|
||||||
|
float fillersOffset;
|
||||||
constexpr static float textureWidthHeight = 512.0F;
|
constexpr static float textureWidthHeight = 512.0F;
|
||||||
const static u8 mapRows = 3;
|
const static u8 mapRows = 3;
|
||||||
const static u8 mapCols = 3;
|
const static u8 mapCols = 3;
|
||||||
@@ -52,6 +59,15 @@ class IntroPressKeyState : public State<IntroStateType> {
|
|||||||
Vec2 mapPosition;
|
Vec2 mapPosition;
|
||||||
u8 mapDirection;
|
u8 mapDirection;
|
||||||
|
|
||||||
|
Texture* fillerTexture;
|
||||||
|
Sprite* fillerSprite;
|
||||||
|
|
||||||
|
Texture* logoTexture;
|
||||||
|
Sprite* logoSprite;
|
||||||
|
|
||||||
|
Texture* pressKeyTexture;
|
||||||
|
Sprite* pressKeySprite;
|
||||||
|
|
||||||
Texture* mapTextures[mapRows][mapCols];
|
Texture* mapTextures[mapRows][mapCols];
|
||||||
Sprite* mapSprites[mapRows][mapCols];
|
Sprite* mapSprites[mapRows][mapCols];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ using Tyra::FileUtils;
|
|||||||
namespace Demo {
|
namespace Demo {
|
||||||
|
|
||||||
IntroState::IntroState(Engine* t_engine)
|
IntroState::IntroState(Engine* t_engine)
|
||||||
: State(t_engine), stateManager(STATE_PRESS_KEY) {
|
: State(t_engine), stateManager(STATE_PS2DEV) {
|
||||||
state = STATE_INTRO;
|
state = STATE_INTRO;
|
||||||
_wantFinish = false;
|
_wantFinish = false;
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ void IntroState::onStart() {
|
|||||||
engine->audio.loadSong(FileUtils::fromCwd("intro/intro.wav"));
|
engine->audio.loadSong(FileUtils::fromCwd("intro/intro.wav"));
|
||||||
engine->audio.setSongLoop(false);
|
engine->audio.setSongLoop(false);
|
||||||
engine->audio.setSongVolume(80);
|
engine->audio.setSongVolume(80);
|
||||||
// engine->audio.playSong();
|
engine->audio.playSong();
|
||||||
|
|
||||||
stateManager.add(new IntroPs2DevState(engine));
|
stateManager.add(new IntroPs2DevState(engine));
|
||||||
stateManager.add(new IntroTyraState(engine));
|
stateManager.add(new IntroTyraState(engine));
|
||||||
|
|||||||
@@ -27,8 +27,14 @@ namespace Demo {
|
|||||||
IntroPressKeyState::IntroPressKeyState(Engine* t_engine)
|
IntroPressKeyState::IntroPressKeyState(Engine* t_engine)
|
||||||
: State(t_engine), mapPosition(0.0F, 0.0F) {
|
: State(t_engine), mapPosition(0.0F, 0.0F) {
|
||||||
state = STATE_PRESS_KEY;
|
state = STATE_PRESS_KEY;
|
||||||
mapDirection = 0;
|
|
||||||
_wantFinish = false;
|
_wantFinish = false;
|
||||||
|
mapDirection = 0;
|
||||||
|
mapFadeIn = true;
|
||||||
|
fillerFadeIn = false;
|
||||||
|
showPressKey = false;
|
||||||
|
pressKeyAlphaToggle = false;
|
||||||
|
pressKeyAlphaDelayer = 0;
|
||||||
|
fillersOffset = -512.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntroPressKeyState::~IntroPressKeyState() {
|
IntroPressKeyState::~IntroPressKeyState() {
|
||||||
@@ -39,12 +45,22 @@ IntroPressKeyState::~IntroPressKeyState() {
|
|||||||
engine->renderer.core.texture.repository.free(mapTextures[i][j]->getId());
|
engine->renderer.core.texture.repository.free(mapTextures[i][j]->getId());
|
||||||
delete mapSprites[i][j];
|
delete mapSprites[i][j];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
engine->renderer.core.texture.repository.free(fillerTexture->getId());
|
||||||
|
delete fillerSprite;
|
||||||
|
|
||||||
|
engine->renderer.core.texture.repository.free(logoTexture->getId());
|
||||||
|
delete logoSprite;
|
||||||
|
|
||||||
|
engine->renderer.core.texture.repository.free(pressKeyTexture->getId());
|
||||||
|
delete pressKeySprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntroPressKeyState::onStart() {
|
void IntroPressKeyState::onStart() {
|
||||||
for (u8 i = 0; i < mapRows; i++) {
|
for (u8 i = 0; i < mapRows; i++) {
|
||||||
for (u8 j = 0; j < mapCols; j++) {
|
for (u8 j = 0; j < mapCols; j++) {
|
||||||
mapSprites[i][j] = new Sprite;
|
mapSprites[i][j] = new Sprite;
|
||||||
|
mapSprites[i][j]->color.a = 0.0F;
|
||||||
mapSprites[i][j]->setMode(SpriteMode::MODE_STRETCH);
|
mapSprites[i][j]->setMode(SpriteMode::MODE_STRETCH);
|
||||||
mapSprites[i][j]->size.set(textureWidthHeight, textureWidthHeight);
|
mapSprites[i][j]->size.set(textureWidthHeight, textureWidthHeight);
|
||||||
mapSprites[i][j]->position.set(i * textureWidthHeight,
|
mapSprites[i][j]->position.set(i * textureWidthHeight,
|
||||||
@@ -60,6 +76,31 @@ void IntroPressKeyState::onStart() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fillerSprite = new Sprite;
|
||||||
|
fillerSprite->size.set(256.0F, 50.0F);
|
||||||
|
fillerSprite->position.set(0.0F, 224.0F - 25.0F);
|
||||||
|
|
||||||
|
fillerTexture = engine->renderer.core.texture.repository.add(
|
||||||
|
FileUtils::fromCwd("intro/filler.png"));
|
||||||
|
fillerTexture->addLink(fillerSprite->getId());
|
||||||
|
|
||||||
|
pressKeySprite = new Sprite;
|
||||||
|
pressKeySprite->size.set(256.0F, 64.0F);
|
||||||
|
pressKeySprite->scale = 0.5F;
|
||||||
|
pressKeySprite->position.set(192.0F, 380.0F);
|
||||||
|
|
||||||
|
pressKeyTexture = engine->renderer.core.texture.repository.add(
|
||||||
|
FileUtils::fromCwd("intro/press-key.png"));
|
||||||
|
pressKeyTexture->addLink(pressKeySprite->getId());
|
||||||
|
|
||||||
|
logoSprite = new Sprite;
|
||||||
|
logoSprite->size.set(256.0F, 128.0F);
|
||||||
|
logoSprite->position.set(256.0F - 128.0F, 224.0F - 64.0F);
|
||||||
|
|
||||||
|
logoTexture = engine->renderer.core.texture.repository.add(
|
||||||
|
FileUtils::fromCwd("intro/lastalive.png"));
|
||||||
|
logoTexture->addLink(logoSprite->getId());
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +123,31 @@ void IntroPressKeyState::update() {
|
|||||||
mapPosition -= offset;
|
mapPosition -= offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mapFadeIn) {
|
||||||
|
for (u8 i = 0; i < mapRows; i++) {
|
||||||
|
for (u8 j = 0; j < mapCols; j++) {
|
||||||
|
auto* sprite = mapSprites[i][j];
|
||||||
|
if (sprite->color.a >= 16.0F && sprite->color.a < 32.0F) {
|
||||||
|
fillerFadeIn = true;
|
||||||
|
}
|
||||||
|
if (sprite->color.a < 96.0F) {
|
||||||
|
sprite->color.a += 0.2F;
|
||||||
|
} else {
|
||||||
|
mapFadeIn = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fillerFadeIn) {
|
||||||
|
if (fillersOffset < -1.0F) {
|
||||||
|
fillersOffset += 4.0F;
|
||||||
|
} else {
|
||||||
|
fillerFadeIn = false;
|
||||||
|
showPressKey = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateMap();
|
updateMap();
|
||||||
Threading::switchThread();
|
Threading::switchThread();
|
||||||
|
|
||||||
@@ -89,16 +155,39 @@ void IntroPressKeyState::update() {
|
|||||||
for (u8 j = 0; j < mapCols; j++)
|
for (u8 j = 0; j < mapCols; j++)
|
||||||
engine->renderer.renderer2D.render(mapSprites[i][j]);
|
engine->renderer.renderer2D.render(mapSprites[i][j]);
|
||||||
|
|
||||||
|
renderFiller();
|
||||||
|
engine->renderer.renderer2D.render(logoSprite);
|
||||||
|
|
||||||
|
if (showPressKey) {
|
||||||
|
if (pressKeyAlphaDelayer++ > 50) {
|
||||||
|
pressKeyAlphaToggle = !pressKeyAlphaToggle;
|
||||||
|
pressKeyAlphaDelayer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pressKeyAlphaToggle) {
|
||||||
|
engine->renderer.renderer2D.render(pressKeySprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
engine->renderer.endFrame();
|
engine->renderer.endFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
IntroStateType IntroPressKeyState::onFinish() { return STATE_INTRO_END; }
|
IntroStateType IntroPressKeyState::onFinish() { return STATE_INTRO_END; }
|
||||||
|
|
||||||
|
void IntroPressKeyState::renderFiller() {
|
||||||
|
fillerSprite->position.x = -1.0F + fillersOffset;
|
||||||
|
engine->renderer.renderer2D.render(fillerSprite);
|
||||||
|
fillerSprite->position.x = 255.0F + fillersOffset;
|
||||||
|
engine->renderer.renderer2D.render(fillerSprite);
|
||||||
|
}
|
||||||
|
|
||||||
void IntroPressKeyState::updateMap() {
|
void IntroPressKeyState::updateMap() {
|
||||||
for (u8 i = 0; i < mapRows; i++)
|
for (u8 i = 0; i < mapRows; i++)
|
||||||
for (u8 j = 0; j < mapCols; j++) {
|
for (u8 j = 0; j < mapCols; j++) {
|
||||||
mapSprites[i][j]->position.x = i * textureWidthHeight - mapPosition.x;
|
mapSprites[i][j]->position.x =
|
||||||
mapSprites[i][j]->position.y = j * textureWidthHeight - mapPosition.y;
|
i * (textureWidthHeight + 1.0F) - mapPosition.x;
|
||||||
|
mapSprites[i][j]->position.y =
|
||||||
|
j * (textureWidthHeight + 1.0F) - mapPosition.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace Demo
|
} // namespace Demo
|
||||||
|
|||||||
Reference in New Issue
Block a user