multiple levels!
This commit is contained in:
parent
8ad0f7b627
commit
e0f48061e7
@ -15,6 +15,10 @@ run/main_scene="res://scenes/game.tscn"
|
||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
GameController="*res://scripts/gameController.gd"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=320
|
||||
|
@ -1,7 +1,6 @@
|
||||
[gd_scene load_steps=14 format=4 uid="uid://dhgts0kodsujx"]
|
||||
[gd_scene load_steps=13 format=4 uid="uid://dhgts0kodsujx"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://djkjmi7bo58uv" path="res://scenes/crate.tscn" id="1_6shkr"]
|
||||
[ext_resource type="Script" path="res://scripts/gameController.gd" id="1_50x63"]
|
||||
[ext_resource type="Script" path="res://scripts/sceneManager.gd" id="1_ooich"]
|
||||
[ext_resource type="Texture2D" uid="uid://dordo7deet5y0" path="res://assets/graphics/terrains/backgrounds/forestbackground.png" id="2_u8255"]
|
||||
[ext_resource type="PackedScene" uid="uid://b2hyqfqh02ep6" path="res://scenes/player.tscn" id="3_bssht"]
|
||||
@ -384,7 +383,6 @@ distance = -1.0
|
||||
radius = 62.0
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
script = ExtResource("1_50x63")
|
||||
|
||||
[node name="background" type="Parallax2D" parent="."]
|
||||
scroll_offset = Vector2(626, 298)
|
||||
@ -430,7 +428,7 @@ metadata/_edit_group_ = true
|
||||
shape = SubResource("WorldBoundaryShape2D_gasd3")
|
||||
|
||||
[node name="CharacterBody2D" parent="." instance=ExtResource("3_bssht")]
|
||||
position = Vector2(324, 76)
|
||||
position = Vector2(-100, -15)
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
position = Vector2(831, 439)
|
||||
@ -444,11 +442,7 @@ debug_color = Color(0.630721, 0.529414, 1.92523e-07, 0.42)
|
||||
[node name="crates" type="Node2D" parent="."]
|
||||
|
||||
[node name="RigidBody2D4" parent="crates" instance=ExtResource("1_6shkr")]
|
||||
position = Vector2(504, -465)
|
||||
|
||||
[node name="RigidBody2D" parent="crates" groups=["pushables"] instance=ExtResource("1_6shkr")]
|
||||
position = Vector2(147, 68)
|
||||
rotation = 2.09219
|
||||
position = Vector2(693, 307)
|
||||
|
||||
[node name="RigidBody2D2" parent="crates" groups=["pushables"] instance=ExtResource("1_6shkr")]
|
||||
position = Vector2(595, 192)
|
||||
@ -458,8 +452,8 @@ rotation = -1.41512
|
||||
position = Vector2(373, 200)
|
||||
rotation = -0.0982481
|
||||
|
||||
[node name="RigidBody2D5" parent="crates" instance=ExtResource("1_6shkr")]
|
||||
position = Vector2(-49, -64)
|
||||
[node name="RigidBody2D" parent="crates" instance=ExtResource("1_6shkr")]
|
||||
position = Vector2(137.327, 63.5923)
|
||||
|
||||
[connection signal="areaTrigger" from="Area2D" to="." method="_on_trigger"]
|
||||
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]
|
||||
|
459
scenes/level2.tscn
Normal file
459
scenes/level2.tscn
Normal file
File diff suppressed because one or more lines are too long
@ -5,8 +5,9 @@
|
||||
[ext_resource type="Texture2D" uid="uid://c2s48joyna11q" path="res://assets/graphics/player/jump/player jump 48x48.png" id="3_p8gbr"]
|
||||
[ext_resource type="Texture2D" uid="uid://bvat1vqwtua2p" path="res://assets/graphics/player/run/player run 48x48.png" id="3_y36hw"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_uvblg"]
|
||||
radius = 17.172
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_qr8pt"]
|
||||
radius = 9.93
|
||||
height = 35.0
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_cdvw1"]
|
||||
atlas = ExtResource("2_yfuca")
|
||||
@ -179,8 +180,7 @@ PUSH_FORCE = 100
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2(0.7, 1)
|
||||
shape = SubResource("CircleShape2D_uvblg")
|
||||
shape = SubResource("CapsuleShape2D_qr8pt")
|
||||
debug_color = Color(0.872789, 0.000463018, 0.842707, 0.42)
|
||||
|
||||
[node name="RightRay" type="RayCast2D" parent="."]
|
||||
|
@ -82,7 +82,6 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
pushTarget = false
|
||||
if left_ray.is_colliding():
|
||||
print("Left ray collision")
|
||||
var collider = left_ray.get_collider()
|
||||
if collider is Node:
|
||||
if collider.is_in_group("pushables"):
|
||||
@ -92,7 +91,6 @@ func _physics_process(delta: float) -> void:
|
||||
pushLeftEnabled = false
|
||||
|
||||
if right_ray.is_colliding():
|
||||
print("Right ray collision")
|
||||
var collider = right_ray.get_collider()
|
||||
if collider is Node:
|
||||
if collider.is_in_group("pushables"):
|
||||
|
@ -1,44 +1,54 @@
|
||||
extends Node2D
|
||||
|
||||
var timer:= Timer.new()
|
||||
@export var secondCount= 99999999
|
||||
|
||||
var secondCount= 99
|
||||
var totalCrates := 0
|
||||
var cratesDestroyed := 0
|
||||
|
||||
signal destroyBox
|
||||
# level info
|
||||
var levels = ["res://scenes/game.tscn", "res://scenes/level2.tscn"]
|
||||
var timers = [20, 15]
|
||||
var currentLevel = 0
|
||||
|
||||
#Gamecontroller signals
|
||||
signal destroyBox(body)
|
||||
signal levelComplete(leveltoLoad)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
print("Number of levels: "+str(levels.size()))
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
timer.one_shot = false
|
||||
timer.connect("timeout", secondCounter)
|
||||
timer.start()
|
||||
|
||||
func reset():
|
||||
secondCount = timers[currentLevel]
|
||||
|
||||
func secondCounter():
|
||||
print("time left: ", secondCount)
|
||||
secondCount -=1
|
||||
if secondCount <= 0:
|
||||
print("A loser is you")
|
||||
get_tree().reload_current_scene()
|
||||
print("TIME IS UP")
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
func _on_trigger(_effect: Variant, body) -> void:
|
||||
print("they were triggered!")
|
||||
if body is RigidBody2D:
|
||||
print("crate spotted")
|
||||
body.queue_free()
|
||||
|
||||
|
||||
func bulletHit(body):
|
||||
print("Game controller knows bullet hit something")
|
||||
if body.is_in_group("destructables"):
|
||||
|
||||
destroyBox.emit(body)
|
||||
|
||||
totalCrates -= 1
|
||||
cratesDestroyed += 1
|
||||
|
||||
if totalCrates <=0:
|
||||
print("You Won...")
|
||||
currentLevel +=1
|
||||
if currentLevel >= levels.size():
|
||||
currentLevel = 0
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
else:
|
||||
print("Crates Remaining: "+str(totalCrates) )
|
||||
|
||||
# Coming from scenemanager
|
||||
func countCrates(value):
|
||||
totalCrates = value
|
||||
|
@ -1,17 +1,28 @@
|
||||
extends Node
|
||||
@onready var game: Node2D = $".."
|
||||
# @onready var game: Node2D = $".."
|
||||
|
||||
@onready var crates: Node2D = $"../crates"
|
||||
|
||||
var theBullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletArray:Array = []
|
||||
|
||||
var totalCrates := 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
game.destroyBox.connect(boxDestroy)
|
||||
GameController.reset()
|
||||
GameController.destroyBox.connect(boxDestroy)
|
||||
for obj in crates.get_children():
|
||||
if obj.is_in_group("destructables"):
|
||||
totalCrates += 1
|
||||
GameController.countCrates(totalCrates)
|
||||
|
||||
# Subscribe to signals
|
||||
GameController.levelComplete.connect(changeLevel)
|
||||
|
||||
func changeLevel(level):
|
||||
print("New level")
|
||||
get_tree().change_scene_to_file(level)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta: float) -> void:
|
||||
@ -42,7 +53,7 @@ func onBulletHit(bullet, body):
|
||||
bullet.position = Vector2(-100, -100)
|
||||
bullet.setSpeed(0)
|
||||
print("Scene manager knows bullet hit")
|
||||
game.bulletHit(body)
|
||||
GameController.bulletHit(body)
|
||||
|
||||
func boxDestroy(body):
|
||||
print("sceneMgr knows body destroyed")
|
||||
|
Loading…
Reference in New Issue
Block a user