Skip to content
This repository was archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagrad committed Oct 12, 2024
2 parents a07510f + 9d98e61 commit 9390217
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
40 changes: 28 additions & 12 deletions main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ extends Node
@export var power_up_scene: PackedScene = preload("res://power_up.tscn")

var score
var mob_initial_velocity = 150
var mob_initial_velocity = 200
var mob_final_velocity = 250
var powerup_initial_velocity = 50
var powerup_final_velocity = 100

var powerup_initial_velocity = 200
var powerup_final_velocity = 250
var speedDifficulty = 0

func _ready():
#$HUD.connect("start_game", self, "new_game")
$HUD.start_game.connect(self.new_game)

$Player.connect("power_up_collected", Callable(self, "_on_power_up_collected"))
$MobTimer.wait_time = 1
score = 0
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
Expand Down Expand Up @@ -46,31 +48,45 @@ func _on_mob_timer_timeout():
# Set the mob's position to a random location.
mob.position = mob_spawn_location.position

# Set the direction to be between 90 degrees (PI/2) and 180 degrees (PI)
var direction = randf_range(PI / 2, PI)
# Convert 80 and 100 degrees to radians
var direction = randf_range(1.39626, 1.74533)
mob.rotation = direction

if score % 10 == 0 and score != 0:
speedDifficulty += 30
$MobTimer.wait_time = max(0.5, $MobTimer.wait_time - 0.05)

# Choose the velocity for the mob.
var velocity = Vector2(randf_range(mob_initial_velocity, mob_final_velocity), 0.0)
var velocity = Vector2(randf_range(mob_initial_velocity + speedDifficulty, mob_final_velocity + speedDifficulty), 0.0)
mob.linear_velocity = velocity.rotated(direction)

# Spawn the mob by adding it to the Main scene.
add_child(mob)

func _on_elevation_timer_timeout() -> void:
score += 1
$HUD.update_score(score)




func _on_power_up_collected():
score += 3
$HUD.update_score(score)

func _on_power_up_timer_timeout() -> void:
var powerUp = power_up_scene.instantiate()

# Choose a random location on Path2D
var powerUp_spawn_location = $PowerUpPath/PowerUpSpawnLocation
powerUp_spawn_location.progress_ratio = randf()

# Set rotation explicitly to face down (PI / 2 radians)
var direction = PI / 2
powerUp.rotation = direction

# Set the position to the spawn location
powerUp.position = powerUp_spawn_location.position

var velocity = Vector2(randf_range(powerup_initial_velocity, powerup_final_velocity), 0.0)
# Set the velocity to move straight down
var velocity = Vector2(0.0, randf_range(powerup_initial_velocity, powerup_final_velocity)) # Moving down (positive y)
powerUp.linear_velocity = velocity

add_child(powerUp)
7 changes: 5 additions & 2 deletions main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ point_count = 6

[sub_resource type="Curve2D" id="Curve2D_fyrt5"]
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 472, 16, 0, 0, 0, 0, 472, 352, 0, 0, 0, 0, 8, 352, 0, 0, 0, 0, 8, 8)
"points": PackedVector2Array(0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 472, 16, 0, 0, 0, 0, 472, 352, 0, 0, 0, 0, 240, 354, 0, 0, 0, 0, 8, 352, 0, 0, 0, 0, 8, 8)
}
point_count = 5
point_count = 6

[node name="Main" type="Node"]
script = ExtResource("1_t4vn5")
Expand All @@ -32,6 +32,7 @@ offset_bottom = 1536.0
texture = ExtResource("3_ety76")

[node name="Player" parent="." instance=ExtResource("1_iwmrs")]
speed = 300

[node name="MobTimer" type="Timer" parent="."]
wait_time = 0.5
Expand All @@ -58,6 +59,8 @@ rotation = -1.5708
[node name="HUD" parent="." instance=ExtResource("4_6nxef")]

[node name="PowerUpPath" type="Path2D" parent="."]
position = Vector2(0, 4.73988)
scale = Vector2(1, 0.407514)
curve = SubResource("Curve2D_fyrt5")

[node name="PowerUpSpawnLocation" type="PathFollow2D" parent="PowerUpPath"]
Expand Down
1 change: 1 addition & 0 deletions mob.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ height = 88.0

[node name="Mob" type="RigidBody2D" groups=["mobs"]]
collision_mask = 0
gravity_scale = 0.0
script = ExtResource("1_vwjby")

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
Expand Down
3 changes: 2 additions & 1 deletion player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func _ready() -> void:
server = UDPServer.new()
server.listen(4242)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if gesture_flag:
Expand Down Expand Up @@ -96,7 +97,7 @@ func _on_power_up_collision(power_up: Node2D) -> void:

# You might want to hide or remove the power-up from the scene
power_up.queue_free()

# Function to reset the player and start at a specific position
func start(pos):
position = pos
Expand Down
5 changes: 3 additions & 2 deletions power_up.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ animations = [{
}]

[sub_resource type="CircleShape2D" id="CircleShape2D_mel2t"]
radius = 64.0
radius = 37.3571

[node name="PowerUP" type="RigidBody2D" groups=["powerups"]]
collision_mask = 0
gravity_scale = 0.0
script = ExtResource("1_fmasb")

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(0.25, 0.25)
scale = Vector2(0.18, 0.18)
sprite_frames = SubResource("SpriteFrames_3f6y5")
animation = &"power_up"
frame = 5
Expand Down

0 comments on commit 9390217

Please sign in to comment.