Add basic movement code
This commit is contained in:
parent
77d9e833d2
commit
5f70906f71
|
@ -0,0 +1,21 @@
|
|||
extends KinematicBody2D
|
||||
|
||||
const MAX_SPEED = 100
|
||||
|
||||
var velocity = Vector2.ZERO
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
print("Hello world")
|
||||
|
||||
func _physics_process(delta):
|
||||
var input_vector = Vector2.ZERO
|
||||
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
|
||||
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
|
||||
|
||||
if input_vector != Vector2.ZERO:
|
||||
velocity = input_vector
|
||||
else:
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
move_and_collide(velocity * delta * MAX_SPEED)
|
|
@ -0,0 +1,22 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://World/Bush.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Player/Player.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Player/Player.gd" type="Script" id=3]
|
||||
|
||||
[node name="World" type="Node2D"]
|
||||
|
||||
[node name="Bush" type="Sprite" parent="."]
|
||||
position = Vector2( 63, 65 )
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Player" type="KinematicBody2D" parent="."]
|
||||
position = Vector2( 101, 35 )
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_group_": true
|
||||
}
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Player"]
|
||||
texture = ExtResource( 2 )
|
||||
hframes = 60
|
|
@ -1,5 +1,7 @@
|
|||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
|
|
|
@ -21,8 +21,17 @@ _global_script_class_icons={
|
|||
[application]
|
||||
|
||||
config/name="Action RPG"
|
||||
run/main_scene="res://World.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/width=320
|
||||
window/size/height=180
|
||||
window/size/test_width=1280
|
||||
window/size/test_height=720
|
||||
window/stretch/mode="2d"
|
||||
|
||||
[importer_defaults]
|
||||
|
||||
texture={
|
||||
|
|
Loading…
Reference in New Issue