2017-08-13 19:38:49 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2017-08-13 19:38:49 +00:00
|
|
|
#include "gr-sim.h"
|
|
|
|
#include "tfv_utils.h"
|
|
|
|
#include "tfv_zp.h"
|
|
|
|
|
|
|
|
#include "tfv_sprites.h"
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
/* Mode7 code based on code from: */
|
|
|
|
/* http://www.helixsoft.nl/articles/circle/sincos.htm */
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-23 04:43:15 +00:00
|
|
|
static unsigned char flying_map[64]= {
|
|
|
|
2,15,15,15, 15,15,15, 2,
|
|
|
|
13,12,12, 8, 4, 4, 0,13,
|
|
|
|
13,12,12,12, 8, 4, 4,13,
|
|
|
|
13,12,12, 8, 4, 4, 4,13,
|
|
|
|
13,12, 9, 9, 8, 4, 4,13,
|
|
|
|
13,12, 9, 8, 4, 4, 4,13,
|
|
|
|
13,12, 9, 9, 1, 4, 4,13,
|
|
|
|
2,13,13,13, 13,13,13, 2};
|
|
|
|
|
|
|
|
#define TILE_W 64
|
|
|
|
#define TILE_H 64
|
2017-08-23 19:41:37 +00:00
|
|
|
#define MASK_X (TILE_W - 1)
|
|
|
|
#define MASK_Y (TILE_H - 1)
|
|
|
|
|
|
|
|
#define LOWRES_W 40
|
|
|
|
#define LOWRES_H 40
|
|
|
|
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-23 23:52:28 +00:00
|
|
|
|
|
|
|
static int lookup_map(int x, int y) {
|
|
|
|
|
|
|
|
int color;
|
|
|
|
|
|
|
|
color=2;
|
|
|
|
|
|
|
|
x=x&MASK_X;
|
|
|
|
y=y&MASK_Y;
|
|
|
|
|
|
|
|
if ( ((y&0x3)==1) && ((x&7)==0) ) color=14;
|
|
|
|
if ( ((y&0x3)==3) && ((x&7)==4) ) color=14;
|
|
|
|
|
|
|
|
|
|
|
|
if ((y<8) && (x<8)) {
|
|
|
|
color=flying_map[(y*8)+x];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2 2 2 2 2 2 2 2 */
|
|
|
|
/* 14 14 2 2 2 2 2 2 */
|
|
|
|
/* 2 2 2 2 14 14 2 2 */
|
|
|
|
/* 2 2 2 2 2 2 2 2 */
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
static int over_water;
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
// current screen position
|
|
|
|
static int screen_x, screen_y;
|
|
|
|
static char angle=0;
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-24 03:43:49 +00:00
|
|
|
#if 1
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
struct fixed_type {
|
|
|
|
char i;
|
|
|
|
unsigned char f;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// map coordinates
|
|
|
|
struct fixed_type speed = {0,0};
|
|
|
|
|
|
|
|
// the distance and horizontal scale of the line we are drawing
|
|
|
|
struct fixed_type distance = {0,0};
|
|
|
|
struct fixed_type horizontal_scale = {0,0};
|
|
|
|
|
|
|
|
// step for points in space between two pixels on a horizontal line
|
|
|
|
struct fixed_type line_dx = {0,0};
|
|
|
|
struct fixed_type line_dy = {0,0};
|
|
|
|
|
|
|
|
// current space position
|
|
|
|
struct fixed_type space_x;
|
|
|
|
struct fixed_type space_y;
|
|
|
|
|
|
|
|
// height of the camera above the plane
|
|
|
|
struct fixed_type space_z= {0x04,0x80}; // 4.5;
|
|
|
|
|
|
|
|
struct fixed_type BETA = {0xff,0x80}; // -0.5;
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
// map coordinates
|
2017-08-24 18:01:16 +00:00
|
|
|
static double double_cx;
|
|
|
|
static double double_cy;
|
|
|
|
static struct fixed_type cx = {0,0};
|
|
|
|
static struct fixed_type cy = {0,0};
|
|
|
|
static struct fixed_type dx;
|
|
|
|
static struct fixed_type dy;
|
2017-08-24 17:30:19 +00:00
|
|
|
|
|
|
|
#define SPEED_STOPPED 0
|
|
|
|
|
2017-08-24 18:01:16 +00:00
|
|
|
static unsigned char speed=SPEED_STOPPED; // 0..4, with 0=stopped
|
2017-08-24 17:30:19 +00:00
|
|
|
|
|
|
|
// the distance and horizontal scale of the line we are drawing
|
2017-08-24 18:01:16 +00:00
|
|
|
static double distance=0;
|
|
|
|
static double horizontal_scale=0;
|
2017-08-24 17:30:19 +00:00
|
|
|
|
|
|
|
// step for points in space between two pixels on a horizontal line
|
2017-08-24 18:01:16 +00:00
|
|
|
static double line_dx=0;
|
|
|
|
static double line_dy=0;
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
// current space position
|
|
|
|
double space_x,space_y;
|
|
|
|
|
|
|
|
// height of the camera above the plane
|
2017-08-24 18:01:16 +00:00
|
|
|
static double space_z=4.5;
|
|
|
|
static double BETA=-0.5;
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int horizon=-2; // number of pixels line 0 is below the horizon
|
|
|
|
|
2017-08-24 03:43:49 +00:00
|
|
|
#define SCALE_X 20.0
|
|
|
|
#define SCALE_Y 20.0
|
2017-08-23 23:52:28 +00:00
|
|
|
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
#define ANGLE_STEPS 16
|
|
|
|
|
2017-08-24 18:01:16 +00:00
|
|
|
// FIXME: take advantage of symmetry?
|
|
|
|
|
|
|
|
static struct fixed_type fixed_sin[ANGLE_STEPS]={
|
|
|
|
{0x00,0x00}, // 0.000000=00.00
|
|
|
|
{0x00,0x61}, // 0.382683=00.61
|
|
|
|
{0x00,0xb5}, // 0.707107=00.b5
|
|
|
|
{0x00,0xec}, // 0.923880=00.ec
|
|
|
|
{0x01,0x00}, // 1.000000=01.00
|
|
|
|
{0x00,0xec}, // 0.923880=00.ec
|
|
|
|
{0x00,0xb5}, // 0.707107=00.b5
|
|
|
|
{0x00,0x61}, // 0.382683=00.61
|
|
|
|
{0x00,0x00}, // 0.000000=00.00
|
|
|
|
{0xff,0x9f}, // -0.382683=ff.9f
|
|
|
|
{0xff,0x4b}, // -0.707107=ff.4b
|
|
|
|
{0xff,0x14}, // -0.923880=ff.14
|
|
|
|
{0xff,0x00}, // -1.000000=ff.00
|
|
|
|
{0xff,0x14}, // -0.923880=ff.14
|
|
|
|
{0xff,0x4b}, // -0.707107=ff.4b
|
|
|
|
{0xff,0x9f}, // -0.382683=ff.9f
|
|
|
|
};
|
|
|
|
|
|
|
|
// div by 8
|
|
|
|
static struct fixed_type fixed_sin_scale[ANGLE_STEPS]={
|
|
|
|
{0x00,0x00},
|
|
|
|
{0x00,0x0c},
|
|
|
|
{0x00,0x16},
|
|
|
|
{0x00,0x1d},
|
|
|
|
{0x00,0x20},
|
|
|
|
{0x00,0x1d},
|
|
|
|
{0x00,0x16},
|
|
|
|
{0x00,0x0c},
|
|
|
|
{0x00,0x00},
|
|
|
|
{0xff,0xf4},
|
|
|
|
{0xff,0xea},
|
|
|
|
{0xff,0xe3},
|
|
|
|
{0xff,0xe0},
|
|
|
|
{0xff,0xe3},
|
|
|
|
{0xff,0xea},
|
|
|
|
{0xff,0xf4},
|
|
|
|
};
|
|
|
|
|
|
|
|
static double sin_table[ANGLE_STEPS]={
|
2017-08-24 01:16:17 +00:00
|
|
|
0.000000,
|
|
|
|
0.382683,
|
|
|
|
0.707107,
|
|
|
|
0.923880,
|
|
|
|
1.000000,
|
|
|
|
0.923880,
|
|
|
|
0.707107,
|
|
|
|
0.382683,
|
|
|
|
0.000000,
|
|
|
|
-0.382683,
|
|
|
|
-0.707107,
|
|
|
|
-0.923880,
|
|
|
|
-1.000000,
|
|
|
|
-0.923880,
|
|
|
|
-0.707107,
|
|
|
|
-0.382683,
|
|
|
|
};
|
|
|
|
|
2017-08-24 18:01:16 +00:00
|
|
|
static double our_sin(unsigned char angle) {
|
2017-08-24 01:16:17 +00:00
|
|
|
return sin_table[angle&0xf];
|
|
|
|
}
|
|
|
|
|
2017-08-24 18:01:16 +00:00
|
|
|
static double our_cos(unsigned char angle) {
|
2017-08-24 01:16:17 +00:00
|
|
|
|
|
|
|
return sin_table[(angle+4)&0xf];
|
|
|
|
}
|
|
|
|
|
2017-08-24 18:01:16 +00:00
|
|
|
static void fixed_to_double(struct fixed_type *f, double *d) {
|
|
|
|
|
|
|
|
*d=f->i;
|
|
|
|
*d+=((double)(f->f))/256.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fixed_add(struct fixed_type *x, struct fixed_type *y, struct fixed_type *z) {
|
|
|
|
int carry;
|
|
|
|
short sum;
|
|
|
|
|
|
|
|
sum=(short)(x->f)+(short)(y->f);
|
|
|
|
|
|
|
|
if (sum>=256) carry=1;
|
|
|
|
else carry=0;
|
|
|
|
|
|
|
|
z->f=sum&0xff;
|
|
|
|
|
|
|
|
z->i=x->i+y->i+carry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
//
|
|
|
|
// Non-detailed version
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
void draw_background_mode7(void) {
|
2017-08-23 23:52:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
int map_color;
|
|
|
|
|
|
|
|
over_water=0;
|
|
|
|
|
|
|
|
/* Draw Sky */
|
|
|
|
/* Originally wanted to be fancy and have sun too, but no */
|
|
|
|
color_equals(COLOR_MEDIUMBLUE);
|
|
|
|
for(screen_y=0;screen_y<6;screen_y+=2) {
|
|
|
|
hlin_double(ram[DRAW_PAGE], 0, 40, screen_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw hazy horizon */
|
|
|
|
color_equals(COLOR_GREY);
|
|
|
|
hlin_double(ram[DRAW_PAGE], 0, 40, 6);
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
for (screen_y = 8; screen_y < LOWRES_H; screen_y+=2) {
|
2017-08-23 23:52:28 +00:00
|
|
|
// first calculate the distance of the line we are drawing
|
2017-08-24 03:43:49 +00:00
|
|
|
distance = (space_z * SCALE_Y) / (screen_y + horizon);
|
2017-08-23 23:52:28 +00:00
|
|
|
|
|
|
|
// then calculate the horizontal scale, or the distance between
|
|
|
|
// space points on this horizontal line
|
2017-08-24 03:43:49 +00:00
|
|
|
horizontal_scale = (distance / SCALE_X);
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-24 18:01:16 +00:00
|
|
|
// printf("Distance=%lf, horizontal-scale=%lf\n",
|
|
|
|
// distance,horizontal_scale);
|
|
|
|
|
2017-08-23 23:52:28 +00:00
|
|
|
// calculate the dx and dy of points in space when we step
|
|
|
|
// through all points on this line
|
2017-08-24 01:16:17 +00:00
|
|
|
line_dx = -our_sin(angle) * horizontal_scale;
|
|
|
|
line_dy = our_cos(angle) * horizontal_scale;
|
2017-08-23 23:52:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Move camera back a bit
|
|
|
|
double factor;
|
|
|
|
factor=space_z*BETA;
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
// space_x+=factor*our_cos(angle);
|
|
|
|
// space_y+=factor*our_sin(angle);
|
|
|
|
|
|
|
|
// calculate the starting position
|
2017-08-24 18:01:16 +00:00
|
|
|
space_x = double_cx + ((distance+factor) * our_cos(angle)) - LOWRES_W/2 * line_dx;
|
|
|
|
space_y = double_cy + ((distance+factor) * our_sin(angle)) - LOWRES_W/2 * line_dy;
|
2017-08-23 23:52:28 +00:00
|
|
|
|
|
|
|
// go through all points in this screen line
|
|
|
|
for (screen_x = 0; screen_x < LOWRES_W-1; screen_x++) {
|
|
|
|
// get a pixel from the tile and put it on the screen
|
|
|
|
|
|
|
|
map_color=lookup_map((int)space_x,(int)space_y);
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
ram[COLOR]=map_color;
|
|
|
|
ram[COLOR]|=map_color<<4;
|
2017-08-23 23:52:28 +00:00
|
|
|
|
|
|
|
if (screen_x==20) {
|
|
|
|
if (map_color==COLOR_DARKBLUE) over_water=1;
|
|
|
|
else over_water=0;
|
|
|
|
}
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
hlin_double(ram[DRAW_PAGE], screen_x, screen_x+1,
|
|
|
|
screen_y);
|
2017-08-23 23:52:28 +00:00
|
|
|
|
|
|
|
// advance to the next position in space
|
|
|
|
space_x += line_dx;
|
|
|
|
space_y += line_dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
#define SHIPX 15
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
int flying(void) {
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
unsigned char ch;
|
|
|
|
int shipy;
|
|
|
|
int turning=0;
|
|
|
|
int draw_splash=0;
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
/************************************************/
|
|
|
|
/* Flying */
|
|
|
|
/************************************************/
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
gr();
|
|
|
|
shipy=20;
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
while(1) {
|
|
|
|
if (draw_splash>0) draw_splash--;
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
ch=grsim_input();
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
if ((ch=='q') || (ch==27)) break;
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
if ((ch=='w') || (ch==APPLE_UP)) {
|
|
|
|
if (shipy>16) {
|
|
|
|
shipy-=2;
|
|
|
|
space_z+=1;
|
|
|
|
}
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
printf("Z=%lf\n",space_z);
|
|
|
|
}
|
|
|
|
if ((ch=='s') || (ch==APPLE_DOWN)) {
|
|
|
|
if (shipy<28) {
|
|
|
|
shipy+=2;
|
|
|
|
space_z-=1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
draw_splash=10;
|
|
|
|
}
|
|
|
|
printf("Z=%lf\n",space_z);
|
|
|
|
}
|
|
|
|
if ((ch=='a') || (ch==APPLE_LEFT)) {
|
|
|
|
if (turning>0) {
|
|
|
|
turning=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
turning=-20;
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
angle-=1;
|
|
|
|
if (angle<0) angle+=ANGLE_STEPS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((ch=='d') || (ch==APPLE_RIGHT)) {
|
|
|
|
if (turning<0) {
|
|
|
|
turning=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
turning=20;
|
|
|
|
angle+=1;
|
|
|
|
if (angle>=ANGLE_STEPS) angle-=ANGLE_STEPS;
|
|
|
|
}
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
// increase speed
|
2017-08-24 01:16:17 +00:00
|
|
|
if (ch=='z') {
|
2017-08-24 17:30:19 +00:00
|
|
|
if (speed<3) speed++;
|
2017-08-24 01:16:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
// decrease speed
|
2017-08-24 01:16:17 +00:00
|
|
|
if (ch=='x') {
|
2017-08-24 17:30:19 +00:00
|
|
|
if (speed>0) speed--;
|
2017-08-24 01:16:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
// emergency break
|
2017-08-24 01:16:17 +00:00
|
|
|
if (ch==' ') {
|
2017-08-24 17:30:19 +00:00
|
|
|
speed=SPEED_STOPPED;
|
2017-08-24 01:16:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
if (speed!=SPEED_STOPPED) {
|
2017-08-24 01:16:17 +00:00
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
int ii;
|
2017-08-24 01:16:17 +00:00
|
|
|
|
2017-08-24 18:01:16 +00:00
|
|
|
dx.i = fixed_sin_scale[(angle+4)&0xf].i; // cos
|
|
|
|
dx.f = fixed_sin_scale[(angle+4)&0xf].f; // cos
|
|
|
|
dy.i = fixed_sin_scale[angle&0xf].i;
|
|
|
|
dy.f = fixed_sin_scale[angle&0xf].f;
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
|
|
|
|
for(ii=0;ii<speed;ii++) {
|
2017-08-24 18:01:16 +00:00
|
|
|
fixed_add(&cx,&dx,&cx);
|
|
|
|
fixed_add(&cy,&dy,&cy);
|
2017-08-24 17:30:19 +00:00
|
|
|
}
|
2017-08-24 18:01:16 +00:00
|
|
|
fixed_to_double(&cx,&double_cx);
|
|
|
|
fixed_to_double(&cy,&double_cy);
|
2017-08-24 17:30:19 +00:00
|
|
|
|
|
|
|
}
|
2017-08-24 01:16:17 +00:00
|
|
|
|
|
|
|
draw_background_mode7();//our_angle, flyx, flyy);
|
|
|
|
|
|
|
|
if (turning==0) {
|
2017-08-24 17:30:19 +00:00
|
|
|
if ((speed!=SPEED_STOPPED) && (over_water)&&(draw_splash)) {
|
2017-08-24 01:16:17 +00:00
|
|
|
grsim_put_sprite(splash_forward,
|
|
|
|
SHIPX+1,shipy+9);
|
|
|
|
}
|
|
|
|
grsim_put_sprite(shadow_forward,SHIPX+3,31+space_z);
|
|
|
|
grsim_put_sprite(ship_forward,SHIPX,shipy);
|
|
|
|
}
|
|
|
|
if (turning<0) {
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
if ((shipy>25) && (speed!=SPEED_STOPPED)) draw_splash=1;
|
2017-08-24 01:16:17 +00:00
|
|
|
|
|
|
|
if (over_water&&draw_splash) {
|
|
|
|
grsim_put_sprite(splash_left,
|
|
|
|
SHIPX+1,36);
|
|
|
|
}
|
|
|
|
grsim_put_sprite(shadow_left,SHIPX+3,31+space_z);
|
|
|
|
grsim_put_sprite(ship_left,SHIPX,shipy);
|
|
|
|
turning++;
|
|
|
|
}
|
|
|
|
if (turning>0) {
|
|
|
|
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
if ((shipy>25) && (speed!=SPEED_STOPPED)) draw_splash=1;
|
2017-08-24 01:16:17 +00:00
|
|
|
|
|
|
|
if (over_water&&draw_splash) {
|
|
|
|
grsim_put_sprite(splash_right,
|
|
|
|
SHIPX+1,36);
|
|
|
|
}
|
|
|
|
grsim_put_sprite(shadow_right,SHIPX+3,31+space_z);
|
|
|
|
grsim_put_sprite(ship_right,SHIPX,shipy);
|
|
|
|
turning--;
|
|
|
|
}
|
|
|
|
|
|
|
|
page_flip();
|
|
|
|
|
|
|
|
usleep(20000);
|
|
|
|
|
|
|
|
}
|
|
|
|
return 0;
|
2017-08-23 04:43:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-23 19:41:37 +00:00
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
|
|
|
|
|
2017-08-22 20:32:21 +00:00
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
// map coordinates
|
|
|
|
double cx=0.0,cy=0.0;
|
2017-08-24 03:43:49 +00:00
|
|
|
static double space_z=4.5; // height of the camera above the plane
|
|
|
|
static int horizon=-2; // number of pixels line 0 is below the horizon
|
|
|
|
static double scale_x=20, scale_y=20;
|
|
|
|
|
|
|
|
double BETA=-0.5;
|
|
|
|
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
#define ANGLE_STEPS 32
|
|
|
|
|
|
|
|
double our_sin(unsigned char angle) {
|
|
|
|
|
|
|
|
double r;
|
|
|
|
|
|
|
|
r=3.14159265358979*2.0*(double)angle/(double)ANGLE_STEPS;
|
|
|
|
|
|
|
|
return sin(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
double our_cos(unsigned char angle) {
|
|
|
|
|
|
|
|
double r;
|
|
|
|
|
|
|
|
r=3.14159265358979*2.0*(double)angle/(double)ANGLE_STEPS;
|
|
|
|
|
|
|
|
return cos(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Detailed version
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
void draw_background_mode7(void) {
|
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
|
|
|
|
// the distance and horizontal scale of the line we are drawing
|
|
|
|
double distance, horizontal_scale;
|
|
|
|
|
|
|
|
// step for points in space between two pixels on a horizontal line
|
|
|
|
double line_dx, line_dy;
|
|
|
|
|
|
|
|
// current space position
|
|
|
|
double space_x, space_y;
|
2017-08-22 20:32:21 +00:00
|
|
|
int map_color;
|
|
|
|
|
|
|
|
over_water=0;
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-23 18:01:40 +00:00
|
|
|
/* Draw Sky */
|
|
|
|
/* Originally wanted to be fancy and have sun too, but no */
|
2017-08-17 20:00:48 +00:00
|
|
|
color_equals(COLOR_MEDIUMBLUE);
|
|
|
|
for(screen_y=0;screen_y<6;screen_y+=2) {
|
2017-08-23 19:41:37 +00:00
|
|
|
hlin_double(ram[DRAW_PAGE], 0, 40, screen_y);
|
2017-08-17 20:00:48 +00:00
|
|
|
}
|
2017-08-23 18:01:40 +00:00
|
|
|
|
|
|
|
/* Draw hazy horizon */
|
2017-08-17 20:00:48 +00:00
|
|
|
color_equals(COLOR_GREY);
|
2017-08-23 19:41:37 +00:00
|
|
|
hlin_double(ram[DRAW_PAGE], 0, 40, 6);
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-23 04:43:15 +00:00
|
|
|
|
2017-08-23 19:41:37 +00:00
|
|
|
for (screen_y = 8; screen_y < LOWRES_H; screen_y++) {
|
2017-08-17 20:00:48 +00:00
|
|
|
// first calculate the distance of the line we are drawing
|
|
|
|
distance = (space_z * scale_y) / (screen_y + horizon);
|
|
|
|
|
|
|
|
// then calculate the horizontal scale, or the distance between
|
|
|
|
// space points on this horizontal line
|
|
|
|
horizontal_scale = (distance / scale_x);
|
|
|
|
|
|
|
|
// calculate the dx and dy of points in space when we step
|
|
|
|
// through all points on this line
|
2017-08-24 01:16:17 +00:00
|
|
|
line_dx = -our_sin(angle) * horizontal_scale;
|
|
|
|
line_dy = our_cos(angle) * horizontal_scale;
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-22 20:32:21 +00:00
|
|
|
double factor;
|
2017-08-24 17:30:19 +00:00
|
|
|
// Move camera back a bit
|
2017-08-22 20:32:21 +00:00
|
|
|
factor=space_z*BETA;
|
|
|
|
|
2017-08-24 17:30:19 +00:00
|
|
|
// calculate the starting position
|
|
|
|
space_x = cx + ((distance+factor) * our_cos(angle)) - LOWRES_W/2 * line_dx;
|
|
|
|
space_y = cy + ((distance+factor) * our_sin(angle)) - LOWRES_W/2 * line_dy;
|
2017-08-17 20:00:48 +00:00
|
|
|
|
|
|
|
// go through all points in this screen line
|
2017-08-23 19:41:37 +00:00
|
|
|
for (screen_x = 0; screen_x < LOWRES_W-1; screen_x++) {
|
2017-08-17 20:00:48 +00:00
|
|
|
// get a pixel from the tile and put it on the screen
|
|
|
|
|
2017-08-23 04:43:15 +00:00
|
|
|
map_color=lookup_map((int)space_x,(int)space_y);
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
color_equals(map_color);
|
2017-08-23 19:41:37 +00:00
|
|
|
|
2017-08-22 20:32:21 +00:00
|
|
|
if (screen_x==20) {
|
|
|
|
if (map_color==COLOR_DARKBLUE) over_water=1;
|
|
|
|
else over_water=0;
|
|
|
|
}
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
plot(screen_x,screen_y);
|
2017-08-17 20:00:48 +00:00
|
|
|
|
|
|
|
// advance to the next position in space
|
|
|
|
space_x += line_dx;
|
|
|
|
space_y += line_dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
|
2017-08-23 23:52:28 +00:00
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-23 19:41:37 +00:00
|
|
|
#define SHIPX 15
|
|
|
|
|
2017-08-13 19:38:49 +00:00
|
|
|
int flying(void) {
|
|
|
|
|
|
|
|
unsigned char ch;
|
2017-08-23 19:41:37 +00:00
|
|
|
int shipy;
|
2017-08-17 20:00:48 +00:00
|
|
|
int turning=0;
|
|
|
|
double dy,dx,speed=0;
|
2017-08-22 20:32:21 +00:00
|
|
|
int draw_splash=0;
|
2017-08-13 19:38:49 +00:00
|
|
|
|
|
|
|
/************************************************/
|
|
|
|
/* Flying */
|
|
|
|
/************************************************/
|
|
|
|
|
|
|
|
gr();
|
2017-08-23 19:41:37 +00:00
|
|
|
shipy=20;
|
2017-08-13 19:38:49 +00:00
|
|
|
|
|
|
|
while(1) {
|
2017-08-22 20:32:21 +00:00
|
|
|
if (draw_splash>0) draw_splash--;
|
|
|
|
|
2017-08-13 19:38:49 +00:00
|
|
|
ch=grsim_input();
|
|
|
|
|
|
|
|
if ((ch=='q') || (ch==27)) break;
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-23 18:01:40 +00:00
|
|
|
#if 0
|
2017-08-17 20:00:48 +00:00
|
|
|
if (ch=='g') {
|
|
|
|
BETA+=0.1;
|
|
|
|
printf("Horizon=%lf\n",BETA);
|
|
|
|
}
|
|
|
|
if (ch=='h') {
|
|
|
|
BETA-=0.1;
|
|
|
|
printf("Horizon=%lf\n",BETA);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch=='s') {
|
|
|
|
scale_x++;
|
|
|
|
scale_y++;
|
|
|
|
printf("Scale=%lf\n",scale_x);
|
|
|
|
}
|
2017-08-23 18:01:40 +00:00
|
|
|
#endif
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-23 18:01:40 +00:00
|
|
|
if ((ch=='w') || (ch==APPLE_UP)) {
|
2017-08-23 19:41:37 +00:00
|
|
|
if (shipy>16) {
|
|
|
|
shipy-=2;
|
2017-08-17 20:00:48 +00:00
|
|
|
space_z+=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Z=%lf\n",space_z);
|
|
|
|
}
|
2017-08-23 18:01:40 +00:00
|
|
|
if ((ch=='s') || (ch==APPLE_DOWN)) {
|
2017-08-23 19:41:37 +00:00
|
|
|
if (shipy<28) {
|
|
|
|
shipy+=2;
|
2017-08-17 20:00:48 +00:00
|
|
|
space_z-=1;
|
|
|
|
}
|
2017-08-22 20:32:21 +00:00
|
|
|
else {
|
|
|
|
draw_splash=10;
|
|
|
|
}
|
2017-08-17 20:00:48 +00:00
|
|
|
printf("Z=%lf\n",space_z);
|
|
|
|
}
|
2017-08-23 18:01:40 +00:00
|
|
|
if ((ch=='a') || (ch==APPLE_LEFT)) {
|
2017-08-17 20:00:48 +00:00
|
|
|
if (turning>0) {
|
|
|
|
turning=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
turning=-20;
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
angle-=1;
|
|
|
|
if (angle<0) angle+=ANGLE_STEPS;
|
2017-08-17 20:00:48 +00:00
|
|
|
}
|
2017-08-13 19:38:49 +00:00
|
|
|
}
|
2017-08-23 18:01:40 +00:00
|
|
|
if ((ch=='d') || (ch==APPLE_RIGHT)) {
|
2017-08-17 20:00:48 +00:00
|
|
|
if (turning<0) {
|
|
|
|
turning=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
turning=20;
|
2017-08-24 01:16:17 +00:00
|
|
|
angle+=1;
|
|
|
|
if (angle>=ANGLE_STEPS) angle-=ANGLE_STEPS;
|
2017-08-17 20:00:48 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 19:38:49 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
if (ch=='z') {
|
2017-08-22 20:32:21 +00:00
|
|
|
if (speed>0.5) speed=0.5;
|
2017-08-17 20:00:48 +00:00
|
|
|
speed+=0.05;
|
|
|
|
}
|
2017-08-13 19:38:49 +00:00
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
if (ch=='x') {
|
2017-08-22 20:32:21 +00:00
|
|
|
if (speed<-0.5) speed=-0.5;
|
2017-08-17 20:00:48 +00:00
|
|
|
speed-=0.05;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch==' ') {
|
|
|
|
speed=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
dx = speed * our_cos (angle);
|
|
|
|
dy = speed * our_sin (angle);
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
cx += dx;
|
|
|
|
cy += dy;
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
draw_background_mode7();//our_angle, flyx, flyy);
|
2017-08-17 20:00:48 +00:00
|
|
|
|
2017-08-22 20:32:21 +00:00
|
|
|
if (turning==0) {
|
|
|
|
if ((speed>0.0) && (over_water)&&(draw_splash)) {
|
2017-08-23 19:41:37 +00:00
|
|
|
grsim_put_sprite(splash_forward,
|
|
|
|
SHIPX+1,shipy+9);
|
2017-08-22 20:32:21 +00:00
|
|
|
}
|
2017-08-23 19:41:37 +00:00
|
|
|
grsim_put_sprite(shadow_forward,SHIPX+3,31+space_z);
|
|
|
|
grsim_put_sprite(ship_forward,SHIPX,shipy);
|
2017-08-22 20:32:21 +00:00
|
|
|
}
|
2017-08-17 20:00:48 +00:00
|
|
|
if (turning<0) {
|
2017-08-22 20:32:21 +00:00
|
|
|
|
2017-08-23 19:41:37 +00:00
|
|
|
if ((shipy>25) && (speed>0.0)) draw_splash=1;
|
2017-08-22 20:32:21 +00:00
|
|
|
|
|
|
|
if (over_water&&draw_splash) {
|
2017-08-23 19:41:37 +00:00
|
|
|
grsim_put_sprite(splash_left,
|
|
|
|
SHIPX+1,36);
|
2017-08-22 20:32:21 +00:00
|
|
|
}
|
2017-08-23 19:41:37 +00:00
|
|
|
grsim_put_sprite(shadow_left,SHIPX+3,31+space_z);
|
|
|
|
grsim_put_sprite(ship_left,SHIPX,shipy);
|
2017-08-17 20:00:48 +00:00
|
|
|
turning++;
|
|
|
|
}
|
|
|
|
if (turning>0) {
|
2017-08-22 20:32:21 +00:00
|
|
|
|
|
|
|
|
2017-08-23 19:41:37 +00:00
|
|
|
if ((shipy>25) && (speed>0.0)) draw_splash=1;
|
2017-08-22 20:32:21 +00:00
|
|
|
|
|
|
|
if (over_water&&draw_splash) {
|
2017-08-23 19:41:37 +00:00
|
|
|
grsim_put_sprite(splash_right,
|
|
|
|
SHIPX+1,36);
|
2017-08-22 20:32:21 +00:00
|
|
|
}
|
2017-08-23 19:41:37 +00:00
|
|
|
grsim_put_sprite(shadow_right,SHIPX+3,31+space_z);
|
|
|
|
grsim_put_sprite(ship_right,SHIPX,shipy);
|
2017-08-17 20:00:48 +00:00
|
|
|
turning--;
|
|
|
|
}
|
2017-08-13 19:38:49 +00:00
|
|
|
|
2017-08-23 19:41:37 +00:00
|
|
|
page_flip();
|
2017-08-13 19:38:49 +00:00
|
|
|
|
2017-08-17 20:00:48 +00:00
|
|
|
usleep(20000);
|
|
|
|
|
2017-08-13 19:38:49 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-24 01:16:17 +00:00
|
|
|
#endif
|