⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outpost.cpp

📁 一个太空大战游戏的源程序及演示程序 VC++ 6.0
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// DEMO14_1.CPP - OutPost Game Demo


// INCLUDES ///////////////////////////////////////////////

#define INITGUID

#define WIN32_LEAN_AND_MEAN  

#include <windows.h>   // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h> 
#include <math.h>
#include <io.h>
#include <fcntl.h>

#include <ddraw.h>  // directX includes
#include <dsound.h>
#include <dmksctrl.h>
#include <dmusici.h>
#include <dmusicc.h>
#include <dmusicf.h>
#include <dinput.h>
#include "T3DLIB1.h" // game library includes
#include "T3DLIB2.h"
#include "T3DLIB3.h"


//#include "mono.h"

// DEFINES ////////////////////////////////////////////////

// mathematical defines
CONST float FRICTION = 0.1;

// defines for windows 
#define WINDOW_CLASS_NAME "WINCLASS"  // class name

#define WINDOW_WIDTH    640            // size of window viewport
#define WINDOW_HEIGHT   480

// size of universe
#define UNIVERSE_MIN_X   (-8000)
#define UNIVERSE_MAX_X   (8000)
#define UNIVERSE_MIN_Y   (-8000)
#define UNIVERSE_MAX_Y   (8000)

// weapons defines
#define MAX_PLASMA         32   // max number of plasma pulses
#define PLASMA_SPEED       16   // pixels/sec of plasma pulse
#define PLASMA_SPEED_SLOW  12   // slow version for gunships

#define PLASMA_STATE_OFF   0   // this plasma is dead or off
#define PLASMA_STATE_ON    1   // this one is alive and in flight
#define PLASMA_RANGE_1     30  // type 1 plasma disruptor

#define PLASMA_ANIM_PLAYER     0  // a plasma torpedeo from player
#define PLASMA_ANIM_ENEMY      1  // a plasma torpedeo from any enemy

// asteroid field defines
#define MAX_ROCKS             300
#define ROCK_STATE_OFF        0   // this rock is dead or off
#define ROCK_STATE_ON         1   // this one is alive and in flight

#define ROCK_LARGE            0   // sizes of rock
#define ROCK_MEDIUM           1
#define ROCK_SMALL            2

// explosion defines 
#define MAX_BURSTS            8
#define BURST_STATE_OFF       0   // this burst is dead or off
#define BURST_STATE_ON        1   // this one is alive

// defines for player states
#define PLAYER_STATE_DEAD           0
#define PLAYER_STATE_DYING          1
#define PLAYER_STATE_INVINCIBLE     2
#define PLAYER_STATE_ALIVE          3
#define PLAYER_REGEN_COUNT          100 // click before regenerating

#define WRAITH_INDEX_DIR            3 // index of direction var

#define MAX_PLAYER_SPEED            16

// sound id's
#define MAX_FIRE_SOUNDS       8
#define MAX_EXPL_SOUNDS       8

// defines for gunships
#define MAX_GUNSHIPS          8

#define GUNSHIP_RANGE_RING       1000 // distance from player gunship will be created at

#define GUNSHIP_RIGHT            0
#define GUNSHIP_LEFT             1

#define MAX_GUNSHIP_DAMAGE       150
#define INDEX_GUNSHIP_DAMAGE     2  // damage level of gunship
#define INDEX_GUNSHIP_DIR        3  // direction of ship 
#define INDEX_GUNSHIP_TURRET     4  // direction of turret

// life state for gunships
#define GUNSHIP_STATE_DEAD        0
#define GUNSHIP_STATE_ALIVE       1
#define GUNSHIP_STATE_DAMAGED     2  
#define GUNSHIP_STATE_DYING       3
#define GUNSHIP_MIN_ATTACK_RANGE  500

// defines for powerups
#define POWERUP_TYPE_AMMO       0
#define POWERUP_TYPE_SHLD       1

#define POWERUP_STATE_DEAD      0
#define POWERUP_STATE_ALIVE     1
#define MAX_POWERUPS            16
#define INDEX_POWERUP_TYPE      0


// defines for stations
#define MAX_STATIONS           20

// life state for stations
#define STATION_STATE_DEAD       0
#define STATION_STATE_ALIVE      1
#define STATION_STATE_DAMAGED    2  
#define STATION_STATE_DYING      3

#define STATION_SHIELDS_ANIM_ON  0  // animations for shields
#define STATION_SHIELDS_ANIM_OFF 1 

#define STATION_RANGE_RING       300

#define INDEX_STATION_DAMAGE     2  // tracks the current damage of station
#define MAX_STATION_DAMAGE      100

#define STATION_MIN_UPLINK_DISTANCE  150


// defines for mines
#define MAX_MINES                16

// life state for stations
#define MINE_STATE_DEAD       0
#define MINE_STATE_ALIVE      1
#define MINE_STATE_DAMAGED    2  
#define MINE_STATE_DYING      3

#define MINE_STATE_AI_ACTIVATED   1
#define MINE_STATE_AI_SLEEP       0

#define INDEX_MINE_AI_STATE       1  // state of ai system
#define INDEX_MINE_DAMAGE         2  // tracks the current damage of MINE
#define INDEX_MINE_CONTACT_COUNT  3  // tracks how long mine has been in contact with player

#define MAX_MINE_DAMAGE            50 
#define MAX_MINE_CONTACT_COUNT     20

#define MAX_MINE_VELOCITY        16  
#define MIN_MINE_TRACKING_DIST   1000
#define MIN_MINE_ACTIVATION_DIST 250 

// defines for the star field

#define MAX_STARS                256   // number of stars in universe

#define STAR_PLANE_0             0    // far plane
#define STAR_PLANE_1             1    // near plane
#define STAR_PLANE_2             2

#define STAR_COLOR_0             8    // color of farthest star plane
#define STAR_COLOR_1             7
#define STAR_COLOR_2             15   // color of nearest star plane


// defines for particle system
#define PARTICLE_STATE_DEAD               0
#define PARTICLE_STATE_ALIVE              1

// types of particles
#define PARTICLE_TYPE_FLICKER             0
#define PARTICLE_TYPE_FADE                1 

// color of particle
#define PARTICLE_COLOR_RED                0
#define PARTICLE_COLOR_GREEN              1
#define PARTICLE_COLOR_BLUE               2
#define PARTICLE_COLOR_WHITE              3

#define MAX_PARTICLES                     128

// color ranges
#define COLOR_RED_START                   32
#define COLOR_RED_END                     47

#define COLOR_GREEN_START                 96
#define COLOR_GREEN_END                   111

#define COLOR_BLUE_START                  144
#define COLOR_BLUE_END                    159

#define COLOR_WHITE_START                 16
#define COLOR_WHITE_END                   31

// indices used to access data arrays in BOBs 
#define INDEX_WORLD_X                     8
#define INDEX_WORLD_Y                     9

// defines for the states of the main loop
#define GAME_STATE_INIT                  0
#define GAME_STATE_MENU                  1
#define GAME_STATE_RESTART               2
#define GAME_STATE_RUNNING               3
#define GAME_STATE_UPLINK                4
#define GAME_STATE_EXIT                  5
#define GAME_STATE_WAITING_FOR_EXIT      6
#define GAME_STATE_PAUSED                7

// the menu defines
#define MENU_STATE_MAIN                  0   // main menu state 
#define MENU_STATE_INST                  1   // instructions state
#define MENU_SEL_NEW_GAME                0
#define MENU_SEL_INSTRUCTIONS            1
#define MENU_SEL_EXIT                    2
#define MAX_INSTRUCTION_PAGES            6  

// defines for font
#define FONT_NUM_CHARS         96  // entire character set
#define FONT_WIDTH             12
#define FONT_HEIGHT            12
#define FONT_WIDTH_NEXT_NUM    8
#define FONT_WIDTH_NEXT_LOWER  7
#define FONT_WIDTH_NEXT_UPPER  8

// number of starting objects
#define NUM_ACTIVE_GUNSHIPS          8
#define NUM_ACTIVE_MINES             8
#define NUM_ACTIVE_STATIONS          8


// PROTOTYPES /////////////////////////////////////////////

// game console
int  Game_Init(void *parms=NULL);
int  Game_Shutdown(void *parms=NULL);
int  Game_Main(void *parms=NULL);
void Game_Reset(void);

// helper functions for game logic
void Draw_Info(void);
void Start_Burst(int x, int y, int width, int height, int xv,int yv);
void Draw_Bursts(void);
void Move_Bursts(void);
void Delete_Bursts(void);
void Init_Bursts(void);
void Reset_Bursts(void);

void Draw_Rocks(void);
void Start_Rock(int x, int y, int size,int xv, int yv);
void Move_Rocks(void);
void Delete_Rocks(void);
void Init_Rocks(void);
void Reset_Rocks(void);


void Draw_Powerups(void);
void Start_Powerups(int type, int x, int y);
void Move_Powerups(void);
void Delete_Powerups(void);
void Init_Powerups(void);
void Reset_Powerups(void);


void Init_Gunships(void);
void Move_Gunships(void);
void Draw_Gunships(void);
void Start_Gunship(int override, int x, int y, int dir);
void Reset_Gunships(void);

void Fire_Plasma(int x,int y, int xv, int yv, int source);
void Draw_Plasma(void);
void Move_Plasma(void);
void Delete_Plasma(void);
void Init_Plasma(void);
void Reset_Plasma(void);

void Move_Stars(void);
void Draw_Stars(void);
void Init_Stars(void);
void Reset_Stars(void);


void Init_Reset_Particles(void);
void Draw_Particles(void);
void Move_Particles(void);
void Start_Particle(int type, int color, int count, int x, int y, int xv, int yv);
void Start_Particle_Explosion(int type, int color, int count, 
                              int x, int y, int xv, int yv, int num_particles);

void Reset_Particles(void);


void Init_Stations(void);
void Move_Stations(void);
void Draw_Stations(void);
void Start_Station(int override, int x, int y);
void Reset_Stations(void);


void Init_Mines(void);
void Move_Mines(void);
void Draw_Mines(void);
void Start_Mine(int override, int x, int y, int ai_state);
void Reset_Mines(void);


void Create_Tables(void);
float Fast_Distance_2D(float x, float y);
void Seed_Rocks(void);
int Load_Player(void);
void Draw_Scanner(void);
int Pad_Name(char *filename, char *extension, char *padstring, int num);

int Copy_Screen(UCHAR *source_bitmap,UCHAR *dest_buffer, int lpitch, int transparent);

void Load_Buttons(void);
void Load_HUD(void);


inline void Copy_Palette(LPPALETTEENTRY dest, LPPALETTEENTRY source)
{ memcpy(dest, source, 256*sizeof(PALETTEENTRY)); }


// TYPES //////////////////////////////////////////////////

// used to contain a single star
typedef struct STAR_TYP
        {
        int x,y;                   // position of star
        UCHAR color;               // color of star
        int plane;                 // plane that star is in

        } STAR, *STAR_PTR;


// a single particle
typedef struct PARTICLE_TYP
        {
        int state;           // state of the particle
        int type;            // type of particle effect
        int x,y;             // world position of particle
        int xv,yv;           // velocity of particle
        int curr_color;      // the current rendering color of particle
        int start_color;     // the start color or range effect
        int end_color;       // the ending color of range effect
        int counter;         // general state transition timer
        int max_count;       // max value for counter

        } PARTICLE, *PARTICLE_PTR;

// MACROS ////////////////////////////////////////////////

// used to compute the min and max of two expresions
#define MIN(a, b)  (((a) < (b)) ? (a) : (b)) 
#define MAX(a, b)  (((a) > (b)) ? (b) : (a)) 

// returns a rand in a range
#define RAND_RANGE(a,b) ((a)+(rand()%((b)-(a)+1)))

// GLOBALS ////////////////////////////////////////////////

HWND main_window_handle = NULL; // save the window handle
HINSTANCE main_instance = NULL; // save the instance
char buffer[80];                // used to print text

BITMAP_IMAGE background_bmp, menu_bmp; // used to hold backgrounds
BITMAP_IMAGE menu_sel_bmps[3];   // holds the menu selections
BITMAP_IMAGE andre;

BOB wraith;                   // the player 
BOB plasma[MAX_PLASMA];       // plasma pulses
BOB rocks[MAX_ROCKS];         // the asteroids
BOB rock_s, rock_m, rock_l;   // the master templates for surface info
BOB bursts[MAX_BURSTS];       // the explosion bursts
BOB gunships[MAX_GUNSHIPS];   // the gunships
BOB powerups[MAX_POWERUPS];   // the powerups
BOB stations[MAX_STATIONS];   // the starbase stations
BOB mines[MAX_MINES];         // the predator mines
BOB hud;                      // the art for the scanner hud
BOB stationsmall;             // small station bob

int rock_sizes[3] = {96,56,32}; // X,Y dims for scaler

STAR stars[MAX_STARS];          // the star field

PARTICLE particles[MAX_PARTICLES]; // the particles for the particle engine

// player state variables
int player_state       = PLAYER_STATE_ALIVE;
int player_score       = 0;   // the score
int player_ships       = 3;   // ships left
int player_regen_counter = 0; // used to track when to regen
int player_damage      = 0;   // damage of player
int player_ammo        = 1000;// ammo of player
int player_counter     = 0;   // used for state transition tracking
int player_regen_count = 0;   // used to regenerate player
int player_shield_count = 0;  // used to display shields
int ready_counter = 0,        // used to draw a little "get ready"
    ready_state   = 0;

float mine_tracking_rate = 2; // rate that mines track player

int win_counter = 0,          // tracks if player won
    player_won = 0;   

int station_id = -1,          // uplink station id
    num_stations_destroyed = 0;

int intro_done = 0;           // flags if intro has played already

int game_paused      = 0,
    pause_debounce   = 0,
    huds_on          = 1,
    scanner_on       = 1,
    huds_debounce    = 0,
    scanner_debounce = 0;

// color palettes, so we don't have to reload all the time
PALETTEENTRY         game_palette[256]; // holds the main game palette
PALETTEENTRY         menu_palette[256]; // gee what do you think
PALETTEENTRY         andre_palette[256]; // for me

// positional and state info for player
float player_x=0,
      player_y=0,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -