The Daily Click ::. Forums ::. Klik Coding Help ::. Some help with multiple enemies
 

Post Reply  Post Oekaki 
 

Posted By Message

Benny Lindberg



Registered
  08/11/2010
Points
  54
10th December, 2010 at 18:05:27 -

Hi there! I have a problem when it comes to hitting the enemies I've created. As it is now, they have a collision mask that the enemy sprite is set to follow constantly.
When the player hits the collision mask while animation "Hitting" is playing, the ACTION string of the collision mask is set to "HURT", and sprite automatically adopts the value of ACTION. (At start of the frame I spread value through all existing sprites and collision masks of the enemy.).
Furthermore, when the enemy has ACTION = HURT the animation is changed to hurt for the duration of the hit-timer(an alterable value on the collision mask).
The problem I'm having is that if i set the animation-change to "only once when event loops" the animation changes for a split second and then goes back to the "walking" animation.
If I don't set it to only once when event loops, enemy just plays the first frame of the "hurt" animation. Unless, I'm hitting both instances of the enemy at the same time.
The animation for the enemy is supposed to be set to walking only when ACTION = MOVING. ACTION is set to MOVING when HitTimer is 0 and On Ground = TRUE.

Any idea what might be causing this? If you need an mfa let me know.

 
n/a

Benny Lindberg



Registered
  08/11/2010
Points
  54
10th December, 2010 at 19:57:10 -

An interesting sidenote is that the player doesnt have to hit them at the same time.
As long as the "hurt" animation of both enemies are active at the same time, it will play all frames for some reason.
But if only one is playing, it wont go through the full animation.

 
n/a

monkeytherat

Hero of Time Jr

Registered
  07/11/2010
Points
  1293

VIP MemberI donated an open source project
11th December, 2010 at 03:04:25 -

It would seem like this could be solved by adding something like "if enemy animation is not hurt" before whatever you have coded so that the enemy can move around and stuff, or by putting all of your enemies actions(walking, attacking, jumping etc) into a group of events and say that when your enemy gets hurt it deactivates the group of events and reactivates them when hurt finishes, but to do that all of your enemies events would have to be in their behavior, which may not work out if you have your enemies interacting with qualifiers/groups... If that doesn't work I'll try to look into it some more.

 
If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.
The rest of them will write Perl programs.

Benny Lindberg



Registered
  08/11/2010
Points
  54
11th December, 2010 at 12:24:34 -

I'm not sure I made myself clear.
The animation for hurt is being played, but only the first frame, unless both enemies are playing it at the same time, then the whole animation gets played.

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
11th December, 2010 at 14:30:23 -

It's probably your code... otherwise i wouldnt suggest you make any events whatsoever with conditions like this: animation is playing or not playing etc... ever.
Use flags or strings instead.


Edited by Don Luciano

 
Code me a sausage!

Benny Lindberg



Registered
  08/11/2010
Points
  54
11th December, 2010 at 14:54:57 -

http://www.mediafire.com/?zbvw77pkzi77hn7

This is a link to the .mfa file I'm using.


As you see, I'm only using strings to say when things are going to happen to the crab.

 
n/a

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
11th December, 2010 at 19:16:38 -

I'm looking at the code right now, and I've noticed a few thing.

You have a ton of loops, even for things that shouldn't need loops, like walking, and planting detectors to the character. Since there is only one of the character, you shouldn't need a loop to do either of those. If your detectors are lagging behind, you either need to put the code after all the movement code for your character, or put them directly into your movement code. I could be wrong, it's just that I've never done it that way.

Also, I'm thinking your issue is going to be the selection between the enemy and the detector object, I didn't see any real selection with that, and I think that might be one of your issues. For that you'll need a loop. Let me play around with it for a bit and see if I can't get it to work, then I'll let you know what I did.

Movement code is all messed up, at least for jumping and falling. On my system, he doesn't even fall to the ground at the beginning, he stops in midair.

Other than that, the sprites looked great.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
11th December, 2010 at 20:40:27 -

Yeah, I'm sorry but you've got some crazy stuff going on there, and it would take me way too long to figure out how it's even supposed to work - you shouldn't need nested fastloops for a simple platform engine (and you shouldn't be using the fastloop extension period - it's built-in to MMF2 now).

 
n/a

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
11th December, 2010 at 21:38:20 -

Alright, I took a hacksaw to most of your code and I managed to fix most of it. I'll try to explain what changes I made, and if I missed anything, please feel free to let me know.

First off, I noticed that you had a ton of problems with selection. Every enemy you have has 3 detectors along with them, 2 side, and one center. So, in order for MMF2 to recognize these individual sprites on different bodies you need to set it up so that it can make each one specific. The way I like to do this is through a creation loop. There is a new group in your code called "crabCreation" or something like that. Basically, what it does is it starts a loop, during that loop it spreads a value in the ID (I always do this in a loop, I always seem to run into issues when it isn't). Then it checks for all the crabs with a -1 in their "collisionDetector" value (I used altValue B on the crab.) If it doesn't it creates the three detectors, and (this is crucial), it sets 3 values on the crab, collisionDetector, leftDetector and rightDetector, to the fixed number of each respective item. You must do this during it's creation, because that is the one exception to MMF2 where you will allow you to get the correct selection every time. The fixed number is a must because it is always unique to each specific instance of everything, there will never be the exact same fixed number for anything every time you play your game.

Now with that set up, you should be able to get a 100% correct selection every time, provided you place the right code where you want multiple objects selected. Now, keep in mind if during a particular event, the event only checks say the collision object and only effects the collision object, you will never need to check for selection, it is only when you have 2 objects, for instance, your enemy sprite and the collision detector effected OR checked will you need to do this. Basically, I set up a loop, "enemies". During that loop it spreads the ID value again (you only need it for the sprite). Now, if you want more than two objects selected, they need to be in this loop. You also need to check the id of an enemy (to make sure you single out one) then you check the fixed value of another object you want to check to the respective alt value on your enemy. So if you want the collision detector and the enemy sprite in an event, you need to have

On Loop "enemies"
ID of enemy = "enemies" loop index
Fixed of Collision = alt value collision of enemy

Pay attention to the order of the conditions as well, ID to loop and Fixed to Alt value. If you get them backwards say Loop to ID or Alt value to Fixed, it won't do jack crap for you.

Now, I can't tell you exactly what I did to your enemy code, I just basically rearranged the code to fit this criteria, as well as got rid of a few unnecessary items, such as the Direction string and the collision true false, I basically put those into the loops as well, and it works just fine, and probably a bit less confusing if you can grasp this loop selection concept. I also changed the X/Y positions to an alt Value, because you can use floats with that (as you can see, their speed is set to 0.5 instead of 1, in the loop it made the enemies twice as fast as you had them out of the loop).

Next, I just mangled your player walking code. All I really did was got rid of the loops, and added a new object called "player variables". In there I put a few alt values that corresponds to your player code, such as walking speeds, jump/fall speeds, jump strengths. So that way, if you ever need to change the speeds of your character, just change those values and it will update. I also added some weak gravity values to your player, so he doesn't have that whole "triangle" jump thing going on. I also fixed up the collision detection as well. I added a "floor Detector" object, which is different from your bottom collision detector, in that this one tests to see if the player inside the ground, rather than just on the ground. It basically stops him from floating into the ground.

I think that's about all I've changed, if I have forgotten anything, or you're confused, please let me know, and I will try to explain them the best I can.

http://cid-ebc278b0075af4c4.office.live.com/self.aspx/.Public/Squid.mfa

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Benny Lindberg



Registered
  08/11/2010
Points
  54
12th December, 2010 at 01:55:14 -

Hiya! I really appreciate all the input, I'm gonna go through it tomorrow. Really, thanks!
The reason I use fastloop objects was that I adapted the platform engine by MacAdam to my project, and I wasn't quite able to tailor it to my needs.
I still consider myself somewhat of a MMF2 newbie, since I only recently started making games again(previously I used The Games Factory 1).
I'll see if I can make some sense of it and I'll return if I still have problems!

 
n/a

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
12th December, 2010 at 03:23:21 -

Who is Macadam and why is he trying to confuse newcomers?

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Benny Lindberg



Registered
  08/11/2010
Points
  54
12th December, 2010 at 11:29:53 -

I had some look at the changes, and while the A.I handling seems much better I'm a bit confused about the movement. As it is, the default jumpspeed and fallspeed and whatnot are at 1, and whenever I change it above 1 the character falls through the floor all the time. Did you get this problem too?


EDIT: This is the engine I modified http://www.create-games.com/download.asp?id=7260

Edited by Benny Lindberg

 
n/a
   

Post Reply



 



Advertisement

Worth A Click