add player movement speed value, also add player movement speed multiplier for moving slowly when holding down a key

This commit is contained in:
Robin Hübner 2017-06-27 15:50:14 +02:00
parent 7d86ed5935
commit d86f6d65a2
3 changed files with 47 additions and 2 deletions

View File

@ -1,9 +1,16 @@
[gd_scene load_steps=5 format=1] [gd_scene load_steps=7 format=1]
[ext_resource path="res://Game.gd" type="Script" id=1] [ext_resource path="res://Game.gd" type="Script" id=1]
[ext_resource path="res://Player.tscn" type="PackedScene" id=2] [ext_resource path="res://Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://Enemy.tscn" type="PackedScene" id=3] [ext_resource path="res://Enemy.tscn" type="PackedScene" id=3]
[ext_resource path="res://Box.tscn" type="PackedScene" id=4] [ext_resource path="res://Box.tscn" type="PackedScene" id=4]
[ext_resource path="res://bullet.png" type="Texture" id=5]
[sub_resource type="OccluderPolygon2D" id=1]
closed = true
cull_mode = 0
polygon = Vector2Array( 0, 0, 32, 0, 32, 32, 0, 32 )
[node name="Game" type="Node"] [node name="Game" type="Node"]
@ -27,4 +34,33 @@ transform/pos = Vector2( 159.592, 142.666 )
transform/pos = Vector2( 139.69, 112.812 ) transform/pos = Vector2( 139.69, 112.812 )
[node name="Light2D" type="Light2D" parent="."]
transform/pos = Vector2( 150.335, 218.809 )
enabled = true
editor_only = false
texture = ExtResource( 5 )
offset = Vector2( 0, 0 )
scale = 25.0
color = Color( 1, 0.539062, 0, 1 )
energy = 1.0
mode = 0
range/height = 15.0
range/z_min = -1024
range/z_max = 1024
range/layer_min = 0
range/layer_max = 0
range/item_mask = 1
shadow/enabled = true
shadow/color = Color( 0, 0, 0, 0 )
shadow/buffer_size = 2048
shadow/esm_multiplier = 80.0
shadow/item_mask = 1
[node name="LightOccluder2D" type="LightOccluder2D" parent="."]
transform/pos = Vector2( 80.2667, 219.558 )
occluder = SubResource( 1 )
light_mask = 1

View File

@ -1,9 +1,12 @@
extends KinematicBody2D extends KinematicBody2D
var bullet = load("res://Bullet.tscn") var bullet = load("res://Bullet.tscn")
var player_movement_speed = 256 # pixels per second
var velocity = Vector2(0, 0) var velocity = Vector2(0, 0)
var pointer var pointer
var velocity_mul = 1
func _ready(): func _ready():
# Called every time the node is added to the scene. # Called every time the node is added to the scene.
pointer = get_node("Pointer") pointer = get_node("Pointer")
@ -25,6 +28,11 @@ func _fixed_process(delta):
if Input.is_action_pressed("move_down"): if Input.is_action_pressed("move_down"):
velocity.y = 1 velocity.y = 1
if Input.is_action_pressed("move_slow"):
velocity_mul = 0.5
else:
velocity_mul = 1
# shooty # shooty
if Input.is_action_pressed("primary_fire"): if Input.is_action_pressed("primary_fire"):
var new_bullet = bullet.instance() var new_bullet = bullet.instance()
@ -35,6 +43,6 @@ func _fixed_process(delta):
# rotatey pointer thingy # rotatey pointer thingy
pointer.look_at(get_viewport().get_mouse_pos()) pointer.look_at(get_viewport().get_mouse_pos())
self.move(velocity) self.move(velocity * velocity_mul * (player_movement_speed * delta))
velocity.x = 0 velocity.x = 0
velocity.y = 0 velocity.y = 0

View File

@ -6,6 +6,7 @@ icon="res://icon.png"
[input] [input]
move_slow=[key(Shift)]
move_up=[key(W), key(Up)] move_up=[key(W), key(Up)]
move_down=[key(Down), key(S)] move_down=[key(Down), key(S)]
move_left=[key(Left), key(A)] move_left=[key(Left), key(A)]