From 1d72cd7b53ff14f7396f5aaeb424003355707ce8 Mon Sep 17 00:00:00 2001 From: Dragos Stefan Cirstian Date: Fri, 5 Jul 2024 11:53:32 +0300 Subject: [PATCH] Add Miscari caracter --- Miscari caracter | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Miscari caracter diff --git a/Miscari caracter b/Miscari caracter new file mode 100644 index 0000000..70a11cc --- /dev/null +++ b/Miscari caracter @@ -0,0 +1,40 @@ +Ziua 1: +Realizarea miscarii nodului: // circular + +var speed = 400 # pixel per second +var angular_speed = PI # radian per second + +func _process(delta): + rotation += angular_speed * delta + var velocity = Vector2.UP.rotated(rotation) * speed + position += velocity * delta +As we already saw, the var keyword defines a new variable. If you put it at the top of the script, it defines a property of the class. Inside a function, it defines a local variable: it only exists within the function’s scope. + +We define a local variable named velocity, a 2D vector representing both a direction and a speed. To make the node move forward, we start from the Vector2 class’s constant Vector2.UP, a vector pointing up, and rotate it by calling the Vector2 method rotated(). This expression, Vector2.UP.rotated(rotation), is a vector pointing forward relative to our icon. Multiplied by our speed property, it gives us a velocity we can use to move the node forward. + +We add velocity * delta to the node’s position to move it. The position itself is of type Vector2, a built-in type in Godot representing a 2D vector. + + +Ziua 2: +Cum procesam datele oferite de la tastatura // continuare joc zi anterioara: +var speed = 400 +var angular_speed = PI + +func _process(delta): + var direction = 0 + if Input.is_action_pressed("ui_left"): + direction = -1 + if Input.is_action_pressed("ui_right"): + direction = 1 + + rotation += angular_speed * direction * delta + + var velocity = Vector2.ZERO + if Input.is_action_pressed("ui_up"): + velocity = Vector2.UP.rotated(rotation) * speed + + if Input.is_action_pressed("ui_down"): + velocity = Vector2.DOWN.rotated(rotation) * speed + + position += velocity * delta +