Compare commits
3 commits
ed854ba96b
...
2dd7404263
| Author | SHA1 | Date | |
|---|---|---|---|
| 2dd7404263 | |||
| 6a3b5cb089 | |||
| 1c1be19cfa |
2 changed files with 32 additions and 8 deletions
|
|
@ -17,8 +17,8 @@ config/icon="res://icon.svg"
|
|||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=480
|
||||
window/size/viewport_height=320
|
||||
window/size/viewport_width=320
|
||||
window/size/viewport_height=240
|
||||
window/stretch/mode="viewport"
|
||||
window/stretch/scale_mode="integer"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,42 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
const MAX_SPEED: float = 200
|
||||
const MAX_SPEED: float = 150
|
||||
|
||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
var was_moving: bool = false
|
||||
var anim_dir: String = 'down'
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
sprite.play('down')
|
||||
sprite.frame = 1
|
||||
sprite.pause()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _physics_process(_delta: float) -> void:
|
||||
var movement_vector: Vector2 = get_movement_vector()
|
||||
var direction: Vector2 = movement_vector.normalized()
|
||||
velocity = direction * MAX_SPEED
|
||||
|
||||
|
||||
move_and_slide()
|
||||
|
||||
var is_moving: bool = velocity.length() > 10
|
||||
|
||||
if is_moving:
|
||||
if abs(velocity.x) > abs(velocity.y):
|
||||
anim_dir = 'right' if velocity.x > 0 else 'left'
|
||||
else:
|
||||
anim_dir = 'down' if velocity.y > 0 else 'up'
|
||||
|
||||
sprite.play(anim_dir)
|
||||
else:
|
||||
if was_moving:
|
||||
sprite.play('down')
|
||||
sprite.frame = 1
|
||||
sprite.pause()
|
||||
|
||||
was_moving = is_moving
|
||||
|
||||
func get_movement_vector() -> Vector2:
|
||||
var x_mov: float = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
|
||||
var y_mov: float = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
|
||||
var x_mov: float = Input.get_action_strength('move_right') - Input.get_action_strength('move_left')
|
||||
var y_mov: float = Input.get_action_strength('move_down') - Input.get_action_strength('move_up')
|
||||
return Vector2(x_mov, y_mov)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue