Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions .github/workflows/deploy.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy GitHub Pages

on:
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
pages:
uses: adsgames/deploy-to-adsgames/.github/workflows/deploy-asw-pages.yml@v1
permissions:
contents: read
pages: write
id-token: write
with:
# Pull requests only check that the web build works
deploy: ${{ github.event_name == 'push' }}
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
tags:
- v*
pull_request:
branches:
- main

jobs:
release:
uses: adsgames/deploy-to-adsgames/.github/workflows/release-game.yml@v1
permissions:
id-token: write
contents: read
with:
project-id: memory
# Pull requests only check that every platform builds, and dry run adsgames.json
deploy: ${{ startsWith(github.ref, 'refs/tags/v') }}
secrets:
ADSGAMES_API_KEY: ${{ secrets.ADSGAMES_API_KEY }}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target)

include(cmake/get_cpm.cmake)
CPMAddPackage("gh:adsgames/asw@0.8.0")
CPMAddPackage("gh:adsgames/asw@0.12.1")

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h)
Expand Down
11 changes: 6 additions & 5 deletions src/Card.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Card.h"

#include <numbers>
#include <cmath>
#include <string>

asw::Texture Card::backImage { nullptr };
Expand Down Expand Up @@ -98,8 +98,8 @@ void Card::update(float dt)
{
auto screen_size = asw::display::get_logical_size();

if (!selected_ && asw::input::mouse.pressed[1] && number_selected < 2
&& transform_.contains(asw::input::mouse.position)) {
if (!selected_ && asw::input::get_mouse_button_down(asw::input::MouseButton::Left)
&& number_selected < 2 && transform_.contains(asw::input::get_mouse().position)) {
animation_time_ = 0.0F;
asw::sound::play(card_flip_);
selected_ = true;
Expand All @@ -115,8 +115,9 @@ void Card::update(float dt)
if (!animation_done_) {
animation_time_ += dt;
auto interpolation = animation_time_ / CARD_FLIP_TIME_S;
auto widthMult = (cos(2.0F * std::numbers::pi_v<float> * interpolation) + 1.0F) / 2.0F;
animation_width_ = transform_.size.x * widthMult;
// Shrink to nothing at the halfway point, then grow back
animation_width_ = asw::easing::ease(0.0F, transform_.size.x,
std::abs((2.0F * interpolation) - 1.0F), asw::easing::ease_in_out_sine);

if (selected_) {
if (!flipped_ && interpolation > 0.5F) {
Expand Down
36 changes: 36 additions & 0 deletions src/Controls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "Controls.h"

namespace {
using asw::input::ControllerButton;
using asw::input::ControllerButtonBinding;
using asw::input::Key;
using asw::input::KeyBinding;

constexpr auto ANY = asw::input::ANY_CONTROLLER;

asw::ui::Navigation navigation_;
} // namespace

void controls::bind()
{
// Arrows, Tab, Return, Space, Escape, D-pad, left stick, A and B
navigation_ = asw::ui::bind_default_navigation();
asw::input::bind_action(
navigation_.back, ControllerButtonBinding { ControllerButton::Back, ANY });

asw::input::bind_action(CONFIRM, KeyBinding { Key::Return });
asw::input::bind_action(CONFIRM, ControllerButtonBinding { ControllerButton::A, ANY });
asw::input::bind_action(CONFIRM, ControllerButtonBinding { ControllerButton::Start, ANY });
}

const asw::ui::Navigation& controls::navigation()
{
return navigation_;
}

bool controls::any_controller_skip()
{
return asw::input::get_controller_button_down(ANY, ControllerButton::A)
|| asw::input::get_controller_button_down(ANY, ControllerButton::B)
|| asw::input::get_controller_button_down(ANY, ControllerButton::Start);
}
20 changes: 20 additions & 0 deletions src/Controls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <asw/asw.h>

// Input actions shared by keyboard and controllers
namespace controls {

// Confirm the name at the end of a game
inline constexpr const char* CONFIRM = "confirm";

// Bind all actions, call once after asw::core::init
void bind();

// UI navigation actions, set on asw::ui::Root::ctx.navigation
const asw::ui::Navigation& navigation();

// Check if a controller button that skips a screen was pressed
bool any_controller_skip();

} // namespace controls
27 changes: 17 additions & 10 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <random>
#include <ranges>

#include "Controls.h"
#include "globals.h"

GameDifficulty Game::difficulty = GameDifficulty::EASY;
Expand All @@ -31,9 +32,18 @@ void Game::init()
const auto font = asw::assets::load_font("assets/fonts/jersey-10.ttf", 48);

ui_ = asw::ui::Root();
ui_.root.transform.set_size(screen_size.x, screen_size.y);
ui_.ctx.navigation = controls::navigation();
ui_.ctx.theme.font = font;
ui_.ctx.theme.text = asw::Color(0, 0, 0);
ui_.root.bg_image = asw::assets::load_texture("assets/img/backgrounds/background.png");

// Go to menu, unless the game is over and the name is being entered
ui_.on_back = [this]() {
if (!cards_.empty()) {
manager.set_next_scene(States::Menu);
}
};

// Moves panel
auto& pnl_moves = ui_.root.add_child<asw::ui::Panel>();
pnl_moves.transform.set_position(15, 15);
Expand All @@ -42,7 +52,6 @@ void Game::init()

auto& lbl_moves = pnl_moves.add_child<asw::ui::Label>();
lbl_moves.transform.set_position(20, 20);
lbl_moves.font = font;
lbl_moves_ = &lbl_moves;

// Level end panel
Expand All @@ -56,13 +65,11 @@ void Game::init()
auto& in_name = end_panel.add_child<asw::ui::InputBox>();
in_name.transform.set_position(screen_size.x / 2 - 200, screen_size.y / 2 - 50);
in_name.transform.set_size(400, 80);
in_name.font = font;
in_name.value = "Player";
in_name_ = &in_name;

auto& lbl_complete = end_panel.add_child<asw::ui::Label>();
lbl_complete.transform.set_position(screen_size.x / 2, screen_size.y / 2 - 100);
lbl_complete.font = font;
lbl_complete.text = "Congratulations! Enter Your Name";
lbl_complete.justify = asw::TextJustify::Center;

Expand Down Expand Up @@ -113,10 +120,6 @@ void Game::update(float dt)
if (cards_.empty()) {
endgame_update();
}
// Go to menu
else if (asw::input::get_key_down(asw::input::Key::Escape)) {
manager.set_next_scene(States::Menu);
}

erase_off_screen_cards();
calculate_selected_cards();
Expand All @@ -133,9 +136,13 @@ void Game::update(float dt)

void Game::endgame_update()
{
end_panel_->visible = true;
// Show the name entry and focus it so typing goes to it
if (!end_panel_->visible) {
end_panel_->visible = true;
ui_.focus(*in_name_);
}

if (asw::input::get_key_down(asw::input::Key::Return)) {
if (asw::input::get_action_down(controls::CONFIRM)) {
const auto& config = DIFFICULTY_CONFIG[difficulty];
score_manager_.add(in_name_->value, moves_);
score_manager_.save(config.highscore_file);
Expand Down
1 change: 0 additions & 1 deletion src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "Card.h"
#include "GameDifficulty.h"
#include "State.h"
#include "ui/InputBox.h"
#include "util/ScoreManager.h"

struct DifficultyConfig {
Expand Down
16 changes: 6 additions & 10 deletions src/HighScores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <string>
#include <vector>

#include "Controls.h"

std::map<GameDifficulty, std::string> HighScores::SCORE_FILES {
{ GameDifficulty::EASY, "assets/data/highscores_easy.dat" },
{ GameDifficulty::MEDIUM, "assets/data/highscores_medium.dat" },
Expand All @@ -18,8 +20,11 @@ void HighScores::init()
font_ = asw::assets::load_font("assets/fonts/jersey-10.ttf", 48);

ui_ = asw::ui::Root();
ui_.root.transform.size = asw::Vec2<float>(1280, 960);
ui_.ctx.navigation = controls::navigation();
ui_.ctx.theme.font = font_;
ui_.ctx.theme.text = asw::Color(0, 0, 0);
ui_.root.bg_image = background;
ui_.on_back = [this]() { manager.set_next_scene(States::Menu); };

auto& pnl_scores = ui_.root.add_child<asw::ui::Panel>();
pnl_scores.transform.set_position(320, 130);
Expand All @@ -29,7 +34,6 @@ void HighScores::init()
auto& btn_left = ui_.root.add_child<asw::ui::Button>();
btn_left.transform = { 0, 0, 64, 960 };
btn_left.text = "<";
btn_left.font = font_;
btn_left.on_click = [this, click]() {
if (difficulty_ != GameDifficulty::EASY) {
difficulty_ = static_cast<GameDifficulty>(static_cast<int>(difficulty_) - 1);
Expand All @@ -41,7 +45,6 @@ void HighScores::init()
auto& btn_right = ui_.root.add_child<asw::ui::Button>();
btn_right.transform = { 1216, 0, 64, 960 };
btn_right.text = ">";
btn_right.font = font_;
btn_right.on_click = [this, click]() {
if (difficulty_ != GameDifficulty::EXTREME) {
difficulty_ = static_cast<GameDifficulty>(static_cast<int>(difficulty_) + 1);
Expand All @@ -52,13 +55,11 @@ void HighScores::init()

auto& lbl_title = ui_.root.add_child<asw::ui::Label>();
lbl_title.transform = { 640, 50, 0, 0 };
lbl_title.font = font_;
lbl_title.text = "High Scores";
lbl_title.justify = asw::TextJustify::Center;

auto& lbl_mode = ui_.root.add_child<asw::ui::Label>();
lbl_mode.transform = { 640, 150, 0, 0 };
lbl_mode.font = font_;
lbl_mode.text = "";
lbl_mode.justify = asw::TextJustify::Center;
lbl_mode_ = &lbl_mode;
Expand All @@ -80,11 +81,6 @@ void HighScores::update(float dt)
} else if (difficulty_ == GameDifficulty::EXTREME) {
lbl_mode_->text = "Extreme";
}

// Go to menu
if (asw::input::get_key_down(asw::input::Key::Escape)) {
manager.set_next_scene(States::Menu);
}
}

void HighScores::draw()
Expand Down
6 changes: 3 additions & 3 deletions src/Intro.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Intro.h"

#include <string>
#include <vector>
#include "Controls.h"

void Intro::init()
{
Expand All @@ -14,7 +13,8 @@ void Intro::update(float dt)

timer_ += dt;

if (timer_ >= 3.0F || asw::input::keyboard.any_pressed) {
if (timer_ >= 3.0F || asw::input::get_keyboard().any_pressed
|| controls::any_controller_skip()) {
manager.set_next_scene(States::Menu);
}
}
Expand Down
Loading
Loading