mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-09-10 23:54:33 +00:00
tfv: first pass at collision detection
This commit is contained in:
parent
2c276a6d4e
commit
9372096b5c
@ -1205,3 +1205,40 @@ int hlin_double(int page, int x1, int x2, int at) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int collision(int xx, int yy, int ground_color) {
|
||||
|
||||
int page=0;
|
||||
int beach_color;
|
||||
int collide=1;
|
||||
|
||||
hlin_addr=gr_addr_lookup[yy/2];
|
||||
|
||||
hlin_addr+=(page*4)<<8;
|
||||
|
||||
hlin_addr+=xx;
|
||||
|
||||
beach_color=COLOR_YELLOW|(COLOR_YELLOW<<4);
|
||||
|
||||
if ((ram[hlin_addr]==ground_color) &&
|
||||
(ram[hlin_addr+1]==ground_color) &&
|
||||
(ram[hlin_addr+2]==ground_color)) {
|
||||
|
||||
printf("NOCOLLIDE %x!\n",ground_color);
|
||||
collide=0;
|
||||
}
|
||||
|
||||
if ((ram[hlin_addr]==beach_color) &&
|
||||
(ram[hlin_addr+1]==beach_color) &&
|
||||
(ram[hlin_addr+2]==beach_color)) {
|
||||
|
||||
printf("NOCOLLIDE %x!\n",beach_color);
|
||||
collide=0;
|
||||
}
|
||||
|
||||
printf("COLLIDE %x %x %x not %x %x\n",
|
||||
ram[hlin_addr],ram[hlin_addr+1],ram[hlin_addr+2],
|
||||
ground_color,beach_color);
|
||||
|
||||
return collide;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ int hlin_continue(int width);
|
||||
int hlin_double_continue(int width);
|
||||
int hlin_double(int page, int x1, int x2, int at);
|
||||
|
||||
int collision(int xx, int yy, int ground_color);
|
||||
|
||||
#define APPLE_UP 11
|
||||
#define APPLE_DOWN 10
|
||||
|
102
gr-sim/tfv.c
102
gr-sim/tfv.c
@ -30,9 +30,9 @@ static unsigned char items1=0xff,items2=0xff;
|
||||
static unsigned char steps=0;
|
||||
|
||||
/* location */
|
||||
static int map_x=5;
|
||||
static int tfv_x=15,tfv_y=15;
|
||||
|
||||
static unsigned char map_x=5;
|
||||
static char tfv_x=15,tfv_y=19;
|
||||
static unsigned char ground_color;
|
||||
|
||||
static void draw_segment(void) {
|
||||
|
||||
@ -784,9 +784,11 @@ static int do_battle(void) {
|
||||
|
||||
static int load_map_bg(void) {
|
||||
|
||||
int i,temp,ground_color;
|
||||
int i,temp;
|
||||
int start,end;
|
||||
|
||||
ground_color=(COLOR_LIGHTGREEN|(COLOR_LIGHTGREEN<<4));
|
||||
|
||||
if (map_x==3) {
|
||||
grsim_unrle(harfco_rle,0x800);
|
||||
return 0;
|
||||
@ -809,9 +811,9 @@ static int load_map_bg(void) {
|
||||
hlin_double(1,0,40,i);
|
||||
}
|
||||
|
||||
if (map_x<4) ground_color=COLOR_WHITE;
|
||||
else if (map_x==13) ground_color=COLOR_ORANGE;
|
||||
else ground_color=COLOR_LIGHTGREEN;
|
||||
if (map_x<4) ground_color=(COLOR_WHITE|(COLOR_WHITE<<4));
|
||||
else if (map_x==13) ground_color=(COLOR_ORANGE|(COLOR_ORANGE<<4));
|
||||
else ground_color=(COLOR_LIGHTGREEN|(COLOR_LIGHTGREEN<<4));
|
||||
|
||||
/* grassland/sloped left beach */
|
||||
if ((map_x&3)==0) {
|
||||
@ -900,6 +902,7 @@ static int world_map(void) {
|
||||
int ch;
|
||||
int direction=1;
|
||||
int i,limit;
|
||||
int newx=0,newy=0,moved;
|
||||
|
||||
/************************************************/
|
||||
/* Landed */
|
||||
@ -922,20 +925,21 @@ static int world_map(void) {
|
||||
int refresh=1;
|
||||
|
||||
while(1) {
|
||||
moved=0;
|
||||
newx=tfv_x;
|
||||
newy=tfv_y;
|
||||
|
||||
ch=grsim_input();
|
||||
|
||||
if ((ch=='q') || (ch==27)) break;
|
||||
|
||||
if ((ch=='w') || (ch==APPLE_UP)) {
|
||||
tfv_y-=2;
|
||||
odd=!odd;
|
||||
steps++;
|
||||
newy=tfv_y-2;
|
||||
moved=1;
|
||||
}
|
||||
if ((ch=='s') || (ch==APPLE_DOWN)) {
|
||||
tfv_y+=2;
|
||||
odd=!odd;
|
||||
steps++;
|
||||
newy=tfv_y+2;
|
||||
moved=1;
|
||||
}
|
||||
if ((ch=='a') || (ch==APPLE_LEFT)) {
|
||||
if (direction>0) {
|
||||
@ -943,10 +947,9 @@ static int world_map(void) {
|
||||
odd=0;
|
||||
}
|
||||
else {
|
||||
odd=!odd;
|
||||
tfv_x--;
|
||||
newx=tfv_x-1;
|
||||
moved=1;
|
||||
}
|
||||
steps++;
|
||||
}
|
||||
if ((ch=='d') || (ch==APPLE_RIGHT)) {
|
||||
if (direction<0) {
|
||||
@ -954,33 +957,9 @@ static int world_map(void) {
|
||||
odd=0;
|
||||
}
|
||||
else {
|
||||
odd=!odd;
|
||||
tfv_x++;
|
||||
newx=tfv_x+1;
|
||||
moved=1;
|
||||
}
|
||||
steps++;
|
||||
}
|
||||
|
||||
if (tfv_x>36) {
|
||||
map_x++;
|
||||
tfv_x=0;
|
||||
refresh=1;
|
||||
}
|
||||
if (tfv_x<0) {
|
||||
map_x--;
|
||||
tfv_x=35;
|
||||
refresh=1;
|
||||
}
|
||||
|
||||
if (tfv_y<4) {
|
||||
map_x-=4;
|
||||
tfv_y=28;
|
||||
refresh=1;
|
||||
}
|
||||
|
||||
if (tfv_y>28) {
|
||||
map_x+=4;
|
||||
tfv_y=4;
|
||||
refresh=1;
|
||||
}
|
||||
|
||||
if (ch=='h') print_help();
|
||||
@ -1015,6 +994,45 @@ static int world_map(void) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Collision detection + Movement */
|
||||
if (moved) {
|
||||
odd=!odd;
|
||||
steps++;
|
||||
|
||||
if (collision(newx,newy+10,ground_color)) {
|
||||
}
|
||||
else {
|
||||
tfv_x=newx;
|
||||
tfv_y=newy;
|
||||
}
|
||||
|
||||
if (tfv_x>36) {
|
||||
map_x++;
|
||||
tfv_x=0;
|
||||
refresh=1;
|
||||
}
|
||||
if (tfv_x<=0) {
|
||||
map_x--;
|
||||
tfv_x=35;
|
||||
refresh=1;
|
||||
}
|
||||
|
||||
if ((tfv_y<4) && (map_x>=4)) {
|
||||
map_x-=4;
|
||||
tfv_y=28;
|
||||
refresh=1;
|
||||
}
|
||||
|
||||
if (tfv_y>=28) {
|
||||
map_x+=4;
|
||||
tfv_y=4;
|
||||
refresh=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (direction==-1) {
|
||||
if (odd) grsim_put_sprite(0,tfv_walk_left,tfv_x,tfv_y);
|
||||
else grsim_put_sprite(0,tfv_stand_left,tfv_x,tfv_y);
|
||||
|
Loading…
Reference in New Issue
Block a user