ID:155726
 
I searched for this but couldn't find exactly what I wanted so bluh.

I'm trying to create an effect where, you slash your weapon and it appears in front of you, basically like in the old school Zelda games.

I've toyed with a few methods but they had some problems:

Creating a new obj and placing it in front of the player works, but if you were say moving and then slashed, the sword obj would appear and you would move up to it, disjointedly which... bleh.

I also considered making it an overlay but I couldn't think of an efficient way to set the overlay's pixel offset without having to check the player's dir and set it based on that.

Any suggestions?
If your hearts are full (you are at full life) you should have the "shooting sword" that can kill your enemys with a range attack. Otherwise you have to find hearts to fill your life bar back up.
LordAndrew wrote:
I also considered making it an overlay but I couldn't think of an efficient way to set the overlay's pixel offset without having to check the player's dir and set it based on that.

How is that not efficient? That's probably how I'd do it.

You could make the overlay 96x96 (assuming your mobs are 32x32 and make the overlay centered on the mob. That way you can use the same pixel offset all the time and just draw the sword in the correct part of the big icon.
In response to Forum_account
Forum_account wrote:
LordAndrew wrote:
I also considered making it an overlay but I couldn't think of an efficient way to set the overlay's pixel offset without having to check the player's dir and set it based on that.

How is that not efficient? That's probably how I'd do it.

You could make the overlay 96x96 (assuming your mobs are 32x32 and make the overlay centered on the mob. That way you can use the same pixel offset all the time and just draw the sword in the correct part of the big icon.

<small>It probably is efficient but I am an overcritical obsessive-compulsive and must make all of my programming efficient and perfect. :(</small>

I didn't think about the overlay thing which sounds like it could work, though I'm not a fan of messing with larger sized things since the icon editor lacks zooming.

Also in my original post I forgot to mention slashing at different angles which... I have no idea how I would handle with overlays. Ish. Hrm.

Looking at the overlay thing I threw this together but... I dunno. It doesn't take into account diagonals blah.

    verb
Stab_Forward()
var
obj/O = new

O.icon_state = "sword"
O.dir = dir

world << O.dir

switch(O.dir)
if(NORTH, SOUTH)
O.pixel_y = O.dir & NORTH ? 32 : -32

if(EAST, WEST)
O.pixel_x = O.dir & EAST ? 32 : -32

overlays.Add(O)

lock = TRUE

world << "SLASHING"

spawn(4)
overlays.Remove(O)

lock = FALSE

world << "SLASHING DONE"
In response to LordAndrew
LordAndrew wrote:
the icon editor lacks zooming.


Oh, the joys of using Paint program and copy/paste :)
I went with Forum_account's suggestion of using a large icon overlaid on top of the player's icon. A simple single state stabbing icon works, but a three state slashing icon... does not work very well. The animation is wonky in how it plays.

orginial coed do not sateal

I... I have no idea how to work around that.