Game Development Reference
In-Depth Information
by minus 1 so that the ship will go up when you push up rather than down). This
vector is then multiplied by the elapsed time so that the movement will be
constant no matter the frame rate. The scaled vector is then used to move
the ship. There is also support for the keyboard. The values of the control stick
are checked, and if the control stick doesn't seem to have moved, then the
keyboard keys are checked. It's assumed if you're not moving the control stick,
then you might be playing on the keyboard. The keyboard is less granular than
the control stick; it can only give up, down, left, and right as absolute, 0 or 1,
values. The keyboard input is used to make a vector so that it can be treated
in the same way as the control stick input. IsKeyHeld is used instead of
IsKeyPressed because we assume that if the user is holding down the left key,
he wants to continue to move left rather than move left once and stop.
Run the program and you will be able to move the ship around the screen. The
movement goal is complete!
Faking Movement with a Scrolling Background
Adding a background is going to be fairly easy. There are two basic starfield tex-
tures on the CD in the Assets directory called background.tga and background_p.
tga. Add these files to the solution and alter the properties so they're copied to the
build directory as you've done for all the other textures. Then load them into the
texture manager in the form.cs InitializeTextures function.
_textureManager.LoadTexture("background", "background.tga");
_textureManager.LoadTexture("background_layer_1",
"background_p.tga");
Two backgrounds have been chosen so that they can be layered on top of each
other to make a more interesting effect than would be achievable with only one
texture.
This background is going to be animated by using UV scrolling. This can all be
done by making a new class called ScrollingBackground . This scrolling
background class could also be reused to make the start and game over menu
more interesting, but the priority at the moment is the inner game.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
Search WWH ::




Custom Search