# Visual Basic > Games and Graphics Programming > Game Demos >  Wormipede and source(vb6, dx7, English)

## Lord Orwell

This demo shows how to do a couple of things:
Initialize and run Directx, And resize a window during game play.  It uses directsound as well.

Special features include similar creatures to the original centipede game including the flea and spider.  My own addition is spider webs.  You won't see any of this on level one, but hang tight.  The difficulty increases exponentially for each level.
The spider becomes VERY dangerous at higher levels.

Ignore Everything before post 32.  It was a trial-and-error bug-fix extravaganza.  The zip is now in a different thread.


Here's an updated link to the submission:
http://www.vbforums.com/showthread.php?t=498393
I am not claiming any rights to this code.  Feel free to expand on it.

----------


## Lord Orwell

I just did some testing of my own, and It turns out that the top speed at higher levels (around level 3 or so) is greatly affected by your graphics card.  If anyone wants to know why the grid is so big, the speed at higher levels will explain it to you.  but feel free to take this code and run with it.  I had originally planned to add other Centipede things to it like the flea that dropped mushrooms.  I just got lazy thats all. (actually the real reason is i switched to vb.net)

----------


## singularis

I am impressed by the smoothness but I can tell you included your own, 'programmer art'  :Wink: 

Please, Please, Please, Please do not allow the player to go back on themselvles and kill themselves instantly. E.g pressing left when the player is facing right

----------


## Lord Orwell

hmm i thought i had code in there to prevent that.  Must have lost it during a random lock up.  I had a vb6 add-in raising hell with vb.  I did the graphics with Photoshop 7, except the game over message, which is simply wordart from msword.

----------


## Lord Orwell

ok here's an update that fixes the issue you mentioned.  You can't kill yourself by going in reverse any more.  Note that this game is skinnable and you can plug in any sounds you like too.  Just replace the appropriate files.
[Edit:  Link to latest version is in post 32]

----------


## Whosat

My arrow keys lag... Gotta spam it a few times to get it in the right direction...

----------


## zynder

Nice effort there. But i wonder why the game doesnt quit when i press the quit button. It should prompt a message box saying "Quit playing games? y/n"   :Smilie: 

Is it a bug? 

ok later on i found out bug #2.

Run the application (not on VB IDE), then minimize it. After a minute click the game or maximize it and it will throw an error saying "Error starting direct Input, please make sure you have directx installed".

----------


## Lord Orwell

I get that too.  Its an issue with directx evidently in xp because i used code directly out of the sdk for the directinput.  I also noticed the program is a process hog.  If anyone has any suggestions by looking at the code to lower processor usage, i would love to hear it.  This may be why you are having keyboard lag.

----------


## zynder

Maybe it's throwing an error because the form is minimized. Don't you think? I think you must add a condition where not to start activating directx input while the form is minimized sort of putting into freeze state.

----------


## Lord Orwell

i don't know.  and it always does three of them.  Really odd considering i only have one message box.  Have to look into it one of these days.

----------


## singularis

Tsch Tsch Tsch Mr Orwell. Its the timer that is causing the keyboard lag!  :Stick Out Tongue:  

Get rid of it at once and implement a game loop  :Wink:

----------


## Lord Orwell

blah.  I have a game loop.  The keyboard input just isn't in it, that's all.  I didn't see the need to poll the keyboard that often.  If anyone wants to experiment with it, that's why the code is there.  It doesn't lag at all on my system, but my computer's not a slow model either  :Wink:   Anyone having input problems, what are you running?

----------


## singularis

You have a loop inside a timer? Are you insane?

----------


## zynder

It doesn't lag at my system though. well, there are still room for improvements.

----------


## Lord Orwell

no i DON'T have a loop inside a timer.  you will notice the very first line of that timer disables the timer.

----------


## singularis

Yes you do, You sly dog....

----------


## Lord Orwell

the code has two timers on it, just because.  The purpose of one of them is merely to update the screen, because when i had it inside the main game loop it was bogging down my system, and i have what was at the time of my making this game a top of the line system (i built myself).
Here's something DIRECTLY from my code:


```
Private Sub GameTimer_Timer()
Dim cl As Long
Dim stored
Dim zz As Long, yy As Long
GameTimer.Enabled = False
```

notice anything odd?  The timer will only fire one time.  I did this so the program could do things at the same time.  I in fact got the idea straight from a code sample in the directx7 sdk, which does some really insane stuff with timers. One will enable the other and disable itself, then the other will do the same thing.

----------


## chemicalNova

I saw a tutorial once that checked the state of the window on Form_Resize(), and if it was minimized it shut down DirectInput/DirectX, and on maximizing it again it reloaded it all.

chem

----------


## Lord Orwell

you only need to do that if you are running a Legitimate full-screen app in Exclusive Mode, which i am not.  If you don't do that in exclusive-mode dx apps, they will crash when you restore the window, because they lost all video memory when the application lost focus.  I cheated and i am running the app in windowed mode, even when maximized.

----------


## singularis

@Lord_Orwell: I meant yes you do.... you sly dog e.g. your timer only fires once. What I said came out wrong  :Wink:

----------


## Lord Orwell

don't mention it.  I text message my wife so i am used to having texting misunderstood.

----------


## cptHotkeys

OMG, I was going to make a game verry much like this the other day, taken after the classic "Snake" from the old school cell phones...

Hey Lord Orwell, would you be keen to work on a game?

----------


## Lord Orwell

That's funny you said that.  I wrote this game because our new cell phones didn't have the game, and my wife complained.  Took about a day.

I had ideas for it but i am lazy.  I have also written in the past a game like Collapse (but no sound) completely in VBA as a Word macro on a vba form, a tetris clone, but with extra shapes that appear at higher levels, and a remake of minesweeper.

What kind of game did you have in mind?  Tell me this, your vb version, and whether or not you want it to use Directx.  If we write it in .net, i vote against using dx because i don't know how to use 9 yet.

----------


## cptHotkeys

WOW great minds think alike, I have also made a mine sweeper game, It had messy code but it worked with no bugs, I still have it somewhere, I might upload it here for the hell of it, but if anyone wanted to read it, I cant garentee that they could make sence of anything as I wrote it form top to bottom, start to finish, hacking my way through...

I was thinking about a card game (Last card? easy logic), as Im not quite ready to attempt a 3D game yet, maybe multiplayer online...

----------


## Lord Orwell

i wouln't know where to begin on a 3d game  :Frown:   Directx is also used for 2d as well though.  Still need to know which version of basic?  And i barely know how to add the comm control to a form, let alone use it.

----------


## cptHotkeys

I have never used directX, I might make up a few classes to demonstrate my ideas for the game, and then I will make a new thread...

PS: I use VB.net 2005

----------


## Lord Orwell

I am pretty weak at using classes, but i'll try and puzzle it out.  You will notice my Wormipede doesn't use any, although i make liberal use of custom objects.

----------


## 03myersd

I found a great 3D game written in VB 2006. It works very well and is an excellent example of how adaptable VB is.

Attachment 58019
Attachment 58020

Note: You must extract the image from background.zip and place it in the textures folder of 3D Racer.zip.

----------


## drivenbywhat

I tried your game. Unfortunately, my system isn't powerful enough to play it well. It is 933mhz & 8mb vid card  :Blush:  I get that keyboard lag. I have to actually hold down the key for about 3 secs for the worm to move in a direction. However, it does look like a cool game.  :Thumb:

----------


## Lord Orwell

sorry about that.  If i ever get the time, i am going to convert it to .net and not use directx at all.  Either that or more precisely control what parts of the screen are redrawn (automatic in .net) to speed it up.  It isnt the fact that the keyboard input is slow, it is that the video drawing is hogging the resources.

----------


## drivenbywhat

Yeah, from what I read on the previous posts, it looks like if the vid card isn't good, the resources will get hogged. I would upgrade it but it's a laptop (not too much available to upgrade) and it's from 2001.

----------


## Lord Orwell

here's an update i should have made aeons ago:  I made some major game changes to the game, and submitted it as a contest submission.  I figured out why it was maxing out the processor usage:  I had a doevents in the loop.  I have lowered processor usage, added new features, and tweaked the leveling for game balance.  for example:
1.  The dropping flea, which leaves a random trail of mushrooms
2.  A spider introduced at level 2(?) with webs you can get stuck in.  He comes to eat you if you do.
3.  Higher levels he doesn't wait for you to get stuck and goes on a spastic hunt similar to behavior in the original centipede game.  This makes him VERY dangerous.

There are other changes i don't recall right now, but basically it's more stable and the keyboard input should work for everyone now.
Here's an updated link to the submission:
http://www.vbforums.com/showthread.php?t=498393
anyone is free to learn from and expand on the code as they wish.  I no longer program in vb6 since it's outdated so i am releasing the game to the public domain.  Have fun.

----------


## Lord Orwell

Error from the programmer:  I uploaded updated source files for the code submission, but evidently didn't recompile it first.  If you download the code sample to view in vb6, delete the .exe file.  it's from a much older version of the program and doesn't include the advanced features the newer version of the game has.  Nothing i can do about it now since the thread is locked.  I will see if i can get a mod to delete the .exe from it.

----------


## minitech

I don't have a VB6 compiler. Could you please post another exe here, please?

----------


## Lord Orwell

it's against forum rules to upload an .exe.  Have someone compile it for you.

Besides which, i don't program in vb6 anymore either and no longer have a compiler.

----------


## minitech

In the rules (I made sure to look through them thouroughly), it says something along the lines of: "Feel free to upload an exe for your game, but note that less people will download them."

Anyways, I don't have anybody who could compile it for me.

----------

