The Daily Click ::. Projects ::. Hasslevania 2 This Space for Rent
 

Project: Hasslevania 2: This Space for Rent
Project Started: 12th August, 2009 Last Update: 20th September, 2014
Project Owner: Del Duio Project Members:
Project Type: Adventure Game Project Progress:
More Info: http://dxfgames.com Faves: 19

You could say H2 is now "Fixed"!
Posted 4th Oct 09, by Del Duio  
Oh man, I don't have any pictures to accomodate this entry but while working on my in-between game I had accidentally figured out a great way to have melee collisions vs. enemies where each enemy would only get hit once by the weapon but where you could possibly hit 2 (or more) said enemies during that same swing.

What I had been doing in H2 since 2007-ish was using a flag whenever Rovert hit an enemy and after the swing was done the flag was reset to "off". This worked all fine and dandy except when bunches of enemies would try to get you all at once. In that event you'd damage one of them, sure, but the others that would be getting struck with your weapon would go uninjured (and probably laughing at Rovert on the inside to boot.) I then tried taking out this flag and have some "if the WOOSH sound isn't playing" and other checks n' balances but what'd then happen with the slower swinging 2-handers is you'd hit multiple times on the enemy on that same swing. And for what I was trying to do, that sucked!

Flash forward to last week: I was screwing around the MMF2 event editor and saw something I've never used before, which was an object's Fixed Value. As I've recently learned this is the overall object ID on any given frame and can't be changed. Then it hit me on not only how to make a decent hit system on the new one, but how I could also use this new method on H2 and fix it.

Extremely basic (and forgive me if all of you already know how to do this, which I don't doubt) princible:

*Your hero has an alt value, which for now I'm calling "WHO HIT".

*Whenever your melee weapon makes contact with any enemy, a condition of damage is "If alt value WHO HIT <> Fixed Value(Enemy)". If damage is scored, the player's WHO HIT value is then updated with the target enemy's fixed value (which keeps it getting hit just that once per swing).

*Lastly down at the bottom there's a simple check saying "If player weapon isn't overlapping any enemies, set WHO HIT to 0". This resets the weapons so you can hit more things again.

--

The great thing about this is now you can hit an enemy once per swing, but if there's another enemy right behind it the weapon will strike (updating WHO HIT to that first one's fixed value) and then hit the second enemy exactly one time only while it's following through because the value for WHO HIT is now different. This is incredibly useful for this game's axe weapon where now you can hit monsters on either side of you with a single swing.

Anyhow, this new way has been added to every monster in Hasslevania 2, and it really only took me a solid 2 days or so to make all the appropriate changes and deletions to the code. It might be easy and simple to most but it was one hell of a "Eureka!" moment for me.

Thank you and Good Night.

Posted by alastair john jack 4th October, 2009

nice work. I don't quite fully understand that, but at least its working for you.
Although couldn't you have just put the flag on the enemies instead? (then reset the flag once swing is done) so that they can only hit once per swing.
 
Posted by Ski 4th October, 2009

You've been working on this since 07? o.o; I didnt realise it was so long.
 
Posted by UrbanMonk 4th October, 2009

I have these Eureka moments too.

I slap myself everytime because the solution is always so simple.
 
Posted by Pixelthief 4th October, 2009

>.> exactly like alistair said, a very easy way to do this is to have every enemy have a flag indicating if they have "already been hit", and then every time you swing, you unset this flag, and every time you hit them, it sets them. So something like this:

+Upon Pressing Space
=Set Bat Flag 0 off
=Set Skeleton Flag 0 off
...etc
=Play Attack Animaton
=Play Swing SFX

+Attack Animation is overlapping Skeleton
+Skeleton Flag 0 is off
=Set Skeleton Flag 0 on
=Damage Skeleton

I did just this in Gridquest for the the spell effects; it works like a charm in terms of "one spell can hit each enemy only once". The problem is that if you have projectiles that you can have more of one of at a time, it can cause some inconsistencies; if your first fireball is already overlapping an enemy, and you cast a second, it will instantly *hit* the enemy a second time, and the second fireball won't hit at all. So if you noticed sometimes in Gridquest if you held down the Fireball spell, it would actually shoot straight through enemies "every other shot" and not explode, which made the spell kind of suck tbh.


Now if you're really interested, the way most professional projects do this (and is almost impossible to implement in MMF) is that each projectile will actually keep an array or list inside of its object class, which will record the fixed ID of every single object it hits; that way a single fireball never hits any object more than once, but you can shoot multiples and it will work consistently. The downside is that this must be implemented as a linked list in order to avoid N^2 memory usage (N fireballs storing N objects' ids), and the worst case scenario of the linked lists exploding out of control can create 'bad stuff'

Also, the implementation you wrote out would cause a situation in which, if your animation was overlapping two enemies *at the same time*, they'd both be damaged every alternate frame!


Hope all that helps!
 
Posted by Del Duio 5th October, 2009

Yeah I noticed that already with one enemy where his animation was so that the sword would hit, he'd move a bit (causing the sword to not overlap anymore and reset the WHO HIT value to 0) and then the sword would hit the enemy again once it caught up to the animation.

But overall this really does work so much better than before. The killing is a lot faster, which I guess is good in any action-y game. Next time I'll try the enemy flag idea though, never thought about that before.

You've been working on this since 07?

On and off, yeah. Hasslevania 1 was out, and then I was hard working on the special edition (which was never finished in favor of the whole sequel H2) and then I took a 2 month break from it due to burnout, put out the Neil Peart game and the rest is history. I'm not working on it every single day for 6 or 7 hours like I would've before and that's slowing the process down too. I do still have those big 6 hour nights working on the game but they're not nearly as frequent now.
 
Posted by Pixelthief 5th October, 2009

Oh no I meant, what happens if you swing your sword, and its overlapping two different enemies at the exact same time? I think the way you wrote it, it would instantly kill both of them-

When it overlaps the first, it would record his ID so it doesnt hit him again. But then it overlaps the second, and records *his* ID, so it doesn't hit him again. But that means it will hit the first enemy again, and record his ID, and then the second, etc etc. Should be hitting both 50 times per second as long as its overlapping 2+ enemies


You'd probably never notice that because of how hasslevania doesn't have too much overlapping enemies, but I was thinking you ought to test your boss fights or whatever to make sure that doesn't happen! Hope it helps
 
Posted by Del Duio 5th October, 2009

Ah!

No that doesn't happen because there are other checks in there aside from the WHO HIT variable. I hit both a spider and skelly who were overlapping in testing and while they both took damage (different damage values to boot, neat-o) neither died during that strike. I'll test it out some more later because you're right and there aren't too many instances of enemy bunches. The bats always seem to pose the real threats because they add up fast. I'll make up a room with a ton of bats and see what happens.
 
Posted by alastair john jack 8th October, 2009

I'm looking forward to this game
 


 



Project Forums


Favourite

Advertisement

Worth A Click