Tackyworld Pov shooting engine

Started by Wabbit, Mon 31/01/2005 03:21:31

Previous topic - Next topic

Wabbit

Tackyworld had a demo game on the AGS site demonstrating their new POV shooting engine. The demo is blade burner. Does anyone know how it works?

Gilbert

You meaned Porch's Barn Runner games? Haven't played teh games yet, but I think you can get better responses asking him.

Ponch

#2
Beware! Lengthy post follows!

Wabbit, thanks for downloading the game:
http://www.adventuregamestudio.co.uk/games.php?action=download&game=486
I'm glad you liked it.

The code wasn't too hard. It just takes a while to type it all in. Mostly it's just a lot of timer checks and other assorted repeatedly execute bits. But bear in mind that I coded it with AGS v2.61 so some of these commands are probably out of date. I don't plan to upgrade to a newer version of AGS until I finish The Forever Friday later this year, so anybody using the newer versions please feel free to correct me.

Keep in mind that this is a VASTLY simplified explanation. I think a lot of beginners may take a look at this so I want it be as easy to understand as possible. If you're at all handy with code then you'll want to use more advanced operators to check your variables. These will streamline your code and make it easier to include more bells and whistles but for the moment, please excuse the clunky but easy-to-follow code that follows. Basically, this is how it was done...

First off, let's define a couple of game design points:
The gun will only hold three shots (as it did in my game).
The gun will start fully loaded.
The player will have two spare clips for the gun (each with three shots).
The gun will have no muzzle flash (this is easy to include later but isn't important right now).
There will only be a simple reloading graphic, nothing spiffy.
The targets will not shoot back, respawn, or summon help. (This can be done later).
The player only has one type of weapon available. (You can add as many more as you want later).
Distance is not a factor. If the player can see it, he can shoot it. (This can be changed later too).
There will be only two targets to shoot at. (Throw an army at the player later).

So let's get cracking...

----------GLOBAL SCRIPT----------
In the Global Script you'll need a few variables. (We'll use Global Integers because everyone who wants to attempt this should understand the basics and GlobalInts are VERY basic -- but in your own game you might want to use custom integers... I did.)

    SetGlobalInt (2,3); // Gun Ammo Status (3-shots in gun)
    SetGlobalInt (3,1); // Gun Clip status (spare clips number remaining)
    SetGlobalInt (4,0); // Jon HIDE check (0=no shoot, 1=shoot now, 2=too late)

----------CURSOR STUFF----------
You'll need to create a spiffy "Gun Sight" cursor in the UserMode1 cursor slot. I'll rename the slot to SHOOT! so it will be easy to spot in the editor.

----------ACTOR AND OBJECT CODE----------
You'll need a few targets for the player to shoot at. We'll name ours Ponch and Jon. Ponch will be a simple target that runs in from one side of the screen and off the other side. Jon will be a hiding target that will "pop" to face the player just one  time and then go back to hiding (where he can't be shot).

For PONCH, include the following code under the actors SHOOT! tab:

// SHOOT PONCH
if (GetGlobalInt(2)>0) { // If the gun has any bullets left
StopMoving(PONCH);
  {// Move Ponch off screen
  character[PONCH].room=0;
  character[PONCH].x=0;
  character[PONCH].y=0;
  }
SetGlobalInt(2, GetGlobalInt(2)-1);//Minus one shot from pistol
  }
else {} // Gun is empty, do nothing.

For JON, let's make him an object instead of an actor so you can see how that's done. Under the objects SHOOT! tab, put the following code:

// SHOOT JON
//if gun is loaded & Jon is in 'Shoot Now' mode
if ((GetGlobalInt(2)>0) && (GetGlobalInt(4)==1)){
ObjectOff(0); // Remove Jon from room
SetGlobalInt(2, GetGlobalInt(2)-1); // Minus one shot from gun
  }
// otherwise if gun is loaded but Jon is hiding
else if (GetGlobalInt(2)>0) {
SetGlobalInt(2, GetGlobalInt(2)-1); // Minus one shot from gun
  }

----------ROOM STUFF----------
First off, create a room that is larger than what the player can see and place the player in the middle of it. This allows you to place Ponch off-camera where the player can't see him or shoot him until you bring him into view. This also makes it easy to have Ponch easily run off-screen where the player can't shoot at him. Plus, he won't "pop" into view as he would if you used .room commands. He'll enter and exit frame smoothly. Just make sure that you make the room big enough to allow your target to be completely out of frame on either side of visible area of the room.

Next, draw a nice HUD on top of the screen. In the future, you can use a GUI for this but they're tricky for beginners so we'll stick with a nice picture with HotSpots at the top of the screen. Put a RELOAD button somewhere on the HUD, make it a HotSpot and add this code to it's SHOOT! tab:

// SHOOT RELOAD BUTTON

if (GetGlobalInt(3)==2) { // If the player has two clips left
SetGlobalInt(3, GetGlobalInt(3)-1);//lose one clip
SetTimer(1, 90); // Set Reload Timer
//AnimateObject - Reloading Graphic
HideMouseCursor(); // so the player can't shoot while reloading
  } 
else if (GetGlobalInt(3)==1) { // if the player has one clip left
SetGlobalInt(3, GetGlobalInt(3)-1);//lose last clip
SetTimer(1, 90); // Start Reload Timer
//AnimateObject - Reloading Graphic
HideMouseCursor(); // so the player can't shoot while reloading
  }
else { // the player is out of ammo
//Display Message - Out of Ammo!
  }


Also, so the game can keep track of missed shots, make the rest of the room (not to include the HUD) a different HotSpot and add this code to it's SHOOT! tab:

// SHOOT BACKGROUND
if (GetGlobalInt(2)>0) { // if gun is loaded
SetGlobalInt(2, GetGlobalInt(2)-1); // minus one shot from gun
  }
else {} // gun is empty so do nothing.
Now place the actor Ponch just off-screen and the object Jon somewhere on-screen and get ready to add the room code.

----------ROOM CODE----------

(Enter Before Fade In)

//Disable all cursors except the the SHOOT! mode.
// Disable all GUIs
//Set Jon Object to proper view


(Repeatedly Execute)

// Reload Timer
if (IsTimerExpired(1)==1){ // Timer 1 expired
  ShowMouseCursor();
SetGlobalInt(2,3);//give gun three shots
    }
// Jon timer
if (IsTimerExpired(2) == 1) { // Timer 2 expired
   if (GetGlobalInt(4)==1) { // Player has not shot Jon in time
      SetGlobalInt(4,2); // Jon goes back to hiding and cannot be shot.
      //Animate Object to "Hiding" view
          }
   if (GetGlobalInt(4)==0) { // Jon was hiding
      SetGlobalInt(4,1); // Jon is in "Shoot Now" mode
      //Animate Object to "Exposed" view
      SetTimer(2,80); // Player has a limited amount of time to shoot Jon
   }
}


(Enter After Fade In)

SetTimer(2,200); // Jon waits to reveal himself
MoveCharacterDirect(PONCH, x, y); // Ponch makes his dash for freedom.


(Leaves Screen)

//Be sure to enable all the cursor modes and GUI as the player leaves the arcade room.


And that's it. These are just the basics of what I did with the first build of the arcade code but you can do a lot more with it after some practice. In the current build of the Forever Friday, I have one arcade sequence with over twenty bad guys that attack you with crow bars and pistols with varying degrees of accuracy. Some attack from sniper positions while others dash back and forth between buildings for cover. They even call for reinforcements that arrive in cars. Plus you can choose two (of three) different weapons to carry, each with a different range, rate of fire, ammunition capacity and accuracy. Please bear in mind that it sounds a LOT cooler than it actually appears. This is NOT Halo 2 by any stretch of the imagination but I think it's a pretty cool action sequence for an AGS game. Hopefully when the Forever Friday comes out this summer others will think so too. (In the meantime, that code is classified "Double Top Secret" and isn't up for grabs.)

In the mean time, I hope this serves as a nice starting point for you to drop your own action-ish bits into your games. Good luck and other posters should feel free to criticize / modify this code as needed.

-Ponch

Gilbert

* Gilbot V7000a wonders if Terran ever read this thread carefully before moving it.

In my opinion this thread fits perfectly in either of the two Technical forums. :=

Ponch

Yeah, it did seem strange to find it here. But, hey, I go where the wind (and moderators) take me... like that guy in Kung Fu... if he were named after that guy in CHiPs...

onewabbit

Quote from: Ponch on Mon 31/01/2005 08:08:44
Yeah, it did seem strange to find it here. But, hey, I go where the wind (and moderators) take me... like that guy in Kung Fu... if he were named after that guy in CHiPs...
Sorry guys, and thanks Ponch. I am a total rookie trying to make his first game. After fighting it out with AGS for a couple of hours, I can't find the light switch sometimes. Thanks again Ponch.

Dr Lecter

#6
For the 2.7 "objectoff" is now obsolete.
(I only found these by trying to compile the game then looking in the manual for the updated version, but it'll save anyone that wants to use this for needing to, but I haven't tested it yet so they could still be wrong, even though the compiler doesn't say so)
You need to replace it with:
object[0].Visible = false;

DisableCursorMode is now obsolete
You need to replace it with:
mouse.DisableMode(eModeSHOOT!);

EnableCursorMode becomes:
mouse.EnableMode(eModeSHOOT!);

MoveCharacterDirect(PONCH, x, y); becomes:
character[PONCH].Walk(x, y);

StopMoving becomes:
character[PONCH].StopMoving();

I'm not quite sure what to replace the:
  character[PONCH].room=0;
  character[PONCH].x=0;
  character[PONCH].y=0;

but try:
character[PONCH].ChangeRoom(0, 0, 0);

(After testing)
Something is wrong with it though since it, it won't display the sight, the targets won't move and picture is stuck at the side, I'll mess about with it abit and see if I can make it al work. Probably the compiler missed something or I didn't put the right variables in.

*edit*
I can't seem to find what the problems are so I'm just going to start the whole code from stratch using Ponch's as a guideline, I'll post it when I'm done.

(We have lift off, sorry but this post has been spread out over about 2 hours, even though it looks like just one time frame)

Ponch

Thanks for updating the code, Dr. Lecter. I loved you in most of your movies -- though I think you should stay away from anything Brett Ratner directs.

I'm not familiar with the new version of AGS. I built Don't Jerk the Trigger of Love (which was the first game to use my shooter code) with either 26_sp1 or 261 and my next game The Forever Friday is being built with 262. I won't make the move to the new version of AGS until I start work on Recycle My Heart in late 2006.

I hope you can get the kinks worked out with the new commands. Mostly because I'm going to have to upgrade the code for the Recycle and it would be great if somebody laid the groundwork for me.  ;)

Thanks for taking an interest in my work!

- Ponch

Rui 'Trovatore' Pires

Ponch, you don't really *have* to change your code. You can still code in the "old-fashioned way" with AGS 2.7 and all you have to do is check a checkbox.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Dr Lecter

#9
Well I was working on it all yesterday after I made my game interface code. So far, I've made the target move accross the screen, I've disabled all the other cursors and actions apart from shoot, I've made it reload, about the only thing that won't happen is that the target won't die!!!!!!! He just keeps moving across the screen! I think I know what the problem is but when I've fixed it, it will be cool.

Also, in response to Brisby, its important to keep code up-to-date, as there may be future versions of AGS where old-fashioned-coding is not usable. That and, I like using the new version, I've never made and real games with the any version so I thought I may aswell get stuck into the 2.7 code.

*edit*
Oh my god, I can't believe how simple it was! I reference it to move the main character out the room, not the target, no wonder it wasn't doing anything! Basically, now I've got it to do just about everything apart from reload so thats the next step, once thats done I'll put my cards on the table. Of course its not standardised because its modified to work with the interface for the game I making meaning that I could cut quite abit of code where other people probably couldn't.

SMF spam blocked by CleanTalk