Initial repo
This commit is contained in:
78
Scripts/player.gd
Normal file
78
Scripts/player.gd
Normal file
@@ -0,0 +1,78 @@
|
||||
extends Area2D
|
||||
class_name player
|
||||
|
||||
#setting up signals
|
||||
signal spawn_laser(location)
|
||||
signal spawn_missile(location)
|
||||
|
||||
#loading the muzzle position on load
|
||||
@onready var muzzle = $muzzle
|
||||
|
||||
#speed, health and direction, direction is for future animations vector sets up an Axis.
|
||||
var speed = 250
|
||||
var health = 3
|
||||
var direction = "none"
|
||||
var input_vector = Vector2()
|
||||
|
||||
var missile_total = 3
|
||||
var missile_current = 3
|
||||
#mostly movement stuff below, + some firing commands, check happens between every frame
|
||||
func _physics_process(delta):
|
||||
input_vector.x = 0
|
||||
if Input.is_action_pressed("move_right"):
|
||||
input_vector.x += 1
|
||||
direction = "right"
|
||||
if Input.is_action_pressed("move_left"):
|
||||
input_vector.x -= 1
|
||||
direction = "left"
|
||||
|
||||
input_vector.y = 0
|
||||
if Input.is_action_pressed("move_forward"):
|
||||
#print("fwd")
|
||||
input_vector.y -= 1
|
||||
if Input.is_action_pressed("move_back"):
|
||||
input_vector.y += 1
|
||||
global_position += input_vector * speed * delta
|
||||
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
$AnimatedSprite2D.play("shoot")
|
||||
shoot_laser()
|
||||
#$AnimatedSprite2D.play("default")
|
||||
|
||||
#Missile launching signal
|
||||
if Input.is_action_just_pressed("fire_missile"):
|
||||
if missile_current > 0:
|
||||
$AnimatedSprite2D.play("shoot")
|
||||
shoot_missile()
|
||||
missile_current -= 1
|
||||
print(str(missile_current))
|
||||
else:
|
||||
print("No Missiles")
|
||||
|
||||
#if entering an area with enemy, DO damage.
|
||||
func take_damage(damage):
|
||||
health -= damage
|
||||
get_tree().current_scene.player_health(health)
|
||||
if health <= 0:
|
||||
get_tree().current_scene.player_health(health)
|
||||
queue_free()
|
||||
|
||||
#if entering an area with enemy = collision, does 1 damage
|
||||
func _on_area_entered(area):
|
||||
if area.is_in_group("enemies"):
|
||||
area.take_damage(1)
|
||||
|
||||
#sends laser shoot command to worl + muzzle position
|
||||
func shoot_laser():
|
||||
emit_signal("spawn_laser",muzzle.global_position)
|
||||
|
||||
#sends missile launch command to world + muzzle position
|
||||
func shoot_missile():
|
||||
emit_signal("spawn_missile",muzzle.global_position)
|
||||
|
||||
|
||||
func refil_missiles():
|
||||
if missile_current < missile_total:
|
||||
missile_current = missile_total
|
||||
else:
|
||||
pass
|
||||
Reference in New Issue
Block a user