added player into world scene

updated player script with basic movement logic
updated project keybindings so WASD can be used along with arrows
master
Zac 5 years ago
parent e561c8009b
commit 9178c777b9

@ -13,6 +13,27 @@ config_version=3
config/name="2DWalkingSim"
config/icon="res://icon.png"
[input]
ui_left=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
]
ui_right=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
]
ui_up=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
]
ui_down=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
]
interact=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
]
[layer_names]
2d_physics/layer_1="player"

@ -1,26 +1,57 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://images/test_char.png" type="Texture" id=1]
[ext_resource path="res://scripts/Player.gd" type="Script" id=1]
[ext_resource path="res://images/test_char.png" type="Texture" id=2]
[node name="Player" type="KinematicBody2D" index="0"]
[node name="Player" type="KinematicBody2D"]
input_pickable = false
collision_layer = 1
collision_mask = 14
collision/safe_margin = 0.08
_sections_unfolded = [ "Collision" ]
script = ExtResource( 1 )
Speed = 5
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." index="0"]
editor/display_folded = true
position = Vector2( 0.00320625, -0.00740051 )
scale = Vector2( 0.403093, 0.403093 )
build_mode = 0
polygon = PoolVector2Array( -26.5097, -40.0408, -36.4849, -29.9804, -36.3144, 14.9503, -16.4493, 40.016, 18.5063, 40.016, 36.4956, 14.9503, 36.4956, -4.82946, 23.4512, -39.9556 )
[node name="Sprite" type="Sprite" parent="CollisionPolygon2D" index="0"]
texture = ExtResource( 1 )
texture = ExtResource( 2 )
hframes = 3
region_enabled = true
region_rect = Rect2( 0, 0, 73, 80 )
_sections_unfolded = [ "Region" ]
[node name="Camera2D" type="Camera2D" parent="." index="1"]
anchor_mode = 1
rotating = false
current = true
zoom = Vector2( 1, 1 )
limit_left = -10000000
limit_top = -10000000
limit_right = 10000000
limit_bottom = 10000000
limit_smoothed = false
drag_margin_h_enabled = true
drag_margin_v_enabled = true
smoothing_enabled = true
smoothing_speed = 5.0
offset_v = 0.0
offset_h = 0.0
drag_margin_left = 0.2
drag_margin_top = 0.2
drag_margin_right = 0.2
drag_margin_bottom = 0.2
editor_draw_screen = true
editor_draw_limits = true
editor_draw_drag_margin = true
_sections_unfolded = [ "Editor", "Smoothing" ]

@ -1,11 +1,14 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://resources/tiles.res" type="TileSet" id=1]
[ext_resource path="res://scenes/Player.tscn" type="PackedScene" id=2]
[node name="World" type="Node2D" index="0"]
[node name="Tiles" type="Node2D" parent="." index="0"]
editor/display_folded = true
[node name="Walls" type="TileMap" parent="Tiles" index="0"]
mode = 0
@ -25,7 +28,6 @@ collision_mask = 13
occluder_light_mask = 1
format = 1
tile_data = PoolIntArray( -196610, 0, 0, -196609, 0, 0, -262144, 0, 0, -262143, 0, 0, -262142, 0, 0, -262141, 0, 0, -262140, 0, 0, -262139, 0, 0, -262138, 0, 0, -262137, 0, 0, -262136, 0, 0, -262135, 0, 0, -131074, 0, 0, -196599, 0, 0, -65540, 0, 0, -65539, 0, 0, -65538, 0, 0, -131071, 0, 0, -131070, 0, 0, -131069, 0, 0, -131068, 0, 0, -131067, 0, 0, -131066, 0, 0, -131065, 0, 0, -131063, 0, 0, -4, 0, 0, -65535, 0, 0, -65529, 0, 0, -65527, 0, 0, 65532, 0, 0, 1, 0, 0, 7, 0, 0, 9, 0, 0, 131068, 0, 0, 131070, 0, 0, 131071, 0, 0, 65536, 0, 0, 65537, 0, 0, 65543, 0, 0, 65545, 0, 0 )
_sections_unfolded = [ "Collision" ]
[node name="ground" type="TileMap" parent="Tiles" index="1"]
@ -48,4 +50,8 @@ format = 1
tile_data = PoolIntArray( -131073, 1, 0, -196608, 1, 0, -196607, 1, 0, -196606, 1, 0, -196605, 1, 0, -196604, 1, 0, -196603, 1, 0, -196602, 1, 0, -196601, 1, 0, -196600, 1, 0, -65537, 1, 0, -131072, 1, 0, -131064, 1, 0, -3, 1, 0, -2, 1, 0, -1, 1, 0, -65536, 1, 0, -65528, 1, 0, 65533, 1, 0, 65534, 1, 0, 65535, 1, 0, 0, 1, 0, 8, 1, 0, 131069, 1, 0, 65544, 1, 0, 196604, 0, 0, 196605, 0, 0, 196606, 0, 0, 196607, 0, 0, 131072, 0, 0, 131073, 0, 0, 131079, 0, 0, 131080, 0, 0, 131081, 0, 0 )
_sections_unfolded = [ "Collision" ]
[node name="Player" parent="." index="1" instance=ExtResource( 2 )]
Speed = 20

@ -8,7 +8,7 @@
custom_solver_bias = 0.0
extents = Vector2( 32.0076, 31.9661 )
[node name="map" type="Node2D" index="0"]
[node name="map" type="Node2D"]
[node name="wall" type="Sprite" parent="." index="0"]

@ -1,4 +1,27 @@
extends KinematicBody2D
export var Speed = 5
func _ready():
pass
func _process(delta):
var velocity = Vector2()
if Input.is_action_pressed('ui_left'):
velocity.x -= Speed
elif Input.is_action_pressed('ui_right'):
velocity.x += Speed
if Input.is_action_pressed('ui_up'):
velocity.y -= Speed
elif Input.is_action_pressed('ui_down'):
velocity.y += Speed
if Input.is_key_pressed(KEY_SHIFT):
velocity *= 2
move_and_slide(velocity)
pass

Loading…
Cancel
Save