Skip to content

Commit

Permalink
add secondary title image
Browse files Browse the repository at this point in the history
  • Loading branch information
evanbowman committed Oct 17, 2020
1 parent 28ad17f commit ff2abc3
Show file tree
Hide file tree
Showing 8 changed files with 637 additions and 16 deletions.
2 changes: 2 additions & 0 deletions build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ if(GAMEBOY_ADVANCE)
${DATA_DIR}/spritesheet_launch_anim.s
${DATA_DIR}/launch_flattened.s
${DATA_DIR}/title_1_flattened.s
${DATA_DIR}/title_2_flattened.s
${DATA_DIR}/sound_msg.s
${DATA_DIR}/sound_pop.s
${DATA_DIR}/sound_coin.s
Expand Down Expand Up @@ -480,6 +481,7 @@ if(GAMEBOY_ADVANCE)
add_spritesheet(spritesheet_boss2_final 2 4 NO)
add_spritesheet(spritesheet_launch_anim 2 4 NO)
add_tilesheet(title_1 0 0 YES)
add_tilesheet(title_2 0 0 YES)
add_tilesheet(launch 0 0 YES)
add_tilesheet(tilesheet_intro_cutscene 0 0 YES)
add_tilesheet(tilesheet 4 3 NO)
Expand Down
Binary file added images/title_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/title_2_flattened.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions source/data/title_2_flattened.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

//{{BLOCK(title_2_flattened)

//======================================================================
//
// title_2_flattened, 3368x8@4,
// Transparent color : FF,00,FF
// + palette 256 entries, not compressed
// + 421 tiles not compressed
// Total size: 512 + 13472 = 13984
//
// Time-stamp: 2020-10-17, 13:55:41
// Exported by Cearn's GBA Image Transmogrifier, v0.8.16
// ( http://www.coranac.com/projects/#grit )
//
//======================================================================

#ifndef GRIT_TITLE_2_FLATTENED_H
#define GRIT_TITLE_2_FLATTENED_H

#define title_2_flattenedTilesLen 13472
extern const unsigned int title_2_flattenedTiles[3368];

#define title_2_flattenedPalLen 512
extern const unsigned short title_2_flattenedPal[256];

#endif // GRIT_TITLE_2_FLATTENED_H

//}}BLOCK(title_2_flattened)
538 changes: 538 additions & 0 deletions source/data/title_2_flattened.s

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions source/platform/gba/images.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
//;
#include "data/title_1_flattened.h"
//;
#include "data/title_2_flattened.h"
//;
#include "data/launch_flattened.h"
//;
#include "data/tilesheet_intro_cutscene_flattened.h"
Expand Down Expand Up @@ -134,6 +136,8 @@ static const TextureData sprite_textures[] = {
static const TextureData tile_textures[] = {

TEXTURE_INFO(title_1_flattened),
//;
TEXTURE_INFO(title_2_flattened),
//;
TEXTURE_INFO(launch_flattened),
//;
Expand Down
1 change: 1 addition & 0 deletions source/state/state_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class TitleScreenState : public State {
fade_in,
wait,
select,
swap_image,
fade_out,
pause,
} display_mode_ = DisplayMode::sleep;
Expand Down
79 changes: 63 additions & 16 deletions source/state/titleScreenState.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include "state_impl.hpp"


static const auto fade_in_color = custom_color(0xaec7c1);

static auto fade_in_color(const Game& game)
{
if (game.level() == 0) {
return custom_color(0xaec7c1);
} else {
return custom_color(0x4d7493);
}
}


void TitleScreenState::enter(Platform& pfrm, Game& game, State& prev_state)
Expand All @@ -22,7 +30,11 @@ void TitleScreenState::enter(Platform& pfrm, Game& game, State& prev_state)
pfrm.speaker().stop_music();

pfrm.load_overlay_texture("overlay");
pfrm.load_tile0_texture("title_1_flattened");
if (game.level() == 0) {
pfrm.load_tile0_texture("title_1_flattened");
} else {
pfrm.load_tile0_texture("title_2_flattened");
}
pfrm.load_tile1_texture("tilesheet_top");

const Vec2<Float> arbitrary_offscreen_location{1000, 1000};
Expand All @@ -43,20 +55,20 @@ void TitleScreenState::enter(Platform& pfrm, Game& game, State& prev_state)
pfrm.set_tile(Layer::overlay, i, screen_tiles.y - 3, 112);
}

pfrm.screen().fade(1.f, fade_in_color);
pfrm.screen().fade(1.f, fade_in_color(game));

draw_image(pfrm, 1, 0, 3, 30, 14, Layer::background);

for (int i = 0; i < screen_tiles.x; ++i) {
pfrm.set_tile(Layer::background, i, 2, 8);
pfrm.set_tile(Layer::background, i, 2, 9);
}

// We need to share vram memory for the background image and the tileset
// layer. Therefore, in order for the tilemap not to show up, we need to
// designate part of the image as one transparent 4x3 chunk. Now, this code
// covers up that transparent chunk with another tile.
for (int i = 11; i < 23; ++i) {
pfrm.set_tile(Layer::background, i, 3, 8);
pfrm.set_tile(Layer::background, i, 3, 9);
}
}

Expand All @@ -68,6 +80,28 @@ void TitleScreenState::exit(Platform& pfrm, Game& game, State& next_state)
}


static void draw_title(Platform& pfrm, Game& game, int sel, std::optional<Text>& title)
{
auto str = locale_string(pfrm, LocaleString::game_title);
const auto margin =
centered_text_margins(pfrm, utf8::len(str->c_str()));

title.emplace(pfrm, OverlayCoord{u8(margin), 3});

const auto text_bg_color = [&] {
if (game.level() == 0 or sel == 1) {
return custom_color(0x4091AD);
} else {
return custom_color(0x527597);
}
}();

title->assign(str->c_str(),
Text::OptColors{{custom_color(0xFFFFFF),
text_bg_color}});
}


StatePtr TitleScreenState::update(Platform& pfrm,
Game& game,
Microseconds delta)
Expand Down Expand Up @@ -141,16 +175,35 @@ StatePtr TitleScreenState::update(Platform& pfrm,
} else if (pfrm.keyboard().down_transition<Key::left>()) {
if (cursor_index_ > 0) {
--cursor_index_;
pfrm.speaker().play_sound("scroll", 1);
timer_ = seconds(1);
title_.reset();
display_mode_ = DisplayMode::swap_image;
}
} else if (pfrm.keyboard().down_transition<Key::right>()) {
if (cursor_index_ < 1) {
++cursor_index_;
pfrm.speaker().play_sound("scroll", 1);
timer_ = seconds(1);
title_.reset();
display_mode_ = DisplayMode::swap_image;
}
}
break;

case DisplayMode::swap_image:
switch (cursor_index_) {
case 0:
if (game.level() not_eq 0) {
pfrm.load_tile0_texture("title_2_flattened");
}
break;

case 1:
pfrm.load_tile0_texture("title_1_flattened");
break;
}
display_mode_ = DisplayMode::select;
draw_title(pfrm, game, cursor_index_, title_);
pfrm.speaker().play_sound("scroll", 1);
break;

case DisplayMode::fade_in: {
Expand All @@ -165,21 +218,15 @@ StatePtr TitleScreenState::update(Platform& pfrm,

} else {
pfrm.screen().fade(1.f - smoothstep(0.f, fade_duration, timer_),
fade_in_color);
fade_in_color(game));
}
} break;

case DisplayMode::wait:
timer_ += delta;
if (timer_ > milliseconds(300)) {
auto str = locale_string(pfrm, LocaleString::game_title);
const auto margin =
centered_text_margins(pfrm, utf8::len(str->c_str()));

title_.emplace(pfrm, OverlayCoord{u8(margin), 3});
title_->assign(str->c_str(),
Text::OptColors{{custom_color(0xFFFFFF),
custom_color(0x4091AD)}});

draw_title(pfrm, game, cursor_index_, title_);

const char* opt_1 = "continue";
const char* opt_2 = "new game";
Expand Down

0 comments on commit ff2abc3

Please sign in to comment.