zz
This commit is contained in:
		
							parent
							
								
									5cb51ec0e2
								
							
						
					
					
						commit
						1943250c40
					
				
							
								
								
									
										11
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								main.c
									
									
									
									
									
								
							@ -31,6 +31,9 @@ void init_snake(struct event* world, struct state* st){
 | 
			
		||||
        st->foodx[i] = rand() % w;
 | 
			
		||||
        st->foody[i] = rand() % h;
 | 
			
		||||
    }
 | 
			
		||||
    // Initial game vector
 | 
			
		||||
    st->sx = 1;
 | 
			
		||||
    st->sy = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Step is called in a loop once in interval.
 | 
			
		||||
@ -70,11 +73,15 @@ int world_event(struct event* w,void* game){
 | 
			
		||||
    }
 | 
			
		||||
    // Called on interval timeout
 | 
			
		||||
    else if (w->type == EVENT_TIMEOUT){
 | 
			
		||||
        clear_screen();
 | 
			
		||||
        // Copy screen size
 | 
			
		||||
        st->width = w->width;
 | 
			
		||||
        st->height = w->height;
 | 
			
		||||
        // Change game state
 | 
			
		||||
        int r = step_state(st);
 | 
			
		||||
        char ms[200];
 | 
			
		||||
        sprintf(ms,"r %d\n",r);
 | 
			
		||||
        set_message(ms,9,9);
 | 
			
		||||
        // Draw snake
 | 
			
		||||
        struct snake* sn = st->snake;
 | 
			
		||||
        while (sn != NULL){
 | 
			
		||||
@ -90,9 +97,7 @@ int world_event(struct event* w,void* game){
 | 
			
		||||
        // Stop the game
 | 
			
		||||
        if (r){
 | 
			
		||||
            char message[] = "Koniec";
 | 
			
		||||
            for (int i = 0; i < 6; i++){
 | 
			
		||||
                set_cell(message[i],10+i,10);
 | 
			
		||||
            }
 | 
			
		||||
            set_message(message,10,10);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								world.h
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								world.h
									
									
									
									
									
								
							@ -104,10 +104,19 @@ void set_color_cell(int character,int x,int y,short front_color,short back_color
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
int start_world(void* (*init_game)(),int (*world_event)(struct event* event,void* game),void (*destroy_game)(void* game));
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set timeout interval in miliseconds
 | 
			
		||||
 */
 | 
			
		||||
void game_speed(int value);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Prints a message in screen on a position x,y
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
void set_message(const char* message,int x,int y);
 | 
			
		||||
/*
 | 
			
		||||
 * Clears screen
 | 
			
		||||
 */
 | 
			
		||||
void clear_screen();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user