JFranco
New member
Note: This presumes you were following and completed the Adventure Game Basics tutorial videos #1 to 7
IN 4 STEPS:
1. Create HUD elements
create a HUD element.
Type: string
Text: 'Health:'
create another HUD element
Type: number
Element Var: playerHealth
Max Value: 1
2. Create user variable called 'playerHealth'
go to Project Settings -> User Variables
create a new Variable. Name it 'playerHealth'. Give it an initial value of whatever you'd like player health to be (don't go higher than 9)
3. Create a 'Hurt' action state for your player
Go to Game Objects -> Player
Click on 'Object Details'
Go to Animations tab. Create a new Animation Type called 'Hurt'
Go to Actions tab. Set Action Step 7 to Animation Type 'Hurt'. Set Timer to 3. Set End Action to 'Go to First'.
4. Assign this script to your Common/Handle Player Hurt routine (via Project Settings -> Script Settings):
------------------------------------------------
KNOWN ISSUES:
-if a monster walks into a player his health decreases by one, but if a player walks into a monster his health decreases by two.
IN 4 STEPS:
1. Create HUD elements
create a HUD element.
Type: string
Text: 'Health:'
create another HUD element
Type: number
Element Var: playerHealth
Max Value: 1
2. Create user variable called 'playerHealth'
go to Project Settings -> User Variables
create a new Variable. Name it 'playerHealth'. Give it an initial value of whatever you'd like player health to be (don't go higher than 9)
3. Create a 'Hurt' action state for your player
Go to Game Objects -> Player
Click on 'Object Details'
Go to Animations tab. Create a new Animation Type called 'Hurt'
Go to Actions tab. Set Action Step 7 to Animation Type 'Hurt'. Set Timer to 3. Set End Action to 'Go to First'.
4. Assign this script to your Common/Handle Player Hurt routine (via Project Settings -> Script Settings):
Code:
;;;;;;;;;;;;;;;;;; Presumes there is a variable called myLives defined in user variables.
;;;;;;;;;;;;;;;;;; You could also create your own variable for this.
LDA gameHandler
AND #%10000000
BEQ +canHurtPlayer
JMP +skipHurt
+canHurtPlayer:
;;;;;;;;;;;;;;;;;;;;;
;;;; Player takes health damage - custom code
;;;;;;;;;;;;;;;;;;;;;
LDX player1_object ; load player1 object into x
TXA ; transfer x to accumulator
STA temp ; store accumulator value into 'temp' variable
GetActionStep temp ; run GetActionStep macro, 'temp' contains player1 object (aka "what is player 1's current Action state?")
CMP #$07 ; are we in ActionState #7 (aka: 'Hurt' mode). My hurt ActionState might be different than yours. adjust accordingly.
BEQ +skipHurt ; yes? then exit this script
ChangeActionStep temp, #$07 ; no? then change action state to 'hurt'
LDA #$80 ; I'm not sure why this is important -- i think it's the amount of time to stay hurt?
STA Object_action_timer,x ; stay hurt for this amount of time
DEC playerHealth ;decrease player health by one
UpdateHudElement #$07 ;update HUD -- myHealth is assigned to HUD element 7 in my game. it may be different in yours. adjust accordingly
LDA playerHealth ;load player health into accumulator
BEQ +loseLife ;if player health equals zero, lose a life
JMP +skipHurt ;else, exit this script
+loseLife:
;;;;;;;;;;;;;;;;;;;;;
;;;;; End of custom code
;;;;;;;;;;;;;;;;;;;;;
Dec myLives
LDA myLives
BNE myLivesNotZero
JMP RESET ;; game over.
;;;; also could warp to game over screen here instead.
myLivesNotZero:
;;;;;;;;;;;;;;;;;;;;;;;;;
;;; When Player begins new life, refresh health back to 9 - custom code
;;;;;;;;;;;;;;;;;;;;;;;;;
LDA #$09 ;load '9' into accumulator
STA playerHealth ;update playerHealth to 9
UpdateHudElement #$07 ;update HUD -- myHealth is assigned to HUD element 7 in my game. it may be different in yours. adjust accordingly
;;;;;;;;;;;;;;;;;;;;;;;;;
;;; End of custom code
;;;;;;;;;;;;;;;;;;;;;;;;;
LDA continueMap
STA warpMap
LDA continueScreen
STA currentNametable
LDX player1_object
STA Object_screen,x
LDA #$02 ;; this is continue type warp.
STA screenTransitionType ;; is of warp type
LDA gameHandler
ORA #%10000000
STA gameHandler ;; this will set the next game loop to update the screen.
+skipHurt
KNOWN ISSUES:
-if a monster walks into a player his health decreases by one, but if a player walks into a monster his health decreases by two.