Asteroids (no sound)

Teric
07-26-2001, 10:37 AM
Here is a pretty crude version of the old Asteroids game. I'm going to try to include all of the source files. Use the following controls:

Up Arrow: Thrust
Left Arrow: Turn Counter-clockwise
Right Arrow: Turn Clockwise
Down Arrow: Brake (Slow down & stop)
Space Bar: Fire

NOTE: I couldn't include the bitmap background with the file (to big to attach), so you will probably get an error loading the form at first. Ignore it.

This game was developed in VB 5 without any DirectX support nor sound. I'd love to put some sound into the game, but I'm not sure how. Any suggestions?

Please let me know what you think!

Teric
07-30-2001, 07:33 PM
BUMPING this thread back to the top. Does anyone want to download it? Please give any comments/feedback. Thanks!

dcl3500
07-30-2001, 08:28 PM
Cool haven't played asteroids in ages.

Okay this worked

Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Case vbKeySpace
gFireKeyDown = True
Call PlaySound("c:\windows\ImpulseSwish.wav", 0, 0)

Search msdn for all the particulars and I assume you can do the collision detection and whatnot.

Don

Time is the best teacher; unfortunately it kills all its students.

Spectre
07-31-2001, 01:33 AM
The only problem with PlaySound is that it won't mix [i.e. if you try to play two waves at once, they will terminate the previous one [or other things, depending on your flags]].
Since games often play sounds simulataneously, that could lead to problems.

Teric
07-31-2001, 06:42 PM
That's a good idea; I'll try that.

It looks like it doesn't keep the sound file in memory, though--I'll take a look.

Thanks for the feedback!

Teric
07-31-2001, 06:53 PM
Ok, I tried that in my code, adding a laser sound and an explosion sound. I discovered that, while the sounds played when they were supposed to, all animation STOPPED while the sound was playing. Hm... maybe I should start learning about DirectSound...

dcl3500
07-31-2001, 10:29 PM
Nothing stopped when I tried it, but then I used a very short sound. So it may have stopped but it was so brief I didn't notice. I've never put sound into an app, but Spectre is right. You can't put sounds together or have them overlap using my method.

Don

Time is the best teacher; unfortunately it kills all its students.

orufet
07-31-2001, 11:23 PM
I just downloaded it, and it's pretty good! (Way better than I could do)

Maybe if you used a different device to play the sound, it would work? I'm not sure, I have't tried it

Jacob Sheehy
http://www.sheehy.ca

The more I C, the less I see.

Spectre
07-31-2001, 11:24 PM
Ok, if you are gonna use PlaySound, you need to pass he flag SND_ASYNCH or something like that. Then it won't pause the program while doing the .wav.
REALLY, you should use DMusic.. hehe, which i just put in my last program.. it mixes and plays midis and the like, so i like it.. :)

Teric
08-01-2001, 07:42 AM
Thanks for the compliment, orufet. :)

Yeah, I'd like to start studying up on DirectSound & DirectMusic. (sigh) time constraints... 4 week old baby...

Teric
08-03-2001, 11:26 AM
For all who downloaded and tried my Asteroids Game (see attachment above), how fast does it run on your machine, and what are the specs on your machine?

Here at work, I have a Pentium III running at 450 Mhz with 128MB of RAM, and the game runs as fast as the old arcade version. However, at home, I run it on a brand new Duron 900 Mhz with 256MB of RAM, and the game runs depressingly slow.

What gives? Is anyone else seeing something like this?

BillSoo
08-03-2001, 11:34 AM
I have a PIII 500 with 128MB and it runs smoothly, although not as fast as at the arcade. I was running in IDE mode though.....

....I just compiled it (with full speed optimizations) and tried it again. Still seems to be running at the same rate....



"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

orufet
08-03-2001, 02:56 PM
Pentium II, 128 MB RAM.....Pretty slow, but not horrible

Jacob Sheehy
http://www.sheehy.ca

The more I C, the less I see.

dcl3500
08-03-2001, 06:30 PM
Celeron 466 256mb ram Run pretty good after I sped it up a bit images/icons/smile.gif

Don

Time is the best teacher; unfortunately it kills all its students.

TommyHM111
08-04-2001, 04:51 PM
uhh i am making a asteriouds game too how did you get it to stop?and slow down

orufet
08-04-2001, 05:28 PM
uhh, I think the idea is that you look at the code to see how he did it. That's the whole idea of posting it here

Jacob Sheehy
http://www.sheehy.ca

The more I C, the less I see.

restfern
08-05-2001, 05:28 PM
Hey Teric...I downloaded the Asteroids game and thought it was wicked!! Being new to the game programmer arena, I was pretty dumbfounded when I looked at the code, but I am trying to get my head around it all.
I just wanted to say that I added a Reverse function, basically 'cos there wasn't one in your original and I wanted to see if I could do it. It's pretty much using your code for the Thrust() function, so it's nothing special.

If anybody wants to use the code, it is as follows....but if anybody has done it better, I wouldn't mind seeing how it is done properly.

Thanks

Public Sub SlowDown()
'Bring the x thrust and the y thrust closer to 0.
If gXThrust > 0 Then
gXThrust = gXThrust - SLOW_FACTOR
If gXThrust < 0 Then gXThrust = 0
Else
gXThrust = gXThrust + SLOW_FACTOR
If gXThrust > 0 Then gXThrust = 0
End If
If gYThrust > 0 Then
gYThrust = gYThrust - SLOW_FACTOR
If gYThrust < 0 Then gYThrust = 0
================= the following two lines are the extra bits in this function
ElseIf gYThrust = 0 And gXThrust = 0 Then
Reverse
Else
gYThrust = gYThrust + SLOW_FACTOR
If gYThrust > 0 Then gYThrust = 0
End If
End Sub

Public Sub Reverse()
Dim YMax As Single, YThrust As Single, XMax As Single, XThrust As Single

XMax = (Cos((gShipDegrees / 360) * 2 * PI))
XThrust = XMax * ACCEL_FACTOR
gXThrust = (gXThrust - XThrust) / ACCEL_FACTOR
YMax = -1 * (Sin((gShipDegrees / 360) * 2 * PI))
YThrust = YMax * ACCEL_FACTOR
gYThrust = (gYThrust - YThrust) / ACCEL_FACTOR

If gXThrust < XMax Then gXThrust = gXThrust + ACCEL_FACTOR
If gYThrust < YMax Then gYThrust = gYThrust + ACCEL_FACTOR

End Sub

Finally, congrats again on the game man. Really cool.



"The face of a child can say it all, especially the mouth part of the face."

Teric
08-06-2001, 09:57 AM
Geez, Restfern. I'm flattered. Thanks for the great comments!

Hey, great idea with the reverse function--that's what I love about game programming, you can do whatever you want. :)

dragnut
08-11-2001, 06:31 PM
Pretty cool, Brings back memories :) It runs slow on win95 with a p233 and 32mb ram (in ide), but gets better when I changed a few numbers. Good job!
Shawn

Teric
01-25-2002, 08:31 AM
Since all the attachments were lost, I'm going to re-attach mine here.

serickson
02-21-2002, 09:45 AM
Good work. The code is great to get started with game programming.

Thanks,
Steve

Teric
02-21-2002, 11:12 AM
Thanks, Steve! I'd love to get into professional game programming some day...

denmeister
02-25-2002, 10:53 AM
If you want to bypass DS and be able to mix waves, create multiple WindowsMediaPlayer (WMP) objects. This is an acceptable method if you have few sound effects as it takes saveral seconds to load a sound file. This would force you to create one object per sound effect. Memory intensive, yes, but you can play multiple MP3's, MID's, WAV's, you name it. And each WMP object has it's own play rate, volume, and (if you have Windows Media Player 7.1) equalizer control. I think that would be plenty for your project.

Teric
02-25-2002, 11:17 AM
Yes, Denmeister, that would probably work. But I'm afraid I would end up with a severely bloated game that would eat up a lot of system resources.

No, I'd rather do this right the first time--it looks like learning DirectSound is the way to go.

Thanks for the suggestion, though!

denmeister
02-25-2002, 12:52 PM
That's your best choice, and yes, it bloats a program beyond belief. The first 4 instances of the WMP server are fairly cheap. But after that you really start to feel the effects. DirectSound was built for gaming and is, by-far, the best solution. Good luck.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum