This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues/pull-requests.
evospace/entities/powerups/powerup.gd

37 lines
798 B
GDScript
Raw Permalink Normal View History

2020-09-06 23:02:19 +03:00
extends KinematicBody2D
export (Resource) var weapon
var rng = RandomNumberGenerator.new()
var speed
var velocity = Vector2(0, 0.2)
var dir = 0
func _ready():
rng.randomize()
speed = rng.randf_range(0.2, 0.8)
velocity.x = speed
func _physics_process(delta):
if dir == 0 && position.x > ProjectSettings.get("display/window/size/width") - 8:
dir = 1
velocity.x = -speed
elif dir == 1 && position.x < 8:
dir = 0
velocity.x = speed
var collision_info = move_and_collide(velocity)
if collision_info && collision_info.collider is Player:
var player = (collision_info.collider as Player)
reward(player)
func _on_visiblity_notifier_screen_exited():
queue_free()
func reward(player):
player.weapon = weapon
player.update_weapon()
player.increase_score(50)
queue_free()