Изменить 'a4/game.c'

This commit is contained in:
Oleksandr Hryshchenko 2021-04-17 16:40:53 +00:00
parent 2bba9bdbdb
commit 0e5571b2e8

View File

@ -28,7 +28,7 @@ int game_event(struct event* event,void* game){
// Get state pointer // Get state pointer
struct game* state = game; struct game* state = game;
char msg[200]; char msg[200];
sprintf(msg,"%d",event->type); sprintf(msg,"%d",event->type);
set_message(msg,10,0); set_message(msg,10,0);
if ( event->type == EVENT_ESC){ if ( event->type == EVENT_ESC){
// Non zero means finish the loop and stop the game. // Non zero means finish the loop and stop the game.
@ -69,20 +69,7 @@ int game_event(struct event* event,void* game){
int cx = state->catx_position + state->catx; int cx = state->catx_position + state->catx;
int cy = state->caty_position + state->caty; int cy = state->caty_position + state->caty;
if (cx < 1 || cy < 0 || cx > event->width || cy > event->height){ if (cx < 1 || cy < 0 || cx > event->width || cy > event->height){
/*state->catx_position = cx;
state->caty_position = cy;
if(state->catx_position < 0){
state->catx_position = 0;
}
else if(state->catx_position >= event->width){
state->catx_position = event->width-1;
}
else if(state->caty_position < 0){
state->caty_position = 0;
}
else if(state->caty_position >= event->height){
state->caty_position = event->height-1;
}*/
} }
else { else {
state->catx_position = cx; state->catx_position = cx;
@ -108,8 +95,7 @@ int game_event(struct event* event,void* game){
else if (m == 3 && state->mousey[i] < event->height){ else if (m == 3 && state->mousey[i] < event->height){
state->mousey[i] += 1; state->mousey[i] += 1;
} }
} }
//Je
} }
else if (event->type == EVENT_KEY){ else if (event->type == EVENT_KEY){
// Move cat according to keyboard // Move cat according to keyboard
@ -131,14 +117,14 @@ int game_event(struct event* event,void* game){
} }
} }
// Draw world state // Draw world state
//
// Draw cat // Draw cat
clear_screen(); clear_screen();
set_color_cell('c',state->catx_position,state->caty_position,COLOR_YELLOW,COLOR_RED); set_color_cell('c',state->catx_position,state->caty_position,COLOR_YELLOW,COLOR_RED);
set_color_cell('-',state->catx_position-1,state->caty_position,COLOR_YELLOW,COLOR_GREEN); set_color_cell('-',state->catx_position-1,state->caty_position,COLOR_YELLOW,COLOR_GREEN);
//set_cell('c',state->catx_position,state->caty_position); //set_cell('c',state->catx_position,state->caty_position);
// Draw mouse
// Draw mouse
for(int i = 0; i < MOUSE_COUNT; i++){ for(int i = 0; i < MOUSE_COUNT; i++){
if(state->mouse_state[i] != 1){ if(state->mouse_state[i] != 1){
set_cell('m', state->mousex[i], state->mousey[i]); set_cell('m', state->mousex[i], state->mousey[i]);