Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
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   
  Show Posts
Pages: [1]
1  Game Development / Game Mechanics / Re: Simple melee attacks, looking for advice on: 2012-10-19 07:28:51
You can save a list of damaged entities in your attack instance. If enemy is already in list, do not damage it again.
You can save a list of damaged entities in your attack instance. If enemy is already in list, do not damage it again.
This. A HashSet can be used for it.

That's great! Thank you guys so much. I didn't think to create an instance of the attack. Rather, my attack consisted of a box that followed the player around and a player state that determined whether to check for objects within the box. Now I feel silly.
2  Game Development / Game Mechanics / Re: Simple melee attacks, looking for advice on: 2012-10-18 15:44:23
I'll elaborate with an example scenario.

My designer decides to give the player a slashing sword attack that can definitely hit multiple enemies. He sets the hit box of this attack so that it will hit anything in front of the player, where the sword will swing. It takes one full second for the sword to go from the initial position to the end of the swing.

The player is testing this, and two enemies are in front of him. One of the enemies is already within the hit box, and the other is fast approaching. So the player hits the attack button, and the sword swings. The second enemy steps into the hit box while the sword is swinging, exactly .5 sec after the attack is initiated. The pixels of the sword make clear contact with both enemies.

Currently, here is what happens: The game logic is updated at 60 frames per second. The first enemy, who was within the hit box for the entire length of the attack, is damaged 60 times. The second enemy, who is only present for half of the attack, is damaged 30 times. These numbers might be off, but that is essentially what happens.

Ideally, I would like to damage each enemy only once.

Quote
But I'd just clear the player attack hit frame once every intersecting object has been damaged

This is attractive to me, but in my example scenario the second enemy would not be damaged. Perhaps that is correct, and an enemy should not be damaged if they were not in range at the exact moment the attack begins. But visually, the player still sees the sword make contact.
3  Game Development / Game Mechanics / Simple melee attacks, looking for advice on: 2012-10-18 15:11:13
I have run into a problem calculating attacks.
If the player is attacking and an object intersects his attack hit box, I call the damage() function of the object.
Problem is, this happens every loop, and the object is damaged several times during a single attack animation.

I searched the forums for a solution, but I didn't find anything. My ideas:
  • I thought I might end the attack after causing damage once, but that makes cleaving attacks impossible.
  • I thought of "tagging" the enemy as damaged, and testing for this before applying more damage, but I would have to reset each object between attack animations.
  • My best idea is to use a timer, allowing damage() to be called only so often, so there is a recovery period after being attacked, during which the object cannot take damage. Problem is, the recovery period cannot be shorter than the animation. If it is too short, the attack will still hit multiple times. If it is too long, the next attack might not cause damage. I don't want to use a set animation length. Maybe I can pass the animation length to the object when it is damaged...

Any thoughts? How do you handle this kind of attack?
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (11 views)
2014-09-21 23:33:17

BurntPizza (29 views)
2014-09-21 02:42:18

BurntPizza (19 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (30 views)
2014-09-19 03:14:18

Dwinin (47 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!