Hi
This question gives me a weird feeling, actually I'm not really sure if this is relevant.
Anyway, here we go:
I'm (still) busy coding my first game in C. The goal is simple: the player is a fisherman and needs to catch all the fish in the water. If you like an example of how it looks I can draw it here but I don’t think it’s necessary.
Everything works fine, I have a function to move the fisherman, a function to move the fishes, but I can’t make the fishes move while playing. Unless I make the fishes move at the same time the player moves the fisherman. So the problem is that I can’t make the fishes move independent from user input without still being able to move the fisherman around.
This is the code I have now, it makes the fishes move when the player moves the fisherman. The for-loop in first case statement is experimental, too move more than one fish. (I translated function some names to make it easier to understand the code.)
do {
if(!stop){
do { // input from the keyboard
key = getch();
switch (key){
case UP:
for(i=0;i<fish_left;i++) {
rand_fish = rand() %fish_left;
move_fish(rand_fish);
}
hook_up();
break;
case DOWN:
random_fish = rand() %fish_left;
move_fish(rand_fish);
hook_down();
break;
case LEFT:
random_fish = rand() %fish_left;
move_fish(rand_fish);
fisherman_toleft();
break;
case RIGHT:
random_fish = rand() %fish_left;
move_fish(rand_fish);
fisherman_toright();
break;
default:
NULL; // ignore other input
}
}
while ((vissenresterend > aantalbommen) && (bomgevangen != 1));
What I hope to achieve is something like this:
Execute this:
while(timer<5){
timer=clock()/CLK_TCK;
sw_timer=timer*10;
switch(timer){
case 0: move_fish(1); clrscr(); break;
case 10: move_fish (2); clrscr(); break;
case 20: move_fish (3); clrscr(); break;
case 30: move_fish (1); clrscr(); break;
case 40: move_fish (2); clrscr(); break;
case 50: move_fish (3); clrscr(); break;
}
}
And at the same time run this so that the user can move the fisherman around to try to catch a fish.
switch (key){
case UP:
hook_up();
break;
case DOWN:
hook_down();
break;
case LEFT:
fisherman_toleft();
break;
case RIGHT:
fisherman_toright();
break;
default:
NULL; // ignore other input
Is it possible to do something like that? How should I program something like this? I’m fine with the explanation or some useful link/code. I’m not asking people to program this specific code for me.
Greetz
Abberline