GPWiki.org
GPWiki.org
It is currently Wed Jun 19, 2013 2:20 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Apr 23, 2012 3:55 am 
Rookie

Joined: Mon Apr 16, 2012 2:31 am
Posts: 4
At the suggestion of fellow forumers, I am using this for a game I am programming:

http://msdn.microsoft.com/en-us/library ... estudio.31).aspx

It is working great, but I'm having a little trouble figuring out just what does and doesn't need to be done here. The primary problem is all the tutorials for this try to do way more than what I want done. What I need to know is what is the bare minimum I need to implement the shot mechanic. And how would I code it? All I want is:

-The shot comes from the player object itself, not an additional gun object (as I don't intend to implement that)
-The shot is culled when it either collides with an enemy or leaves the screen, but not with a tile. It should appear in the foreground.
-The shot reads its direction from a variable, with a default setting to right. I don't need to know how to alter its direction as I can take care of that myself.
-The shot appears on screen.

I just want to get it functioning so I can see it in game without a crash. As long I can do that, I'll gladly work out the details myself.


Top
 Profile  
 
PostPosted: Mon Apr 23, 2012 2:11 pm 
King Code Monkey
User avatar

Joined: Wed Sep 01, 2004 3:05 pm
Posts: 11199
Location: Abingdon, MD
Have you seen this?

_________________
Bored? Head on over to my blog and see what I'm up to.

Microsoft XNA MVP


Top
 Profile  
 
PostPosted: Mon Apr 23, 2012 10:40 pm 
Rookie

Joined: Mon Apr 16, 2012 2:31 am
Posts: 4
Yes and it is exactly what I am NOT looking for, hence my emphasis on the shot coming from the player object, not an additional arm. As well, I also emphasized not adding in the directional aim, as I intend to use a very different method, I was really hoping those hints would cause me to not get linked to that. I mean, I could use it, but for everything I'd have to overhaul, I may as well do it from scratch.

I do appreciate the attempt at helping, but I need something which addresses the specifics of the original post.


Last edited by Onaga on Mon Apr 23, 2012 11:04 pm, edited 3 times in total.

Top
 Profile  
 
PostPosted: Sun Apr 29, 2012 12:30 am 
Make a bullet class that has a Texture2D texture, Vector2 position, Vector2 velocity, Vector2 direction, Rectangle rectangle, and float speed.

When the bullet is fired, create one and add it to a list and loop through it to update each bullet and to check for collisions against each enemy.

-The shot comes from the player object itself, not an additional gun object (as I don't intend to implement that)

*When whatever button is pressed that you want to fire a bullet, initialize the bullets position to the players position.

-The shot is culled when it either collides with an enemy or leaves the screen, but not with a tile. It should appear in the foreground.

*If an active bullet intersects with an enemy rectangle remove it from the list of active bullets. To check if its left the screen again use rectangle collision against the camera/viewport rectangle

-The shot reads its direction from a variable, with a default setting to right. I don't need to know how to alter its direction as I can take care of that myself.

*Use a Vector2 in the bullet class for direction. Set its x to 1 in the constructor. Use a formula like position += direction * speed * (float)gameTime.ElapsedTime.TotalSeconds;

-The shot appears on screen.

*Loop through the list of active bullets in the draw method and draw the bullets texture at the bullets position.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group