# Visual Basic > Games and Graphics Programming > Game Demos >  vb6/5:    Alpha DogDighter 3D!!!

## technorobbo

Okay it was so much fun I had to make it 3D.

All new motion math to make the 3D experience more immersive.
Direct3D 7 for max vb compatibility.


AI motion using an elliptical calculation for realistic motion and reactions.Jet uses LPF(low-pass filter) calcs for a fluid, floating-in-water like, motion.Super Fast 3D API sprite collision detection for realistic game play.6 rockets in a row. Explosion look really cool.All Model Meshes done in Google Sketchup (free!!!!!) with a free directx plugin available at http://edecadoudal.googlepages.com/sketchupwithdirectx Dynamic FPS (frames per second) control keeps a tight gaming loop for smoother animation.All backgrounds rendered in Google Sketchup and with some help from Adobe Photoshop

Too big to upload available at my website:
http://home.comcast.net/~technorobbo/AlPha3D.zip

Here's the instructions:

----------


## technorobbo

Updates:

5/16/2009 version 1.1.305 available for download
Bug FixesBetter textures
2/21/2009 version 1.1.302 available for download
System keyblocker in place - this will make it hard to debug, so REM out the last line of the Init routine to disable the blocker.


2/11/09 version 1.1.270 available for download
Bounding Boxes scaled back for long afterburners.


2/11/09 version 1.1.269 available for download
This version Incorporates some suggestions made by Jim Davis (thanks Jim).
QPC High Resolion counter incorporated for smoother frame rate control.Increased frame rate to 30 FPSNew Paper Airplane Fighter - Introduces new SFX_WRAP effect .


2/04/2009 version 1.1.223 available for download
Afterburner animation system complete - 1,2 or 3 afterburners can be added to the fightersNew directiry structure to organize meshes, textures, sounds and backgroundsShips.inf file expanded for afterburners or rotating animation description.Ship filenames are changed to their programming names:
Alpha Dog - original blue fighter.FatMan - oval flying wing designDart - needle nosed airplaneFooFighter - flying saucerBogey - enemy airplaneCopter - Helicopter 

1/29/2009 Version 1.1.175 available for download
SFX animation in place for planesShips.inf file defines ships and animationsSFX animation type 1 implemented 2 & 3 to follow

1/25/2009 Version 1.1.166 available for download
Flying Sacuer model added - play as a space alien, annihilate the earth. 

1/24/2009 Version 1.1.164 available for download
Game Flow Enhancements - LastScore and Token Variables added.
Demo allowed to go beyond 20 Points (No limit).

1/23/2009 Version 1.1.147 available for download
Bug Fixed - Phantom Rocket from Copter. Missle was not fully converted to Elliptical object type.
Enhancement - AI stay with in screen so they're easier to kill.
Programming Tip - Look for the Rem'd out bounding box routine for tracking collision zone.

1/23/2009 Version 1.1.17 available for download
Huge Changes - all Sprites (Planes, Bogeys, Rockets, Copter, Missles) are now custom objects called Elliptical for ease of modding. All Collision detection is automated - No bounding box constants to put in. Pesky Helicopter added!! Wicked cool! Hunts you down like a hound. Game flow control enhanced for modding with new flags. (NoRegen, Spawn)


1/11/2009 Version 1.0.52 available for download
Bug Fix!
AI altitude settings could created endless loop at about 3 AI's. Fixed by simplifying altitude scheme.New HUD Heads up Display!!! Added to gauge jets relative heigth to AI's. (My brothers Idea.)


1/11/2009 Version 1.0.39 available for download
Splash Screen Music added.

1/11/2009 Version 1.0.37 available for download
Major Changes:
New Screen (3D Menu) lets you pick your fighter.2 new fighter models were added (3 altogether).AlternateJet Constant now indicates how many fighters to choose from.Windshield texture was corrected to a 128X128 bitmap. Previous dimension not allowed by d3d7Terrain Maps updated - more detail in the Tundra Map

1/10/2009 Version 1.0.13 available for download
Forgot about hiding the mouse, oops.Alternate Jet (Jet2-T) has been modfied took look sleeker.

1/10/2009 Version 1.0.09 available for download
Bug Fixes and Changes
Splash Screen Bug Fix - Plane was loaded in center of screen blocking view of splash screen. Only noticeable when alternnate plane designs were loaded.New Constant added for Model testing. Constant is called "AlternateJet", change it's value to 1 and it will load the Jet2-T.x model.New Jet2-T.x model added for example purposes. Yes, I know they aren't aerodynamic, but they look cool!

1/07/2009 Version 1.0.1 available for download
Minor changes includes -
Multiple Bogeys come out sooner.Verion numbers now being tracked.New Windows Icon replacing stock VB  Icon

Game Play Tip - Lead your target, shoot ahead anticipating a collision with the missle.  There is a safe harbor, I put it in so you can get out of a 5 bogey situation when they're all attacking you, fly to the very top - the bogeys can't go there. This will help you get your score up until more bogeys appear, after that your on your own. You can make the game easier or harder by adjusting a constant called "AttackPotential " - 1000 is the default the lower the number (8 is the low limit) the deadlier the bogeys.


I'll post editing this reply for version updates.

----------


## technorobbo

Modders - new available for download. Built to be modded!!! See Post#2 for latest info.

----------


## trenmost

it looks nice, but the download link in the first post is bad (404)
edit: oh sorry, now it works
edit2: nice game  :Smilie:  i like the multiple backgrounds.

----------


## technorobbo

Thanks - they were meant to be different levels but i haven't gotten that far.

----------


## technorobbo

Bad Link on post corrected- actually on  my upload to the FTP site I misspelled the name as Aplha3d.zip - it's been corrected, sorry.

----------


## Jim Davis

Hmm am i missing something or what, but i cant find the 3d version. All i found so far is the 2d version (alpha.zip) you are shown in your signature. 

I see you already implemented the dynamic fps method i'm talking about, damn it  :Big Grin:  It would be nice to see how you have been done. Can you post a working url to the 3d version?

----------


## technorobbo

Sorry about that, I thought I had it fixed - it turns out that I was naming the file AlPha3D.zip and I was calling it Alpha3d.zip and in some cases it was Alpha3D.zip. I thought I fixed it but I had edited out the 3D and you saw the 2D version. - It's fixed now - in my signature as well as the post. 

The dynamic FPS works like this


```
        bztemp = Abs(FPS - (GetTickCount - FPSCount))
        If bztemp > 1000 Then bztemp = 20
        Sleep bztemp
        FPSCount = GetTickCount
```

if the clock rolls over midnite it corrects to 20. GetTickcount is the API call. FPS is a constant currently set to
Const FPS = 1000 / 20 '20 FPS

----------


## technorobbo

Oh and the secret to defeating the Helicopter is to fly down as low as you can and fight it there. You have more room to manuever. My son hasn't figured that out yet :Cool:  .

----------


## Jim Davis

Eeek the heli just killled my last 2 planes, i had no chance to test it! But i will, later  :Smilie:  

Anyway, i have seen this engine, now you are limited the game to 20 fps (30-50 would be better). However, the techniqe i post on the 2d thread, is can be implemented the same way, to this 3d version. Without the fps limitations, your game will run even smoother (but not faster), the animations will look better, just give a try, you will not be disappointed, i'm sure about that.

About the gettickcount, i thought it has an cca 50 days cycle before resets itself. But i'm still recommend you to use QueryPerformanceCounter because of the outstanding precision. You can also build a 10 elements array, that will holds the last 10 measurements of QPC. You can get the average of this array, to make it even smoother, in case the pc have some background job that is does some spikes in cpu time (just like an mp3 player).

I also saw that you merged up everything to one single form! Nice  :Smilie:

----------


## technorobbo

Jim,
You're right I'm protecting against timer rollover , not midnite rollover but I tend to type faster than I think.  Which is slow in both accounts.

You are also right on the inaccuracy of gettickcount using the code below I noticed errors on my computer as large as 10 ms.



```
Private Declare Function GetTickCount& Lib "kernel32" ()

Private Sub Form_Click()
    Dim x As Long, y As Long
    If Not Timer_InitTimer Then
        MsgBox "Your hardware doesn't support a high-resolution performance counter!", vbInformation
    Else
        x = GetTickCount
        Timer_ResetTimer
        For T = 0 To 100000
            DoEvents
        Next T
        Timer_StopTimer
        y = GetTickCount
        MsgBox Timer_Elapsed & " " & (y - x)
    End If
End Sub


Private Sub Form_DblClick()
    Dim x As Long, y As Long
    If Not Timer_InitTimer Then
        MsgBox "Your hardware doesn't support a high-resolution performance counter!", vbInformation
    Else
        
        Timer_ResetTimer
        x = GetTickCount
        For T = 0 To 100000
            DoEvents
        Next T
        y = GetTickCount
        Timer_StopTimer
        
        MsgBox Timer_Elapsed & " " & (y - x)
    End If
End Sub
```

I did make one mod to your code  the Timer_InitTimer routine (now a function). It did not return a false on fail so I modified it like this:


```
Function Timer_InitTimer() As Boolean
    Timer_InitTimer = QueryPerformanceFrequency(m_curFrequency)
    m_curFrequency = m_curFrequency * 10000
End Function
```

Thanks for the tip, a 10ms variance is a 20% margin of error on my frame rate, though small it would noticeable. I'll have to modify my code in case the QPC timer exists on the users computer.

----------


## Jim Davis

Yeah QPC should be exist, from Windows 95 / NT 3.1, as msdn said. 
http://msdn.microsoft.com/en-us/library/ms644904.aspx

Well it was a "haunted" story on me, but 7-8 years ago on win2k i got some accuracy errors by using qpc. In almost every minute once, the timer just gave me a strange/illegal value. I never found the reason why, but it just happened on me, but not on anyone else! I have sent out some test app over my buddies, but noone noticed, even under win2k. Maybe it was just, because of some kind of hardware malfunction on my pc. As soon as i switched to xp, the problem was gone. I also didnt found any article about this error.

I have to say, dont worry about this, qpc is stable and works great in every games/applications! Well, i just thought its better to telling my story.

About "m_HasCounter" vs "Timer_InitTimer", you are absolultely right. Its better to use a function instead of subroutine. I just used the m_hascounter boolean, because in one of my apps, i had to check its availability more than once, so it would better to immediately store it, in a public value. However, the QPC is available al the time, i never got any false response  :Smilie:

----------


## minidesigner

should have a change of view

----------


## technorobbo

Do you mean like a First Person POV? Thought about it.

I'm still working on the graphics end of things, so I haven't given much thought to the next step of game play. Top down view is kind of a cheat so I don't have to model an entire 3D world in CAD.

I had discussed taken the fighters into outer space with my son as a next level. This would mean that I wouldn't have to model an entire 3D world and I can go first person with Star Wars like action. 

Right now I'm integrating Jim Davis' suggestion and I've added a paper airplane fighter made out of newspaper (Chicago Tribune of course). My goal is to have more Bossses like the Copter and more objectives. My son has suggested bombing raids - which I like. Maybe fire missles from the battle ships.

----------


## minidesigner

or just up and behind like top gun or the ability to change yiew like need for speed or highdro thunder, probably spelled that wrong.

----------


## technorobbo

Jim,
New Download available. Incorporated the QPC counter into the code. Still using the "Take Up the Slack" method to pad the frames to reduce the math.  Thanks for the Tip. Oh and I did increase the frame rate to 30 FPS.

----------


## Jim Davis

Sorry i didnt noticed your post. Ok, i will check out!

-------------

I have tested, and it works great. Excellent 3d implementation, i like the way you did. Including everything to one single subroutine, is gives a pretty good performance.  :Smilie:

----------


## Cruncher

maybe im an idiot but i get:

Run-Time error '-2005532292 (8876017c)':

Automation Error

----------


## technorobbo

Does that occur while the game is running you alt-tab out and you try to alt-tab back in? If your trying to leave the game make sure you use the escape key. I gotta trap those other keys. But until I'm completetly done with the game trapping the keys will only hamper my debug efforts.

----------


## technorobbo

For the sake of academia I've uploaded a new the version with the Alt+Tab Blocked as well as other system keystrokes. Windows dumps all direct3d buffers when you switch programs and requires you to reinitialize. The work around is to disable the keys. Lots of people still have trouble because the programs use DirectInput that disables the block but I use GetKeyboardState instead to work around this. 

The blocker will make it hard to debug, so REM out the last line of the Init routine to disable the blocker.

----------


## ngreenwood6

I just tried this game on my laptop and the backgrounds work randomly. If I shoot a missile the background shows up for 1 second. Is that how its supposed to be or is there always supposed to be a background, because i see a black background for the most part. I can run other games on my laptop no prob other than a little slow. I will check it out on my desktop later

----------


## technorobbo

It's HAL render no Open GL so the chip must be up to it. Make sure all you acceleration is on on on full. I can turn on an option for software rendering if HAL isn't on but I rem'd it out for development. Let me know how it works on the desktop.

----------


## ngreenwood6

It works fine on the desktop and it has full acceration already on my laptop. Neat game, it is kinda hard to tell if you are the same height as the other players but I saw in one of the other posts that you were going to work on the view at some point.

----------


## Cruncher

TR,

its not when i alt tab out, its on initial launch...

hrmm..

----------


## technorobbo

Cruncher,
download the new upload - I added the keytrap

----------


## technorobbo

ngreenwood6

Fly by the heads up display  - it will be easier than trying to judge by eye.

----------


## ngreenwood6

I just tried the new version and its way different. How do you fly by the heads up display on the old one? Also, another cool thing to add would be a highscore for users.

----------


## ngreenwood6

nvm i figured out the heads up display, didnt realize what that was. That is cool never seen anything like it before.

----------


## Cruncher

TR, i just downloaded the new one same error its obviously something incompatible with my computer not your code as it works with everyone else:S

----------


## technorobbo

Cruncher,

Did you compile first? Try compiling and running the new executable. Make sure it's in the project folder since it references the subdirectories. Also make sure that no other programs are running in the background.  

The reason i say all this is because the error your reporting is an "out of video memory" error. Usually this hasn't been the case and was caused indirectly by windows switching modes which cause all hardware graphics to reset. That's why I block all the system keys, to avoid graphic switching.

The game itself is not that large but it is possible the the VB IDE is taking up some memory or some background program is. Also make sure your hardware acceleration is up all the way cause as I mentioned before, this is game is hardware only, no software rendering.

----------


## Jim Davis

> My goal is to have more Bossses like the Copter and more objectives


- bombing raids <- place a minimap that show you where the bombers will 'bombing' so the pl have to hurry to hunt em down  :Smilie: 
- fire missles from the battle ships <- good idea!

- And, there would be cool to see some surface to air missiles, that is launched rarely and randomly, but you can avoid to crash if you can move good enough. Some meep-meep warning may show the Pl that missiles are incoming. (these stingers should destroy enemy planes also!)

- On a later level, some outer-space to air laser rays could appear, that is will replace the stingers.

Also, the minimap would be really nice, to see where a new plan/stinger/laser attack will appear on screen.

Is there Weapon/armor powerups are planned (armor may give you to survive 2 or more rockets)? Some heat-seeker special rockets would be nice also  :Smilie:

----------


## technorobbo

All cool Ideas - especially the minimap. I'm texture mapping all the planes right now. Theyre looking pretty tough (BA as my son would say), after I'm done with the textures I think I'll tackle that minimap.

----------


## Jim Davis

There is also a yet old but still addictive 'receipt' for these plane-shooter games. I call em 'mass bullet' games, where the enemies are appear frequently, and they are 'pissing' the bullets (rockets) by using some pretty nice math algos.

http://www.mamedb.com/category/Shooter/Flying+Vertical

Just go thru the classic 'roots' that is may give you even more ideas. You can also pick up an arcade emulator, to see these games in action.

----------


## Cruncher

> Cruncher,
> 
> Did you compile first? Try compiling and running the new executable. Make sure it's in the project folder since it references the subdirectories. Also make sure that no other programs are running in the background.  
> 
> The reason i say all this is because the error your reporting is an "out of video memory" error. Usually this hasn't been the case and was caused indirectly by windows switching modes which cause all hardware graphics to reset. That's why I block all the system keys, to avoid graphic switching.
> 
> The game itself is not that large but it is possible the the VB IDE is taking up some memory or some background program is. Also make sure your hardware acceleration is up all the way cause as I mentioned before, this is game is hardware only, no software rendering.


uhmm well i do only have 64mb of graphics memory which is a pain in the ass, but i play gunz online and diablo 2, which i would assume are more graphicially intense... and i just closed everything and its still being uncooperative.

----------


## technorobbo

> uhmm well i do only have 64mb of graphics memory which is a pain in the ass, but i play gunz online and diablo 2, which i would assume are more graphicially intense... and i just closed everything and its still being uncooperative.


I should add a switch for software render, Just to see if it works. Give me a few days.

----------


## Jim Davis

Diablo 2 uses pre-rendered sprites for every single animation frame. Theres no true, real time 3d rendering. I bet that diablo also uses the system memory for the sprites, but not the vga memory.

----------


## Justa Lol

what to do when you get a run-time error 429?
activex component cant create object

----------


## technorobbo

When and where do you get the error?
 Do you you use Vista? 
Do you have DirectX-7 in the references? 
Who invented liquid soap and why?

Ignore the last question? I'll figure it out myself.

I'm betting it's the directx-7 reference.

----------


## Justa Lol

exactly... i didnt see that...  i have the newest directx only...

1 on load
2 yes
3 no
4 Liquid Soap was invented by Hendrik Willem Brouwer, because non-liquid soap left some bacteria on it.

----------


## technorobbo

Very informative

----------


## RaZeR

I tied to play that game. First time after some time i pressed Esc to exit. Game exited normally, but when i try to play again and totally crashed, i got BSOD  :Frown: 

P.S: Sorry for my english  :Smilie:

----------


## technorobbo

Thanks for the heads up I'll check for memory leaks. I'm posting a new version soon.

----------


## technorobbo

Changes made hopefully your memory problems are OK - added some plane textures.

----------

