fix
This commit is contained in:
parent
167ff53247
commit
3e55eb2087
34
a5/game.c
34
a5/game.c
@ -11,13 +11,13 @@ void* init_game(){
|
|||||||
// Initialize cat
|
// Initialize cat
|
||||||
st->catx = 0;
|
st->catx = 0;
|
||||||
st->caty = 0;
|
st->caty = 0;
|
||||||
st->catx_position = 15;
|
st->catx_position = 20;
|
||||||
st->caty_position = 15;
|
st->caty_position = 10;
|
||||||
st->caught_count = 0;
|
st->caught_count = 0;
|
||||||
|
|
||||||
// Initialize 5 mice at random positions
|
// Initialize 5 mice at random positions (within boundaries)
|
||||||
for(int i = 0; i < MOUSE_COUNT; i++){
|
for(int i = 0; i < MOUSE_COUNT; i++){
|
||||||
st->mousex[i] = 5 + rand() % 30;
|
st->mousex[i] = 5 + rand() % 50;
|
||||||
st->mousey[i] = 5 + rand() % 15;
|
st->mousey[i] = 5 + rand() % 15;
|
||||||
st->mouse_state[i] = 0; // alive
|
st->mouse_state[i] = 0; // alive
|
||||||
}
|
}
|
||||||
@ -58,8 +58,8 @@ 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;
|
||||||
|
|
||||||
// Check boundaries
|
// Check boundaries (leave room for borders)
|
||||||
if (cx > 0 && cx < event->width && cy > 0 && cy < event->height){
|
if (cx > 1 && cx < event->width - 2 && cy > 2 && cy < event->height - 2){
|
||||||
state->catx_position = cx;
|
state->catx_position = cx;
|
||||||
state->caty_position = cy;
|
state->caty_position = cy;
|
||||||
}
|
}
|
||||||
@ -76,8 +76,8 @@ int game_event(struct event* event,void* game){
|
|||||||
else if (m == 2) mx -= 1;
|
else if (m == 2) mx -= 1;
|
||||||
else if (m == 3) mx += 1;
|
else if (m == 3) mx += 1;
|
||||||
|
|
||||||
// Check boundaries
|
// Check boundaries (leave room for borders)
|
||||||
if (mx > 0 && mx < event->width && my > 0 && my < event->height){
|
if (mx > 1 && mx < event->width - 2 && my > 2 && my < event->height - 2){
|
||||||
state->mousex[i] = mx;
|
state->mousex[i] = mx;
|
||||||
state->mousey[i] = my;
|
state->mousey[i] = my;
|
||||||
}
|
}
|
||||||
@ -107,20 +107,30 @@ int game_event(struct event* event,void* game){
|
|||||||
// Draw world state
|
// Draw world state
|
||||||
clear_screen();
|
clear_screen();
|
||||||
|
|
||||||
|
// Draw borders
|
||||||
|
for(int x = 0; x < event->width; x++){
|
||||||
|
set_cell('#', x, 1);
|
||||||
|
set_cell('#', x, event->height - 2);
|
||||||
|
}
|
||||||
|
for(int y = 1; y < event->height - 1; y++){
|
||||||
|
set_cell('#', 0, y);
|
||||||
|
set_cell('#', event->width - 1, y);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw cat
|
// Draw cat
|
||||||
set_color_cell('c',state->catx_position,state->caty_position,COLOR_YELLOW,COLOR_RED);
|
set_cell('c', state->catx_position, state->caty_position);
|
||||||
|
|
||||||
// Draw mice
|
// Draw mice
|
||||||
for(int i = 0; i < MOUSE_COUNT; i++){
|
for(int i = 0; i < MOUSE_COUNT; i++){
|
||||||
if(state->mouse_state[i] == 0){ // only draw alive mice
|
if(state->mouse_state[i] == 0){ // only draw alive mice
|
||||||
set_cell('m',state->mousex[i],state->mousey[i]);
|
set_cell('m', state->mousex[i], state->mousey[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw caught count
|
// Draw caught count
|
||||||
char msg[100];
|
char msg[100];
|
||||||
sprintf(msg,"Chytene: %d/%d", state->caught_count, MOUSE_COUNT);
|
sprintf(msg, "Chytene: %d/%d", state->caught_count, MOUSE_COUNT);
|
||||||
set_message(msg, 1, 0);
|
set_message(msg, 2, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user