added gumba mushroom and sound
This commit is contained in:
+2
-1
@@ -1,8 +1,9 @@
|
||||
extends Area2D
|
||||
@onready var animation_player = $AnimationPlayer
|
||||
|
||||
func collect_coin(body):
|
||||
body.increase_coins()
|
||||
queue_free()
|
||||
animation_player.play("pickup")
|
||||
|
||||
func _on_body_entered(body):
|
||||
collect_coin(body)
|
||||
|
||||
@@ -6,4 +6,5 @@ func _ready():
|
||||
animated_sprite_2d.play("default")
|
||||
|
||||
func _on_activate_body_entered(body):
|
||||
queue_free()
|
||||
if body.is_big:
|
||||
queue_free()
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
extends RigidBody2D
|
||||
|
||||
@export var speed = -70
|
||||
@onready var ray_cast_left = $RayCastLeft
|
||||
@onready var ray_cast_right = $RayCastRight
|
||||
@onready var animated_sprite_2d = $AnimatedSprite2D
|
||||
@onready var timer = $Timer
|
||||
@onready var die = $die
|
||||
@onready var ray_cast_left_2 = $RayCastLeft2
|
||||
@onready var ray_cast_right_2 = $RayCastRight2
|
||||
var innocent = false
|
||||
@onready var timer_2 = $Timer2
|
||||
|
||||
func _physics_process(delta):
|
||||
linear_velocity.x = speed
|
||||
|
||||
if ray_cast_left_2 == null:
|
||||
return
|
||||
|
||||
if ray_cast_left.is_colliding() or ray_cast_left_2.is_colliding():
|
||||
speed = abs(speed)
|
||||
elif ray_cast_right.is_colliding() or ray_cast_right_2.is_colliding():
|
||||
speed = abs(speed) * -1
|
||||
|
||||
var body = null
|
||||
if innocent:
|
||||
return
|
||||
if ray_cast_left_2.is_colliding():
|
||||
body = ray_cast_left_2.get_collider()
|
||||
elif ray_cast_right_2.is_colliding():
|
||||
body = ray_cast_right_2.get_collider()
|
||||
if body != null:
|
||||
body.shrink()
|
||||
innocent = true
|
||||
timer_2.start()
|
||||
|
||||
@onready var die_sound = $dieSound
|
||||
|
||||
func f_die():
|
||||
speed = 0
|
||||
animated_sprite_2d.play("die")
|
||||
timer.start()
|
||||
die.queue_free()
|
||||
die_sound.play()
|
||||
ray_cast_left_2.queue_free()
|
||||
ray_cast_right_2.queue_free()
|
||||
|
||||
func _on_die_body_entered(body):
|
||||
f_die()
|
||||
body.velocity.y = body.JUMPt_velocity/1.5
|
||||
|
||||
func _on_timer_timeout():
|
||||
queue_free()
|
||||
|
||||
func _on_timer_2_timeout():
|
||||
innocent = false
|
||||
@@ -1,5 +1,6 @@
|
||||
extends RigidBody2D
|
||||
@onready var animated_sprite_2d = $AnimatedSprite2D
|
||||
@export var hit_object:PackedScene
|
||||
|
||||
var destroyed = false
|
||||
|
||||
@@ -12,3 +13,10 @@ func _on_activate_body_entered(body):
|
||||
|
||||
destroyed = true
|
||||
animated_sprite_2d.play("destroy")
|
||||
|
||||
if hit_object == null:
|
||||
return
|
||||
|
||||
var instance = hit_object.instantiate()
|
||||
add_child(instance)
|
||||
instance.position.y -= 17
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
extends RigidBody2D
|
||||
|
||||
@export var speed = 70
|
||||
@onready var ray_cast_left = $RayCastLeft
|
||||
@onready var ray_cast_right = $RayCastRight
|
||||
@onready var animation_player = $AnimationPlayer
|
||||
|
||||
func _physics_process(delta):
|
||||
linear_velocity.x = speed
|
||||
|
||||
if ray_cast_left.is_colliding():
|
||||
speed = abs(speed)
|
||||
elif ray_cast_right.is_colliding():
|
||||
speed = abs(speed) * -1
|
||||
|
||||
|
||||
func _on_area_2d_body_entered(body):
|
||||
body.grow()
|
||||
speed = 0
|
||||
animation_player.play("pickup")
|
||||
+26
-3
@@ -5,6 +5,8 @@ extends CharacterBody2D
|
||||
@onready var pipe_timer = $pipe_timer
|
||||
@onready var pipe_timer_half = $pipe_timer_half
|
||||
@onready var coin_amt = $CanvasLayer/Control/CoinAmt
|
||||
@onready var collision_shape_2d = $CollisionShape2D
|
||||
@onready var pipedetector_ground = $pipedetector_ground
|
||||
|
||||
|
||||
const SPEED = 130.0
|
||||
@@ -19,6 +21,7 @@ var coins = 0
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
var on_pause = false
|
||||
var is_big = false
|
||||
|
||||
# touch controls
|
||||
var touch_anchor = Vector2.ZERO
|
||||
@@ -96,11 +99,20 @@ func _physics_process(delta):
|
||||
# play animation
|
||||
if is_on_floor():
|
||||
if direction != 0:
|
||||
animated_sprite_2d.play("run")
|
||||
if is_big:
|
||||
animated_sprite_2d.play("run_big")
|
||||
else:
|
||||
animated_sprite_2d.play("run")
|
||||
else:
|
||||
animated_sprite_2d.play("idle")
|
||||
if is_big:
|
||||
animated_sprite_2d.play("idle_big")
|
||||
else:
|
||||
animated_sprite_2d.play("idle")
|
||||
else:
|
||||
animated_sprite_2d.play("jump")
|
||||
if is_big:
|
||||
animated_sprite_2d.play("jump_big")
|
||||
else:
|
||||
animated_sprite_2d.play("jump")
|
||||
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
@@ -109,6 +121,17 @@ func _physics_process(delta):
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func grow():
|
||||
is_big = true
|
||||
collision_shape_2d.shape.height = 32
|
||||
pipedetector_ground.position.y += 8
|
||||
|
||||
func shrink():
|
||||
if is_big:
|
||||
is_big = false
|
||||
collision_shape_2d.shape.height = 16
|
||||
pipedetector_ground.position.y -= 8
|
||||
|
||||
func increase_coins():
|
||||
coins += 1
|
||||
coin_amt.text = str(coins)
|
||||
|
||||
Reference in New Issue
Block a user