mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
[box] place ships underneath grid #1639
This commit is contained in:
parent
a39b5f9347
commit
29b161f1c0
@ -94,21 +94,28 @@ move_ships(struct notcurses* nc, struct ship* ships, unsigned shipcount){
|
|||||||
if(ships[s].n == NULL){
|
if(ships[s].n == NULL){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int y, x;
|
int yoff, xoff, ny, nx;
|
||||||
ncplane_yx(ships[s].n, &y, &x);
|
ncplane_yx(ships[s].n, &yoff, &xoff);
|
||||||
y += ships[s].vely;
|
ncplane_dim_yx(ships[s].n, &ny, &nx);
|
||||||
x += ships[s].velx;
|
int dimy = ncplane_dim_y(stdn);
|
||||||
if(x < 0){
|
int dimx = ncplane_dim_x(stdn);
|
||||||
x = 0;
|
yoff += ships[s].vely;
|
||||||
}else if(x >= ncplane_dim_x(stdn) - SHIPWIDTH){
|
xoff += ships[s].velx;
|
||||||
x = ncplane_dim_x(stdn) - SHIPWIDTH - 1;
|
if(xoff <= 0){
|
||||||
|
xoff = 0;
|
||||||
|
ships[s].velx = -ships[s].velx;
|
||||||
|
}else if(xoff >= dimx - nx){
|
||||||
|
xoff = dimx - nx - 1;
|
||||||
|
ships[s].velx = -ships[s].velx;
|
||||||
}
|
}
|
||||||
if(y < 0){
|
if(yoff <= 1){
|
||||||
y = 0;
|
yoff = 2;
|
||||||
}else if(y >= ncplane_dim_y(stdn) - SHIPHEIGHT){
|
ships[s].vely = -ships[s].vely;
|
||||||
y = ncplane_dim_y(stdn) - SHIPHEIGHT - 1;
|
}else if(yoff >= dimy - ny){
|
||||||
|
yoff = dimy - ny - 1;
|
||||||
|
ships[s].vely = -ships[s].vely;
|
||||||
}
|
}
|
||||||
ncplane_move_yx(ships[s].n, y, x);
|
ncplane_move_yx(ships[s].n, yoff, xoff);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -142,8 +149,12 @@ get_ships(struct notcurses* nc, struct ship* ships, unsigned shipcount){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ncplane_move_below(ships[s].n, notcurses_stdplane(nc));
|
ncplane_move_below(ships[s].n, notcurses_stdplane(nc));
|
||||||
ships[s].vely = random() % 5 - 2;
|
if((ships[s].vely = random() % 6 - 3) == 0){
|
||||||
ships[s].velx = random() % 5 - 2;
|
ships[s].vely = 3;
|
||||||
|
}
|
||||||
|
if((ships[s].velx = random() % 6 - 3) == 0){
|
||||||
|
ships[s].velx = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ncvisual_destroy(wmv);
|
ncvisual_destroy(wmv);
|
||||||
return 0;
|
return 0;
|
||||||
@ -167,10 +178,6 @@ int box_demo(struct notcurses* nc){
|
|||||||
const int targx = 7;
|
const int targx = 7;
|
||||||
const int targy = 7;
|
const int targy = 7;
|
||||||
int ytargbase = (ylen - targy) / 2;
|
int ytargbase = (ylen - targy) / 2;
|
||||||
nccell c = CELL_CHAR_INITIALIZER(' ');
|
|
||||||
nccell_set_bg_default(&c);
|
|
||||||
ncplane_set_base_cell(n, &c);
|
|
||||||
nccell_release(n, &c);
|
|
||||||
ncplane_set_fg_rgb8(n, 180, 40, 180);
|
ncplane_set_fg_rgb8(n, 180, 40, 180);
|
||||||
ncplane_set_bg_default(n);
|
ncplane_set_bg_default(n);
|
||||||
if(notcurses_canutf8(nc)){
|
if(notcurses_canutf8(nc)){
|
||||||
@ -209,7 +216,7 @@ int box_demo(struct notcurses* nc){
|
|||||||
int y = 1, x = 0;
|
int y = 1, x = 0;
|
||||||
ncplane_dim_yx(n, &ylen, &xlen);
|
ncplane_dim_yx(n, &ylen, &xlen);
|
||||||
--ylen;
|
--ylen;
|
||||||
while(ylen - y >= targy * 2 && xlen - x >= targx * 2){
|
while(ylen - y >= targy && xlen - x >= targx){
|
||||||
if(ncplane_cursor_move_yx(n, y, x)){
|
if(ncplane_cursor_move_yx(n, y, x)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -242,7 +249,7 @@ int box_demo(struct notcurses* nc){
|
|||||||
ncplane_dim_yx(n, &ylen, &xlen);
|
ncplane_dim_yx(n, &ylen, &xlen);
|
||||||
--ylen;
|
--ylen;
|
||||||
move_ships(nc, ships, sizeof(ships) / sizeof(*ships));
|
move_ships(nc, ships, sizeof(ships) / sizeof(*ships));
|
||||||
while(ylen - y >= targy * 2 && xlen - x >= targx * 2){
|
while(ylen - y >= targy && xlen - x >= targx){
|
||||||
if(ncplane_cursor_move_yx(n, y, x)){
|
if(ncplane_cursor_move_yx(n, y, x)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user