Flashy: Taking apart GunFlash states

by DoomRater

in Completed Works

< 'Spectre (SNES)' by DoomRater

Flashy: Taking apart GunFlash states

The GunFlash states are a powerful addition to anyone working on weaponry in DECORATE. Unlike DeHackEd work where the frames tended to get in the way by using valuable frames that could otherwise be used for extra gun animation, in DECORATE these frames are invaluable. But using them requies some thought.

First off, let's start with what the frames actually are. The GunFlash frames themselves are drawn overtop any weapon sprites that are actually there. When you use A_GunFlash, these frames are referenced and run seperately overtop your current gun sprite. Another important thing is that they run independently of the normal gun sprites, allowing for some interesting effects.

But we'll start with a more common use for GunFlash sprites- making muzzle flashes. It shouldn't surprise anyone that the gunflash sprites were originally created to overlay gun sprites with muzzle flashes to help keep the total amount of memory used on sprites down. A more interesting side effect is that only the part that is actually overwritten is turned bright when using the bright feature. The oeverall effect is a muzzle flash that brightens only what it was intended to brighten.

Here's some code to demonstrate a two frame muzzle flash:
[code] Fire:
BAR1 A 0 A_GunFlash
BAR1 A 2 A_FireBullets(6,6,-1,7,0)
BAR1 B 2 A_FireBullets(6,6,-1,7,0)
BAR1 A 2 A_FireBullets(6,6,-1,7,0)
BAR1 CDC 2
BAR1 A A_Refire
Goto Ready
GunFlash:
BAR2 ABA 2 Bright
Stop[/code]

Notice how the durations of the flash states correspond with the states where the gun is actually firing. While it's not required to follow each frame exactly, the effect is usually nicer if you do. Perhaps if I showed an example where the gunflashes didn't match up properly it would make more sense.
[code] Fire:
BAR1 A 0 A_GunFlash
BAR1 A 2 A_FireBullets(6,6,-1,7,0)
BAR1 B 2 A_FireBullets(6,6,-1,7,0)
BAR1 A 2 A_FireBullets(6,6,-1,7,0)
BAR1 CDC 2
BAR1 A A_Refire
Goto Ready
GunFlash:
BAR2 ABA 3 Bright
Stop[/code]

In this example of code the gun advances before the gunflash frames, and they won't match up properly when the gun is firing. It'll seem like the flashes are a bit late.

Of course there are always gunflashes that go for two frames for each one frame of the gun. Doom's Shotgun behaves this way. But really, it is all a matter of matching the flash pattern with the gun firing sequence itself.

Keep in mind, however, the fact that the GunFlash states run concurrently with the regular states. This can be used to create interesting effects. For example, let's say I have a knife that I can hold until I'm ready to release it. You might recognize some of the code from a knife example I used in another tutoiral:
[code]
Fire:
tnt1 A 2 A_GiveInventory("TargetHUD",1) //Reset the HUD
knif B 2
knif B 0 A_Refire
knif C 0 A_PlayWeaponSound("knife_slash")
knif C 0 A_FireCustomMissile("CheapAlert", 0, 0, 0, 0) //GargoyLOL
knif C 2 A_CustomPunch(15,0,0,1)
knif DE 2
tnt1 A 0 A_WeaponReady
tnt1 A 2
Goto Ready 6 //I did some other stuff at the ready state
Hold:
knif G 1 A_GunFlash //Activate the HUD
knif G 2 A_Refire
knif H 3
knif I 7 A_CustomPunch(25,0,0,1,70)
knif HG 3
tnt1 A 2 A_Refire
Goto Ready 6[/code]
Notice where I added the GunFlash state in. It's called just before I start in the hold state. I've also defined a TargetHUD inventory item and notice how I set that before I called the GunFlash state. Let's look at that in more detail:
[code] GunFlash:
Targ A 0 A_JumpIfInventory("TargetHUD",1,1)
Stop
Targ A 0 A_JumpIfCloser(56,2)
Targ A 1
Loop
Targ B 1
Loop[/code]

Imagine TARGA0 is a red X and TARGB0 is a green O, placed just below the crosshair. The idea is to measure the distance between a hittable object and yourself, and show on screen if you're in range. When you see the green O, you know that your attack will connect, assuming you're looking at it.

The possibilites for the functions you can add on in here are almost limitless. For example, you could build a simple radar that beeps when something is close, or perform some other HUD function. However, if you're using a toggle system that runs overtop the WeaponReady frames, keep in mind they bob with the weapon, so you may want to think about adding the DONTBOB flag if you have any visible graphics that you don't want bobbing around on the screen.

Here's another example that uses a gun with a pop-up HUD to tell you how much ammo is left in the clip.
[code] Ready:
D3MG A 0 A_GiveInventory("TargetHUD",1)
D3MG A 0 A_GunFlash
D3MG A -1 A_WeaponReady
Fire:
D3MG B 2 A_FireBullets(3,3,1,5,0)
D3MG C 2
D3MG D 0 A_Refire
D3MG D 0 A_WeaponReady
D3MG 4
Goto Ready 1
AltFire:
D3MR A 0 A_JumpIfInventory("Doom3Clip",0,19)
D3MR A 0 A_TakeInventory("TargetHUD",1)
D3MR A 3 A_PlaySound("weapons/clipout")
D3MR BCDCB 3
D3MR B 0 A_JumpIfInventory("Doom3Clip",0,4)
D3MR B 0 A_JumpIfInventory("Clip",1,1)
Goto AltFire 10
D3MR B 0 A_TakeInventory("Clip",1)
D3MR B 0 A_GiveInventory("Doom3Clip",1)
Goto AltFire 7
D3MR A 4 A_PlaySound("weapons/clipload")
D3MR E 3
D3MR F 3 A_PlaySound("Weapons/cockgun")
D3MR GHF 3
D3MR EA 3
D3MR A 0
Goto Ready
Flash:
TNT1 A 0 A_JumpIfInventory("TargetHUD",1,1)
Stop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",1,3)
DHU0 A 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",2,3)
DHU0 B 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",3,3)
DHU0 C 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",4,3)
DHU0 D 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",5,3)
DHU0 E 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",6,3)
DHU0 F 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",7,3)
DHU0 G 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",8,3)
DHU0 H 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",9,3)
DHU0 I 2
TNT1 A 2
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",10,2)
DHU0 J 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",11,2)
DHU1 A 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",12,2)
DHU1 B 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",13,2)
DHU1 C 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",14,2)
DHU1 D 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",15,2)
DHU1 E 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",16,2)
DHU1 F 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",17,2)
DHU1 G 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",18,2)
DHU1 H 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",19,2)
DHU1 I 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",20,2)
DHU1 J 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",21,2)
DHU2 A 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",22,2)
DHU2 B 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",23,2)
DHU2 C 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",24,2)
DHU2 D 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",25,2)
DHU2 E 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",26,2)
DHU2 F 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",27,2)
DHU2 G 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",28,2)
DHU2 H 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",29,2)
DHU2 I 1
Loop
TNT1 A 0 A_JumpIfInventory("Doom3Clip",30,2)
DHU2 J 1
Loop
DHU3 A 1
Loop[/code]

Notice the long code in the GunFlash. DHU??0 refers to a long series of HUD replacements for the Doom 3 Machine Gun. Even if you're not sure why the TNT1A0 is in there, the concept is that the Machine Gun flash states report the ammo left in the gun by checking it for ammo and showing a frame that reclects the ammo. It's a long bit of code though since there's a state for each possible amount of ammo. The important thing though is that it demonstrates a possible way to report the amount of ammo left in a weapon without using alternate ammo or ACS code.

I'd like to mention a lot of these concepts DO apply in DDF as well. Since I am not well versed in DDF code, however, I can't provide any examples. Also limiting is DDF's ability to make descisions based on internal data... I'm not even sure if that exists in some form or other.

My next tutorial is a doozy- getting reloading in DECORATE to work on your own.
> 'Undefeated run vs. IWanaPlay' by DoomRater

Description

Apr 1st 2006
Tags:
decorate general weapon zdoom
Views:
287
Comments:
0
Score:
-1
Favorites:
0
ZDoom's DECORATE is extremely powerful. It allows people to pull together weaponry that otherwise would never be built for a 15 year old engine. Here I take apart the GunFlash states to show just what kind of crazy effects someone can put together for a weapon.

Comments