character animations, gamecontroller
This commit is contained in:
1 parent
205e8d43b5
commit
65ad562241
21 files changed
+556
-36
No files matched your search
@@ -1,4 +1,5 @@
|
||||
class_name Bullet extends Area2D
|
||||
@onready var bulletGraphic: Sprite2D = $Sprite2D
|
||||
|
||||
var speed = 700
|
||||
signal hit
|
||||
@@ -16,9 +17,13 @@ func _physics_process(delta: float) -> void:
|
||||
position += transform.x * speed * delta
|
||||
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 hits something")
|
||||
if not body.is_in_group("player"):
|
||||
hit.emit(body)
|
||||
hit.emit(self, body)
|
||||
@@ -13,21 +13,25 @@ var pushTarget
|
||||
var pushRightEnabled = false
|
||||
var pushLeftEnabled = false
|
||||
@export var PUSH_FORCE = 700
|
||||
@onready var animation: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
# Bullet Attack Variables
|
||||
@onready var right_target: Node2D = $RightTarget
|
||||
@onready var left_target: Node2D = $LeftTarget
|
||||
|
||||
|
||||
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("jump") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
animation.play("jump")
|
||||
isJumping = true
|
||||
|
||||
# Shove Attack
|
||||
if Input.is_action_just_pressed("shove"):
|
||||
@@ -39,25 +43,33 @@ func _physics_process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
#print("I want to shoot")
|
||||
#make a new bullet
|
||||
var myBullet = %SceneManager.bulletFactory()
|
||||
|
||||
#var myBullet = bullet.instantiate()
|
||||
owner.add_child(myBullet)
|
||||
myBullet.transform = right_target.global_transform
|
||||
|
||||
|
||||
if faceLeft == true:
|
||||
myBullet.transform = left_target.global_transform
|
||||
myBullet.setSpeed(-700)
|
||||
|
||||
var myBullet = %SceneManager.makeBullet(left_target.global_transform,-700)
|
||||
#myBullet.transform = left_target.global_transform
|
||||
#myBullet.setSpeed(-700)
|
||||
if faceLeft == false:
|
||||
var myBullet = %SceneManager.makeBullet(right_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("left", "right")
|
||||
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)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
@@ -3,7 +3,8 @@ extends Node2D
|
||||
var boxTotal = 4
|
||||
var timer:=Timer.new()
|
||||
var countdown = 10
|
||||
|
||||
var totalCrates = 0
|
||||
signal destroyBox(body)
|
||||
# C alled when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
add_child(timer)
|
||||
@@ -37,4 +38,8 @@ func _on_trigger(effect: Variant, body) -> void:
|
||||
func bulletHit(body):
|
||||
print("Game controller knows bullet hit something")
|
||||
if body.is_in_group("destructable"):
|
||||
body.queue_free()
|
||||
destroyBox.emit(body)
|
||||
|
||||
func countCrates(value):
|
||||
totalCrates = value
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
extends Node
|
||||
@onready var game: Node2D = $".."
|
||||
@onready var crates: Node2D = $"../crates"
|
||||
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletArray:Array = []
|
||||
var bulletsMadeTotal :=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 the box counter
|
||||
totalCrates +=1
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
@@ -13,10 +23,28 @@ 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() < 10:
|
||||
myBullet = bullet.instantiate()
|
||||
myBullet.connect("hit", onBulletHit)
|
||||
owner.add_child(myBullet)
|
||||
else:
|
||||
myBullet = bulletArray.pop_back()
|
||||
bulletArray.push_front(myBullet)
|
||||
return myBullet
|
||||
func makeBullet(position, speed):
|
||||
var myBullet = bulletFactory()
|
||||
myBullet.transform = position
|
||||
myBullet.setSpeed(speed)
|
||||
|
||||
return myBullet
|
||||
|
||||
|
||||
func onBulletHit(body):
|
||||
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("test")
|
||||
body.queue_free()
|
||||
Reference in new issue
Block a user