MarchTTLGame/scripts/player.gd

47 lines
1.4 KiB
GDScript3
Raw Permalink Normal View History

class_name Player extends CharacterBody2D
2026-03-09 21:11:08 +00:00
@onready var right_gun: Marker2D = $"Right Gun"
@onready var left_gun: Marker2D = $"Left Gun"
2026-03-09 21:11:08 +00:00
const SPEED = 300
const JUMP_VELOCITY = -1000.0
2026-03-09 21:11:08 +00:00
const BUMP_POWER = 50
enum FaceDirection{LEFT, RIGHT}
var facing:FaceDirection = FaceDirection.RIGHT
2026-03-09 21:11:08 +00:00
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
#Handle Shoot
if Input.is_action_just_pressed("Shoot"):
print("player wants to shoot")
match facing:
FaceDirection.RIGHT:
print("shoot to the right")
%SceneManager.makeBullet(right_gun.global_transform, 700)
FaceDirection.LEFT:
print("shoot to the left")
%SceneManager.makeBullet(left_gun.global_transform, -700)
2026-03-09 21:11:08 +00:00
# Handle jump.
if Input.is_action_just_pressed("ui_accept") :
2026-03-09 21:11:08 +00:00
velocity.y = JUMP_VELOCITY
# 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:
velocity.x = direction * SPEED
if direction >0:
facing=FaceDirection.RIGHT
if direction <0:
facing=FaceDirection.LEFT
2026-03-09 21:11:08 +00:00
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
for i in get_slide_collision_count():
var c = get_slide_collision(i)
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal()*BUMP_POWER)