add week3 (up to tilesets)

This commit is contained in:
KevinGorman committed 2025-01-20 20:44:35 -05:00
1 parent 3b09af598b
commit e49c3288b0
22 files changed
+609 -49

No files matched your search

+26 -9
View File
@@ -1,14 +1,31 @@
extends Area2D
class_name Bullet extends Area2D
@export var speed := 700
signal hit(bullet, body)
@onready var bulletGraphic: Sprite2D = $Sprite2D
func set_speed(speedval):
speed = speedval
var speed = 700
signal hit
func _physics_process(delta):
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
func _physics_process(delta: float) -> void:
position += transform.x * speed * delta
func _on_body_entered(body):
print ("Hit a thing") # Replace with function body.
func setSpeed(value):
speed = value
if speed < 0:
bulletGraphic.flip_h = true
else:
bulletGraphic.flip_h = false
func _on_body_entered(body: Node2D) -> void:
print("Bullet hit sumtin")
if not body.is_in_group("player"):
hit.emit(self, body)
+22 -17
View File
@@ -5,7 +5,7 @@ const SPEED = 500.0
const JUMP_VELOCITY = -600.0
@export var BUMP_FORCE = 90
@export var PUSH_FORCE = 700
@onready var animation: AnimatedSprite2D = $AnimatedSprite2D
var faceLeft = false
var pushLeftEnabled = false
@@ -19,14 +19,18 @@ var bullet = preload("res://scenes/bullet.tscn")
@onready var marker_right = $MarkerRight
@onready var marker_left = $MarkerLeft
var isJumping = false
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
else:
isJumping = false
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
isJumping = true
velocity.y = JUMP_VELOCITY
if pushTarget:
@@ -41,32 +45,33 @@ func _physics_process(delta: float) -> void:
pushRightEnabled = false
if Input.is_action_just_pressed("Shoot"):
var mybullet = bullet.instantiate()
print("I will shoot")
if faceLeft:
print("shoot left")
mybullet.set_speed(-700)
mybullet.transform = marker_right.global_transform
var _myBullet = %SceneManager.makeBullet(marker_left.global_transform, -700)
else:
print("shoot right")
mybullet.transform = marker_right.global_transform
owner.add_child(mybullet)
var _myBullet = %SceneManager.makeBullet(marker_right.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 < 0:
faceLeft = true
if direction > 0:
faceLeft = false
if direction:
if direction < 0:
faceLeft = true
if direction > 0:
faceLeft = false
animation.flip_h = faceLeft
if not isJumping:
animation.play("playerRun")
else:
animation.play("playerJump")
velocity.x = direction * SPEED
else:
if not isJumping:
animation.play("playerIdle")
else:
animation.play("playerJump")
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
+15 -9
View File
@@ -1,8 +1,11 @@
extends Node2D
var boxTotal = 3
var timer:= Timer.new()
@export var secondCount= 15
@export var secondCount= 30
var totalCrates := 0
signal destroyBox
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@@ -21,18 +24,21 @@ func secondCounter():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
func _process(_delta: float) -> void:
pass
func _on_trigger(effect: Variant, body) -> void:
func _on_trigger(_effect: Variant, body) -> void:
print("they were triggered!")
if body is RigidBody2D:
print("crate spotted")
boxTotal -= 1
body.queue_free()
if boxTotal <=0:
print("A winner is you")
get_tree().reload_current_scene()
func bulletHit(body):
print("Game controller knows bullet hit something")
if body.is_in_group("destructables"):
destroyBox.emit(body)
func countCrates(value):
totalCrates = value
+51
View File
@@ -0,0 +1,51 @@
extends Node
@onready var game: Node2D = $".."
@onready var crates: Node2D = $"../crates"
var theBullet = preload("res://scenes/bullet.tscn")
var bulletArray:Array = []
var totalCrates := 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
game.destroyBox.connect(boxDestroy)
for obj in crates.get_children():
if obj.is_in_group("destructables"):
totalCrates += 1
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
func bulletFactory():
print("Factory will make a bullet")
var myBullet
if bulletArray.size() < 4:
myBullet = theBullet.instantiate()
myBullet.connect("hit", onBulletHit)
owner.add_child(myBullet)
else:
myBullet = bulletArray.pop_back()
bulletArray.push_front(myBullet)
print("there are ", bulletArray.size(), " bullets")
return myBullet
func makeBullet(position, speed):
var myBullet = bulletFactory()
myBullet.transform = position
myBullet.setSpeed(speed)
return
func onBulletHit(bullet, body):
bullet.position = Vector2(-100, -100)
bullet.setSpeed(0)
print("Scene manager knows bullet hit")
game.bulletHit(body)
func boxDestroy(body):
print("sceneMgr knows body destroyed")
body.queue_free()
+1 -1
View File
@@ -9,7 +9,7 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
func _process(_delta: float) -> void:
pass