Mario: add arrow key controls

This commit is contained in:
zv0n 2022-09-24 20:44:52 +02:00
parent 45ab92c31f
commit f9a32bdb72

View File

@ -1,4 +1,5 @@
#include "../sdlpp/sdlpp.hpp" #include "../sdlpp/sdlpp.hpp"
#include "SDL2/SDL_keycode.h"
#include "sprites.hpp" #include "sprites.hpp"
#include <memory> #include <memory>
#ifdef _WIN32 #ifdef _WIN32
@ -44,16 +45,20 @@ std::mutex gamescene_mutex;
void handleKeyDown(SDL_Keycode key, SDLPP::Scene &scene) { void handleKeyDown(SDL_Keycode key, SDLPP::Scene &scene) {
switch (key) { switch (key) {
case SDLK_a: case SDLK_a:
case SDLK_LEFT:
mario->walkLeft(); mario->walkLeft();
break; break;
case SDLK_d: case SDLK_d:
case SDLK_RIGHT:
mario->walkRight(); mario->walkRight();
break; break;
case SDLK_SPACE: case SDLK_SPACE:
case SDLK_w: case SDLK_w:
case SDLK_UP:
mario->jump(); mario->jump();
break; break;
case SDLK_s: case SDLK_s:
case SDLK_DOWN:
break; break;
case SDLK_r: case SDLK_r:
scene.getRenderer().setRenderColiders( scene.getRenderer().setRenderColiders(
@ -76,13 +81,16 @@ void handleKeyUp(SDL_Keycode key) {
createGameMainMenuScene(renderer, false, true, true)); createGameMainMenuScene(renderer, false, true, true));
} break; } break;
case SDLK_a: case SDLK_a:
case SDLK_LEFT:
mario->walkRight(); mario->walkRight();
break; break;
case SDLK_d: case SDLK_d:
case SDLK_RIGHT:
mario->walkLeft(); mario->walkLeft();
break; break;
case SDLK_SPACE: case SDLK_SPACE:
case SDLK_w: case SDLK_w:
case SDLK_UP:
mario->stopJump(); mario->stopJump();
default: default:
break; break;