# Video Game Development Study Notes (2)

Source: Internet
Author: User

(5)
Transform
Translation
Rotate
Zoom
Translation
Translate and transform an genie by redrawing
In short, it is moving from one coordinate to another.
Tx and ty are respectively called the moving distance along the X and Y axes.
T (tx, ty) is called a translation vector.

Rotate
Rotate along the circular path
Determine a Rotation Transformation:
-Angle
-Center of gravity (reference point of rotation)
-Axis of rotation (in a two-dimensional plane, the Axis-Z axis of a plane composed of the vertical X axis and Y axis)
-Clockwise or counterclockwise
Note that the positive rotation angle is the clockwise angle and the Reverse Rotation Angle.
Is the clockwise corner.

Zoom
Scale to change its size
Sx and sy are required in a two-dimensional space.
The ratio of X axis to Y axis.
Multiply the x and y axes by the scaling ratio respectively to get the scaling result.
For example, if there is a vector (x, y), the following method gets the scaling result:
X' = sx * x
Y' = sy * y
If sx = sy, it means proportional Scaling

Rectangular collision
Each frame is a rectangular image.
The edge of the genie is rectangular.
By calculating the relative relationship between two sprite edges (rectangles)
Location to determine whether a collision has occurred

Detection of collision or crossover
Edge of the first rectangle: L = 1, R = 3, T = 3, B = 1
Edge of the second rectangle: L' = 2, R' = 4, T' = 4, B '= 2
The following result is displayed:
Max (L, l') = Max (1, 2) = 2
Min (R, R') = Min (3, 4) = 3
Max (B, B ') = Max (1, 2) = 2
Min (T, T') = Min (3, 4) = 3
Crossover of computing boundaries:
-Max (L, l')-Min (R, R'), Max (B, B ')-Min (T, T') <= 0
-Max (2-3, 2-3) <= 0
-Max (-1,-1) =-1
--1 <= 0, so a crossover occurs.
After the boundary of the two rectangles
Forming a new rectangle: L = 2,
R = 3, T = 3, B = 2
Detection of collision or crossover
Edge of the first rectangle: L = 1.2, R = 2.8, T = 2.6, B = 1
Edge of the second rectangle: L' = 3.6, R' = 5.3, T' = 4.5, B '= 3
Available:
Max (L, l') = Max (1.2, 3.6) = 3.6
Min (R, R') = Min (2.8, 5.3) = 2.8
Max (B, B ') = Max (1, 3) = 3
Min (T, T') = Min (2.6, 4.5) = 2.6
Crossover of computing boundaries:
-Max (L, l')-Min (R, R'), Max (B, B ')-Min (T, T') <= 0
-Max (3.6-2.8, 3-2.6) <= 0
-Max (0.8, 0.4) = 0.8
-0.8> 0, so no crossover
Because the result is positive, it indicates that
Are not forming a new rectangle

Other coordinate systems
The screen coordinate system uses the cursor as the origin (0, 0)
Make a slight modification in the preceding scheme:
-The left and right directions remain unchanged.
-Since the top is smaller than the bottom coordinate value:
Max (B, B ') to Min (B, B ')
Min (T, T') to Max (T, T ')
-The equation is changed:
Max (L, l')-Min (R, R'), Min (B, B ')-Max (T, T') <= 0

Speed
The speed V (x, y) indicates the moving step and direction of an object.
Step Size
-The step size is the length of the vector V (x, y ).
-Example:
S = (x2 + y2) ^ (-2)
Direction
-The unit vector is a vector with a length of "1 ".
-Used to indicate the direction
-For example, uv (x/L, y/L), where L is the length of the original vector V:
L = (x2 + y2) ^ (-2)

(6)
Direct X namespace
Microsoft. DirectX. AudioVideoPlayback
The AudioVideoPlaybackapplication programming
Interface (API) provides for basic playback and simple
Control of audio and video files.

Microsoft. DirectX. Direct3D
Microsoft Direct3D is a low-level graphics application
Programming interface (API) that enables you
Manipulate visual models of 3-D objects and take

Microsoft. DirectX. DirectInput
Microsoft DirectInput is used to process data from
Keyboard, mouse, joystick, or other game controller.

Microsoft. DirectX. DirectSound
Microsoft DirectSound provides a system to capture
Sounds from input devices and play sounds through
Various playback devices using advanced 3-D
Positioning effects, and filters for echo, distortion,
Reverberation, and other effects.

Microsoft. DirectX. PrivateImplementationDetails
The PrivateImplementationDetailsnamespace contains
Structures and interfaces that allow the managed
Application programming interface (API) to have access
To the unmanaged portions of the Microsoft DirectXAPI.

Microsoft. DirectX. Security
Controls permissions related to Microsoft Direct3D,
Microsoft DirectInput, Microsoft DirectPlay, and Microsoft DirectSound.

Input
Press the keyboard
"Press" is the status of a button.
The keyboard input is executed when the key is pressed.
Call the 'ispressed 'method to obtain the key status (that is, whether the key is pressed.
This method returns a Boolean value.
For example, the following code checks whether the 'up arrow' key is pressed.
Keyboard. IsPressed (Key. UpArrow)
Trigger
This is another State of the key, when the key is not pressed to press.
To obtain the status (whether the status has changed), call the 'istriggered' method.
This method returns a Boolean value.
For example, the following code checks whether the Space key has changed its status
Keyboard. IsTriggered (Key. Space)

Game implementation
In the game, direction keys are used to control the movement of cavalry
Press the Up arrow key to control the cavalry Up, and also press the Down arrow key to control Down
When the Space key is triggered, the cavalry will launch a bullet. (Bullets are dynamically created)

If (Keyboard. IsTriggered (Key. Space ))
{
Fire fire = (Fire) startrow.fire. Clone ();
Fire. Position = new PointF (Position. X, Position. Y-35 );
Fire. Velocity = new Vector2 (0,-4 );
}

(7)
Sound
Effect sound
Effect sound: The sound played when an event occurs in the game.
It is generally the sound of a specific action, for example:
Bullets
Tank Explosion
Bullet ball hitting the wall

Add an effect sound to the game
First, create a Sound class instance.
And then specify a WAV file.
Public static sound shoot;
Add a sound object to a game
Note: In
Specified in the initial constructor of the startroopergame class.
Create a sound object
Shoot = new sound ("shoot.wav ");

Sound
Add the following code in 'startroopergame. CS 'to declare the effect sound.
Public static sound shoot;
Public static sound die;
Add the following code in the 'initializeresources 'method:
Shoot = new sound ("shoot.wav ");
Die = new sound ("die.wav ");

Background Music
During game operation, we turn background music into music
The background music can be played cyclically or only once.
The background music can also change with the plot
The background music can be Midi, WAV, or compressed, such as Ogg Vorbis or mp3.

Add background music to the game
Background Music is a music object and a WAV file is specified.
Public static music;
Add music objects to the game
Note: the path of the folder where the wav file of the background music is located is specified in the initial constructor of the startroopergame class.
Create a music object:
Music = new music ("music.wav ");
Background music is played cyclically in the game. The following code
Used to play wav files
Music. Play ();
To play background music cyclically, add the following code to the 'update' method of the 'startroopergame. CS 'file.
If (! Music. isplaying)
Music. Play ();

Text
What is text?
Text is a string displayed on the screen
Text has the following attributes: value, Font, color, position, visible, active
Why use text?
Used to display the content of a text file
Show variable values
Display specific messages during the game

First, select the font
Font objects
To create a new font object, you must set the type, size, and style attributes and add them to the game.
Font font = new font ("Arial", 14.0f, fontstyle. Regular );
Create a Text2D object based on the font to display game scores
Public static Text2D Score;
Text2D Score = new Text2D (font );

Add text objects to the game
Set the text, position, and color attributes of the text object.
Score. Text = "Score: 0 ";
Score. Position = new Point (150, 0 );
Score. Color = Color. Red;
Finally, add the game score to the game.
Startrow.score = Score;
Note: to add a new text class, you can add a file, such as 'yourtext. cs ', and then derive a class named 'yourtext' from the Text2D class.

(8)
Behavior Introduction
Behavior is a series of user-defined functions
Behaviors describe how a game or game object moves or acts.
We can define the behavior of Game objects like Genie and text.
After assigning a function to a game behavior, the function occurs continuously.

Game object behavior
In interstellar cavalry games, game behavior is allocated to multiple objects that constitute the game.
These objects include:
Cavalry
Condor
File
Cavalry object behavior is a combination of multiple actions
Sports
Shooting

Condor behavior relies on Collision Detection
If the condor collide with the bullet, it will explode and increase the score
If the condor collide with the cavalry, The Condor dies and scores are reduced.
The bullet behavior is simple:
After a bullet hits the Condor, it will die. Otherwise, it will continue to exercise.

Condor Behavior
Create a list of all conflict elves
Each element is in the list.
If the element is a bullet object, execute the bullet action for the conflict
If the element is a cavalry object, perform cavalry actions for the conflict

Bullet Behavior
If a bullet hits the Condor, the bullet disappears (as a colleague of the Condor)
If the bullet does not hit any object, if the bullet has passed through the top of the game screen, it should be deleted from the game
If (y <-100)
Game. Remove (this );
If the space key is the emission key, a bullet wizard is created at the same time.
The emitted sound effect will be executed.
The opening text will be added and displayed
If (Keyboard. IsTriggered (Key. Space ))
{
Fire fire = (Fire) startrow.fire. Clone ();
Fire. Position = new PointF (Position. X, Position. Y-35 );
Fire. Velocity = new Vector2 (0,-4 );
Startrow.shoot. Play ();
M_Shoots ++;
Startrow.shoots. Text = "Shots:" + m_Shoots.ToString ();
}

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.