feat: choose outfit from library when creating a dragon
This commit is contained in:
parent
fd8609c0ab
commit
f07b28d2dc
22 changed files with 370 additions and 17 deletions
|
@ -10,9 +10,9 @@ func _init(dragon: PackedScene, viewport: Viewport, window: Window) -> void:
|
|||
_dragon_template = dragon
|
||||
|
||||
|
||||
func instantiate(position: Vector2) -> Node:
|
||||
func instantiate(position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Texture2D) -> Node:
|
||||
var relative_position: Vector2i = _calculate_relative_position(position)
|
||||
return _instantiate_dragon(relative_position)
|
||||
return _instantiate_dragon(relative_position, hat, shirt, shoes)
|
||||
|
||||
|
||||
func _calculate_window_scale() -> Vector2:
|
||||
|
@ -27,13 +27,14 @@ func _calculate_relative_position(position: Vector2) -> Vector2i:
|
|||
return Vector2i(Vector2(position) * scale)
|
||||
|
||||
|
||||
func _instantiate_dragon(relative_position: Vector2i) -> Node:
|
||||
func _instantiate_dragon(relative_position: Vector2i, hat: Texture2D, shirt: Texture2D, shoes: Texture2D) -> Node:
|
||||
var dragon: Dragon = _dragon_template.instantiate()
|
||||
|
||||
var window_position: Vector2i = DisplayServer.window_get_position()
|
||||
var window_size: Vector2i = DisplayServer.window_get_size()
|
||||
|
||||
dragon.position = window_position + relative_position - dragon.size / 2
|
||||
dragon.dress(hat, shirt, shoes)
|
||||
|
||||
var size: float = _calculate_window_scale().y
|
||||
dragon.set_scale(size)
|
||||
|
|
19
src/dragon_outfit.gd
Normal file
19
src/dragon_outfit.gd
Normal file
|
@ -0,0 +1,19 @@
|
|||
extends Resource
|
||||
class_name DragonOutfit
|
||||
|
||||
|
||||
@export var outfits: Array[Texture2D]
|
||||
var index: int = 0
|
||||
|
||||
|
||||
func _init(outfits: Array[Texture2D] = []):
|
||||
self.outfits = outfits
|
||||
|
||||
|
||||
func pick_next() -> Texture2D:
|
||||
index += 1
|
||||
index %= (len(outfits) + 1)
|
||||
if index == 0:
|
||||
return null
|
||||
|
||||
return outfits[index - 1]
|
1
src/dragon_outfit.gd.uid
Normal file
1
src/dragon_outfit.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://rw26nny160xh
|
Loading…
Add table
Add a link
Reference in a new issue