Week 4
10: NPC health floating on them
NPC health variable and textfield
- Editing NPC script
- When level starts
- Set number health to 50
- Create new textfield with text “create text with” “number health” “ HP”
- Set font colour red
- Set font size 26

NPC health text floating
- Constantly…
- Set x position of instance textfield to x position of myself
- Set y position of instance textfield to y position of myself
- Playtest

NPC health decrease when attacked
- In When animation hitDown has looped:
- Set health to health - 20
- Set text of textfield to “create text with” “number health” “ HP”
- Playtest

NPC death
- If health <= 0
- Destroy instance textfield
- Destroy myself
- Playtest

11: Health potion
Health potion item
- Place a health potion in the Items layer (make new layer for it)
- Add script
- When level starts, set movable to false (explain difference to immovable)
- When touched get toucher
- If toucher has tag player
- Broadcast “health potion”
- Destroy myself
- playtest

Player receives health from potion
- Edit player script
- When I receive “health potion”
- Set health to health + 10
- Duplicate “set text…” blocks to update textfield
- playtest

12: A friendly NPC
Add a new friendly NPC
- Place friendly NPC on npc layer
- Add script to friendly NPC
- When level starts
- Set immovable to true
- When I am touched get toucher
- If toucher has tag player
- Broadcast “display chat” with “Can you save us? Kill all 5 orcs please!”
- Playtest

13: Chat box for dialog
Add a chat box
- Create a new layer for Interface (menus, windows, buttons, etc that will appear on top of everything else)
- Add chat box object outside of level
- Add script to chat box object
- When level starts, set physics enabled false, set visibility false
- When I receive “display chat” with a value, set visibility true
- Playtest

Make chat box aligned to camera
- Constantly set x position to camera x, set y position to camera y

Displaying text in chat box
- When level starts… Create new textfield with text “This is the chatbox”
- Set visibility of textfield to false

- When I receive "display chat" set visibility of textfield to true

- Constantly… set x and y position of textfield to camera x and y

Positioning box and text at the bottom of the camera
- Position to camera x and y as before, + these numbers

Using text from message value
- When I receive… set text of textfield to
- true/false value, change it to text

14: Improving the chat box
Making text nicer: When level starts...
- set font size 24, set font colour yellow
- set max width 900 (so it will have multiple lines if necessary)

Dismissing chat box with spacebar
- When spacebar pressed
- Set visibility false
- Set visibility textfield false

Freezing and unfreezing the player
- When I receive… broadcast “freeze”

- When spacebar pressed… broadcast "unfreeze"

- Then on the player script:
- When I receive “freeze”, set moves false
- When I receive “unfreeze”, set moves true

⚡ Bonus Activities ⚡
Bonus 4.1: Fancy Textfields
Bonus 4.1: More uses for chat boxes
Bonus 4.3: Friendly NPCs that wander around