week 2 update
This commit is contained in:
parent
4f0ed45ab5
commit
616afe6dbb
13
Scenes/bullet.tscn
Normal file
13
Scenes/bullet.tscn
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[gd_scene format=3 uid="uid://dvg70drsbendq"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://u1ubij2eih4r" path="res://Scripts/bullet.gd" id="1_xjght"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4mw4s"]
|
||||||
|
size = Vector2(10, 4)
|
||||||
|
|
||||||
|
[node name="Bullet" type="Area2D" unique_id=1549351635]
|
||||||
|
script = ExtResource("1_xjght")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=687436499]
|
||||||
|
shape = SubResource("RectangleShape2D_4mw4s")
|
||||||
|
debug_color = Color(0.9064841, 0.22817236, 0.5106338, 0.41960785)
|
||||||
@ -1,17 +1,13 @@
|
|||||||
[gd_scene format=3 uid="uid://bportqr2j3d7s"]
|
[gd_scene format=3 uid="uid://bportqr2j3d7s"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bwyucgbes44rd" path="res://Scripts/trigger.gd" id="1_ebmjs"]
|
|
||||||
[ext_resource type="Script" uid="uid://cvrssvw6p8myl" path="res://Scripts/game.gd" id="1_wrm1d"]
|
[ext_resource type="Script" uid="uid://cvrssvw6p8myl" path="res://Scripts/game.gd" id="1_wrm1d"]
|
||||||
[ext_resource type="Script" uid="uid://bfh1ec3bb5oki" path="res://Scripts/scene_manager.gd" id="2_3dryh"]
|
[ext_resource type="Script" uid="uid://bfh1ec3bb5oki" path="res://Scripts/scene_manager.gd" id="2_3dryh"]
|
||||||
[ext_resource type="Script" uid="uid://cq2vf132xjtli" path="res://Scripts/player.gd" id="2_qxrlw"]
|
[ext_resource type="PackedScene" uid="uid://dyb6tnhpivflf" path="res://Scenes/trigger.tscn" id="3_i6g32"]
|
||||||
[ext_resource type="PackedScene" uid="uid://b5y6rb2t0eaqr" path="res://Scenes/crate.tscn" id="3_wowpa"]
|
[ext_resource type="PackedScene" uid="uid://b5y6rb2t0eaqr" path="res://Scenes/crate.tscn" id="3_wowpa"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://en40721f6qwj" path="res://Scenes/player.tscn" id="4_wowpa"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2poj3"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2poj3"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_2poj3"]
|
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ebmjs"]
|
|
||||||
|
|
||||||
[node name="Game" type="Node2D" unique_id=1651082265]
|
[node name="Game" type="Node2D" unique_id=1651082265]
|
||||||
script = ExtResource("1_wrm1d")
|
script = ExtResource("1_wrm1d")
|
||||||
|
|
||||||
@ -43,25 +39,11 @@ metadata/_edit_group_ = true
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Floor3" unique_id=92737610]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Floor3" unique_id=92737610]
|
||||||
shape = SubResource("RectangleShape2D_2poj3")
|
shape = SubResource("RectangleShape2D_2poj3")
|
||||||
|
|
||||||
[node name="Trigger" type="Area2D" parent="." unique_id=1126418572]
|
[node name="Trigger" parent="." unique_id=1055766094 instance=ExtResource("3_i6g32")]
|
||||||
position = Vector2(627, 517)
|
position = Vector2(627, 517)
|
||||||
scale = Vector2(4.6, 4.6)
|
|
||||||
script = ExtResource("1_ebmjs")
|
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Trigger" unique_id=2040815744]
|
[node name="Player" parent="." unique_id=478864706 instance=ExtResource("4_wowpa")]
|
||||||
shape = SubResource("CircleShape2D_2poj3")
|
|
||||||
debug_color = Color(0.47473383, 0.5864115, 0.1707469, 0.41960785)
|
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" parent="." unique_id=1131424030]
|
|
||||||
position = Vector2(538.00006, 420)
|
position = Vector2(538.00006, 420)
|
||||||
scale = Vector2(1.64, 1.64)
|
|
||||||
script = ExtResource("2_qxrlw")
|
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player" unique_id=628686782]
|
|
||||||
shape = SubResource("CircleShape2D_ebmjs")
|
|
||||||
debug_color = Color(0.6308279, 0.36922106, 0.95607406, 0.41960785)
|
|
||||||
|
|
||||||
[node name="Crates" type="Node2D" parent="." unique_id=799685623]
|
[node name="Crates" type="Node2D" parent="." unique_id=799685623]
|
||||||
|
|
||||||
@ -72,4 +54,3 @@ position = Vector2(683, 406)
|
|||||||
position = Vector2(716, 382)
|
position = Vector2(716, 382)
|
||||||
|
|
||||||
[connection signal="areaTriggerSignal" from="Trigger" to="." method="_on_trigger"]
|
[connection signal="areaTriggerSignal" from="Trigger" to="." method="_on_trigger"]
|
||||||
[connection signal="body_entered" from="Trigger" to="Trigger" method="_on_body_entered"]
|
|
||||||
|
|||||||
26
Scenes/player.tscn
Normal file
26
Scenes/player.tscn
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
[gd_scene format=3 uid="uid://en40721f6qwj"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://cq2vf132xjtli" path="res://Scripts/player.gd" id="1_v0iea"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_ebmjs"]
|
||||||
|
|
||||||
|
[node name="Player" type="CharacterBody2D" unique_id=478864706]
|
||||||
|
scale = Vector2(1.64, 1.64)
|
||||||
|
script = ExtResource("1_v0iea")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=842765438]
|
||||||
|
shape = SubResource("CircleShape2D_ebmjs")
|
||||||
|
debug_color = Color(0.6308279, 0.36922106, 0.95607406, 0.41960785)
|
||||||
|
|
||||||
|
[node name="RightCast" type="RayCast2D" parent="." unique_id=448970826]
|
||||||
|
target_position = Vector2(17.073172, 0)
|
||||||
|
|
||||||
|
[node name="LeftCast" type="RayCast2D" parent="." unique_id=1038607459]
|
||||||
|
target_position = Vector2(-17.073172, 0)
|
||||||
|
|
||||||
|
[node name="RightSpawn" type="Marker2D" parent="." unique_id=1358832037]
|
||||||
|
position = Vector2(11.585366, -8.536586)
|
||||||
|
|
||||||
|
[node name="LeftSpawn" type="Marker2D" parent="." unique_id=1880777693]
|
||||||
|
position = Vector2(-12.195123, -8.536585)
|
||||||
16
Scenes/trigger.tscn
Normal file
16
Scenes/trigger.tscn
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[gd_scene format=3 uid="uid://dyb6tnhpivflf"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://bwyucgbes44rd" path="res://Scripts/trigger.gd" id="1_vcq5i"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_2poj3"]
|
||||||
|
|
||||||
|
[node name="Trigger" type="Area2D" unique_id=1055766094]
|
||||||
|
scale = Vector2(4.6, 4.6)
|
||||||
|
script = ExtResource("1_vcq5i")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1717927145]
|
||||||
|
shape = SubResource("CircleShape2D_2poj3")
|
||||||
|
debug_color = Color(0.47473383, 0.5864115, 0.1707469, 0.41960785)
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
13
Scripts/bullet.gd
Normal file
13
Scripts/bullet.gd
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class_name Bullet extends Area2D
|
||||||
|
var speed:float = 700
|
||||||
|
signal bulletHitSignal(body, bullet)
|
||||||
|
func setSpeed(value)->void:
|
||||||
|
speed = value
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
position += transform.x * speed * delta
|
||||||
|
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
|
if body is Crate:
|
||||||
|
bulletHitSignal.emit(body,self)
|
||||||
1
Scripts/bullet.gd.uid
Normal file
1
Scripts/bullet.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://u1ubij2eih4r
|
||||||
@ -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
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
extends Node2D
|
class_name GameController extends Node2D
|
||||||
|
signal destroySignal(body)
|
||||||
|
|
||||||
var numberOfCrates = 2
|
var numberOfCrates = 2
|
||||||
var timer = Timer.new()
|
var timer = Timer.new()
|
||||||
var timeAvailable = 5
|
var timeAvailable = 50
|
||||||
|
|
||||||
# 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:
|
||||||
|
get_window().grab_focus()
|
||||||
add_child(timer)
|
add_child(timer)
|
||||||
# time based on seconds
|
# time based on seconds
|
||||||
timer.wait_time = 1
|
timer.wait_time = 1
|
||||||
@ -26,14 +28,18 @@ func _process(delta: float) -> void:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _on_trigger(body: Variant, trigger: Variant) -> void:
|
func _on_trigger(body: Variant, trigger: Variant, intent:String) -> void:
|
||||||
print("Game controller knows trigger fired")
|
print("Game controller knows trigger fired")
|
||||||
body.queue_free()
|
match intent:
|
||||||
numberOfCrates -= 1
|
"destroy":
|
||||||
if numberOfCrates == 0:
|
destroySignal.emit(body)
|
||||||
print("WINNER!")
|
|
||||||
get_tree().reload_current_scene()
|
|
||||||
|
|
||||||
func crateTotal(howMany):
|
func crateTotal(howMany):
|
||||||
numberOfCrates = howMany
|
numberOfCrates = howMany
|
||||||
print("GC knows crates: "+str(numberOfCrates))
|
print("GC knows crates: "+str(numberOfCrates))
|
||||||
|
if numberOfCrates == 0:
|
||||||
|
print("YOU WON!!!")
|
||||||
|
get_tree().reload_current_scene()
|
||||||
|
func bulletDamage(body, _bullet)->void:
|
||||||
|
if body.is_in_group("shootable"):
|
||||||
|
destroySignal.emit(body)
|
||||||
|
|||||||
@ -1,9 +1,21 @@
|
|||||||
extends CharacterBody2D
|
class_name Player extends CharacterBody2D
|
||||||
|
signal pushSignal(body, direction)
|
||||||
|
signal shootSignal(markerPosition, speed)
|
||||||
|
|
||||||
const SPEED = 300.0
|
const SPEED = 300.0
|
||||||
const JUMP_VELOCITY = -400.0
|
const JUMP_VELOCITY = -400.0
|
||||||
|
@onready var right_cast: RayCast2D = $RightCast
|
||||||
|
@onready var left_cast: RayCast2D = $LeftCast
|
||||||
|
@onready var right_spawn: Marker2D = $RightSpawn
|
||||||
|
@onready var left_spawn: Marker2D = $LeftSpawn
|
||||||
|
|
||||||
|
var pushRightEnabled = false
|
||||||
|
var pushLeftEnabled = false
|
||||||
|
var pushTarget
|
||||||
|
var pushTimer = 0
|
||||||
|
|
||||||
|
enum FaceDirection {RIGHT,LEFT}
|
||||||
|
var facing:FaceDirection = FaceDirection.RIGHT
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
# Add the gravity.
|
# Add the gravity.
|
||||||
@ -13,17 +25,59 @@ func _physics_process(delta: float) -> void:
|
|||||||
# Handle jump.
|
# Handle jump.
|
||||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||||
velocity.y = JUMP_VELOCITY
|
velocity.y = JUMP_VELOCITY
|
||||||
|
#Handle shove target
|
||||||
|
if Input.is_action_just_pressed("shove"):
|
||||||
|
print("I want to shove")
|
||||||
|
pushTimer = Time.get_ticks_msec()
|
||||||
|
if Input.is_action_just_released("shove"):
|
||||||
|
var pushForce = Time.get_ticks_msec() - pushTimer
|
||||||
|
if pushForce>4000:
|
||||||
|
pushForce=4000
|
||||||
|
if pushRightEnabled and facing==FaceDirection.RIGHT:
|
||||||
|
#deliver the boom
|
||||||
|
pushSignal.emit(pushTarget, Vector2(1,0)*100*(pushForce/100))
|
||||||
|
if pushLeftEnabled and facing==FaceDirection.LEFT:
|
||||||
|
pushSignal.emit(pushTarget, Vector2(-1,0)*100*(pushForce/100))
|
||||||
|
|
||||||
|
#Handle Shoot Bullet
|
||||||
|
if Input.is_action_just_pressed("shoot"):
|
||||||
|
print("Ima shoot a bullet")
|
||||||
|
#marker postion, speed
|
||||||
|
match facing:
|
||||||
|
FaceDirection.RIGHT:
|
||||||
|
shootSignal.emit(right_spawn.global_transform, 800)
|
||||||
|
FaceDirection.LEFT:
|
||||||
|
shootSignal.emit(left_spawn.global_transform, -800)
|
||||||
# Get the input direction and handle the movement/deceleration.
|
# Get the input direction and handle the movement/deceleration.
|
||||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||||
var direction := Input.get_axis("ui_left", "ui_right")
|
var direction := Input.get_axis("ui_left", "ui_right")
|
||||||
if direction:
|
if direction:
|
||||||
velocity.x = direction * SPEED
|
velocity.x = direction * SPEED
|
||||||
|
if direction >0:
|
||||||
|
facing = FaceDirection.RIGHT
|
||||||
|
else:
|
||||||
|
facing = FaceDirection.LEFT
|
||||||
else:
|
else:
|
||||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
if right_cast.is_colliding():
|
||||||
|
print("Right raycast collision")
|
||||||
|
var collider = right_cast.get_collider()
|
||||||
|
if collider is Node:
|
||||||
|
pushRightEnabled = true
|
||||||
|
pushTarget = collider
|
||||||
|
else:
|
||||||
|
pushRightEnabled = false
|
||||||
|
|
||||||
|
if left_cast.is_colliding():
|
||||||
|
print("Left raycast collision")
|
||||||
|
var collider = left_cast.get_collider()
|
||||||
|
if collider is Node:
|
||||||
|
pushLeftEnabled = true
|
||||||
|
pushTarget = collider
|
||||||
|
else:
|
||||||
|
pushLeftEnabled = false
|
||||||
#a loop
|
#a loop
|
||||||
for i in get_slide_collision_count():
|
for i in get_slide_collision_count():
|
||||||
var c = get_slide_collision(i)
|
var c = get_slide_collision(i)
|
||||||
|
|||||||
@ -1,10 +1,20 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
# hold control and drag + drop
|
# hold control and drag + drop
|
||||||
@onready var game: Node2D = $".."
|
@onready var game:GameController = $".."
|
||||||
@onready var crates: Node2D = $"../Crates"
|
@onready var crates: Node2D = $"../Crates"
|
||||||
|
@onready var player: Player = $"../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.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
player.pushSignal.connect(pushTarget)
|
||||||
|
player.shootSignal.connect(makeBullet)
|
||||||
|
|
||||||
|
#signals from the GameController
|
||||||
|
game.destroySignal.connect(destroy)
|
||||||
buildLevel()
|
buildLevel()
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
@ -12,11 +22,39 @@ func _process(delta: float) -> void:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
func buildLevel() -> void:
|
func buildLevel() -> void:
|
||||||
# Tell GC how many crates
|
#tell GC how many crates...
|
||||||
|
updateCrates()
|
||||||
|
func updateCrates()->void:
|
||||||
var totalCrates = 0
|
var totalCrates = 0
|
||||||
# check if any crates in scene
|
|
||||||
if crates:
|
if crates:
|
||||||
for obj in crates.get_children():
|
for obj in crates.get_children():
|
||||||
if obj is Crate:
|
if obj is Crate:
|
||||||
totalCrates += 1
|
if not obj.tree_exited.is_connected(updateCrates):
|
||||||
|
obj.tree_exited.connect(updateCrates)
|
||||||
|
totalCrates +=1
|
||||||
|
|
||||||
game.crateTotal(totalCrates)
|
game.crateTotal(totalCrates)
|
||||||
|
func pushTarget(body,pushDirection)->void:
|
||||||
|
if body is RigidBody2D:
|
||||||
|
body.apply_central_impulse(pushDirection)
|
||||||
|
func destroy(body)->void:
|
||||||
|
body.queue_free()
|
||||||
|
func bulletFactory()->Bullet:
|
||||||
|
var myBullet:Bullet
|
||||||
|
#how many bullets have been produced?
|
||||||
|
if bulletArray.size() <= totalAllowedBullets:
|
||||||
|
#make a new bullet
|
||||||
|
myBullet = bullet.instantiate()
|
||||||
|
add_sibling(myBullet)
|
||||||
|
if not myBullet.bulletHitSignal.is_connected(game.bulletDamage):
|
||||||
|
myBullet.bulletHitSignal.connect(game.bulletDamage)
|
||||||
|
else:
|
||||||
|
myBullet = bulletArray.pop_back()
|
||||||
|
|
||||||
|
bulletArray.push_front(myBullet)
|
||||||
|
return myBullet
|
||||||
|
func makeBullet(spawnPosition, speed)->void:
|
||||||
|
print("make bullet")
|
||||||
|
var myBullet:Bullet = bulletFactory()
|
||||||
|
myBullet.transform = spawnPosition
|
||||||
|
myBullet.setSpeed(speed)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
extends Area2D
|
class_name Trigger extends Area2D
|
||||||
signal areaTriggerSignal(body, trigger)
|
signal areaTriggerSignal(body, trigger, intent)
|
||||||
|
@export var intent = "destroy"
|
||||||
|
|
||||||
# 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:
|
||||||
@ -13,4 +14,4 @@ func _process(delta: float) -> void:
|
|||||||
|
|
||||||
func _on_body_entered(body: Node2D) -> void:
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
print("YEAHHHHH TRIGGERED")
|
print("YEAHHHHH TRIGGERED")
|
||||||
areaTriggerSignal.emit(body, self)
|
areaTriggerSignal.emit(body, self, intent)
|
||||||
|
|||||||
@ -15,6 +15,19 @@ run/main_scene="uid://bportqr2j3d7s"
|
|||||||
config/features=PackedStringArray("4.6", "Forward Plus")
|
config/features=PackedStringArray("4.6", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
shove={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
shoot={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
3d/physics_engine="Jolt Physics"
|
3d/physics_engine="Jolt Physics"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user