mirror of
https://github.com/thepigeongenerator/breakout_clone.git
synced 2025-12-16 22:05:45 +01:00
input handling
This commit is contained in:
21
level.c
21
level.c
@@ -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
2
main.c
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user