3c6f31b503
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
41 lines
996 B
GDScript
41 lines
996 B
GDScript
class_name Powerup
|
|
extends Area2D
|
|
## 掉落道具:缓慢下落 + 左右摇摆 + 缓慢自转,玩家接触即收集。
|
|
## kind: Kind.POWER 火力升级 / Kind.BOMB 炸弹+1
|
|
|
|
enum Kind { POWER, BOMB }
|
|
|
|
const FALL_SPEED := 105.0
|
|
const SWAY_AMP := 26.0
|
|
const TEX_POWER := preload("res://assets/svg/powerup.svg")
|
|
const TEX_BOMB := preload("res://assets/svg/bomb_powerup.svg")
|
|
|
|
var kind := Kind.POWER
|
|
|
|
var _t := 0.0
|
|
var _base_x := 0.0
|
|
var _sprite: Sprite2D
|
|
|
|
|
|
func _ready() -> void:
|
|
collision_layer = 16
|
|
collision_mask = 0
|
|
_base_x = position.x
|
|
_sprite = Sprite2D.new()
|
|
_sprite.texture = TEX_BOMB if kind == Kind.BOMB else TEX_POWER
|
|
add_child(_sprite)
|
|
var shape := CollisionShape2D.new()
|
|
var circle := CircleShape2D.new()
|
|
circle.radius = 15.0
|
|
shape.shape = circle
|
|
add_child(shape)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
_t += delta
|
|
position.y += FALL_SPEED * delta
|
|
position.x = _base_x + sin(_t * 1.9) * SWAY_AMP
|
|
_sprite.rotation += delta * 2.4
|
|
if position.y > 1010.0:
|
|
queue_free()
|