character is now running on screen

This commit is contained in:
Your Name
2025-07-20 18:54:24 +04:00
parent e9761aa162
commit 8881f442bb
8 changed files with 576 additions and 0 deletions

View File

@@ -12,10 +12,18 @@ func _on_any_key_pressed():
press_any_key_screen.queue_free()
show_main_menu()
func show_game():
print("Starting game scene")
clear_current_menu()
var game_scene = preload("res://scenes/Game_Scene.tscn").instantiate()
add_child(game_scene)
current_menu = game_scene
func show_main_menu():
clear_current_menu()
var main_menu = preload("res://ui/MainMenu.tscn").instantiate()
main_menu.open_settings.connect(_on_open_settings)
main_menu.open_game.connect(_on_open_game)
add_child(main_menu)
current_menu = main_menu
@@ -31,6 +39,10 @@ func clear_current_menu():
current_menu.queue_free()
current_menu = null
func _on_open_game():
print("Starting new game")
show_game()
func _on_open_settings():
print("Opening settings menu")
show_settings_menu()

View File

@@ -1,12 +1,14 @@
extends Control
signal open_settings
signal open_game
func _ready():
print("MainMenu ready")
func _on_new_game_button_pressed():
print("New Game pressed")
open_game.emit()
func _on_settings_button_pressed():
print("Settings pressed")

View File

@@ -0,0 +1,37 @@
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var last_direction = Vector2.DOWN
func get_input():
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = input_direction * SPEED
return input_direction
func _physics_process(delta: float) -> void:
print(get_input())
move_and_slide()
func _process(delta: float) -> void:
if not $AnimatedSprite2D:
return
var input_direction = get_input()
var animation_name = ""
if input_direction != Vector2.ZERO:
last_direction = input_direction
# Determine dominant direction and build animation name
if abs(input_direction.x) > abs(input_direction.y):
animation_name = "Run" + ("Right" if input_direction.x > 0 else "Left")
else:
animation_name = "Run" + ("Down" if input_direction.y > 0 else "Up")
else:
# Use last direction for idle
if abs(last_direction.x) > abs(last_direction.y):
animation_name = "Idle" + ("Right" if last_direction.x > 0 else "Left")
else:
animation_name = "Idle" + ("Down" if last_direction.y > 0 else "Up")
$AnimatedSprite2D.play(animation_name)

View File

@@ -0,0 +1 @@
uid://coqdjfhn4plph