added fireballs
This commit is contained in:
@@ -19,4 +19,4 @@ func _on_activate_body_entered(body):
|
||||
|
||||
var instance = hit_object.instantiate()
|
||||
add_child(instance)
|
||||
instance.position.y -= 17
|
||||
instance.position.y -= 16
|
||||
@@ -0,0 +1,6 @@
|
||||
extends Area2D
|
||||
@onready var animation_player = $AnimationPlayer
|
||||
|
||||
func _on_body_entered(body):
|
||||
body.flower()
|
||||
animation_player.play("pickup")
|
||||
@@ -0,0 +1,23 @@
|
||||
extends RigidBody2D
|
||||
@onready var timer = $Timer
|
||||
var enter_count = 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
timer.start()
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func _on_timer_timeout():
|
||||
queue_free()
|
||||
|
||||
func _on_area_2d_body_entered(body):
|
||||
enter_count += 1
|
||||
if enter_count > 2:
|
||||
queue_free()
|
||||
|
||||
func _on_enemie_die_body_entered(body):
|
||||
body.f_die()
|
||||
queue_free()
|
||||
+42
-7
@@ -24,21 +24,28 @@ var coins = 0
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
var on_pause = false
|
||||
var is_big = false
|
||||
var is_flower = false
|
||||
|
||||
# touch controls
|
||||
var touch_anchor = Vector2.ZERO
|
||||
var jump = false
|
||||
var crawl = false
|
||||
var fire = false
|
||||
var toucht_velocity = Vector2.ZERO
|
||||
var t_velocity = 0
|
||||
|
||||
@export var fireball_prefab : PackedScene
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventScreenTouch or event is InputEventScreenDrag:
|
||||
if event.is_pressed():
|
||||
if event.position.x < get_viewport_rect().size.x / 2:
|
||||
touch_anchor = event.position
|
||||
elif not jump:
|
||||
jump = true
|
||||
else:
|
||||
if event.position.y > get_viewport_rect().size.y / 2 and not jump:
|
||||
jump = true
|
||||
elif not fire:
|
||||
fire = true
|
||||
elif event.position.x < get_viewport_rect().size.x / 2:
|
||||
toucht_velocity = event.position - touch_anchor
|
||||
if abs(toucht_velocity.x) > 30:
|
||||
@@ -87,8 +94,19 @@ func _physics_process(delta):
|
||||
jump = false
|
||||
velocity.y = JUMPt_velocity
|
||||
|
||||
# check fireball
|
||||
if is_flower and (Input.is_action_just_pressed("flower") or fire):
|
||||
fire = false
|
||||
var instance = fireball_prefab.instantiate()
|
||||
get_parent().add_child(instance)
|
||||
instance.position.x = position.x -8 if animated_sprite_2d.flip_h else position.x + 8
|
||||
instance.position.y = position.y
|
||||
instance.linear_velocity.x = -400 if animated_sprite_2d.flip_h else 400
|
||||
instance.linear_velocity.y = 50
|
||||
instance.angular_velocity = 0
|
||||
|
||||
|
||||
# get input
|
||||
|
||||
var direction = Input.get_axis("move_left", "move_right") + t_velocity
|
||||
|
||||
if on_pause:
|
||||
@@ -103,17 +121,23 @@ func _physics_process(delta):
|
||||
# play animation
|
||||
if is_on_floor():
|
||||
if direction != 0:
|
||||
if is_big:
|
||||
if is_flower:
|
||||
animated_sprite_2d.play("run_flower")
|
||||
elif is_big:
|
||||
animated_sprite_2d.play("run_big")
|
||||
else:
|
||||
animated_sprite_2d.play("run")
|
||||
else:
|
||||
if is_big:
|
||||
if is_flower:
|
||||
animated_sprite_2d.play("idle_flower")
|
||||
elif is_big:
|
||||
animated_sprite_2d.play("idle_big")
|
||||
else:
|
||||
animated_sprite_2d.play("idle")
|
||||
else:
|
||||
if is_big:
|
||||
if is_flower:
|
||||
animated_sprite_2d.play("jump_flower")
|
||||
elif is_big:
|
||||
animated_sprite_2d.play("jump_big")
|
||||
else:
|
||||
animated_sprite_2d.play("jump")
|
||||
@@ -131,11 +155,22 @@ func grow():
|
||||
collision_shape_2d.shape.height = 32
|
||||
pipedetector_ground.position.y += 8
|
||||
|
||||
func flower():
|
||||
if not is_big:
|
||||
collision_shape_2d.shape.height = 32
|
||||
pipedetector_ground.position.y += 8
|
||||
is_big = true
|
||||
is_flower = true
|
||||
|
||||
func shrink():
|
||||
if is_big:
|
||||
if is_flower:
|
||||
is_flower = false
|
||||
elif is_big:
|
||||
is_big = false
|
||||
collision_shape_2d.shape.height = 16
|
||||
pipedetector_ground.position.y -= 8
|
||||
else:
|
||||
print("dead")
|
||||
|
||||
func increase_coins():
|
||||
coins += 1
|
||||
|
||||
Reference in New Issue
Block a user