It is currently Wed Dec 11, 2013 9:10 pm

 All times are UTC

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: The Icing on the Cake - Area of EffectPosted: Sat Nov 13, 2010 9:26 pm
 Harmlessness does no harm

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3913
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

 Post subject: Posted: Sat Nov 13, 2010 10:37 pm
 Corpse Bride

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2221
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

 Post subject: Posted: 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

http://www.gamedev.net/reference/articl ... le2604.asp

Top

 Post subject: Posted: Sat Nov 13, 2010 11:32 pm
 Harmlessness does no harm

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3913
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.

_________________
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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ Forums    Forum Rules and Posting Guidelines Wiki Discussion    Help    Content Issues Game Programming Discussion    C and C++ Game Programming    Java Game Programming    Language Agnostic Programming    .NET Game Programming    VB Game Programming    Mobile Game Programming    Web-Based Game Programming    Other Languages    OpenGL Development    Direct X Development Game Development Discussion    Game Design    Game Media Off-Topic Discussion    Announcements    Off-Topic    Community Projects    News