Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  explosions  (Read 1475 times)
0 Members and 1 Guest are viewing this topic.
Offline sloppyjoe

Junior Newbie

« Posted 2005-12-05 22:40:23 »

I'm in the "pen & paper" stage of my platform/action game idea and I'm trying to think of how I am going to do certain things.  I came to the topic of explosions and really quickly I just thought of doing simple collision checks with the explosion's circle and other nearby objects.  This sounds like it'd work except when the explosion is near something that blocks it, like a wall.  Please excuse my lousy illustrations Cheesy

Using radius/distance checks, there's still the problem of the explosion affecting objects on the other side of the wall (see #1 in pic).  In most cases, this isn't desired but could make for some interesting gameplay options (some explosions go through walls while others do not).

In #3, the explosion is being moved out of the wall and then from there, collision checks would be done.  This moves the center of the explosion, could confuse the player and if the explosion does any "push", it wouldn't be from the spot you'd expect it to be.

Ideally, #2 is how explosions near blocking objects is handled.  The explosion and its effects are "chopped" by walls.

(red represents explosion; black line is wall)

To achieve #2, I came up with the idea of  "damage lines" that would come out of the center of the explosion.

(red dot in middle is the origin of the explosion; lines coming out of origin are the damage lines)

Basically, the damage lines would be extended out from the center until they hit a wall or their length is equal to the explosion's radius.  Those lines would be what is checked for collisions with nearby objects.

Each line would do a fraction of the explosion's max damage.  So, using the above pic as an example, the explosion does 80 max damage, each line does 10 damage.  This way, objects that are barely inside the explosion radius would touch 1 or 2 lines and only receive 20 damage.  An object that was dead center in the explosion would touch every line and get the full 80 damage done to it.

Possible problems with this method is that when the explosion size is a lot bigger than the damagable object size, the explosion can "miss" the object (object small enough to fit between damage lines).  More damage lines could remedy that, or just constraining game objects so that case never arises.

Another possible method would be to draw one line from the explosion origin to the object, if that line doesn't cross any wall and if its length is less than or equal to the explosion's radius, do some damage on the object.  The distance from the explosion center to the object could determine the severity of the damage.

(red dot is explosion; black dot is out of range, green dot in range but behind wall, blue dot is in range and not blocked, blue dot gets damaged)

The single line idea seems more simple than the previous one, except that it'd need to be done for every object that might be colliding with the explosion: draw line from explosion to nearby object 1, see if it crosses a wall and its length <= radius, repeat for nearby objects 2...n.  You'd also need to determine the closest vertex of the object  to the explosion or just test every vertex.  With the damage line idea, the damage line lengths are determined once based on the nearby walls, and then those resulting lines are collision checked with nearby objects.

Any comments/thoughts/ideas?
Offline jbanes

JGO Coder

Projects: 1

"Java Games? Incredible! Mr. Incredible, that is!"

« Reply #1 - Posted 2005-12-05 22:47:46 »

I think you might have an easier time just computing the distance of nearby things that can be damaged. Since only characters in the game can usually be damaged, you can simply loop through each of them and find the hypotenuse between the character and the explosion. If the hypotenuse is less than the radius of the explosion, then you know the character has been hurt. As a bonus, you also know how much the character has been hurt.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Vorax

Senior Member

Projects: 1

System shutting down in 5..4..3...

« Reply #2 - Posted 2005-12-05 23:02:33 »

That wouldn't deal with his problem though, things would still get hurt through the wall.

The best solution is a combination of both:  Use the distance to determine which entities can be hurt by the explosion, then fire a ray at each to see if there is anything blocking them from being hurt.  This way you only test collisions for entities that are actually threatened by the explosion.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
8: Undefined index: online
File: /home/jgo/public_html/Themes/default/Display.template.php (main sub template - eval?)
Line: 151