From 27d0920937e7a033c7f5e7640ca201a3759fe9a8 Mon Sep 17 00:00:00 2001 From: Anzhelika Nikolaieva Date: Sun, 23 Apr 2023 11:04:59 +0000 Subject: [PATCH] Update 'a3/game.c' --- a3/game.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/a3/game.c b/a3/game.c index 13faa69..f3a0d34 100644 --- a/a3/game.c +++ b/a3/game.c @@ -4,7 +4,7 @@ #include "world.h" #include "game.h" - void* init_game(){ + void* init_game(struct game *game){ // Allocate memory for the state struct game* st = calloc(1,(sizeof(struct game))); // Initialize state @@ -32,6 +32,23 @@ int game_event(struct event* event,void* game){ } // Read game variable and update the eventstate + void update_game(struct game *game, int key){ +// Move the cat based on the pressed key + switch(key) { + case 'w': + game->caty -= 1; + break; + case 's': + game->caty += 1; + break; + case 'a': + game->catx -= 1; + break; + case 'd': + game->catx += 1; + break; + } + // Is mouse caught ? if ((state->caty_position == state->mousey) && (state->catx_position == state->mousex)){ clear_screen();