Weapon check/destroy weapon 4.5.9 (SOLVED)

Mulligan

Member
It’s mentioned in the tutorials but it’s never discussed how to do it.

I need to write a weapon check that Will destroy my weapon if I’m not in attack mode. Or at least make it where my character can’t move while in attack mode.

Basically I don’t want to leave my sword behind when I move.
 
Last edited:

tbizzle

Well-known member
You could always make the actual weapon/game object have no animation, just a hit box. And then just make a sword animation that is attached to your actual player object, if you don't mind using one of the same three colors as your player/object. That way the sword animation will always be attached to your player/object and never be able to lag.
 

Mulligan

Member
Thanks again tbizzle your solution helped me solve a couple other problems.

I also found this for a solution.
 

Dietz33

Member
You could always make the actual weapon/game object have no animation, just a hit box. And then just make a sword animation that is attached to your actual player object, if you don't mind using one of the same three colors as your player/object. That way the sword animation will always be attached to your player/object and never be able to lag.
hi i tried this it worked well for the "despawn" of the weapon but now when i turn i aam running big circles and cant draw my collider box correctly because i had to make a 3 by 3 player object because the animation is bigger with the sword and i cant center it now.
 

Dietz33

Member
now i have the problem that the game slows down quickly because i have too many sprites i think .. damnit ! ^^
 

Dietz33

Member
You need to put a limit on it. Limit it to like 1-3 at a time. Check this tutorial out.
thx ! good to know but thats not enough because my player is a 3x3 so 9 tiles by itself .. . my melee weapon is part of the player animations . one for attack up, down, left and right.. When i do 2x2, i cant center the animation anymore and the player movment is messed up when he turns in different directions. /shrug
 

baardbi

Well-known member
thx ! good to know but thats not enough because my player is a 3x3 so 9 tiles by itself .. . my melee weapon is part of the player animations . one for attack up, down, left and right.. When i do 2x2, i cant center the animation anymore and the player movment is messed up when he turns in different directions. /shrug
It's a little hard to say exactly what's going on. But first of all, are you using the Adventure module? And how is the movement messed up?
 

dale_coop

Moderator
Staff member
the slowdown is mainly caused by the fact that there are too many objects on screens (each projectile is an object).
NESmaker's engine is not optimized. By default, as soon as you have more than 4 objects on screen (including the player object), you start having slowdowns.
(with several optimizations, like hard coded custom sprite draw coding, etc... you can have 5 or 6 objects)
 

Dietz33

Member
It's a little hard to say exactly what's going on. But first of all, are you using the Adventure module? And how is the movement messed up?
yes it's andventure module, so yeah when i use 2x1 for player i cant have the sword in the animation, if i do 2x2 the player isn't centered and changes position everytime he turns arround so i had to do 3x3, but now i have a lot of sprites on the screen.
I dont like the create object version for the weapon because i have this delay and it doesnt destroy quickly enough , so my weapon stick to the screen when i turn arround too fast.
 

Dietz33

Member
You could optimize that by not drawing the empty tile:
i read about this yesterday - will try. @CutterCross said it cost more CPU Power - anyways , maybe it's not that bad :)
 

baardbi

Well-known member
yes it's andventure module, so yeah when i use 2x1 for player i cant have the sword in the animation, if i do 2x2 the player isn't centered and changes position everytime he turns arround so i had to do 3x3, but now i have a lot of sprites on the screen.
I dont like the create object version for the weapon because i have this delay and it doesnt destroy quickly enough , so my weapon stick to the screen when i turn arround too fast.
I have some improved input scripts for the adventure module that won't let you move until the sword is gone. This is based on the create object stuff from the tutorial. So it's not a big modification. I'll see if I can find the scripts and post them here.
 

dale_coop

Moderator
Staff member
yes it's andventure module, so yeah when i use 2x1 for player i cant have the sword in the animation, if i do 2x2 the player isn't centered and changes position everytime he turns arround so i had to do 3x3, but now i have a lot of sprites on the screen.
I dont like the create object version for the weapon because i have this delay and it doesnt destroy quickly enough , so my weapon stick to the screen when i turn arround too fast.
For that, just prevent the Left/Right/upDown/Stop... movement scripts when the player is in his attack state, adding :
Code:
    CMP #$02
    BNE +notAttacking
        RTS
    +notAttacking

For example your moveRight input script should look like:
Code:
    TXA
    STA temp ;; assumes the object we want to move is in x.
    GetActionStep temp
    CMP #$07
    BNE +notHurt
        RTS
    +notHurt
    CMP #$02
    BNE +notAttacking
        RTS
    +notAttacking
        StartMoving temp, #RIGHT
        TXA
        STA temp ;; assumes the object we want to move is in x.
        ChangeFacingDirection temp, #FACE_RIGHT
        
    RTS
And do the same with all the other input scripts (that already do a CMP #07).
 

baardbi

Well-known member
Here are my improved scripts if you want to try it out. You need to remove the changeActionToMoving.asm input script. Then set up the inputs like this:

inputs.PNG

moveDown.asm
;;;;

;If there is a weapon object on-screen we can't move
CountObjects #%00000100
BEQ +
RTS
+

STX temp ;; assumes the object we want to move is in x.
GetActionStep temp
CMP #$02 ;Attack
BNE +notAttacking
RTS
+notAttacking
CMP #$07 ;Hurt
BNE +notHurt
RTS
+notHurt
CMP #$01 ;Moving
BEQ +movePlayer
ChangeActionStep temp, #$01 ;Walking

+movePlayer
StartMoving temp, #DOWN
TXA
STA temp ;; assumes the object we want to move is in x.
ChangeFacingDirection temp, #FACE_DOWN

RTS

moveLeft.asm
;;;;

;If there is a weapon object on-screen we can't move
CountObjects #%00000100
BEQ +
RTS
+

STX temp ;; assumes the object we want to move is in x.
GetActionStep temp
CMP #$02 ;Attack
BNE +notAttacking
RTS
+notAttacking
CMP #$07 ;Hurt
BNE +notHurt
RTS
+notHurt
CMP #$01 ;Moving
BEQ +movePlayer
ChangeActionStep temp, #$01 ;Walking

+movePlayer
StartMoving temp, #LEFT
TXA
STA temp ;; assumes the object we want to move is in x.
ChangeFacingDirection temp, #FACE_LEFT

RTS

moveRight.asm
;;;;

;If there is a weapon object on-screen we can't move
CountObjects #%00000100
BEQ +
RTS
+

STX temp ;; assumes the object we want to move is in x.
GetActionStep temp
CMP #$02 ;Attack
BNE +notAttacking
RTS
+notAttacking
CMP #$07 ;Hurt
BNE +notHurt
RTS
+notHurt
CMP #$01 ;Moving
BEQ +movePlayer
ChangeActionStep temp, #$01 ;Walking

+movePlayer
StartMoving temp, #RIGHT
TXA
STA temp ;; assumes the object we want to move is in x.
ChangeFacingDirection temp, #FACE_RIGHT

RTS

moveUp.asm
;;;;

;If there is a weapon object on-screen we can't move
CountObjects #%00000100
BEQ +
RTS
+

STX temp ;; assumes the object we want to move is in x.
GetActionStep temp
CMP #$02 ;Attack
BNE +notAttacking
RTS
+notAttacking
CMP #$07 ;Hurt
BNE +notHurt
RTS
+notHurt
CMP #$01 ;Moving
BEQ +movePlayer
ChangeActionStep temp, #$01 ;Walking

+movePlayer
StartMoving temp, #UP
TXA
STA temp ;; assumes the object we want to move is in x.
ChangeFacingDirection temp, #FACE_UP

RTS

changeActionToStop.asm
STX temp ;; assumes the object we want to move is in x.
;;; It is possible that we are pressing multiple directions, and let go of one of them.
;;; If this happens, we would have our behavior change to stop, even though we'd continue to move.
;;; What we need to do is checkt o see if the relevant dpad buttons are pressed. If any buttons
;;; are pressed that would counter the change to a stop action upon release, we need to skip the
;;; change to stop action.
GetActionStep temp
CMP #$02 ;Attack
BNE +notAttacking
JMP +stopPlayerMovement
+notAttacking
CMP #$07 ;Hurt
BNE +notHurt
RTS
+notHurt
LDA controllerNumber_hold
BNE weAreCheckingCOntroller2
;; we are checking controller 1.
LDA gamepad
AND #%11110000
BEQ changeToStop_NoDpadPressed
RTS
weAreCheckingCOntroller2:
LDA gamepad2
AND #%11110000
BEQ changeToStop_NoDpadPressed
RTS
changeToStop_NoDpadPressed:
ChangeActionStep temp, #$00 ;; assumes that "walk" is in action 1
;arg0 = what object?
;arg1 = what behavior?
+stopPlayerMovement:
StopMoving temp, #$FF

RTS
 

Dietz33

Member
Here are my improved scripts if you want to try it out. You need to remove the changeActionToMoving.asm input script. Then set up the inputs like this:

View attachment 7716

moveDown.asm


moveLeft.asm


moveRight.asm


moveUp.asm


changeActionToStop.asm
your scripts work extremly well - i like them very much ! one issue though (has nothing to do with your scrpts) when i attack and get hurt it recoils me off while my sword is stuck on the screen before it destroys itself .. is there a way to prevent it from creating when i getting hurt ?
maybe i can destroyobject when get hurt ?
 
Last edited:

baardbi

Well-known member
your scripts work extremly well - i like them very much ! one issue though (has nothing to do with your scrpts) when i attack and get hurt it recoils me off while my sword is stuck on the screen before it destroys itself .. is there a way to prevent it from creating when i getting hurt ?
maybe i can destroyobject when get hurt ?
Yes. I know what you're talking about. I have a script for this as well. Let me see if I can find it. I'll get back to you.
 
Top Bottom