Showing posts with label Programming First Person Shooters. Show all posts
Showing posts with label Programming First Person Shooters. Show all posts

Sunday, November 8, 2009

First Person Shooter Game

3D game development is an exciting activity for many students. But getting a handle on 3D game development for novices may be a daunting task. We take this opportunity to present a quick introduction to 3D game development through a few tutorials. For the next few columns a set of tutorials for a 3D first person shooter game developed by graduate and undergraduate students under the guidance of a faculty member from the University of West Florida will be presented. These tutorials were developed with 3D game Studio by Conitec. To follow along, download the software from www.conitec.com. These tutorials include all elements of game development such as modeling and animation, lighting, collision detection, sound and scripting. Each tutorial will focus on one or more of these aspects. This week we start out with creating a room and adding some objects to the room. The instructions for this are presented below.



1  IMPORTING A MODEL

Importing a Model is easy and fun! Models can include your character, non-player characters, level objects, weapons, health supplies, etc. To make a working entity in GameStudio, you must first import a 3D model and then assign functions, or behaviors, to the model. These functions give models unique properties. For example; if you import a model of an elf, you can assign player functions to the model that will allow you to control the elf. Likewise, if you import a health pack, the functions you assign to it will make the model act like a health pack. Things can get really crazy if you assign functions to models incorrectly! How funny would it be if you ran into the elf and it healed you while you controlled the movement of a health pack!
  1. First open the WED (World Editor Program), and click Object -> Load Entity

  1. It is very important that your model is saved into GameStudio's "Work folder"
    This folder is usually under
    "C:\Program Files\GStuido6\work"
    – this is the default folder in the popup menu

  1. From here, select your model and Click Open (open "cbabe.mdl" or "warlock.mdl" )

  1. Notice that "cbabe" may be outside of your room. To get her within the room, simply click the Move button (on the toolbar) and drag her into the room. Be sure to examine all windows to make sure that she's properly aligned

  1. Your model is now inserted into your level. Wow! That was easy! You can now continue to move this model wherever you want it in your level. You can resize and rotate it!

2 ASSIGNING A FUNTION/BEHAVIOR

Once you have the model in your level, you probably want it to do something. In order for your model to have some sort of properties, you must assign a function, or Behavior, to the model. To begin with, make sure that you have assigned a script to the game that you are making. The script, which is written in a programming language called C-Script, is what contains all the variables, functions, and other bits of code that will add to making your game awesome!

Code1.wdl

Open the SED (Script Editor) and copy & paste this code into it. Save the file as "Code1.wdl" into the work folder (usually under " C:\Program Files\GStuido6\work ")



  1. To add a script to your game, click on File à Map Properties

  1. A pop-up menu entitled Map Properties will appear. As you can see in the Script Box, no script has been defined. To do this, click the Folder icon to the right of the Script Box

  1. A pop-up menu will open that defaults to the "Work Folder." From here, select the script file (".wdl") that contains the code for your game. We will use "Code1.wdl"

  1. Now you will return to the Map Properties dialog box. As you can see, the script file is now inside the Script Box

  1. Then close this menu out simply by clicking the close button. Clicking the red X to the right of the Script Box will remove the script you just added to your game

  1. Now select the model that you want to add a Behavior to. When selected, your model will appear in a red wire frame

  1. Right-Click the selected model and choose Behavior

  1. A pop-up menu will appear. In this menu, you can select the Behavior that you want your model to have. The Behaviors are described in your script. For example, if you want your model to be the character that you play as, choose "my_player" for a health pack, choose "health_pack," etc. You can customize any Behavior and even create your own in the script. But for now, simply select "my_player" and press OK

  1. Your model now has the Behavior that you chose for it! See how easy and fun that was? You now should have learned all the basic elements of creating a game. If you want to Build and Run your game, you can do so now!

3  COMPLILING AND RUNNING

In order to test a game out, it needs to be Compiled. Compiling takes all the code, models, and levels that have been put together and converts it into a language that the computer can readily understand: machine language !
Please take note that this doesn't create your executable file. This simply allows you to "run" your game
  1. First, Click the Build button

  1. A pop-up menu will appear that lets you adjust what exactly you want to compile or update. If you're just doing a quick test, make sure that your Visibility Calculations and Light Calculations are set to Off and Low Quality. This will dramatically reduce the time it takes to compile your game. You shouldn't be able to see a difference between these settings, and (for productivity purposes) you should wait to turn these on until you have finished tweaking your game

  1. Make sure that the Build Level button is selected and click OK

  1. A Map Compiler dialog box will appear and, depending on the complexity of your game, the time it takes to compile your game will vary.

  1. Click the Run button

  1. Click the Ok Button once more in the "Run Level" dialog box

  1. Your game will now start! Now how have some fun!

Congratulations you now have all the basic skills to make your own game using GameStudio! Now begin making your own fun games!

source www.jot.fm/issues/issue_2008_01/column5

Flash MX First Person Shooter Game Tutorial


In this Flash tutorial we shall set out the basics for a First Person Shooter Game (hereafter called an fps).

  • We shall do the basics of attaching the gun sights to the mouse movement and hiding the standard mouse icon,
  • Making bullet holes in the background,
  • creating a gun firing sound,
  • and testing for a hit on a very basic moving target.
Later on, I will write a more complex tutorial to fill in the details.
Flash Tutorials in Video Format - Watch them now at LearnFlash.com  

Create the hit area button for the game

Let's start.

  1. Choose the rectangle tool and drag a rectangle to cover the whole stage.
  2. Select the rectangle and hit key F8 and create a button. Call it "hitArea".
  3. Open the library and double click on the hitArea button.
  4. Go to the first frame and hit key F6 to create 3 more keyFrames.
  5. Delete the first 3 frames of the button and leave the "hit" frame. This is going to be an invisible button and when the mouse is clicked , the gunfire sound will play and a bullet hole will appear in the background.
  6. Select the hitArea button on the main stage and in its properties window, call its instance name "hit1".

Load the gunfire Sound


  1. Find or edit a gunfire sound.
  2. Select menu item "File" - "Import to library" and select the audio file. The audio file will appear in the library.
  3. Right click on the audio file and select "linkage".
  4. Tick the "export for Actionscript" textbox and in the identifier box, write "gunfire".
  5. Lock the frame that the hit button is on and create another layer and call it "code".
  6. Hit the F9 key to open the Actions window. Write this code :
  7. // gunfire sounds
    var gunfire = new Sound();
    gunfire.attachSound("gunfire");
    // When mouse is clicked, start sound 
    _root.hit1.onPress = function() {
     gunfire.start();
    }
    

Create the Gun Sights for the game


  1. Create another layer and call it "sights".
  2. Draw a gun sight however you want.
  3. Select the drawing and press F8 to make a movieclip.
  4. Call it "gun".
  5. With the gun still selected name it "gun" in the instance name texbox in the properties window.
  6. Lock its frame and go to the "code" layer and add this under the code we entered earlier :
  7. // initialise the movie
    _root.onLoad = function() {
     // hide the mouse
     Mouse.hide();
    };
    // loop code
    _root.onEnterFrame = function() {
     //put cross hairs to mouse coords
     _root.gun._x = _root._xmouse;
     _root.gun._y = _root._ymouse;
    };
    
    
  8. Hit keys Control + Enter to test the movie. The gunshights should follow the mouse. and when you click the mouse, your gunshot sound should play.

Make the bullet holes


  1. Create a new layer and draw a 20 pixel circle.
  2. Select it and hit key F8 , create a new MovieClip, call it "bullet".
  3. Name it "bull" in the instanceName textbox.
  4. With the bullet hole movieclip selected, write this code in the Actions Window:

  5. onClipEvent(load){
     this._x = _root._xmouse;
     this._y = _root._ymouse;
    }
    
  6. It should say "Actions - Movie Clip" at the top of the Actions window and not "Actions - Frame".
  7. Now select The "code" layer and rewrite the code to this:

  8. var i;
    // gunfire sounds
    var gunfire = new Sound();
    gunfire.attachSound("gunfire");
    _root.hit1.onPress = function() {
     gunfire.start();
     i++;
     //  create bullet holes
     _root.bull.duplicateMovieClip("bulletNew", i);
     if (i == 10) {
      i = 0;
     }
     
    };
    // initialise stuff
    _root.onLoad = function() {
     // hide the mouse
     Mouse.hide();
    };
    //loop
    _root.onEnterFrame = function() {
     //put cross hairs to mouse coords
     _root.gun._x = _root._xmouse;
     _root.gun._y = _root._ymouse;
      
    };
    

Make the Target MovieClip


  1. Make a new layer and call it target.
  2. On it , draw some sort of target. I just made a square 50x50.
  3. Select it and create a Movieclip, call it target_mc in the InstanceName textbox.

Make the explosion for the game


  1. In the library , double clik on the gunsight movieclip.
  2. Select the first frame and hit key F6 to create another keyframe on frame 2.
  3. Delete the contents on frame 2 and draw some sort of explosion. Just a red splash should do.
  4. Create another layer ,
  5. make a keyframe on frame 1 and
  6. put this code in :

  7. stop();
     
Now lets finish off the coding for the hitTest on the target and the moving of the target. For now , we will just move it across the screen.
Go back to the main timeline and select the code layer and delete what was in there and put this in:

var i;
// gunfire sounds
var gunfire = new Sound();
gunfire.attachSound("gunfire");
_root.hit1.onPress = function() {
 gunfire.start();
 i++;
 // make bullet holes 
 _root.bull.duplicateMovieClip("bulletNew", i);
 if (i == 10) {
  i = 0;
 }
 // hit test on target
 if (_root.target_mc.hitTest(_root._xmouse, _root._ymouse, false)) {
  // play explosion
  _root.gun.gotoAndPlay(2);
  // send target off stage
  _root.target_mc._x = 0;
  _root.target_mc._y = random(400);
 }
};
// initialise stuff
_root.onLoad = function() {
 // hide the mouse
 Mouse.hide();
};
//loop
_root.onEnterFrame = function() {
 //put cross hairs to mouse coords
 _root.gun._x = _root._xmouse;
 _root.gun._y = _root._ymouse;
 // target move
 _root.target_mc._x += 10;
 // if it goes offstage, send it stage left
 if (_root.target_mc._x<0 || _root.target_mc._x>Stage.width) {
  _root.target_mc._x = 0;
  _root.target_mc._y = random(400);
 }
};

It is a pretty lame movie but it shows you the basics of a first person shooter game in Flash MX. Next tutorial, we will refine it a lot more and make a real game. So have a good think about it and experiment with it by yourselves in the meantime. Create some targets and make them pop up here and there. Experiment with a scoring system and think about adding further levels. Do it yourself and impress us all with your efforts.

Game Resources

Flash MX2004 tutorials
"Flash MX Bible" by Robert Reinhardt
Download the file here

source www.video-animation.com/flash_32.shtml

Saturday, September 19, 2009

Pang out 3d: An OpenGL mini Game with Source Code


This is a 3d action game that i made for an undergraduate class 6 years ago, it is fully documented and i thing that is a good way to start reading source code for game development under windows using Win 32 sdk and OpenGL

I promise to write a tutorial based on this game soon

The following link contains the video game pang out 3d
click here to download

Have good coding time