better documentation, class 1
This commit is contained in:
1 parent
246bdf0e98
commit
19b2d654d6
6 files changed
+64
-30
No files matched your search
@@ -10,11 +10,12 @@ var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
# Gravity applies any time character is not on floor
|
||||
if not is_on_floor():
|
||||
velocity.y += gravity * delta
|
||||
#eventually, gravity overcomes jump velocity (see below)
|
||||
|
||||
# Handle jump.
|
||||
# Only allow jump from starting on floor
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
@@ -25,7 +26,8 @@ func _physics_process(delta):
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
|
||||
#movde_and_slide is the big function - calculates all the positions and collisions
|
||||
move_and_slide()
|
||||
for i in get_slide_collision_count():
|
||||
var c = get_slide_collision(i)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
extends Area2D
|
||||
|
||||
#an @export is a nice way to expose a variable in the IDE
|
||||
#this could be handy when working in a team, working with others
|
||||
@export var effect = "alert"
|
||||
|
||||
#a custom signal is a way for one object to communicate to another
|
||||
#other objects must assign a handler function to hear about the custom signal
|
||||
signal areatrigger(effect, Object)
|
||||
|
||||
func _on_body_entered(body):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Node2D
|
||||
|
||||
var totalCrates = 2
|
||||
var cratesCollected = 0
|
||||
var totalCrates = 2 #This will be updated in the future, see SceneManager
|
||||
var cratesDestroyed = 0
|
||||
var timeLimit = 10
|
||||
var timer:= Timer.new()
|
||||
|
||||
@@ -21,11 +21,15 @@ func secondCounter():
|
||||
|
||||
|
||||
func _on_area_2d_areatrigger(effect, body):
|
||||
print("Game Controller sees the trigger")
|
||||
# check to ensure the collision is with the crates (RigidBodies)
|
||||
# A CharacterBody2D should not trigger a reaction to the collision
|
||||
if body is RigidBody2D:
|
||||
print("a crate entered trigger")
|
||||
cratesCollected +=1
|
||||
body.queue_free()
|
||||
if cratesCollected>=totalCrates:
|
||||
print("You win baby!")
|
||||
get_tree().reload_current_scene()
|
||||
# crate entered trigger
|
||||
# handle effects
|
||||
match effect:
|
||||
"destroy":
|
||||
cratesDestroyed +=1
|
||||
body.queue_free() # destroy the crate - again will move to SceneManager
|
||||
if cratesDestroyed>=totalCrates:
|
||||
print("You win baby!")
|
||||
get_tree().reload_current_scene()
|
||||
Reference in new issue
Block a user