state machine, graphics, tilemaplayer, terrains, physicslayer

This commit is contained in:
OddlyTimbot committed 2026-07-06 20:58:50 -04:00
1 parent 5fb367e082
commit bb9f58ae08
21 files changed
+976 -14

No files matched your search

+2
View File
@@ -49,6 +49,8 @@ func crateTotal(howmany):
func bulletDamage(body, _bullet)->void:
if body.is_in_group("shootable"):
destroySignal.emit(body)
destroySignal.emit(_bullet)
func rocketDamage(body, rocket)->void:
if body.is_in_group("shootable"):
print("Rocket strikes target!")
+69 -7
View File
@@ -6,6 +6,7 @@ signal fireSignal(markerPosition, direction, speed)
@onready var left_cast: RayCast2D = $LeftCast
@onready var right_spawn: Marker2D = $RightSpawn
@onready var left_spawn: Marker2D = $LeftSpawn
@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic
var pushRightEnabled = false
var pushLeftEnabled = false
@@ -18,18 +19,34 @@ const JUMP_VELOCITY = -400.0
enum FaceDirection {RIGHT,LEFT}
var facing:FaceDirection = FaceDirection.RIGHT
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
enum PlayerStates {IDLE,RUNNING,JUMPING,FALLING,CHARGING,SHOVING}
var current_player_state:PlayerStates = PlayerStates.IDLE
var upJump:bool = false
func _physics_process(delta: float) -> void:
handle_input()
handle_movement(delta)
handle_states()
handle_animation()
move_and_slide()
handle_collisions()
func handle_input()->void:
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
current_player_state=PlayerStates.JUMPING
upJump = true
# Handle shove.
if Input.is_action_just_pressed("shove"):
print("I want to shove")
pushTimer = Time.get_ticks_msec()
if pushRightEnabled and facing==FaceDirection.RIGHT:
current_player_state= PlayerStates.CHARGING
pushTimer = Time.get_ticks_msec()
if pushLeftEnabled and facing==FaceDirection.LEFT:
current_player_state= PlayerStates.CHARGING
pushTimer = Time.get_ticks_msec()
if Input.is_action_just_released("shove"):
var pushForce = Time.get_ticks_msec() - pushTimer
if pushForce>4000:
@@ -37,8 +54,10 @@ func _physics_process(delta: float) -> void:
if pushRightEnabled and facing==FaceDirection.RIGHT:
#deliver the boom
pushSignal.emit(pushTarget, Vector2(1,0)*100*(pushForce/100))
current_player_state = PlayerStates.SHOVING
if pushLeftEnabled and facing==FaceDirection.LEFT:
pushSignal.emit(pushTarget, Vector2(-1,0)*100*(pushForce/100))
current_player_state = PlayerStates.SHOVING
#Handle Shoot Bullet
if Input.is_action_just_pressed("shoot"):
print("Ima shoot a bullet")
@@ -47,7 +66,7 @@ func _physics_process(delta: float) -> void:
FaceDirection.RIGHT:
shootSignal.emit(right_spawn.global_transform, 800)
FaceDirection.LEFT:
shootSignal.emit(left_spawn.global_transform, 800)
shootSignal.emit(left_spawn.global_transform, -800)
#Handle fire rocket
if Input.is_action_just_pressed("fire"):
print("Ima fire rocket")
@@ -63,12 +82,18 @@ func _physics_process(delta: float) -> void:
velocity.x = direction * SPEED
if direction >0:
facing = FaceDirection.RIGHT
player_graphic.flip_h = false
else:
facing = FaceDirection.LEFT
player_graphic.flip_h = true
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
func handle_movement(delta)->void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
func handle_collisions()->void:
if right_cast.is_colliding():
print("Right raycast collision")
var collider = right_cast.get_collider()
@@ -94,3 +119,40 @@ func _physics_process(delta: float) -> void:
if c.get_collider() is RigidBody2D:
#c.get_collider().apply_central_impulse(-c.get_normal() * 100)
pushSignal.emit(c.get_collider(), -c.get_normal() * 100)
#Exciting new stuff
func handle_states()->void:
match current_player_state:
PlayerStates.IDLE when velocity.x !=0:
current_player_state = PlayerStates.RUNNING
PlayerStates.RUNNING when velocity.x ==0:
current_player_state = PlayerStates.IDLE
PlayerStates.JUMPING when velocity.y>0:
current_player_state = PlayerStates.FALLING
PlayerStates.FALLING when is_on_floor():
if velocity.x ==0:
current_player_state = PlayerStates.IDLE
else:
current_player_state = PlayerStates.RUNNING
func handle_animation()->void:
match current_player_state:
PlayerStates.RUNNING:
player_graphic.play("running")
PlayerStates.IDLE:
player_graphic.play("idle")
PlayerStates.JUMPING:
if upJump:
player_graphic.play("jumping")
PlayerStates.FALLING:
player_graphic.play("falling")
PlayerStates.CHARGING:
player_graphic.play("charging")
PlayerStates.SHOVING:
player_graphic.play("shoving")
func _on_animation_finished() -> void:
match current_player_state:
PlayerStates.JUMPING:
upJump = false
PlayerStates.SHOVING:
current_player_state = PlayerStates.IDLE
+16 -3
View File
@@ -47,10 +47,22 @@ func updateCrates()->void:
func pushTarget(body,pushDirection)->void:
if body is RigidBody2D:
body.apply_central_impulse(pushDirection)
func stashBullet(bullet:Bullet)->void:
#hide the bullet
var stashPosition:Vector2 = Vector2(-100,-100)
bullet.position = stashPosition
bullet.setSpeed(0)
bullet.set_process(false)
func destroy(body)->void:
if body is Rocket:
print("removing rocket")
body.queue_free()
match body:
var bod when bod is Bullet:
stashBullet(body)
var bod when bod is Crate:
body.queue_free()
_:
body.queue_free()
func teleportTarget(body)->void:
if body is Crate:
var viewport_size = get_viewport().get_visible_rect().size
@@ -77,6 +89,7 @@ func makeBullet(spawnPosition, speed)->void:
var myBullet:Bullet = bulletFactory()
myBullet.transform = spawnPosition
myBullet.setSpeed(speed)
myBullet.set_process(true)
func rocketFactory()->Rocket:
var myRocket:Rocket