pumpkin carving
This commit is contained in:
@@ -9,13 +9,10 @@ enum Events { NONE, PUMPKIN_CARVE, OUTSIDE_NORMAL }
|
||||
var current_event: Events = Events.NONE
|
||||
|
||||
func transition_start() -> void:
|
||||
player_free = false
|
||||
animation_player.play("transition")
|
||||
|
||||
func transition_end() -> void:
|
||||
animation_player.play_backwards("transition")
|
||||
await animation_player.animation_finished
|
||||
player_free = true
|
||||
|
||||
func run_event(event: Events, player_postion: Vector2 = Vector2.ZERO):
|
||||
current_event = event
|
||||
@@ -24,9 +21,9 @@ func run_event(event: Events, player_postion: Vector2 = Vector2.ZERO):
|
||||
player.position = player_postion
|
||||
match event:
|
||||
Events.PUMPKIN_CARVE:
|
||||
player_free = false
|
||||
get_tree().change_scene_to_file("uid://ccfdsdgaon63m") # scenes/levels/home.tscn
|
||||
await get_tree().scene_changed
|
||||
player.animated_sprite.animation = "sit" # should be replaced with chair interaction trigger
|
||||
|
||||
transition_end()
|
||||
|
||||
func transition_scene_file(scene: String) -> void:
|
||||
|
||||
@@ -16,12 +16,6 @@ func _notification(what: int) -> void:
|
||||
if what == Window.NOTIFICATION_APPLICATION_FOCUS_OUT:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouse:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
elif !event.is_action("escape"):
|
||||
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
||||
|
||||
func toggle_fullscreen() -> void:
|
||||
if config.fullscreen:
|
||||
if OS.get_name() == "Windows":
|
||||
|
||||
@@ -44,7 +44,7 @@ func _on_interacted(p_player: Player) -> void:
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if player:
|
||||
if !Engine.is_editor_hint() && EventManager.player_free && player:
|
||||
move_input = Input.get_vector("move_left","move_right","move_up","move_down")
|
||||
if move_input.length() == 0:
|
||||
input_released = true
|
||||
|
||||
74
scripts/menus/pumpkin_carve.gd
Normal file
74
scripts/menus/pumpkin_carve.gd
Normal file
@@ -0,0 +1,74 @@
|
||||
extends Control
|
||||
|
||||
var image: Image
|
||||
var dtexture: TextureRect
|
||||
var bgtexture: TextureRect
|
||||
|
||||
var drawing: bool = false
|
||||
var erasing: bool = false
|
||||
var undo_stack: Array[Image] = []
|
||||
var bgimage: Image
|
||||
|
||||
func _ready() -> void:
|
||||
image = Image.create_empty(32, 32, false, Image.FORMAT_RGBA8)
|
||||
dtexture = $DrawTexture
|
||||
bgtexture = $Background
|
||||
bgimage = bgtexture.texture.get_image()
|
||||
update_texture()
|
||||
|
||||
func update_texture() -> void:
|
||||
var texture: ImageTexture = ImageTexture.create_from_image(image)
|
||||
dtexture.texture = texture
|
||||
|
||||
func push_undo_state() -> void:
|
||||
var copy: Image = image.duplicate()
|
||||
undo_stack.append(copy)
|
||||
if undo_stack.size() > 20:
|
||||
undo_stack.pop_front()
|
||||
|
||||
func pixel(pposition: Vector2i, color: Color) -> void:
|
||||
if pposition.x >= 0 and pposition.x < image.get_width() and pposition.y >= 0 and pposition.y < image.get_height():
|
||||
var bgcol: Color = bgimage.get_pixel(pposition.x, pposition.y)
|
||||
if bgcol.a > 0.01:
|
||||
image.set_pixel(pposition.x, pposition.y, color)
|
||||
|
||||
func draw_at_mouse() -> void:
|
||||
var lpos: Vector2 = dtexture.get_local_mouse_position()
|
||||
var tex_size: Vector2 = Vector2(image.get_width(), image.get_height())
|
||||
var dscale: Vector2 = dtexture.get_size() / tex_size
|
||||
var pixel_pos: Vector2i = (lpos / dscale).floor()
|
||||
var color: Color = Color.BLACK if not erasing else Color(0, 0, 0, 0)
|
||||
pixel(pixel_pos, color)
|
||||
update_texture()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and event.pressed and not event.is_echo():
|
||||
if event.keycode == KEY_Z and Input.is_key_pressed(KEY_CTRL):
|
||||
undo()
|
||||
return
|
||||
|
||||
if event is InputEventMouseButton and not event.is_echo():
|
||||
if event.button_index == MOUSE_BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
push_undo_state()
|
||||
drawing = true
|
||||
erasing = false
|
||||
draw_at_mouse()
|
||||
else:
|
||||
drawing = false
|
||||
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
if event.pressed:
|
||||
push_undo_state()
|
||||
erasing = true
|
||||
drawing = true
|
||||
draw_at_mouse()
|
||||
else:
|
||||
erasing = false
|
||||
drawing = false
|
||||
elif event is InputEventMouseMotion and drawing:
|
||||
draw_at_mouse()
|
||||
|
||||
func undo() -> void:
|
||||
if undo_stack.size() > 0:
|
||||
image = undo_stack.pop_back()
|
||||
update_texture()
|
||||
1
scripts/menus/pumpkin_carve.gd.uid
Normal file
1
scripts/menus/pumpkin_carve.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b5c8ov4lhocb8
|
||||
@@ -35,12 +35,12 @@ func _ready() -> void:
|
||||
)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("interact") && raycast.is_colliding() && raycast.get_collider() is Interactable:
|
||||
if EventManager.player_free && !EventManager.animation_player.is_playing() && Input.is_action_just_pressed("interact") && raycast.is_colliding() && raycast.get_collider() is Interactable:
|
||||
var interactable: Interactable = raycast.get_collider()
|
||||
interactable.interact(self)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if !STILL_POSITIONS.has(animated_sprite.animation) && EventManager.player_free:
|
||||
if !STILL_POSITIONS.has(animated_sprite.animation) && EventManager.player_free && !EventManager.animation_player.is_playing():
|
||||
var input := Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized()
|
||||
|
||||
var raycast_input := Vector2.ZERO
|
||||
@@ -68,3 +68,9 @@ func _physics_process(delta: float) -> void:
|
||||
animated_sprite.animation = "down"
|
||||
else:
|
||||
animated_sprite.stop()
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouse:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
elif !event.is_action("escape"):
|
||||
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
||||
|
||||
Reference in New Issue
Block a user