Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Area2D
- const MOVE_SPEED = 300
- const SCREEN_WIDTH = 1920
- const SCREEN_HEIGHT = 1080
- var can_shoot = true
- var shot_scene = preload("res://scenes/shot.tscn")
- var explosion_scene = preload("res://Scenes/player_explosion.tscn")
- signal destroyed
- func _process(delta):
- if Input.is_key_pressed(KEY_SPACE) and can_shoot:
- var stage_node = get_parent()
- can_shoot = false
- get_node("reload_timer").start()
- var shot_instance = shot_scene.instance()
- shot_instance.position = position
- stage_node.add_child(shot_instance)
- var input_dir = Vector2()
- if Input.is_key_pressed(KEY_UP):
- input_dir.y -= 1.0
- if Input.is_key_pressed(KEY_DOWN):
- input_dir.y += 1.0
- if Input.is_key_pressed(KEY_LEFT):
- input_dir.x -= 1.0
- $sprite.play("left")
- elif Input.is_key_pressed(KEY_RIGHT):
- input_dir.x += 1.0
- $sprite.play("right")
- else:
- $sprite.play("neutral")
- position += (delta * MOVE_SPEED) * input_dir
- $engine.emitting = true
- if position.x < 0.0:
- position.x = 0.0
- elif position.x > SCREEN_WIDTH:
- position.x = SCREEN_WIDTH
- if position.y < 0.0:
- position.y = 0.0
- elif position.y > SCREEN_HEIGHT:
- position.y = SCREEN_HEIGHT
- func _on_reload_timer_timeout():
- can_shoot = true
- func _on_player_area_entered(area):
- if area.is_in_group("asteroid"):
- queue_free()
- var stage_node = get_parent()
- var explosion_instance = explosion_scene.instance()
- explosion_instance.position = position
- stage_node.add_child(explosion_instance)
- emit_signal("destroyed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement