Design principle about the aircraft shooting game (join time: 2001-3-4)

zhaozj2021-02-08  218

Author: Yoon Yong

Limited horizontal, please don't show :)

As we all know, the aircraft shooting game is almost our first type of computer game, whether it is in the arcade or in a computer, this type of game is very easy to play and recruit. Even in this instant strategic game, 3D first perspective game, the game is also very pleasant to play, playing a plane.

After studying the knowledge about DirectX in these days, I went to the game of the plane shot. It seems that it is very complicated, in fact, it is just a collection of data structures, or it is more easy to implement.

Regarding DirectDraw programming, I don't want to introduce it, because any one can read the book for a few days, it is nothing more than the 2 to 3 surfaces of the application, Win32 The API function seems to have made us no need to spend a very smooth animation.

The following is a brief introduction to the design method, the key is the control of Player airplane and enemy aircraft, and the control of their bullets.

Obviously, you can implement them with 2 objects. They are Player's aircraft (can be 2), enemy aircraft.

Player's plane:

Class CPlayer

{

Private:

Cpoint ptpos; // aircraft coordinates

Struct Bullet * stbullet; // Link of all bullets issued by the plane

Struct Display Plandisplay; / / 用 information about the aircraft's bitmap information pointer, aircraft effective area, etc.

Private:

Freshbullet (); // Timed refreshing bullet linked list, remove bullets that have exploded or disappeared

PUBLIC:

Int noil; // aircraft oil

INT nspeed; // aircraft speed

Int ndisplayState; // Display mode, if you are hit, turn to the explosive state so that

/ / The aircraft display function shows the explosion effect, for example, normal 1,

// Disappear is 0, and the explosion is -15. In this way, the display function can

// Simple according to this plant, calculate image position in Sufface

// Direct display can be, each time 1, this -15 plus 15 times

// turning 0, the animation also shows, the plane also disappeared, no need

// Other processing. Such methods can also be used in the process of bullets,

PUBLIC:

Cpoint getpos (); // Get the coordinates of the plane

Void setpos (cpoint); // Social set aircraft coordinates

Void addbullet (struct bullet *); // Add a bullet to the plane, as long as the TickTime is set

// Join once, you can form a continuous bulk effect

Void runbullet (); // Every set TickTime, press Bullet's attribute update

// bullet's coordinates, you can form a complex bullet effect

Struct Bullet * isattack (cpoint); // Get the current coordinates have bullets, and return to the bullet pointer

// This is to determine if the enemy machine is hitting the function

// The enemy machine can put your coordinates in cpoint, you can

// Know if it is hit, and set the status of the bullet with the pointer

}

Bullet Struct

Struct Bullet

{

Struct Bullet * Next; // Refers to one bullet

INT nStyle; // Type of bullets

INT nspeed; // The speed of bullets

INT nDirection; // Birage direction

Int nDisplayState; // Display mode, if the target is hit, turn to the explosive state so that

/ / Runbullet function shows the explosion effect, the same as the aircraft processing method on the upper

}

The enemy's class and Player's plane is similar, remove the properties of oil, etc., add a MotionStyle property, control the plane

Flight and attack methods such as lines, slashes, curves, SIN methods, tracking methods, etc. Add a Run () method, use

MotionStyle determines the transformation method of the aircraft coordinates when each TickTime, which can be visually visually controlled by the flight and attacks of the aircraft.

When judging if the parties are attacked, just use the PLAYER object's isattack, put the coordinates of all enemile objects in it,

Get all the aircraft hit by Player, in turn calls isattack with all enemy machines, put the coordinates of the Player plane in it.

You can know if the Player is hit.

As for whether it is hit, it can be judged by a rectangle, and the perfect method is of course to be judged by RGN (area), and the contour of the aircraft

It is possible in the region.

As for the design of the background, it is more simple. Just use a two-dimensional array, put the code of the bitmap in each array unit, pass a code and

The mapping of bitmap RECT can generate a background map. If you want to create a three-dimensional sensation, or the unit in the background is covered, you can pass

Set the priority method, draw the priority of the first level, then draw high priority, naturally you can generate stereoscopic effects. A simpler method is

Press directly from top to bottom (assuming background three-dimensional is up), you can.

转载请注明原文地址:https://www.9cbs.com/read-1637.html

New Post(0)