/
evggal
/
math_game
Обзор
Документация
Войти
/
evggal
/
math_game
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
scripts/hero.gd
68 строк
2 KB
Michail Inyushin
added animation + some lighting changes
22 дек 2024, 13:11
22 дек 2024, 13:11
e2392ff
Код
Авторство
О чём код?
extends CharacterBody2D const SPEED = 200.0 var SPEED_temp = 200.0 var type_of_stay = 0; @onready var anim = $AnimatedSprite2D func _physics_process(delta: float) -> void: velocity = Vector2.ZERO if Input.is_action_pressed("Sprint"): SPEED_temp = SPEED + 100 else: SPEED_temp = SPEED if Input.is_action_pressed("Right"): velocity.x += SPEED_temp if Input.is_action_pressed("Left"): velocity.x -= SPEED_temp if Input.is_action_pressed("Up"): velocity.y -= SPEED_temp if Input.is_action_pressed("Down"): velocity.y += SPEED_temp velocity = velocity.normalized() * SPEED_temp if (velocity.x < 0): if (velocity.y == 0): anim.flip_h = false anim.play("walk_x") type_of_stay = 0; elif (velocity.y > 0): anim.flip_h = false anim.play("walk_xy_down") type_of_stay = 1; else: anim.flip_h = false anim.play("walk_xy_up") type_of_stay = 2; elif (velocity.x > 0): if (velocity.y == 0): anim.flip_h = true anim.play("walk_x") type_of_stay = 0; elif (velocity.y > 0): anim.flip_h = true anim.play("walk_xy_down") type_of_stay = 1; else: anim.flip_h = true anim.play("walk_xy_up") type_of_stay = 2; else : if (velocity.y > 0): anim.play("walk_y_down") type_of_stay = 3; elif (velocity.y < 0): anim.play("walk_y_up") type_of_stay = 4; else: if(type_of_stay == 0): anim.play("stay_x") if(type_of_stay == 1): anim.play("stay_xy_down") if(type_of_stay == 2): anim.play("stay_xy_up") if(type_of_stay == 3): anim.play("stay_y_down") if(type_of_stay == 4): anim.play("stay_y_up") move_and_slide()