tfv: more tweaks to the flying code

This commit is contained in:
Vince Weaver
2017-08-22 16:32:21 -04:00
parent bd9fd4a42b
commit aff55f6629
4 changed files with 135 additions and 32 deletions

View File

@@ -39,9 +39,9 @@ static unsigned char flying_map[32][32]= {
{2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,}, {2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,},
{2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,}, {2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,},
{2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,}, {2,2,2,2, 2,9,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,},
{2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,}, {2,2,2,2, 9,0,9,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,},
{2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,}, {2,2,2,2, 2,9,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,},
{2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,}, {2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,},
{2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,}, {2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2,},
@@ -61,15 +61,17 @@ static int tile_w=32,tile_h=32;
/* http://www.helixsoft.nl/articles/circle/sincos.htm */ /* http://www.helixsoft.nl/articles/circle/sincos.htm */
static double space_z=2.5; // height of the camera above the plane static double space_z=0.5; // height of the camera above the plane
static int horizon=-2; // number of pixels line 0 is below the horizon static int horizon=-2; // number of pixels line 0 is below the horizon
static double scale_x=20, scale_y=20; static double scale_x=20, scale_y=20;
// scale of space coordinates to screen coordinates // scale of space coordinates to screen coordinates
static double bmp_w=40, bmp_h=40; static double bmp_w=40, bmp_h=40;
//void mode_7 (BITMAP *bmp, BITMAP *tile, fixed angle, fixed cx, fixed cy, MODE_7_PARAMS params) //void mode_7 (BITMAP *bmp, BITMAP *tile, fixed angle, fixed cx, fixed cy, MODE_7_PARAMS params)
double BETA=-0.6; double BETA=-0.5;
static int over_water;
void draw_background_mode7(double angle, double cx, double cy) { void draw_background_mode7(double angle, double cx, double cy) {
@@ -88,6 +90,9 @@ void draw_background_mode7(double angle, double cx, double cy) {
// current space position // current space position
double space_x, space_y; double space_x, space_y;
int map_color;
over_water=0;
clear_top(0); clear_top(0);
@@ -115,22 +120,39 @@ void draw_background_mode7(double angle, double cx, double cy) {
space_x = cx + (distance * cos(angle)) - bmp_w/2 * line_dx; space_x = cx + (distance * cos(angle)) - bmp_w/2 * line_dx;
space_y = cy + (distance * sin(angle)) - bmp_w/2 * line_dy; space_y = cy + (distance * sin(angle)) - bmp_w/2 * line_dy;
space_x+=(BETA*space_z*cos(angle)); // Move camera back a bit
space_y+=(BETA*space_z*sin(angle));
double factor;
factor=space_z*BETA;
// factor=2.0*BETA;
space_x+=factor*cos(angle);
space_y+=factor*sin(angle);
// go through all points in this screen line // go through all points in this screen line
for (screen_x = 0; screen_x < bmp_w; screen_x++) { for (screen_x = 0; screen_x < bmp_w; screen_x++) {
// get a pixel from the tile and put it on the screen // get a pixel from the tile and put it on the screen
color_equals(flying_map[(int)space_x & mask_x] map_color=(flying_map[(int)space_x & mask_x]
[(int)space_y&mask_y]); [(int)space_y&mask_y]);
color_equals(map_color);
if (screen_x==20) {
if (map_color==COLOR_DARKBLUE) over_water=1;
else over_water=0;
}
basic_plot(screen_x,screen_y); basic_plot(screen_x,screen_y);
// advance to the next position in space // advance to the next position in space
space_x += line_dx; space_x += line_dx;
space_y += line_dy; space_y += line_dy;
} }
} }
} }
@@ -145,13 +167,14 @@ int flying(void) {
double flyx=0,flyy=0; double flyx=0,flyy=0;
double our_angle=0.0; double our_angle=0.0;
double dy,dx,speed=0; double dy,dx,speed=0;
int draw_splash=0;
/************************************************/ /************************************************/
/* Flying */ /* Flying */
/************************************************/ /************************************************/
gr(); gr();
xx=17; yy=26; xx=15; yy=28;
color_equals(COLOR_BLACK); color_equals(COLOR_BLACK);
@@ -167,6 +190,8 @@ int flying(void) {
} }
while(1) { while(1) {
if (draw_splash>0) draw_splash--;
ch=grsim_input(); ch=grsim_input();
if ((ch=='q') || (ch==27)) break; if ((ch=='q') || (ch==27)) break;
@@ -195,10 +220,13 @@ int flying(void) {
printf("Z=%lf\n",space_z); printf("Z=%lf\n",space_z);
} }
if ((ch=='m') || (ch==APPLE_DOWN)) { if ((ch=='m') || (ch==APPLE_DOWN)) {
if (yy<30) { if (yy<28) {
yy+=2; yy+=2;
space_z-=1; space_z-=1;
} }
else {
draw_splash=10;
}
printf("Z=%lf\n",space_z); printf("Z=%lf\n",space_z);
} }
if ((ch=='j') || (ch==APPLE_LEFT)) { if ((ch=='j') || (ch==APPLE_LEFT)) {
@@ -211,6 +239,7 @@ int flying(void) {
our_angle-=(6.28/32.0); our_angle-=(6.28/32.0);
if (our_angle<0.0) our_angle+=6.28; if (our_angle<0.0) our_angle+=6.28;
} }
// printf("Angle %lf\n",our_angle); // printf("Angle %lf\n",our_angle);
} }
if ((ch=='k') || (ch==APPLE_RIGHT)) { if ((ch=='k') || (ch==APPLE_RIGHT)) {
@@ -223,14 +252,15 @@ int flying(void) {
if (our_angle>6.28) our_angle-=6.28; if (our_angle>6.28) our_angle-=6.28;
} }
} }
if (ch=='z') { if (ch=='z') {
if (speed>0.5) speed=0.5;
speed+=0.05; speed+=0.05;
} }
if (ch=='x') { if (ch=='x') {
if (speed<-0.5) speed=-0.5;
speed-=0.05; speed-=0.05;
} }
@@ -251,14 +281,39 @@ int flying(void) {
draw_background_mode7(our_angle, flyx, flyy); draw_background_mode7(our_angle, flyx, flyy);
grsim_put_sprite(0,ship_shadow,xx,30);
if (turning==0) grsim_put_sprite(0,ship_forward,xx,yy); printf("%d %d %d\n",over_water,draw_splash,yy);
if (turning==0) {
if ((speed>0.0) && (over_water)&&(draw_splash)) {
grsim_put_sprite(0,splash_forward,
xx+1,yy+9);
}
grsim_put_sprite(0,shadow_forward,xx+3,31+space_z);
grsim_put_sprite(0,ship_forward,xx,yy);
}
if (turning<0) { if (turning<0) {
if ((yy>25) && (speed>0.0)) draw_splash=1;
if (over_water&&draw_splash) {
grsim_put_sprite(0,splash_left,
xx+1,36);
}
grsim_put_sprite(0,shadow_left,xx+3,31+space_z);
grsim_put_sprite(0,ship_left,xx,yy); grsim_put_sprite(0,ship_left,xx,yy);
turning++; turning++;
} }
if (turning>0) { if (turning>0) {
if ((yy>25) && (speed>0.0)) draw_splash=1;
if (over_water&&draw_splash) {
grsim_put_sprite(0,splash_right,
xx+1,36);
}
grsim_put_sprite(0,shadow_right,xx+3,31+space_z);
grsim_put_sprite(0,ship_right,xx,yy); grsim_put_sprite(0,ship_right,xx,yy);
turning--; turning--;
} }

View File

@@ -64,34 +64,74 @@ unsigned char test_sprite[]={
0xff,0x1f,0x4f,0x2f,0xff,0x22,0x20,0x00, 0xff,0x1f,0x4f,0x2f,0xff,0x22,0x20,0x00,
0x5f,0x5f,0x5f,0x5f,0xff,0xf2,0xf2,0xf2, 0x5f,0x5f,0x5f,0x5f,0xff,0xf2,0xf2,0xf2,
}; };
#endif #endif
unsigned char ship_shadow[]={
0x5,0x3, unsigned char splash_forward[]={
0x00,0x00,0x00,0x00,0x00, 0x7,0x2,
0x00,0x00,0xaa,0x00,0x00, 0x00,0xee,0x00,0x00,0x00,0xee,0x00,
0x00,0x00,0xaa,0x00,0x00, 0xee,0x00,0x00,0x00,0x00,0x00,0xee,
};
unsigned char splash_right[]={
0x7,0x2,
0x00,0x00,0x00,0x00,0x00,0xee,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xee,
};
unsigned char splash_left[]={
0x7,0x2,
0x00,0xee,0x00,0x00,0x00,0x00,0x00,
0xee,0x00,0x00,0x00,0x00,0x00,0x00,
};
unsigned char shadow_forward[]={
0x3,0x2,
0x00,0xaa,0x00,
0xa0,0xaa,0xa0,
};
unsigned char shadow_right[]={
0x3,0x2,
0xa0,0x00,0xaa,
0x00,0x0a,0xa0,
};
unsigned char shadow_left[]={
0x3,0x2,
0xaa,0x00,0xa0,
0xa0,0x0a,0x00,
}; };
unsigned char ship_forward[]={ unsigned char ship_forward[]={
0x5,0x3, 0x9,0x5,
0x00,0x00,0x77,0x00,0x00, 0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x00,
0x50,0x55,0x77,0x55,0x50, 0x00,0x00,0x00,0x66,0xff,0x66,0x00,0x00,0x00,
0x01,0x00,0x07,0x00,0x01, 0x00,0x00,0x70,0x2f,0x12,0x2f,0x70,0x00,0x00,
0xf0,0xf7,0xf7,0xf2,0xd9,0xf2,0xf7,0xf7,0xf0,
0x00,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x00,
}; };
unsigned char ship_right[]={ unsigned char ship_right[]={
0x5,0x3, 0x9,0x5,
0x50,0x00,0x70,0x77,0x00, 0x00,0x00,0x00,0x00,0x00,0x60,0x60,0xf0,0x00,
0x01,0x55,0x77,0x55,0x50, 0x00,0xf0,0x70,0x70,0xf6,0xf6,0x6f,0x66,0x00,
0x00,0x77,0x07,0x00,0x15, 0x00,0x07,0xff,0x2f,0x12,0x27,0xf6,0x00,0x00,
0x00,0x00,0x00,0xdd,0xd9,0xf2,0x77,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0x70,0x00,
}; };
unsigned char ship_left[]={ unsigned char ship_left[]={
0x5,0x3, 0x9,0x5,
0x00,0x77,0x70,0x00,0x50, 0x00,0xf0,0x60,0x60,0x00,0x00,0x00,0x00,0x00,
0x50,0x55,0x77,0x55,0x01, 0x00,0x66,0x6f,0xf6,0xf6,0x70,0x70,0xf0,0x00,
0x15,0x00,0x07,0x77,0x00, 0x00,0x00,0xf6,0x27,0x12,0x2f,0xff,0x07,0x00,
0x00,0x00,0x77,0xf2,0xd9,0xdd,0x00,0x00,0x00,
0x00,0x70,0xff,0x0f,0x00,0x00,0x00,0x00,0x00,
}; };

View File

@@ -3,9 +3,17 @@ extern unsigned char tfv_walk_right[];
extern unsigned char tfv_stand_left[]; extern unsigned char tfv_stand_left[];
extern unsigned char tfv_walk_left[]; extern unsigned char tfv_walk_left[];
extern unsigned char tfv_led_sword[]; extern unsigned char tfv_led_sword[];
extern unsigned char ship_forward[]; extern unsigned char ship_forward[];
extern unsigned char ship_right[]; extern unsigned char ship_right[];
extern unsigned char ship_left[]; extern unsigned char ship_left[];
extern unsigned char shadow_forward[];
extern unsigned char shadow_right[];
extern unsigned char shadow_left[];
extern unsigned char splash_forward[];
extern unsigned char splash_right[];
extern unsigned char splash_left[];
extern unsigned char killer_crab[]; extern unsigned char killer_crab[];
extern unsigned char palm_tree[]; extern unsigned char palm_tree[];
extern unsigned char pine_tree[]; extern unsigned char pine_tree[];
@@ -13,4 +21,4 @@ extern unsigned char snowy_tree[];
extern unsigned char cactus[]; extern unsigned char cactus[];
extern unsigned char mountain[]; extern unsigned char mountain[];
extern unsigned char lightning[]; extern unsigned char lightning[];
extern unsigned char ship_shadow[];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB