sprites, character animations

This commit is contained in:
GabriellePipo committed 2025-01-20 20:44:30 -05:00
1 parent 8adfc2b674
commit 6650e5ae9d
21 files changed
+554 -31

No files matched your search

+8 -1
View File
@@ -1,6 +1,9 @@
class_name Bullet extends Area2D
@onready var bulletGraphic: Sprite2D = $Sprite2D
var speed = 700
signal hit
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
@@ -15,9 +18,13 @@ func _physics_process(delta: float) -> void:
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("hit")
if not body.is_in_group("player"):
hit.emit(body)
hit.emit(self, body)
+8 -1
View File
@@ -2,6 +2,10 @@ extends Node2D
var totalBoxes = 3
var timer:= Timer.new()
var countdown = 10
var totalCrates = 0
signal destroyBox(body)
# Called when the node enters the scene tree for the first time.
func _ready():
add_child(timer)
@@ -31,4 +35,7 @@ func _on_trigger_alert(body):
func bulletHit(body):
print("game controller knows bullet hit something")
if body.is_in_group("destructable"):
body.queue_free()
destroyBox.emit(body)
func coutnCrates(value):
totalCrates = value
+21 -7
View File
@@ -4,6 +4,7 @@ extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
@export var BUMP_FORCE = 90
@onready var animation: AnimatedSprite2D = $AnimatedSprite2D
# Shove attack
@onready var right_ray: RayCast2D = $RightRay
@@ -22,14 +23,18 @@ var bullet = preload("res://scenes/bullet.tscn")
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var isJumping = false
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
else:
isJumping = false
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
animation.play("jump")
isJumping = true
# shove attack
if Input.is_action_just_pressed("shove"):
@@ -41,10 +46,18 @@ func _physics_process(delta):
if direction:
velocity.x = direction * SPEED
if direction<0:
if not isJumping:
animation.play("run")
faceleft = true
animation.flip_h = true
if direction>0:
if not isJumping:
animation.play("run")
faceleft = false
animation.flip_h = false
else:
if not isJumping:
animation.play("idle")
velocity.x = move_toward(velocity.x, 0, SPEED)
@@ -52,12 +65,13 @@ func _physics_process(delta):
if Input.is_action_just_pressed("shoot"):
# make bullet
var myBullet = %SceneManager.bulletFactory()
owner.add_child(myBullet)
myBullet.transform = right_target.global_transform
if faceleft:
myBullet.transform = left_target.global_transform
myBullet.setSpeed(-700)
#owner.add_child(myBullet)
#myBullet.transform = right_target.global_transform
if faceleft == true:
var myBullet = %SceneManager.makeBullet(left_target.global_transform,-700)
if faceleft == false:
var myBullet = %SceneManager.makeBullet(right_target.global_transform,700)
move_and_slide()
if right_ray.is_colliding():
+32 -4
View File
@@ -1,11 +1,20 @@
extends Node
@onready var game: Node2D = $".."
@onready var crates: Node2D = $"../crates"
var bullet = preload("res://scenes/bullet.tscn")
var bulletArray:Array = []
var bulletMadeTotal:= 0
var totalCrates := 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
game.destroyBox.connect(boxDestroy)
for obj in crates.get_children():
if obj.is_in_group("destructable"):
#increase box counter
totalCrates +=1
# Called every frame. 'delta' is the elapsed time since the previous frame.
@@ -14,10 +23,29 @@ func _process(delta: float) -> void:
func bulletFactory():
print("factory will make a bullet")
var myBullet = bullet.instantiate()
myBullet.connect("hit", onBulletHit)
var myBullet
if bulletArray.size() < 4:
myBullet = bullet.instantiate()
myBullet.connect("hit", onBulletHit)
owner.add_child(myBullet)
else:
myBullet = bulletArray.pop_back()
bulletArray.push_front(myBullet)
return myBullet
func onBulletHit(body):
func makeBullet(position, speed):
var myBullet = bulletFactory()
myBullet.transform = position
myBullet.setSpeed(speed)
return myBullet
func onBulletHit(bullet, body):
bullet.position = Vector2(-100,-100)
bullet.setSpeed(0)
print("Scene manager knows bullet hit")
game.bulletHit(body)
func boxDestroy(body):
body.queue_free()