Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | O_Chernobas |
I’m making a game for a Game Jam that’s going on here in Brazil, and the theme is “Towers”. So my game is based in many “cake pieces” falling from sky, while the player needs to catch then, and make a “cake tower”.
But when the player catch a cake piece, all the cake pieces at the screen are deleted (via queue_free
).
(I have not yet done the mechanics of counting how many cake pieces the player picked up)
Someone can help me to delete just that one piece that the player caught ?
code of the World Scene:
extends Node2D
var cake_piece = preload("res://Cake/CakePiece.tscn")
var Cake_piece = null
signal cake_col
func _ready():
$Timer.start(1.5)
func _on_Timer_timeout():
Cake_piece = cake_piece.instance()
get_parent().add_child(Cake_piece)
Cake_piece.position.x = 384
Cake_piece.position.y = 0
connect("cake_col", Cake_piece, "on_World_cake_col")
func _on_Player_cake_collected():
emit_signal("cake_col")
code of the player scene:
extends KinematicBody2D
const UP = Vector2(0,-1)
var velocity = Vector2.ZERO
var move_speed = 5 * 96
var gravity = 1200
var jump_force = 600
signal cake_collected
func _physics_process(delta):
get_input()
velocity.y += gravity * delta
velocity = move_and_slide_with_snap(velocity,Vector2.ZERO, UP)
func _input(event):
if event.is_action_pressed("ui_up") and self.is_on_floor():
velocity.y = -jump_force
func get_input():
var move_direction = - int(Input.get_action_strength("ui_left")) + int(Input.get_action_strength("ui_right"))
velocity.x = lerp(velocity.x, move_speed * move_direction, 0.2)
func _on_Area2D_area_entered(area):
emit_signal("cake_collected")
code of the Cake Piece scene:
extends KinematicBody2D
const UP = Vector2(0,-1)
var gravity = 12000
var velocity = Vector2.ZERO
func _physics_process(delta):
velocity.y = gravity * delta
velocity = move_and_slide(velocity, UP)
func on_World_cake_col():
queue_free()
The World scene: ( I’m using a 1368x720 monitor, so the print quality is not that good)
(The Godot Logo most at right side is the player, the other 2 are cake pieces)