sliders-demo: factor out move_square() #72

pull/100/head
nick black 5 years ago committed by Nick Black
parent 9f4fa94209
commit 570b42b78b

@ -9,6 +9,19 @@
#define MOVES 45
#define GIG 1000000000
static int
move_square(struct notcurses* nc, struct ncplane* chunk, int* holey, int* holex){
int newholex, newholey;
ncplane_yx(chunk, &newholey, &newholex);
ncplane_move_yx(chunk, *holey, *holex);
*holey = newholey;
*holex = newholex;
if(notcurses_render(nc)){
return -1;
}
return 0;
}
// we take (MOVES / 5) * demodelay to play MOVES moves
static int
play(struct notcurses* nc, struct ncplane** chunks){
@ -43,17 +56,10 @@ play(struct notcurses* nc, struct ncplane** chunks){
}
}while(mover == chunkcount);
lastdir = direction;
int newholex, newholey;
ncplane_yx(chunks[mover], &newholey, &newholex);
ncplane_move_yx(chunks[mover], holey, holex);
holey = newholey;
holex = newholex;
move_square(nc, chunks[mover], &holey, &holex);
chunks[hole] = chunks[mover];
chunks[mover] = NULL;
hole = mover;
if(notcurses_render(nc)){
return -1;
}
nanosleep(&movetime, NULL);
}
return 0;

Loading…
Cancel
Save