|
-
Feb 23rd, 2010, 02:15 PM
#1
Please show me the best shooter example
Hello.
I am looking for a simple example of "shooting," with a gun, bullets, a target, and the explosion upon hitting the target. Would like a bitblt example, not DX...
Can you point me to a favorite?
Thanks!
Bryce
(VB6)
-
Feb 25th, 2010, 10:15 AM
#2
Re: Please show me the best shooter example
There are none that I know of, simple that is.
Why is is that everyone wants to learn some shoddy way to make an action game using BitBlit and PictureBoxes under GDI, something this system was NEVER intended to be used for, and as a result is a TON harder to make work and get decent results with; than just getting over their prejudicial fears of DirectX, an EASY to use API that was DESIGNED SPECIFICALLY for this kind of stuff?
With DirectX, XNA and VB.NET, I can show you an example of an animation of a shot, a collision event and an explosion animation in about a page of code. It would take three times that just to get the BitBlit to work properly let alone the collision event and animation and it would be ugly, jumpy, and flickery.
You can do stuff like this with XNA:
Code:
Dim TargetBounds As New BoundingBox
Dim BulletBounds As New BoundingSphere
If BulletBounds.Intersects(TargetBounds) Then
'It hit!
'Remove bullet sprite
'Replace target with explosion animation
End If
How much simpler do you need?
Last edited by Jenner; Feb 26th, 2010 at 02:50 PM.
-
Feb 25th, 2010, 02:50 PM
#3
Re: Please show me the best shooter example
Gee, I certainly didn't mean to offend!
The reason I'm choosing to go this route is because I intend to make a very simple game for my kids.
-
Feb 26th, 2010, 02:49 PM
#4
Re: Please show me the best shooter example
I apologize, I'm just a bit tired of seeing people bang their heads against the wall trying to force the system that Windows designed for business graphics to do things it really can't do. Then they come on here and ask for help expecting there to be some magical trick for making it work and specify "but not DirectX!!" as if the API is the plague.
That's like walking up to a carpenter with a nail and a screwdriver and asking him "How do I pound this nail in with a screwdriver, NOT with a HAMMER?" 
DirectX is just as simple and easy to use as most everything else Microsoft has. Yes, you need to install some extra packages to use it because it isn't specifically attached to the Framework. Yes, there is a small learning curve, and yes, there's enough junk in there to make even the most tech savvy programmer's head spin... but you won't be using even 90% of it.
I was intimidated at first too, but then I learned the basics: How to start up a window in DirectX mode, how to load sprites and how to move sprites. I still don't have a clue how to bump-map texture a mesh or how to apply per-pixel shader effects, but I know enough to make a simple 2D game.
Once you have it installed and in your programming environment, i.e. once you're holding that hammer, even the simplest games become a walk in the park, and God forbid, you use one of the many popular 2D game engines out there and it's not even fair how simple it is. Here's an example of a gun, shooting bullets at a space invader and the invader exploding. This example uses VB.NET, XNA and the FlatRedBall game engine; all free components:
Code:
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input
Imports FlatRedBall
Imports FlatRedBall.Math
Imports FlatRedBall.Math.Geometry
Imports FlatRedBall.Graphics
Imports FlatRedBall.Graphics.Particle
Imports FlatRedBall.Input
Public Class Game1
Inherits Game
Private graphics As GraphicsDeviceManager
Private sprGun As Sprite
Private sprBullets As New SpriteList
Private sprInvader As Sprite
Private emtExplosion As New Emitter
Public Sub New()
graphics = New GraphicsDeviceManager(Me)
End Sub
Protected Overrides Sub Initialize()
'Set up my graphics
Dim grOp As New GraphicsOptions
grOp.SuspendDeviceReset()
grOp.SetResolution(250, 500)
grOp.ResumeDeviceReset()
FlatRedBallServices.InitializeFlatRedBall(Me, Me.graphics, grOp)
'Set up the camera
SpriteManager.Camera.Orthogonal = True
SpriteManager.Camera.OrthogonalWidth = FlatRedBallServices.ClientWidth
SpriteManager.Camera.OrthogonalHeight = FlatRedBallServices.ClientHeight
SpriteManager.Camera.UsePixelCoordinates(True)
'Make the gun
sprGun = SpriteManager.AddSprite("gun.png")
sprGun.ScaleX = sprGun.Texture.Width / 2.0F
sprGun.ScaleY = sprGun.Texture.Height / 2.0F
sprGun.X = FlatRedBallServices.ClientWidth / 2.0F
sprGun.Y = sprGun.ScaleY
'Make the target
sprInvader = SpriteManager.AddSprite("invader.png")
sprInvader.ScaleX = sprInvader.Texture.Width / 2.0F
sprInvader.ScaleY = sprInvader.Texture.Height / 2.0F
sprInvader.X = FlatRedBallServices.ClientWidth / 2.0F
sprInvader.Y = FlatRedBallServices.ClientHeight - 50
Dim rectangle As New AxisAlignedRectangle With {.ScaleX = sprInvader.ScaleX, .ScaleY = sprInvader.ScaleY}
sprInvader.SetCollision(rectangle)
'Setup the explosion
SpriteManager.AddEmitter(emtExplosion)
emtExplosion.ParticleBlueprint = SpriteManager.AddSprite("explosion.jpg")
emtExplosion.EmissionSettings.ScaleX = sprGun.ScaleX
emtExplosion.EmissionSettings.ScaleY = sprGun.ScaleY
emtExplosion.EmissionSettings.AlphaRate = -1.0F
emtExplosion.EmissionSettings.ScaleXVelocity = 70
emtExplosion.EmissionSettings.ScaleYVelocity = 70
emtExplosion.RemovalEvent = Emitter.RemovalEventType.Alpha0
emtExplosion.Position = sprInvader.Position
End Sub
Protected Overrides Sub Update(ByVal gameTime As Microsoft.Xna.Framework.GameTime)
FlatRedBallServices.Update(gameTime)
'Check if the spacebar is being pressed
If InputManager.Keyboard.KeyPushed(Keys.Space) Then
'Make a bullet
Dim sprBullet As Sprite = FlatRedBall.SpriteManager.AddSprite("bullet.png")
sprBullet.ScaleX = sprBullet.Texture.Width / 2.0F
sprBullet.ScaleY = sprBullet.Texture.Height / 2.0F
Dim circle As New Circle With {.Radius = 1}
sprBullet.SetCollision(circle)
sprBullet.X = sprGun.X
sprBullet.Y = sprBullet.ScaleY
sprBullet.YVelocity = 1000
sprBullets.Add(sprBullet)
End If
'Check if any bullets hit or are moved off the screen
Dim sprTemp As New SpriteList
For Each sprBullet As Sprite In sprBullets
If sprBullet.CollideAgainst(sprInvader) Then
'If bullet hit the invader
SpriteManager.RemoveSprite(sprInvader)
sprTemp.Add(sprBullet)
emtExplosion.Emit()
End If
If sprBullet.Y > FlatRedBallServices.ClientHeight Then
'If bullet is off the screen
sprTemp.Add(sprBullet)
End If
Next
SpriteManager.RemoveSpriteList(sprTemp)
MyBase.Update(gameTime)
End Sub
Protected Overrides Sub Draw(ByVal gameTime As Microsoft.Xna.Framework.GameTime)
FlatRedBallServices.Draw()
MyBase.Draw(gameTime)
End Sub
End Class
In this example, we're using an XNA Game object. Initialize is called when the program is run, all it does is set everything up: My screen, my camera, my two objects, and defines the explosion maker. Update happens every frame: Check for input, check for collision.
   
In one page of code and four graphics,you can do 60fps, non-jumpy, silky smooth animation with hyper accurate collision detection. I even fired multiple shots. The explosion is done with a particle emitter so it even looks real as it expands and fades out.
All I'm saying is I applaud you for wanting to make a simple game for your kids, but game programming is still game programming. It's very different from application programming. There are some very simple, easy ways to do it, but they got big scary professional sounding names like "DirectX". In the end, you gotta be willing to drop the screwdriver and pick up the hammer.
-
Mar 2nd, 2010, 11:52 AM
#5
Re: Please show me the best shooter example
Ok, Jenner, thanks for the example.
I'll meet you halfway to picking up the hammer.
For now, I'm staying in VB6 (even though I actually purchased VisStudio, and I have it at home...). I will look into DX.
Any good VB6 WITH DX examples?
(Not looking for anyone to do my homework for me...just want an example or two to get me started!)
Thanks!
Bryce
-
Mar 2nd, 2010, 12:35 PM
#6
Re: Please show me the best shooter example
There was a VB6 DirectX implementation posted here recently: http://www.vbforums.com/showthread.php?t=605201
-
Mar 2nd, 2010, 02:08 PM
#7
Re: Please show me the best shooter example
I saw that, and it frightened me a bit!
I'll check it out, though.
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|