GPWiki.org
GPWiki.org
It is currently Thu May 23, 2013 7:31 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Nov 13, 2010 9:26 pm 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3808
Location: Ferriday, LA, US
So, I've been working hard on my game, and have come down to the last major feature that needs to be implemented: The plasma cannon.

The way the plasma cannon works is that... well, it completely obliterates everything in front of the player's ship. Basically, I need to be able to test for anything within the blast area, which is probably about 1000 pixels toward the angle the player is pointing, and about 250 pixels wide. The blast is pretty much a square shape.

Any pointers on the best way to code this beauty?

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 13, 2010 10:37 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
Location: England
Do you mean a rotated rectangle, 1000 pixels long and 250 pixels wide?

Should the blast happen all at once, or progress along that 1000px length over time?

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 13, 2010 10:46 pm 
Ankle Nibbler

Joined: Tue Jun 29, 2010 6:41 pm
Posts: 129
Well I suppose you could do a collision check and then just destroy them.

Please note, I have no idea how the language looks you are making it in, so I have no idea what would work or not.

A way it could be done:
For the sprite and the rectangle, check if the bounding box for the sprite has any pixels in the other rectangle.
In other words: Separating Axis Theorem

The ships rectangle values would be something like this:
left = ship x value
right = ship x value + ship sprite width
top = ship y value
bottom = ship y value + ship sprite height

The blast rectangle might be something like this:
left = player x value + player sprite size/2 - 125
right = player x value + player sprite size + 125
To get it in the middle we simply subtract some stuff

I added the extra 30 just so that it wouldn't collide with the player, when collision is tested.
top = player y value + 1030
bottom = player y value + 30

From here on, I suggest you check out this article:
http://www.gamedev.net/reference/articl ... le2604.asp


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 13, 2010 11:32 pm 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3808
Location: Ferriday, LA, US
I figured it out already, and now my game is pretty much complete.

Code:
var blastCos = Math.cos(cannon.angle);
var blastSin = Math.sin(cannon.angle);

var x1a = target.x - cannon.x;
var y1a = target.y - cannon.y;
var x2a = blastCos * x1a + blastSin * y1a;
var y2a = blastCos * y1a - blastSin * x1a;
                     
if (x2a > 0 && x2a < 800 && y2a > -64 && y2a < 64) target.damage += target.maxDamage;


Awesomesauce. :D

_________________
What most people don't understand about "enlightenment" is that it is not an end-goal; but where you find yourself just before taking a new "first step."


Top
 Profile  
 
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 1 guest


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