?? demo12_3.cpp
字號:
plane_2_dy = -int(player_yv);
// move all the stars based on the motion of the player
for (index=0; index < MAX_STARS; index++)
{
// locally cache star position to speed up calculations
star_x = stars[index].x;
star_y = stars[index].y;
// test which star field star is in so it is translated with correct
// perspective
switch(stars[index].plane)
{
case STAR_PLANE_0:
{
// move the star based on differntial motion of player
// far plane is divided by 4
star_x+=plane_0_dx;
star_y+=plane_0_dy;
} break;
case STAR_PLANE_1:
{
// move the star based on differntial motion of player
// middle plane is divided by 2
star_x+=plane_1_dx;
star_y+=plane_1_dy;
} break;
case STAR_PLANE_2:
{
// move the star based on differntial motion of player
// near plane is divided by 1
star_x+=plane_2_dx;
star_y+=plane_2_dy;
} break;
} // end switch plane
// test if a star has flown off an edge
if (star_x >= SCREEN_WIDTH)
star_x = star_x-SCREEN_WIDTH;
else
if (star_x < 0)
star_x = SCREEN_WIDTH + star_x;
if (star_y >= SCREEN_HEIGHT)
star_y = star_y-SCREEN_HEIGHT;
else
if (star_y < 0)
star_y = SCREEN_HEIGHT+star_y;
// reset stars position in structure
stars[index].x = star_x;
stars[index].y = star_y;
} // end for index
} // end Move_Stars
/////////////////////////////////////////////////////////////////////////////
void Draw_Stars(void)
{
// this function draws all the stars
// lock back surface
DDraw_Lock_Back_Surface();
// draw all the stars
for (int index=0; index < MAX_STARS; index++)
{
// draw stars
Draw_Pixel(stars[index].x,stars[index].y, stars[index].color,back_buffer, back_lpitch);
} // end for index
// unlock the secondary surface
DDraw_Unlock_Back_Surface();
} // end Draw_Stars
///////////////////////////////////////////////////
void Draw_Scanner(void)
{
// this function draws all the stars
int index,sx,sy; // looping and position
// lock back surface
DDraw_Lock_Back_Surface();
// draw all the rocks
for (index=0; index < MAX_ROCKS; index++)
{
// draw rock blips
if (rocks[index].state==ROCK_STATE_ON)
{
sx = ((rocks[index].varsI[INDEX_WORLD_X] - UNIVERSE_MIN_X) >> 7) + (SCREEN_WIDTH/2) - ((UNIVERSE_MAX_X - UNIVERSE_MIN_X) >> 8);
sy = ((rocks[index].varsI[INDEX_WORLD_Y] - UNIVERSE_MIN_Y) >> 7) + 32;
Draw_Pixel(sx,sy,8,back_buffer, back_lpitch);
} // end if
} // end for index
// draw all the mines
for (index=0; index < MAX_MINES; index++)
{
// draw gunship blips
if (mines[index].state==MINE_STATE_ALIVE)
{
sx = ((mines[index].varsI[INDEX_WORLD_X] - UNIVERSE_MIN_X) >> 7) + (SCREEN_WIDTH/2) - ((UNIVERSE_MAX_X - UNIVERSE_MIN_X) >> 8);
sy = ((mines[index].varsI[INDEX_WORLD_Y] - UNIVERSE_MIN_Y) >> 7) + 32;
Draw_Pixel(sx,sy,12,back_buffer, back_lpitch);
Draw_Pixel(sx,sy+1,12,back_buffer, back_lpitch);
} // end if
} // end for index
// unlock the secondary surface
DDraw_Unlock_Back_Surface();
// draw all the stations
for (index=0; index < MAX_STATIONS; index++)
{
// draw station blips
if (stations[index].state==STATION_STATE_ALIVE)
{
sx = ((stations[index].varsI[INDEX_WORLD_X] - UNIVERSE_MIN_X) >> 7) + (SCREEN_WIDTH/2) - ((UNIVERSE_MAX_X - UNIVERSE_MIN_X) >> 8);
sy = ((stations[index].varsI[INDEX_WORLD_Y] - UNIVERSE_MIN_Y) >> 7) + 32;
// test for state
if (stations[index].anim_state == STATION_SHIELDS_ANIM_ON)
{
stationsmall.curr_frame = 0;
stationsmall.x = sx - 3;
stationsmall.y = sy - 3;
Draw_BOB(&stationsmall,lpddsback);
} // end if
else
{
stationsmall.curr_frame = 1;
stationsmall.x = sx - 3;
stationsmall.y = sy - 3;
Draw_BOB(&stationsmall,lpddsback);
} // end if
} // end if
} // end for index
// unlock the secondary surface
DDraw_Lock_Back_Surface();
// draw player as white blip
sx = ((int(player_x) - UNIVERSE_MIN_X) >> 7) + (SCREEN_WIDTH/2) - ((UNIVERSE_MAX_X - UNIVERSE_MIN_X) >> 8);
sy = ((int(player_y) - UNIVERSE_MIN_Y) >> 7) + 32;
int col = rand()%256;
Draw_Pixel(sx,sy,col,back_buffer, back_lpitch);
Draw_Pixel(sx+1,sy,col,back_buffer, back_lpitch);
Draw_Pixel(sx,sy+1,col,back_buffer, back_lpitch);
Draw_Pixel(sx+1,sy+1,col,back_buffer, back_lpitch);
// unlock the secondary surface
DDraw_Unlock_Back_Surface();
// now draw the art around the edges
hud.x = 320-64;
hud.y = 32-4;
hud.curr_frame = 0;
Draw_BOB(&hud,lpddsback);
hud.x = 320+64-16;
hud.y = 32-4;
hud.curr_frame = 1;
Draw_BOB(&hud,lpddsback);
hud.x = 320-64;
hud.y = 32+128-20;
hud.curr_frame = 2;
Draw_BOB(&hud,lpddsback);
hud.x = 320+64-16;
hud.y = 32+128-20;
hud.curr_frame = 3;
Draw_BOB(&hud,lpddsback);
} // end Draw_Scanner
///////////////////////////////////////////////////////////
void Init_Stations(void)
{
// this function loads and initializes the stations to a known state
static int shields_on_anim[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
shields_off_anim[1] = {16};
int frame; // looping va
// create the first bob
Create_BOB(&stations[0],0,0,192,144,17,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM,
DDSCAPS_SYSTEMMEMORY);
// load animation frames
for (frame=0; frame <= 16; frame++)
{
// load the rocks imagery
Pad_Name("OUTART/STATION", "BMP", buffer, frame);
Load_Bitmap_File(&bitmap8bit, buffer);
// load the actual .BMP
Load_Frame_BOB(&stations[0],&bitmap8bit,frame,0,0,BITMAP_EXTRACT_MODE_ABS);
// unload data infile
Unload_Bitmap_File(&bitmap8bit);
} // end if
// set state to off
stations[0].state = STATION_STATE_ALIVE;
// set anim state
stations[0].anim_state = STATION_SHIELDS_ANIM_ON;
// set damage to 0
stations[0].varsI[INDEX_STATION_DAMAGE] = 0;
// set animation rate
Set_Anim_Speed_BOB(&stations[0],15);
// load in the shield on/off animations
Load_Animation_BOB(&stations[0], STATION_SHIELDS_ANIM_ON, 16, shields_on_anim);
Load_Animation_BOB(&stations[0], STATION_SHIELDS_ANIM_OFF, 1, shields_off_anim);
// set animation to on
Set_Animation_BOB(&stations[0], STATION_SHIELDS_ANIM_ON);
// make copies
for (int ship=1; ship < MAX_STATIONS; ship++)
{
memcpy(&stations[ship], &stations[0], sizeof(BOB));
} // end for pulse
// load the miniature station
Create_BOB(&stationsmall,0,0,8,8,2,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_FRAME,
DDSCAPS_SYSTEMMEMORY);
Load_Bitmap_File(&bitmap8bit, "OUTART/STATIONSMALL8.BMP");
// load the actual .BMP
Load_Frame_BOB(&stationsmall,&bitmap8bit,0,0,0,BITMAP_EXTRACT_MODE_CELL);
Load_Frame_BOB(&stationsmall,&bitmap8bit,1,1,0,BITMAP_EXTRACT_MODE_CELL);
// unload data infile
Unload_Bitmap_File(&bitmap8bit);
} // end Init_Stations
///////////////////////////////////////////////////////////
void Reset_Stations(void)
{
// this function resets all the stations in preparation for another run
for (int index=0; index < MAX_STATIONS; index++)
{
// set state to off
stations[index].state = STATION_STATE_DEAD;
// set anim state
stations[index].anim_state = STATION_SHIELDS_ANIM_ON;
// set damage to 0
stations[index].varsI[INDEX_STATION_DAMAGE] = 0;
} // end for
} // end Reset_Stations
///////////////////////////////////////////////////////////
void Start_Station(int override=0, int x=0, int y=0)
{
// this functions starts a station, note that if override = 1
// then the function uses the sent data otherwise it's random
// first find an available stations
for (int index=0; index < MAX_STATIONS; index++)
{
// is this one dead
if (stations[index].state == STATION_STATE_DEAD)
{
// position the station
int xpos = RAND_RANGE((UNIVERSE_MIN_X+256),(UNIVERSE_MAX_X-256));
int ypos = RAND_RANGE((UNIVERSE_MIN_Y+256),(UNIVERSE_MAX_Y-256));
// set position
stations[index].varsI[INDEX_WORLD_X] = xpos;
stations[index].varsI[INDEX_WORLD_Y] = ypos;
// start a mine up in the vicinity
int ang = rand()%16;
float mine_x = xpos + STATION_RANGE_RING*cos_look16[ang];
float mine_y = ypos + STATION_RANGE_RING*sin_look16[ang];
// start a deactivated mine
Start_Mine(1, mine_x, mine_y, MINE_STATE_AI_SLEEP);
// set velocity
stations[index].xv = 0;
stations[index].yv = 0;
// set remaining state variables
stations[index].state = STATION_STATE_ALIVE;
// set animation to on
Set_Animation_BOB(&stations[index], STATION_SHIELDS_ANIM_ON);
// set anim state
stations[index].anim_state = STATION_SHIELDS_ANIM_ON;
// set damage to 0
stations[index].varsI[INDEX_STATION_DAMAGE] = 0;
// done so exit
return;
} // end if
} // end for index
} // end Start_Station
////////////////////////////////////////////////////////////
void Move_Stations(void)
{
// this function moves/animates all the stations
for (int index=0; index < MAX_STATIONS; index++)
{
// test if station is alive
if (stations[index].state == STATION_STATE_ALIVE)
{
// move the stations
stations[index].varsI[INDEX_WORLD_X]+=stations[index].xv;
stations[index].varsI[INDEX_WORLD_Y]+=stations[index].yv;
// test for boundaries
if (stations[index].varsI[INDEX_WORLD_X] > UNIVERSE_MAX_X)
{
stations[index].varsI[INDEX_WORLD_X] = UNIVERSE_MIN_X;
} // end if
else
if (stations[index].varsI[INDEX_WORLD_X] < UNIVERSE_MIN_X )
{
stations[index].varsI[INDEX_WORLD_X] = UNIVERSE_MAX_X;
} // end if
if (stations[index].varsI[INDEX_WORLD_Y] > UNIVERSE_MAX_Y)
{
stations[index].varsI[INDEX_WORLD_Y] = UNIVERSE_MIN_Y;
} // end if
else
if (stations[index].varsI[INDEX_WORLD_Y] < UNIVERSE_MIN_Y )
{
stations[index].varsI[INDEX_WORLD_Y] = UNIVERSE_MAX_Y;
} // end if
// test for damage level
if (stations[index].varsI[INDEX_STATION_DAMAGE] > (MAX_STATION_DAMAGE/4) &&
(rand()%(20 - (stations[index].varsI[INDEX_STATION_DAMAGE] >> 3))) == 1)
{
int width = 20+rand()%60;
// start a burst
Start_Burst(stations[index].varsI[INDEX_WORLD_X] - (stations[index].width*.5)+RAND_RANGE(0,stations[index].width),
stations[index].varsI[INDEX_WORLD_Y] - (stations[index].height*.5)+RAND_RANGE(0,stations[index].height),
width,(width >> 2) + (width >> 1),
int(stations[index].xv)*.5, int(stations[index].yv)*.5);
// add some particles
} // end if
} // end if alive
} // end for index
} // end Move_Stations
///////////////////////////////////////////////////////////
void Draw_Stations(void)
{
// this function draws all the stations
for (int index=0; index < MAX_STATIONS; index++)
{
// test if station is alive
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -