week 2 prep
This commit is contained in:
parent
d0819ead77
commit
d8629e2f81
@ -1,17 +1,15 @@
|
|||||||
[gd_scene format=3 uid="uid://ch6sfehmsskcs"]
|
[gd_scene format=3 uid="uid://ch6sfehmsskcs"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dtv434qd1rfmu" path="res://scripts/game.gd" id="1_lnu2h"]
|
[ext_resource type="Script" uid="uid://dtv434qd1rfmu" path="res://scripts/game.gd" id="1_lnu2h"]
|
||||||
[ext_resource type="Script" uid="uid://g4wclr5vnxk6" path="res://scripts/trigger.gd" id="1_uwrxv"]
|
|
||||||
[ext_resource type="Script" uid="uid://b5c00ybml8rj" path="res://scripts/scene_manager.gd" id="2_lbhrr"]
|
[ext_resource type="Script" uid="uid://b5c00ybml8rj" path="res://scripts/scene_manager.gd" id="2_lbhrr"]
|
||||||
[ext_resource type="PackedScene" uid="uid://byl4bdrupii3k" path="res://scenes/player.tscn" id="4_iywne"]
|
[ext_resource type="PackedScene" uid="uid://byl4bdrupii3k" path="res://scenes/player.tscn" id="4_iywne"]
|
||||||
[ext_resource type="PackedScene" uid="uid://b6cmg0k8qjoxi" path="res://scenes/crate.tscn" id="5_iywne"]
|
[ext_resource type="PackedScene" uid="uid://b6cmg0k8qjoxi" path="res://scenes/crate.tscn" id="5_iywne"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://b3hgbbmb0nohj" path="res://scenes/trigger.tscn" id="5_p57ef"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"]
|
||||||
|
|
||||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_iywne"]
|
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_iywne"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"]
|
|
||||||
|
|
||||||
[node name="Game" type="Node2D" unique_id=981419409]
|
[node name="Game" type="Node2D" unique_id=981419409]
|
||||||
script = ExtResource("1_lnu2h")
|
script = ExtResource("1_lnu2h")
|
||||||
|
|
||||||
@ -72,28 +70,17 @@ shape = SubResource("WorldBoundaryShape2D_iywne")
|
|||||||
|
|
||||||
[node name="Triggers" type="Node2D" parent="." unique_id=193669081]
|
[node name="Triggers" type="Node2D" parent="." unique_id=193669081]
|
||||||
|
|
||||||
[node name="Trigger" type="Area2D" parent="Triggers" unique_id=1742156972]
|
[node name="Trigger" parent="Triggers" unique_id=1050615345 instance=ExtResource("5_p57ef")]
|
||||||
position = Vector2(621.00006, 465.00006)
|
position = Vector2(621.00006, 465.00006)
|
||||||
scale = Vector2(4.2, 4.2)
|
|
||||||
script = ExtResource("1_uwrxv")
|
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Triggers/Trigger" unique_id=1581030951]
|
[node name="Trigger2" parent="Triggers" unique_id=1114882050 instance=ExtResource("5_p57ef")]
|
||||||
shape = SubResource("CircleShape2D_8cj0n")
|
position = Vector2(829, 464)
|
||||||
debug_color = Color(0.3285461, 0.6189337, 0.22834331, 0.41960785)
|
|
||||||
|
|
||||||
[node name="Trigger2" type="Area2D" parent="Triggers" unique_id=318863481]
|
|
||||||
position = Vector2(853.99994, 453.99997)
|
|
||||||
scale = Vector2(4.2, 4.2)
|
|
||||||
script = ExtResource("1_uwrxv")
|
|
||||||
intent = "fan"
|
intent = "fan"
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Triggers/Trigger2" unique_id=1843060141]
|
[node name="Trigger3" parent="Triggers" unique_id=400578019 instance=ExtResource("5_p57ef")]
|
||||||
shape = SubResource("CircleShape2D_8cj0n")
|
position = Vector2(1097, 462.99997)
|
||||||
debug_color = Color(0.3285461, 0.6189337, 0.22834331, 0.41960785)
|
intent = "teleport"
|
||||||
|
|
||||||
[connection signal="areaTriggerSignal" from="Triggers/Trigger" to="." method="_on_trigger"]
|
[connection signal="areaTriggerSignal" from="Triggers/Trigger" to="." method="_on_trigger"]
|
||||||
[connection signal="body_entered" from="Triggers/Trigger" to="Triggers/Trigger" method="_on_body_entered"]
|
|
||||||
[connection signal="areaTriggerSignal" from="Triggers/Trigger2" to="." method="_on_trigger"]
|
[connection signal="areaTriggerSignal" from="Triggers/Trigger2" to="." method="_on_trigger"]
|
||||||
[connection signal="body_entered" from="Triggers/Trigger2" to="Triggers/Trigger2" method="_on_body_entered"]
|
[connection signal="areaTriggerSignal" from="Triggers/Trigger3" to="." method="_on_trigger"]
|
||||||
|
|||||||
26
scenes/trigger.tscn
Normal file
26
scenes/trigger.tscn
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
[gd_scene format=3 uid="uid://b3hgbbmb0nohj"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://g4wclr5vnxk6" path="res://scripts/trigger.gd" id="1_du5ex"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"]
|
||||||
|
|
||||||
|
[node name="Trigger" type="Area2D" unique_id=1050615345]
|
||||||
|
scale = Vector2(4.2, 4.2)
|
||||||
|
script = ExtResource("1_du5ex")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=703121924]
|
||||||
|
shape = SubResource("CircleShape2D_8cj0n")
|
||||||
|
debug_color = Color(0.3285461, 0.6189337, 0.22834331, 0.41960785)
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="." unique_id=1171382845]
|
||||||
|
texture_filter = 1
|
||||||
|
offset_left = -18.333336
|
||||||
|
offset_top = -8.333334
|
||||||
|
offset_right = 21.666664
|
||||||
|
offset_bottom = 2.666666
|
||||||
|
theme_override_font_sizes/font_size = 7
|
||||||
|
text = "trigger"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
@ -1 +1,13 @@
|
|||||||
class_name Crate extends RigidBody2D
|
class_name Crate extends RigidBody2D
|
||||||
|
|
||||||
|
var teleport_target: Vector2 = Vector2.ZERO
|
||||||
|
var should_teleport: bool = false
|
||||||
|
|
||||||
|
func teleport_to(position:Vector2):
|
||||||
|
teleport_target = position
|
||||||
|
should_teleport = true
|
||||||
|
|
||||||
|
func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
|
||||||
|
if should_teleport:
|
||||||
|
state.transform = Transform2D.IDENTITY.translated(teleport_target)
|
||||||
|
should_teleport = false
|
||||||
|
|||||||
@ -6,6 +6,7 @@ var timeAvailable = 50
|
|||||||
signal destroySignal(body)
|
signal destroySignal(body)
|
||||||
signal levelChangeSignal(level)
|
signal levelChangeSignal(level)
|
||||||
signal fanUpSignal(body,direction)
|
signal fanUpSignal(body,direction)
|
||||||
|
signal teleportSignal(body)
|
||||||
|
|
||||||
var timer = Timer.new()
|
var timer = Timer.new()
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
@ -33,7 +34,9 @@ func _on_trigger(body: Variant, trigger: Variant, intent:String) -> void:
|
|||||||
"fan":
|
"fan":
|
||||||
if body is RigidBody2D:
|
if body is RigidBody2D:
|
||||||
fanUpSignal.emit(body,Vector2(0,-1)*100*9)
|
fanUpSignal.emit(body,Vector2(0,-1)*100*9)
|
||||||
|
"teleport":
|
||||||
|
if body is Crate:
|
||||||
|
teleportSignal.emit(body)
|
||||||
#from scene manager
|
#from scene manager
|
||||||
func crateTotal(howmany):
|
func crateTotal(howmany):
|
||||||
numberOfCrates = howmany
|
numberOfCrates = howmany
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
extends CharacterBody2D
|
class_name Player extends CharacterBody2D
|
||||||
|
|
||||||
@onready var label: Label = $Label
|
@onready var label: Label = $Label
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ func _ready() -> void:
|
|||||||
game.destroySignal.connect(destroy)
|
game.destroySignal.connect(destroy)
|
||||||
game.levelChangeSignal.connect(changeScene)
|
game.levelChangeSignal.connect(changeScene)
|
||||||
game.fanUpSignal.connect(push)
|
game.fanUpSignal.connect(push)
|
||||||
|
game.teleportSignal.connect(teleport)
|
||||||
buildLevel()
|
buildLevel()
|
||||||
|
|
||||||
func buildLevel()->void:
|
func buildLevel()->void:
|
||||||
@ -35,6 +36,15 @@ func updateCrates()->void:
|
|||||||
func push(body, direction)->void:
|
func push(body, direction)->void:
|
||||||
body.apply_central_impulse(direction)
|
body.apply_central_impulse(direction)
|
||||||
|
|
||||||
|
func teleport(body, _bodyposition=null)->void:
|
||||||
|
print("teleport a body")
|
||||||
|
if body is Crate:
|
||||||
|
var viewport_size = get_viewport().get_visible_rect().size
|
||||||
|
var random_x = randf_range(0, viewport_size.x)
|
||||||
|
var random_y = randf_range(0, viewport_size.y)
|
||||||
|
var newPosition = Vector2(random_x,random_y)
|
||||||
|
body.teleport_to(newPosition)
|
||||||
|
|
||||||
func destroy(body)->void:
|
func destroy(body)->void:
|
||||||
body.queue_free()
|
body.queue_free()
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
extends Area2D
|
extends Area2D
|
||||||
signal areaTriggerSignal(body, trigger, intent)
|
signal areaTriggerSignal(body, trigger, intent)
|
||||||
@export var intent:String="destroy"
|
@export var intent:String="destroy"
|
||||||
|
@onready var label: Label = $Label
|
||||||
|
|
||||||
# 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:
|
||||||
print("Trigger is ready.")
|
print("Trigger is ready.")
|
||||||
|
label.text = str(intent)
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user