#include <ncurses.h>
#include <stdlib.h>
struct coordinates{
int x;
int y;
};
void animation(struct coordinates monkey, struct coordinates banana);
void draw(struct coordinates monkey, struct coordinates banana);
void clear_win(struct coordinates monkey, struct coordinates banana);
void find_new(struct coordinates monkey, struct coordinates banana);
int main(){
srand(time(NULL));
int number1, number2;
FILE *c_File = fopen("coordinates.c", "r");
if(c_File == NULL){
printf("File does not exist");
return 1;
}
fscanf(c_File, "%d%d", &number1, &number2);
struct coordinates banana = {number1, number2};
struct coordinates monkey = {banana.x + 1, banana.y + 1};
initscr();
curs_set(0);
animation(monkey, banana);
fclose(c_File);
endwin();
return 0;
}
void animation(struct coordinates monkey, struct coordinates banana){
int step, max_steps = 20;
for(step = 1; step < max_steps; step++){ //tutaj się coś sypie
draw(monkey, banana);
refresh();
system("sleep 0.5");
clear_win(monkey, banana);
refresh();
}
}
void draw(struct coordinates monkey, struct coordinates banana){
mvprintw(banana.y, banana.x, "]");
mvprintw(monkey.y, monkey.x, "@");
}
void clear_win(struct coordinates monkey, struct coordinates banana){
mvprintw(banana.y, banana.x, " ");
mvprintw(monkey.y, monkey.x, " ");
}
void find_new(struct coordinates monkey, struct coordinates banana){
int random = rand()%3-1;
banana.x += 5;
banana.y -= 5;
monkey.x = banana.x + random;
monkey.y = banana.y - random;
}
Mam następujący problem. Gdzie bym nie wrzucił funkcji find_new**(dlatego też aktualnie nie jest nigdzie umieszczona!!)**, nie są wyliczane nowe współrzędne do funkcji draw. Drukowanie na ekranie jest tylko dla wartości podstawowych i tam są przez 20 "step'ów". Wczytywane wartości z pliku to 0 oraz 0.