week 2 prep
This commit is contained in:
1 parent
d0819ead77
commit
d8629e2f81
7 files changed
+63
-23
No files matched your search
@@ -1 +1,13 @@
|
||||
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
|
||||
+4
-1
@@ -6,6 +6,7 @@ var timeAvailable = 50
|
||||
signal destroySignal(body)
|
||||
signal levelChangeSignal(level)
|
||||
signal fanUpSignal(body,direction)
|
||||
signal teleportSignal(body)
|
||||
|
||||
var timer = Timer.new()
|
||||
# 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":
|
||||
if body is RigidBody2D:
|
||||
fanUpSignal.emit(body,Vector2(0,-1)*100*9)
|
||||
|
||||
"teleport":
|
||||
if body is Crate:
|
||||
teleportSignal.emit(body)
|
||||
#from scene manager
|
||||
func crateTotal(howmany):
|
||||
numberOfCrates = howmany
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
extends CharacterBody2D
|
||||
class_name Player extends CharacterBody2D
|
||||
|
||||
@onready var label: Label = $Label
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ func _ready() -> void:
|
||||
game.destroySignal.connect(destroy)
|
||||
game.levelChangeSignal.connect(changeScene)
|
||||
game.fanUpSignal.connect(push)
|
||||
game.teleportSignal.connect(teleport)
|
||||
buildLevel()
|
||||
|
||||
func buildLevel()->void:
|
||||
@@ -35,6 +36,15 @@ func updateCrates()->void:
|
||||
func push(body, direction)->void:
|
||||
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:
|
||||
body.queue_free()
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
extends Area2D
|
||||
signal areaTriggerSignal(body, trigger, intent)
|
||||
@export var intent:String="destroy"
|
||||
@onready var label: Label = $Label
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
print("Trigger is ready.")
|
||||
label.text = str(intent)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
||||
Reference in new issue
Block a user