week 2 prep
This commit is contained in:
1 parent
d5fc80ff7b
commit
7824bcd6cd
11 files changed
+279
-57
No files matched your search
@@ -0,0 +1,19 @@
|
||||
class_name Bullet extends Area2D
|
||||
|
||||
var speed:float = 700
|
||||
|
||||
signal bulletDamageSignal(body, bullet)
|
||||
|
||||
func setSpeed(value:int)->void:
|
||||
speed = value
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
position += transform.x * speed *delta
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
bulletDamageSignal.emit(body, self)
|
||||
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
bulletDamageSignal.emit(area, self)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bvy43aky6y3er
|
||||
+23
-14
@@ -1,11 +1,16 @@
|
||||
extends Node2D
|
||||
|
||||
var numberOfCrates = 2
|
||||
var timeAvailable = 5
|
||||
var timeAvailable = 50
|
||||
|
||||
signal destroySignal(body)
|
||||
signal levelChangeSignal(level)
|
||||
signal fanUpSignal(body,direction)
|
||||
|
||||
var timer = Timer.new()
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
get_window().grab_focus()
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
timer.one_shot = false
|
||||
@@ -17,21 +22,25 @@ func countdown()->void:
|
||||
timeAvailable-=1
|
||||
if timeAvailable<=0 and numberOfCrates>0:
|
||||
print("LOOOOOSAH")
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
levelChangeSignal.emit("res://scenes/game.tscn")
|
||||
|
||||
func _on_trigger(body: Variant, trigger: Variant, intent:String) -> void:
|
||||
print("GC knows trigger fired "+intent)
|
||||
match intent:
|
||||
"destroy":
|
||||
print("GC sending destroy signal")
|
||||
destroySignal.emit(body)
|
||||
"fan":
|
||||
if body is RigidBody2D:
|
||||
fanUpSignal.emit(body,Vector2(0,-1)*100*9)
|
||||
|
||||
func _on_trigger(body: Variant, trigger: Variant) -> void:
|
||||
print("GC knows trigger fired")
|
||||
body.queue_free()
|
||||
numberOfCrates -=1
|
||||
if numberOfCrates == 0:
|
||||
print("YOU WON!!!")
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
#from scene manager
|
||||
func crateTotal(howmany):
|
||||
numberOfCrates = howmany
|
||||
print("GC knows about crates: "+str(numberOfCrates))
|
||||
if numberOfCrates == 0:
|
||||
print("YOU WON!!!")
|
||||
levelChangeSignal.emit("res://scenes/game.tscn")
|
||||
|
||||
func bulletDamage()->void:
|
||||
print("bullet damage")
|
||||
+72
-2
@@ -1,10 +1,28 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@onready var label: Label = $Label
|
||||
|
||||
@onready var rightRay: RayCast2D = $RightCast
|
||||
@onready var leftRay: RayCast2D = $LeftCast
|
||||
@onready var right_target: Marker2D = $RightTarget
|
||||
@onready var left_target: Marker2D = $LeftTarget
|
||||
|
||||
|
||||
var pushRightEnabled:=false
|
||||
var pushLeftEnabled := false
|
||||
var pushTarget
|
||||
var pushTimer:int = 0
|
||||
|
||||
signal forcePushSignal(body,direction)
|
||||
signal shootSignal(targetPosition, speed)
|
||||
#track facing direction
|
||||
enum FaceDirection {LEFT,RIGHT}
|
||||
var facing:FaceDirection = FaceDirection.RIGHT
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
@@ -13,12 +31,45 @@ func _physics_process(delta: float) -> void:
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
|
||||
# Handle shove
|
||||
if Input.is_action_just_pressed("shove"):
|
||||
pushTimer = Time.get_ticks_msec() #record start of build
|
||||
|
||||
#Handle shove
|
||||
if Input.is_action_just_released("shove"):
|
||||
var pushForce = Time.get_ticks_msec() - pushTimer
|
||||
#do a maximium force value
|
||||
if pushForce>4000:
|
||||
pushForce = 4000
|
||||
if pushRightEnabled and facing==FaceDirection.RIGHT:
|
||||
label.text = "shove"
|
||||
forcePushSignal.emit(pushTarget, Vector2(1,0)*100*(pushForce/100))
|
||||
if pushLeftEnabled and facing==FaceDirection.LEFT:
|
||||
forcePushSignal.emit(pushTarget, Vector2(-1,0)*100*(pushForce/100))
|
||||
label.text = "shove"
|
||||
# Handle Shoot
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
print("Player wants to shoot")
|
||||
match facing:
|
||||
FaceDirection.RIGHT:
|
||||
print("Shoot to the right")
|
||||
#%SceneManager.makeBullet(right_target.global_transform, 700)
|
||||
shootSignal.emit(right_target.global_transform, 700)
|
||||
FaceDirection.LEFT:
|
||||
print("Shoot to the left")
|
||||
#%SceneManager.makeBullet(left_target.global_transform, -700)
|
||||
shootSignal.emit(left_target.global_transform, -700)
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction := Input.get_axis("ui_left", "ui_right")
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
if direction>0:
|
||||
facing = FaceDirection.RIGHT
|
||||
else:
|
||||
facing = FaceDirection.LEFT
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
@@ -29,3 +80,22 @@ func _physics_process(delta: float) -> void:
|
||||
#is this a bonkable thing?
|
||||
if c.get_collider() is RigidBody2D:
|
||||
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
||||
if rightRay.is_colliding():
|
||||
|
||||
#get the thing causing the collision
|
||||
var collider = rightRay.get_collider()
|
||||
if collider is Node:
|
||||
pushRightEnabled = true
|
||||
pushTarget = collider
|
||||
else:
|
||||
pushRightEnabled = false
|
||||
|
||||
if leftRay.is_colliding():
|
||||
|
||||
#get the thing causing the collision
|
||||
var collider = leftRay.get_collider()
|
||||
if collider is Node:
|
||||
pushLeftEnabled = true
|
||||
pushTarget = collider
|
||||
else:
|
||||
pushLeftEnabled = false
|
||||
@@ -1,23 +1,62 @@
|
||||
extends Node2D
|
||||
@onready var game: Node2D = $".."
|
||||
@onready var crates: Node2D = $"../Crates"
|
||||
@onready var player: CharacterBody2D = $"../Player"
|
||||
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletArray:Array[Bullet] = []
|
||||
var totalAllowedBullets:int = 7
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
#wire up view
|
||||
player.forcePushSignal.connect(push)
|
||||
player.shootSignal.connect(makeBullet)
|
||||
#wire up gamecontroller
|
||||
game.destroySignal.connect(destroy)
|
||||
game.levelChangeSignal.connect(changeScene)
|
||||
game.fanUpSignal.connect(push)
|
||||
buildLevel()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func buildLevel()->void:
|
||||
#tell GC how many crates...
|
||||
var totalCrates = 0
|
||||
updateCrates()
|
||||
|
||||
func updateCrates()->void:
|
||||
var _crateTotal:int = 0
|
||||
if crates:
|
||||
for obj in crates.get_children():
|
||||
if obj is Crate:
|
||||
totalCrates +=1
|
||||
if not obj.tree_exited.is_connected(updateCrates):
|
||||
obj.tree_exited.connect(updateCrates)
|
||||
_crateTotal +=1
|
||||
game.crateTotal(_crateTotal)
|
||||
|
||||
game.crateTotal(totalCrates)
|
||||
#applies impulse to rigidbodies
|
||||
func push(body, direction)->void:
|
||||
body.apply_central_impulse(direction)
|
||||
|
||||
func destroy(body)->void:
|
||||
body.queue_free()
|
||||
|
||||
func changeScene(level)->void:
|
||||
get_tree().call_deferred("change_scene_to_file",level)
|
||||
|
||||
func bulletFactory()->Bullet :
|
||||
var myBullet:Bullet
|
||||
#how many bullets have been made?
|
||||
if bulletArray.size() <= totalAllowedBullets:
|
||||
myBullet = bullet.instantiate()
|
||||
if not myBullet.bulletDamageSignal.is_connected(game.bulletDamage):
|
||||
myBullet.bulletDamageSignal.connect(game.bulletDamage)
|
||||
add_sibling(myBullet)
|
||||
else:
|
||||
myBullet = bulletArray.pop_back()
|
||||
|
||||
bulletArray.push_front(myBullet)
|
||||
return myBullet
|
||||
|
||||
func makeBullet(targetPosition:Transform2D, speed:int)->void:
|
||||
var myBullet:Bullet = bulletFactory()
|
||||
myBullet.transform = targetPosition
|
||||
myBullet.setSpeed(speed)
|
||||
myBullet.set_process(true)
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
extends Area2D
|
||||
signal areaTriggerSignal(body, trigger)
|
||||
signal areaTriggerSignal(body, trigger, intent)
|
||||
@export var intent:String="destroy"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@@ -13,4 +14,4 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print("Something entered the trigger!")
|
||||
areaTriggerSignal.emit(body, self)
|
||||
areaTriggerSignal.emit(body, self, intent)
|
||||
Reference in new issue
Block a user