mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 07:50:22 +01:00
Many tweaks thanks to IAmActuallyCthulhu
Also change apostrophes to double quotes and update C# projects
This commit is contained in:
@@ -36,7 +36,14 @@ func _ready():
|
||||
# - If you split the character into a state machine or more advanced pattern,
|
||||
# you can easily move individual functions.
|
||||
func _physics_process(_delta):
|
||||
_velocity = calculate_move_velocity(_velocity)
|
||||
# If the enemy encounters a wall or an edge, the horizontal velocity is flipped.
|
||||
if not floor_detector_left.is_colliding():
|
||||
_velocity.x = speed.x
|
||||
elif not floor_detector_right.is_colliding():
|
||||
_velocity.x = -speed.x
|
||||
|
||||
if is_on_wall():
|
||||
_velocity.x *= -1
|
||||
|
||||
# We only update the y value of _velocity as we want to handle the horizontal movement ourselves.
|
||||
_velocity.y = move_and_slide(_velocity, FLOOR_NORMAL).y
|
||||
@@ -49,22 +56,6 @@ func _physics_process(_delta):
|
||||
animation_player.play(animation)
|
||||
|
||||
|
||||
# This function calculates a new velocity whenever you need it.
|
||||
# If the enemy encounters a wall or an edge, the horizontal velocity is flipped.
|
||||
func calculate_move_velocity(linear_velocity):
|
||||
var velocity = linear_velocity
|
||||
|
||||
if not floor_detector_left.is_colliding():
|
||||
velocity.x = speed.x
|
||||
elif not floor_detector_right.is_colliding():
|
||||
velocity.x = -speed.x
|
||||
|
||||
if is_on_wall():
|
||||
velocity.x *= -1
|
||||
|
||||
return velocity
|
||||
|
||||
|
||||
func destroy():
|
||||
_state = State.DEAD
|
||||
_velocity = Vector2.ZERO
|
||||
|
||||
@@ -11,6 +11,7 @@ onready var sound_shoot = $Shoot
|
||||
onready var timer = $Cooldown
|
||||
|
||||
|
||||
# This method is only called by Player.gd.
|
||||
func shoot(direction = 1):
|
||||
if not timer.is_stopped():
|
||||
return false
|
||||
|
||||
@@ -7,10 +7,10 @@ const FLOOR_DETECT_DISTANCE = 20.0
|
||||
export(String) var action_suffix = ""
|
||||
|
||||
onready var platform_detector = $PlatformDetector
|
||||
onready var sprite = $Sprite
|
||||
onready var animation_player = $AnimationPlayer
|
||||
onready var shoot_timer = $ShootAnimation
|
||||
onready var gun = $Sprite/Gun
|
||||
onready var sprite = $Sprite
|
||||
onready var gun = sprite.get_node(@"Gun")
|
||||
|
||||
|
||||
func _ready():
|
||||
|
||||
@@ -7,7 +7,7 @@ onready var animation_player = $AnimationPlayer
|
||||
# The Coins only detects collisions with the Player thanks to its collision mask.
|
||||
# This prevents other characters such as enemies from picking up coins.
|
||||
|
||||
# When the player collides with a coin, the coin plays its 'picked' animation.
|
||||
# When the player collides with a coin, the coin plays its "picked" animation.
|
||||
# The animation takes cares of making the coin disappear, but also deactivates its
|
||||
# collisions and frees it from memory, saving us from writing more complex code.
|
||||
# Click the AnimationPlayer node to see the animation timeline.
|
||||
|
||||
Reference in New Issue
Block a user