Basic Wave System is Down
This commit is contained in:
parent
128abc60b8
commit
97a49b122b
4 changed files with 214 additions and 18 deletions
174
Scenes/Game.tscn
Normal file
174
Scenes/Game.tscn
Normal file
|
@ -0,0 +1,174 @@
|
||||||
|
[gd_scene load_steps=17 format=3 uid="uid://c4btepmue6d7p"]
|
||||||
|
|
||||||
|
[ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="1_38041"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/GameManager.gd" id="1_t708k"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="2_ope8r"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="3_o045y"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="4_hpafd"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/PlayerController.gd" id="5_d2cbj"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://db70wcy5ua3jd" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="6_p526i"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="7_mtrts"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="8_fp1vx"]
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_kdxam"]
|
||||||
|
resource_name = "Idle"
|
||||||
|
length = 0.1
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Player Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_dwpep"]
|
||||||
|
resource_name = "MoveDown"
|
||||||
|
length = 0.8
|
||||||
|
loop_mode = 1
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Player Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = false
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
|
||||||
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0, 1, 2, 3, 4, 5, 6, 7]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_2jvl5"]
|
||||||
|
resource_name = "MoveLeft"
|
||||||
|
length = 0.8
|
||||||
|
loop_mode = 1
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Player Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
|
||||||
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [24, 25, 26, 27, 28, 29, 30, 31]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_4ig1u"]
|
||||||
|
resource_name = "MoveRight"
|
||||||
|
length = 0.8
|
||||||
|
loop_mode = 1
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Player Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
|
||||||
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [8, 9, 10, 11, 12, 13, 14, 15]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_pswkh"]
|
||||||
|
resource_name = "MoveUp"
|
||||||
|
length = 0.8
|
||||||
|
loop_mode = 1
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Player Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
|
||||||
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [16, 17, 18, 19, 20, 21, 22, 23]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_o3hln"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Player Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_bi1h3"]
|
||||||
|
_data = {
|
||||||
|
"Idle": SubResource("Animation_kdxam"),
|
||||||
|
"MoveDown": SubResource("Animation_dwpep"),
|
||||||
|
"MoveLeft": SubResource("Animation_2jvl5"),
|
||||||
|
"MoveRight": SubResource("Animation_4ig1u"),
|
||||||
|
"MoveUp": SubResource("Animation_pswkh"),
|
||||||
|
"RESET": SubResource("Animation_o3hln")
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="GameManager" type="Node2D" node_paths=PackedStringArray("map_generator", "bunny_generator")]
|
||||||
|
script = ExtResource("1_t708k")
|
||||||
|
map_generator = NodePath("Map Generator")
|
||||||
|
bunny_generator = NodePath("Bunny Generator")
|
||||||
|
|
||||||
|
[node name="Map Generator" type="TileMap" parent="."]
|
||||||
|
scale = Vector2(1.5, 1.5)
|
||||||
|
tile_set = ExtResource("1_38041")
|
||||||
|
cell_quadrant_size = 32
|
||||||
|
format = 2
|
||||||
|
script = ExtResource("2_ope8r")
|
||||||
|
start_area_corner_size = 3
|
||||||
|
|
||||||
|
[node name="Bunny Generator" type="Node2D" parent="." node_paths=PackedStringArray("player")]
|
||||||
|
script = ExtResource("3_o045y")
|
||||||
|
bunny_prefab = ExtResource("4_hpafd")
|
||||||
|
player = NodePath("../Player")
|
||||||
|
player_save_distance = 320.0
|
||||||
|
|
||||||
|
[node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")]
|
||||||
|
position = Vector2(1440, 810)
|
||||||
|
collision_layer = 0
|
||||||
|
script = ExtResource("5_d2cbj")
|
||||||
|
speed = 200
|
||||||
|
animation_player = NodePath("Player Animator")
|
||||||
|
|
||||||
|
[node name="Player Sprite" type="Sprite2D" parent="Player"]
|
||||||
|
position = Vector2(0, -20)
|
||||||
|
texture = ExtResource("6_p526i")
|
||||||
|
hframes = 8
|
||||||
|
vframes = 4
|
||||||
|
|
||||||
|
[node name="Player Collider" type="CollisionPolygon2D" parent="Player"]
|
||||||
|
position = Vector2(2, -24)
|
||||||
|
polygon = PackedVector2Array(12, 32, -16, 32, -16, -24, 12, -24)
|
||||||
|
|
||||||
|
[node name="Player Camera" type="Camera2D" parent="Player"]
|
||||||
|
position = Vector2(-1, -25)
|
||||||
|
zoom = Vector2(3, 3)
|
||||||
|
position_smoothing_enabled = true
|
||||||
|
drag_horizontal_enabled = true
|
||||||
|
drag_vertical_enabled = true
|
||||||
|
editor_draw_drag_margin = true
|
||||||
|
|
||||||
|
[node name="Player Animator" type="AnimationPlayer" parent="Player"]
|
||||||
|
libraries = {
|
||||||
|
"": SubResource("AnimationLibrary_bi1h3")
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="WeaponController" type="Node2D" parent="Player"]
|
||||||
|
position = Vector2(0, -16)
|
||||||
|
script = ExtResource("7_mtrts")
|
||||||
|
projectile_prefab = ExtResource("8_fp1vx")
|
|
@ -1,4 +1,5 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
class_name BunnyGenerator
|
||||||
|
|
||||||
@export var bunny_prefab : Resource
|
@export var bunny_prefab : Resource
|
||||||
@export var player : CharacterBody2D
|
@export var player : CharacterBody2D
|
||||||
|
@ -13,20 +14,18 @@ func spawn_bunny(pos : Vector2, team : int, health : int) -> Bunny:
|
||||||
bunny.team = team
|
bunny.team = team
|
||||||
return bunny
|
return bunny
|
||||||
|
|
||||||
func spawn_wave(free_tiles : Array, amount : int, health : int):
|
func spawn_wave(free_tiles : Array, team: int, amount : int, health : int) -> Array:
|
||||||
|
var bunnys = []
|
||||||
|
|
||||||
# Make Sure that no possitions to near to the player are insdie of the list
|
# Make Sure that no possitions to near to the player are insdie of the list
|
||||||
for tile in free_tiles:
|
free_tiles = free_tiles.filter(func(val): return val.distance_to(player.global_position) > player_save_distance)
|
||||||
if tile.distance_to(player.global_position) <= player_save_distance:
|
|
||||||
free_tiles.erase(tile)
|
|
||||||
|
|
||||||
# Make sure amount isnt bigger then available positions
|
# Make sure amount isnt bigger then available positions
|
||||||
if free_tiles.size() < amount: amount = free_tiles.size()
|
if free_tiles.size() < amount: amount = free_tiles.size()
|
||||||
|
|
||||||
# Spawn at random psoitions of the list
|
# Spawn at random positions of the list
|
||||||
for i in amount:
|
for i in amount:
|
||||||
var pos = free_tiles.pick_random()
|
var pos = free_tiles.pick_random()
|
||||||
free_tiles.erase(pos)
|
free_tiles.erase(pos)
|
||||||
var bunny = spawn_bunny(pos, TEAM.EVIL, 3)
|
var bunny = spawn_bunny(pos, team, 3)
|
||||||
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
bunnys.push_back(bunny)
|
||||||
pass
|
return bunnys
|
||||||
|
|
23
Scripts/GameManager.gd
Normal file
23
Scripts/GameManager.gd
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
@export var map_generator : Node
|
||||||
|
@export var bunny_generator : Node
|
||||||
|
|
||||||
|
var bunnys = []
|
||||||
|
var gen_data : Dictionary
|
||||||
|
var wave := 0
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
gen_data = map_generator.generate() as Dictionary
|
||||||
|
print("time for generation: " + str(gen_data.time))
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta):
|
||||||
|
if(bunnys.size() == 0):
|
||||||
|
wave += 1
|
||||||
|
bunnys = bunny_generator.spawn_wave(gen_data.free_tiles.duplicate(), TEAM.EVIL, wave, 3)
|
||||||
|
for bunny in bunnys:
|
||||||
|
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
|
||||||
|
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
||||||
|
pass
|
|
@ -15,13 +15,7 @@ extends TileMap
|
||||||
|
|
||||||
var tile_array : Array
|
var tile_array : Array
|
||||||
|
|
||||||
func _ready():
|
func generate() -> Dictionary:
|
||||||
var time = generate()
|
|
||||||
print("time for generation: " + str(time))
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
func generate() -> float:
|
|
||||||
var start_time = Time.get_unix_time_from_system()
|
var start_time = Time.get_unix_time_from_system()
|
||||||
|
|
||||||
randomize()
|
randomize()
|
||||||
|
@ -39,8 +33,14 @@ func generate() -> float:
|
||||||
|
|
||||||
tile_array_to_terrain()
|
tile_array_to_terrain()
|
||||||
|
|
||||||
|
return {"time": Time.get_unix_time_from_system() - start_time, "free_tiles": get_free_tiles()}
|
||||||
return Time.get_unix_time_from_system() - start_time
|
|
||||||
|
func get_free_tiles() -> Array:
|
||||||
|
var free_tiles = []
|
||||||
|
for x in width:
|
||||||
|
for y in height:
|
||||||
|
if get_tile_non_solid(x, y): free_tiles.push_back(Vector2(x, y) * self.cell_quadrant_size * self.scale + (Vector2(self.cell_quadrant_size, self.cell_quadrant_size) / 2))
|
||||||
|
return free_tiles
|
||||||
|
|
||||||
func setup_tile_data_array():
|
func setup_tile_data_array():
|
||||||
tile_array.clear()
|
tile_array.clear()
|
||||||
|
|
Reference in a new issue