Four Direction Attack

CodyLewis

  • Posts: 4
I couldn't find anything on Stencylforge for this, and I started a code but I'm not fluent enough yet to be able to figure my way through it, are you guys aware of any behaviors that allow for four direction attacking?

« Last Edit: May 20, 2015, 05:27:40 pm by CodyLewis »

Donni11

  • *
  • Posts: 2182
Welcome to Stencyl :) ! I'm quite surprised you didn't find any behaviors like this , in fact this behavior is already pre - installed with Stencyl .
Peace

CodyLewis

  • Posts: 4
I saw four direction movement and 8 direction movement, but I didnt see a four direction sword swipe. I guess it could easily be confused with the bullet shooting. I'm meaning a melee attack

xcmn

  • Posts: 89
A single attack in each direction or a one-hits-all spincut?

CodyLewis

  • Posts: 4
just direction dependent attack, like if  you are facing up and attack, you attack up. I have my spritesheet ready, just need to translate it to code.

CodyLewis

  • Posts: 4
Here is the spritesheet to help visualize.

xcmn

  • Posts: 89
It's best for your personal education if you figure this out on your own. And if you're new to Stencyl, this behavior isn't the optimal place to begin. However, I'll be attempting a Zelda clone soon so here's my method for a "4-direction attack" behavior.

This is an Actor Behavior.

Here's my example game: http://www.stencyl.com/game/play/30931

A good approach to making any sort of attack is to use a (usually invisible) actor. When the attack button is pressed, the actor is created in front of the player. When the enemies collide with this "attack actor", they are damaged or killed. In my example game, this actor is a simple blue colored box. Once the behavior appears to be working correctly, I turn it invisible.

If I wanted my attack actor to appear as a weapon in front of my player I would make it look like a sword or something instead of making it invisible. In your sprite, the player has an attack animation with a sword already in it, so you'll be making your "attack actor" invisible.

Your Attack Actor needs its own Collision Group. Set it up as able to collide with your Enemy Group (Actors Group), but not with your Player Group or Tile Group.

Create a "list attribute". I called it Priority list. You also need a "number attribute" to limit the amount of Attacks that can be created. I called it # Of Attacks. If you don't limit the number of Attacks that can be created, you'll spawn a large number of Attack Actors with every key press.

The code is set up so that when you press X, it adds "attack" (as text) to the Priority List. When X is released it removes "attack" (as text) from Priority List. Furthermore, when X is released, any "Actors of Type" (your Attack Actor) will be killed.

Next, in the UPDATED section of the code, you have an "if Priority List contains attack (as text)" followed by a series of "If current animation equals:" blocks. One for each of your four directions. Notice, I put in some "or" statements to include the idle versions of your animations.

So,

if Priority List contains Attack (as text),
     if # Of Attacks is less than 1

Depending on what your current animation is; either up, down, left or right, spawn an "Attack Actor" at X of Self, Y of Self, plus or minus some numbers. These numbers depend on the size of your player actor as well as the size of your "Attack Actor". The best way to figure them out is to put your player in the scene and add the "Attack Actors" on each of his four sides and then examine their positions relative to your player. Look at the numbers located near the bottom of the screen when you click on an actor to get the x and y position, or use the Inspector feature.

When the "Attack Actor" is created, it increments our number attribute, "# Of Attacks," by 1, ensuring that no more than one actor is created.

You'll also need to cover your bases in other ways so that no more than one "Attack Actor" is created at once. I put a "Created" "do after .25 seconds" "kill self" action into the events of my "Attack Actor" so that they automatically disappear if not otherwise killed off. I also like to kill them on contact with the enemy, although I didn't in the example game.

Importantly, you'll need to put something in your 4-way Movement Behavior so that when your attack key is down, your player stops moving. Otherwise, he'll continue moving past the created Attack Actor.

The final step, once your behavior is working properly is to make your Attack Actor invisible. I prefer to create my actors as a single color (a blue square) and to select that color as transparent when importing them. The other method is to use the "fade self" effect when your actors are created in-game.

« Last Edit: May 20, 2015, 09:06:55 pm by xcmn »

t4u

  • Posts: 418
To solution above: Too long to read. I dislike that oyu can still move as you are attacking.
USE PICTURES WHEN YOU ASK SOMETHING!
If I helped you be sure to mention it in your game.

Tutorials + downloads:
http://t4upl.blogspot.com/

liefdeisniets

  • Posts: 8
I need this. I want to make my 4-way attack but i'm still strugling...
http://tommyventevogel.nl/post/123649249448/vereindbazinggimma

right now it only walks... i found an "slash" actor which i could use in a similar fashion as the blue box.

"A good approach to making any sort of attack is to use a (usually invisible) actor. When the attack button is pressed, the actor is created in front of the player. When the enemies collide with this "attack actor", they are damaged or killed."
^ i get that... only i don't know how to program the actor to show up in front of my actor (yet).
[oh edit: i now see the images... makes it a bit more clear. yay, ill try this]

Isn't there a download somewhere to obtain this code right away? it seems like a much-needed piece of code. all the examples i found to download didn't work... :(

+extra info, i also want to add a "switch animation" during the attack moves... what does that code look like? things i tried messed up my game... like my hero turning mad and never end his slashing. he kinda scared me xd

stefan

  • *
  • Posts: 2263
Hey een Hollander!
Creating a 4 way move and attack ssystem is high on the list of tutorials to make. The other ones are not really interesting ones so i might give this one priority.

liefdeisniets

  • Posts: 8
-nederland is op de een of andere manier altijd overal oververtegenwoordigd ;)-

Yes would be great. I'd love to see the tutorial.

Most downloadable things are settings for a 2-day left-right game with jumps. i never need jumps, i need to be able to fight in 4-wayssss like a tru gangsta

stefan

  • *
  • Posts: 2263
If you can find some spritesheets you want to work with for me to do a tutorial with, I would highly appreciate that.

liefdeisniets

  • Posts: 8
i think zelda (a link to the past) always is the best example... i don't know if its accepted to use those sprites.

In a Stencyl tutorial i see the " The Zelda Dilemma" mentioned.
http://www.stencyl.com/help/view/animations/

It's a good example because multiple (additional) problems come in mind here:
-the actor also has to be able to be hurt (and change his animation to pain, and slide 'back' some pixels)
-has to 'pick up' his weapon (i guess a "if weapon is 'true'"-like code is needed?)

The dilemma mentioned is also about the coloured swords and stuff... thats too deep for this one.. but a 4-direction attack (plus the weak spots = all the sides where he is not swining his sword) are quite interesting.

But it might work to use this example. To be honest i googled "zelda-like" all the time when searching for behaviours, actors, codes xd

« Last Edit: July 18, 2015, 01:42:51 pm by liefdeisniets »