bullets playeranimations issue 4 scenemanager issue3 tilemaplayer issue5
This commit is contained in:
1 parent
887bdfbed3
commit
56da77cd2d
21 files changed
+570
-19
No files matched your search
@@ -1,10 +1,15 @@
|
||||
extends Area2D
|
||||
@onready var bulletsprite: Sprite2D = $Sprite2D
|
||||
|
||||
var speed := 700
|
||||
signal hit(bullet, body)
|
||||
|
||||
func setSpeed(speedVal):
|
||||
speed = speedVal
|
||||
if speedVal < 0:
|
||||
bulletsprite.flip_h = true
|
||||
else:
|
||||
bulletsprite.flip_h = false
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
position += transform.x * speed * delta
|
||||
|
||||
@@ -13,6 +13,7 @@ var pushRightEnabled = false
|
||||
@onready var left_ray: RayCast2D = $LeftRay
|
||||
@onready var marker_right: Node2D = $MarkerRight
|
||||
@onready var marker_left: Node2D = $MarkerLeft
|
||||
@onready var playerSprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
var pushTarget
|
||||
|
||||
@@ -39,32 +40,41 @@ func _physics_process(delta: float) -> void:
|
||||
pushRightEnabled=false
|
||||
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
print("I will shoot")
|
||||
var mybullet = bullet.instantiate()
|
||||
|
||||
|
||||
|
||||
if faceLeft:
|
||||
print("shoot left")
|
||||
mybullet.setSpeed(-700)
|
||||
mybullet.transform = marker_left.global_transform
|
||||
# mybullet.setSpeed(-700)
|
||||
#mybullet.transform = marker_left.global_transform
|
||||
%SceneManager.placeBullet(-700, marker_left.global_transform)
|
||||
else:
|
||||
print("shoot right")
|
||||
mybullet.transform = marker_right.global_transform
|
||||
|
||||
owner.add_child(mybullet)
|
||||
#mybullet.transform = marker_right.global_transform
|
||||
%SceneManager.placeBullet(700, marker_right.global_transform)
|
||||
|
||||
# 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
|
||||
playerSprite.flip_h = true
|
||||
if direction >0:
|
||||
faceLeft = false
|
||||
playerSprite.flip_h = false
|
||||
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
if is_on_floor():
|
||||
if direction == 0:
|
||||
playerSprite.play("idle")
|
||||
else:
|
||||
playerSprite.play("run")
|
||||
else:
|
||||
playerSprite.play("jump")
|
||||
|
||||
move_and_slide()
|
||||
for i in get_slide_collision_count():
|
||||
var c = get_slide_collision(i)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
extends Node
|
||||
var crate = preload("res://scenes/crate.tscn")
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletPool:Array = []
|
||||
# crate stuff
|
||||
var cratePool:Array = []
|
||||
@onready var box_trap_target: Node2D = $"../BoxTrapTarget"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
#pool all the crates
|
||||
for obj in owner.get_children():
|
||||
if obj.is_in_group("pushables"):
|
||||
cratePool.push_back(obj)
|
||||
print("Total crates on screen : "+str(cratePool.size() ) )
|
||||
|
||||
func boxTrap():
|
||||
print("Trigger a box trap!")
|
||||
var myCrate = crateFactory()
|
||||
myCrate.transform = box_trap_target.transform
|
||||
owner.add_child(myCrate)
|
||||
|
||||
func bulletFactory():
|
||||
# makes bullets!!
|
||||
var myBullet
|
||||
print("total bullets in play : "+str(bulletPool.size() ))
|
||||
if bulletPool.size() > 3:
|
||||
myBullet = bulletPool.pop_front()
|
||||
else:
|
||||
myBullet = bullet.instantiate()
|
||||
owner.add_child(myBullet)
|
||||
#or....recycles bullets
|
||||
return myBullet
|
||||
|
||||
func placeBullet(speed, markerpos):
|
||||
print("SceneManager: make a bullet")
|
||||
var myBullet = bulletFactory()
|
||||
bulletPool.push_back(myBullet)
|
||||
print("Total bullets in play: "+str(bulletPool.size() ) )
|
||||
# set the speed of bullet
|
||||
myBullet.setSpeed(speed)
|
||||
# set the position of the bullet
|
||||
myBullet.transform = markerpos
|
||||
# make the bullet visible by adding it
|
||||
|
||||
func crateFactory():
|
||||
var myCrate = crate.instantiate()
|
||||
myCrate.add_to_group("pushables")
|
||||
return myCrate
|
||||
@@ -13,6 +13,9 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print("Trigger is fired")
|
||||
if body.is_in_group("player"):
|
||||
print("player entered the trap")
|
||||
%SceneManager.boxTrap()
|
||||
|
||||
|
||||
func _on_body_exited(body: Node2D) -> void:
|
||||
|
||||
Reference in new issue
Block a user