character animations, gamecontroller
This commit is contained in:
1 parent
29acef878e
commit
714e46bf36
21 files changed
+498
-35
No files matched your search
@@ -1,4 +1,5 @@
|
||||
class_name Bullet extends Area2D
|
||||
@onready var bulletGraphic: Sprite2D = $Sprite2D
|
||||
|
||||
var speed = 700
|
||||
signal hit
|
||||
@@ -17,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("Bullet hit sumtin")
|
||||
if not body.is_in_group("player"):
|
||||
hit.emit(body)
|
||||
hit.emit(self, body)
|
||||
@@ -4,6 +4,7 @@ extends CharacterBody2D
|
||||
const SPEED = 500.0
|
||||
const JUMP_VELOCITY = -600.0
|
||||
@export var BUMP_FORCE = 90
|
||||
@onready var animation: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
# Shove Attack Variables
|
||||
@onready var right_ray: RayCast2D = $RightRay
|
||||
@@ -18,15 +19,21 @@ var pushLeftEnabled = false
|
||||
@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"):
|
||||
@@ -36,26 +43,33 @@ func _physics_process(delta: float) -> void:
|
||||
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2 )
|
||||
# Handle Shooting
|
||||
if Input.is_action_just_pressed("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,6 +3,9 @@ extends Node2D
|
||||
var boxTotal = 4
|
||||
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() -> void:
|
||||
@@ -36,5 +39,7 @@ 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,11 +1,23 @@
|
||||
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.
|
||||
@@ -14,10 +26,31 @@ 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()
|
||||
|
||||
Reference in new issue
Block a user