Skip to content

Commit

Permalink
feat: rework spawning system & fix player collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
enzoritto committed Oct 3, 2024
1 parent 46c8cfd commit 882ad36
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
2 changes: 2 additions & 0 deletions scenes/classes/character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class_name Character extends CharacterBody2D
@export var speed: float = 40.0
@export var sprite_frames: Array[SpriteFrames]

@export var display_name: String


func _enter_tree() -> void:
$AnimatedSprite2D.sprite_frames = sprite_frames.pick_random()
24 changes: 16 additions & 8 deletions scenes/levels/level.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
extends Node2D


@export var zombies_num: int = 2
@export var players: int = 2
@export var num_characters: int = 2
@export var num_players: int = 2
@export var zombie_scene: PackedScene
@export var player_scene: PackedScene
@export var spawn_points: Node
@export var character_height: int = 34
@export var colors: Array[Color]
@export var spawn_offset: Vector2 = Vector2(50, 10)

@export var base_height: int = 360

var characters: Array[Character]

@onready var num_zombies: int = num_characters - num_players


@onready var finish_line: Area2D = $Finish

Expand All @@ -23,11 +27,11 @@ func _ready() -> void:


func spawn_characters() -> void:
for i in zombies_num:
for i in num_zombies:
var zombie = zombie_scene.instantiate()
zombie.name = "Zombie " + str(i + 1)
characters.append(zombie)
for i in players:
for i in num_players:
var player = player_scene.instantiate()
player.number = i
player.name = "Player" + str(i)
Expand All @@ -39,9 +43,13 @@ func spawn_characters() -> void:

characters.shuffle()

var points := spawn_points.get_children()
for i in points.size():
characters[i].position = points[i].position
var total_characters: int = num_zombies + num_players
for i in num_zombies + num_players:
var available_height = base_height - spawn_offset.y
var spacing = available_height / total_characters + 1
var y_position = spawn_offset.y + i * spacing

characters[i].position = Vector2(spawn_offset.x, y_position)
add_child(characters[i])


Expand Down
23 changes: 6 additions & 17 deletions scenes/levels/level.tscn

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions scenes/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
[node name="Main" type="Node"]

[node name="Level" parent="." instance=ExtResource("1_js5b6")]
zombies_num = 2
players = 2

[node name="GUI" type="Control" parent="."]
process_mode = 3
Expand Down
1 change: 1 addition & 0 deletions scenes/players/crosshair.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ region = Rect2(97, 49, 14, 14)

[node name="Crosshair" type="Area2D"]
z_index = 200
collision_mask = 2
script = ExtResource("1_gycjl")
speed = 120.0

Expand Down
2 changes: 0 additions & 2 deletions scenes/players/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ extends Character
@export var crosshair_color: Color


var display_name: String

var speed_boost


Expand Down
3 changes: 2 additions & 1 deletion scenes/players/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
[ext_resource type="SpriteFrames" uid="uid://baufp5u5muwll" path="res://resources/zombie_3_frames.tres" id="4_mstxp"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_5wrs1"]
size = Vector2(34, 68)
size = Vector2(32, 64)

[node name="Player" type="CharacterBody2D" groups=["players"]]
z_index = 100
collision_layer = 2
script = ExtResource("1_fff2d")
run_boost = 48.0
speed = 32.0
Expand Down
4 changes: 3 additions & 1 deletion scenes/zombie/zombie.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
[ext_resource type="SpriteFrames" uid="uid://baufp5u5muwll" path="res://resources/zombie_3_frames.tres" id="4_kcvoe"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_6al3e"]
size = Vector2(40, 64)
size = Vector2(32, 64)

[node name="Zombie" type="CharacterBody2D"]
collision_layer = 2
script = ExtResource("1_7wpk0")
speed = 32.0
sprite_frames = Array[SpriteFrames]([ExtResource("2_8m1jv"), ExtResource("3_rc68x"), ExtResource("4_kcvoe")])
display_name = "Zombie"
metadata/_edit_group_ = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
Expand Down

0 comments on commit 882ad36

Please sign in to comment.