setup main scene with mob spawning, score tracking, timers, etc.
This commit is contained in:
parent
d10306a11d
commit
88e5ff56c2
46
main.gd
46
main.gd
|
|
@ -1,11 +1,55 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
@export var mob_scene: PackedScene
|
||||||
|
var score
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass # Replace with function body.
|
new_game()
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func _on_player_hit() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func game_over():
|
||||||
|
$ScoreTimer.stop()
|
||||||
|
$MobTimer.stop()
|
||||||
|
|
||||||
|
func new_game():
|
||||||
|
score = 0
|
||||||
|
$Player.start($StartPosition.position)
|
||||||
|
$StartTimer.start()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_mob_timer_timeout() -> void:
|
||||||
|
var mob = mob_scene.instantiate()
|
||||||
|
|
||||||
|
var mob_spawn_location = $MobPath/MobSpawnLocation
|
||||||
|
mob_spawn_location.progress_ratio = randf()
|
||||||
|
|
||||||
|
mob.position = mob_spawn_location.position
|
||||||
|
|
||||||
|
var direction = mob_spawn_location.rotation + PI/2
|
||||||
|
|
||||||
|
direction += randf_range(-PI/4, PI/4)
|
||||||
|
|
||||||
|
mob.rotation = direction
|
||||||
|
|
||||||
|
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
|
||||||
|
mob.linear_velocity = velocity.rotated(direction)
|
||||||
|
|
||||||
|
add_child(mob)
|
||||||
|
|
||||||
|
func _on_score_timer_timeout() -> void:
|
||||||
|
score += 1
|
||||||
|
|
||||||
|
|
||||||
|
func _on_start_timer_timeout() -> void:
|
||||||
|
$MobTimer.start()
|
||||||
|
$ScoreTimer.start()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
[gd_scene format=3 uid="uid://62ecirhdonkh"]
|
[gd_scene format=3 uid="uid://62ecirhdonkh"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://40xnax86ff5v" path="res://main.gd" id="1_h2yge"]
|
||||||
[ext_resource type="PackedScene" uid="uid://jb11l53ss1a5" path="res://player.tscn" id="1_ig7tw"]
|
[ext_resource type="PackedScene" uid="uid://jb11l53ss1a5" path="res://player.tscn" id="1_ig7tw"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dbqx3rs3h3hfp" path="res://mob.tscn" id="2_1bvp3"]
|
||||||
|
|
||||||
[sub_resource type="Curve2D" id="Curve2D_ig7tw"]
|
[sub_resource type="Curve2D" id="Curve2D_ig7tw"]
|
||||||
_data = {
|
_data = {
|
||||||
|
|
@ -9,6 +11,8 @@ _data = {
|
||||||
point_count = 5
|
point_count = 5
|
||||||
|
|
||||||
[node name="Main" type="Node" unique_id=1884465277]
|
[node name="Main" type="Node" unique_id=1884465277]
|
||||||
|
script = ExtResource("1_h2yge")
|
||||||
|
mob_scene = ExtResource("2_1bvp3")
|
||||||
|
|
||||||
[node name="Player" parent="." unique_id=1124984874 instance=ExtResource("1_ig7tw")]
|
[node name="Player" parent="." unique_id=1124984874 instance=ExtResource("1_ig7tw")]
|
||||||
|
|
||||||
|
|
@ -28,3 +32,8 @@ position = Vector2(240, 450)
|
||||||
curve = SubResource("Curve2D_ig7tw")
|
curve = SubResource("Curve2D_ig7tw")
|
||||||
|
|
||||||
[node name="MobSpawnLocation" type="PathFollow2D" parent="MobPath" unique_id=1309929511]
|
[node name="MobSpawnLocation" type="PathFollow2D" parent="MobPath" unique_id=1309929511]
|
||||||
|
|
||||||
|
[connection signal="hit" from="Player" to="." method="_on_player_hit"]
|
||||||
|
[connection signal="timeout" from="MobTimer" to="." method="_on_mob_timer_timeout"]
|
||||||
|
[connection signal="timeout" from="ScoreTimer" to="." method="_on_score_timer_timeout"]
|
||||||
|
[connection signal="timeout" from="StartTimer" to="." method="_on_start_timer_timeout"]
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ config_version=5
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Warmup"
|
config/name="Warmup"
|
||||||
run/main_scene="uid://jb11l53ss1a5"
|
run/main_scene="uid://62ecirhdonkh"
|
||||||
config/features=PackedStringArray("4.6", "GL Compatibility")
|
config/features=PackedStringArray("4.6", "GL Compatibility")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue