Jonny
Well-known member
I wanted to replicate the grab hook and hang mechanic as used by those two famous ducks. The purple one and the rich one. Say no more.
It's not exactly the same yet but its fairly close. The only part I need to work on (apart from the grab animation for my player) is the dropping. If down is just tapped and not held, the player will try to fall then the tile script, for want of a better term, 'takes over' and snaps him back to the hook. I've tried a few things to no avail so for now this is as good as my grab tile is going to get...
Tile Code:
This is fairly simple but there's a few bits you might want to change to suit your hook grabbing needs. The Y and X offset are unlikely to be the same for your player object, especially if its a different size. Also, my action step for player 'hanging' is #$06 and you might want to use a different one. I should also mention that my action #$06 has ignore gravity ON.
The only other parts are small changes to 2 other input scripts and you can also make a 'drop down' input for down press if you don't want to have to jump off to get down.
For MoveLeft / MoveRight i added another check almost identical to the check for player hurt (directly under the player hurt check for #$07 ...
The 'drop down' script for press down when on hook is just a simple action change to a state with ignore gravity off...
The last and maybe most crutial part is that the grabtile needs to be the tile UNDER the actual hook graphic.
That's it. Enjoy.
EDIT: Code updated as per AllDarnDavey suggestion. Please read his comments regarding inputs also if you want your player to change facing while hanging.
It's not exactly the same yet but its fairly close. The only part I need to work on (apart from the grab animation for my player) is the dropping. If down is just tapped and not held, the player will try to fall then the tile script, for want of a better term, 'takes over' and snaps him back to the hook. I've tried a few things to no avail so for now this is as good as my grab tile is going to get...
Tile Code:
Code:
;;; CHECK IS PLAYER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CPX player1_object
BEQ isThePlayer
JMP dontGrab
;;; CHECK GAMEPAD FOR L OR R PRESS ;;;;;;;;;;;;;;;;;;;;;;;;;
isThePlayer:
LDA gamepad
CMP #%00100000 ;; DOWN, LEFT, OR RIGHT ;;
BCS dontGrab
;;; DONT GRAB WHILE JUMPING UP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA Object_v_speed_hi,x ;; VERT SPEED CHECK ;;
BMI dontGrab
;;; SNAP TO CORRECT PLAYER PLACEMENT ;;;;;;;;;;;;;;;;;;;;;;;
LDA tileX
AND #%11110000
SBC #$00
STA Object_x_hi,x
STA xHold_hi
LDA tileY
AND #%11110000
SBC #$0F
STA Object_y_lo,y
STA yHold_hi
;;; CHANGE ACTION TO GRABBING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ChangeActionStep player1_object, #$06
dontGrab:
This is fairly simple but there's a few bits you might want to change to suit your hook grabbing needs. The Y and X offset are unlikely to be the same for your player object, especially if its a different size. Also, my action step for player 'hanging' is #$06 and you might want to use a different one. I should also mention that my action #$06 has ignore gravity ON.
The only other parts are small changes to 2 other input scripts and you can also make a 'drop down' input for down press if you don't want to have to jump off to get down.
For MoveLeft / MoveRight i added another check almost identical to the check for player hurt (directly under the player hurt check for #$07 ...
Code:
CMP #$06 ;; DUDE, I'M HANGING HERE ;;
BNE +notHurt
RTS
The 'drop down' script for press down when on hook is just a simple action change to a state with ignore gravity off...
Code:
;;; DROP FROM HOOK ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TXA
STA temp
ChangeActionStep temp, #$00 ;; CHANGE TO IDLE ;;
RTS
The last and maybe most crutial part is that the grabtile needs to be the tile UNDER the actual hook graphic.
That's it. Enjoy.
EDIT: Code updated as per AllDarnDavey suggestion. Please read his comments regarding inputs also if you want your player to change facing while hanging.
Last edited: