mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-22 15:38:14 +00:00
added the game
This commit is contained in:
38
Scripts/Classes/Entities/Objects/Bumper.gd
Normal file
38
Scripts/Classes/Entities/Objects/Bumper.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends Node2D
|
||||
|
||||
const LOW_STRENGTH := -300
|
||||
const HIGH_STRENGTH := -450
|
||||
|
||||
func bounce_player(player: Player) -> void:
|
||||
$Sprite.play("Bounce")
|
||||
$AnimationPlayer.stop()
|
||||
if player.global_position.y + 8 < global_position.y:
|
||||
player.velocity.x *= 0.8
|
||||
if Global.player_action_pressed("jump", player.player_id):
|
||||
player.gravity = player.JUMP_GRAVITY
|
||||
player.jump_cancelled = false
|
||||
player.velocity.y = HIGH_STRENGTH
|
||||
player.has_jumped = true
|
||||
AudioManager.play_sfx("bumper_high", global_position)
|
||||
else:
|
||||
AudioManager.play_sfx("bumper", global_position)
|
||||
player.velocity.y = LOW_STRENGTH
|
||||
else:
|
||||
player.velocity = global_position.direction_to(player.global_position) * 200
|
||||
if Global.player_action_pressed("jump", player.player_id):
|
||||
player.gravity = player.JUMP_GRAVITY
|
||||
player.velocity.y = LOW_STRENGTH
|
||||
player.has_jumped = true
|
||||
AudioManager.play_sfx("bumper_high", global_position)
|
||||
else:
|
||||
AudioManager.play_sfx("bumper", global_position)
|
||||
refresh_hitbox()
|
||||
$AnimationPlayer.play("Bounce")
|
||||
await $AnimationPlayer.animation_finished
|
||||
$Sprite.play("Idle")
|
||||
|
||||
func refresh_hitbox() -> void:
|
||||
$Hitbox/CollisionShape2D.set_deferred("disabled", true)
|
||||
await get_tree().physics_frame
|
||||
$Hitbox/CollisionShape2D.set_deferred("disabled", false)
|
||||
|
Reference in New Issue
Block a user