input handling

This commit is contained in:
Quinn
2024-06-10 16:43:01 +02:00
parent cee2b339b9
commit 50d9cbbc41
2 changed files with 21 additions and 2 deletions

21
level.c
View File

@@ -18,4 +18,23 @@ void level_init(Level* level) {
}
//updates the level
void level_update(Level* level, bool* keys) {}
void level_update(Level* level, bool* keys) {
Position* bouncer_pos = &level->bouncer.pos;
// if move bouncer LEFT
if (keys[SDLK_a]) {
bouncer_pos->x--;
if (bouncer_pos->x == 0) {
bouncer_pos->x = SCREEN_WIDTH - level->bouncer.width;
}
}
// if move bouncer RIGHT
if (keys[SDLK_d]) {
bouncer_pos->x++; // increase the bouncer pos
if ((bouncer_pos->x + level->bouncer.width) > SCREEN_WIDTH) {
bouncer_pos->x = 1; //set the bouncer pos to 1
}
}
}

2
main.c
View File

@@ -71,7 +71,7 @@ int main(void) {
Level level = { 0 }; //stores the game's state
SDL_Window* window = NULL; //the window that is given to the OS
SDL_Renderer* renderer = NULL; //the renderer used to draw to the window
bool keys[322] = { 0 }; //stores the key states
bool keys[322] = { 0 }; //stores the key states TODO: find a better method than to use 322 bytes
// initialize
{