Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- const MOVE_SPEED = 150
- const STAMINA_REC_SPEED = 5
- const BULLET_SCENE = preload("res://objects/bullet/Bullet.tscn")
- var stamina = 100
- func _ready():
- yield(get_tree(), "idle_frame")
- get_tree().call_group("zombies", "set_player", self)
- func _physics_process(delta):
- move(delta)
- var look_vec = get_global_mouse_position() - global_position
- global_rotation = atan2(look_vec.y, look_vec.x)
- if Input.is_action_just_pressed("shoot"):
- var b = BULLET_SCENE.instance()
- b.position(look_vec)
- get_parent().add_child(b)
- b.set_position(get_node("Position2D").get_global_position())
- func sprint(delta):
- if Input.is_action_pressed("sprint"):
- if stamina <= 0:
- stamina = 0
- print(stamina)
- return false
- stamina -= STAMINA_REC_SPEED * 4 * delta
- print(stamina)
- return true
- if stamina >= 100:
- stamina = 100
- else:
- stamina += STAMINA_REC_SPEED * delta
- print(stamina)
- return false
- func move(delta):
- var speed = MOVE_SPEED
- if sprint(delta):
- speed = MOVE_SPEED * 2
- var move_vec = Vector2()
- if Input.is_action_pressed("move_up"):
- move_vec.y -= 1
- if Input.is_action_pressed("move_down"):
- move_vec.y += 1
- if Input.is_action_pressed("move_left"):
- move_vec.x -= 1
- if Input.is_action_pressed("move_right"):
- move_vec.x += 1
- move_vec = move_vec.normalized()
- move_and_collide(move_vec * speed * delta)
- func kill():
- get_tree().reload_current_scene()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement