1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
class_name Powerup extends KinematicBody
enum Type {
none
magnet
explosion
superspeed
swap
max_pw
}
var mytype
var initpos
var speed = 0
var toggle = 0
func get_type():
return mytype
func _physics_process(delta):
if abs(speed) > 0.5 * delta:
toggle ^= 1
if toggle:
speed -= 0.01 * delta
else:
speed += 0.01 * delta
translate(Vector3(0, speed, 0))
func _ready():
var color = Color(0, 0, 0, 0)
var material = $MeshInstance.get_active_material(0).duplicate()
match mytype:
Type.magnet:
color = Color(0, 0.8, 0.8, 1.0)
material.albedo_texture = load("res://magnet.png")
Type.explosion:
color = Color(0.8, 0, 0, 1.0)
material.albedo_texture = load("res://explosion.png")
Type.superspeed:
color = Color(0, 0.8, 0, 1.0)
material.albedo_texture = load("res://speed.png")
Type.swap:
color = Color(0.8, 0.8, 0.8, 1.0)
material.albedo_texture = load("res://swap.png")
$MeshInstance.set_surface_material(0, material)
$light.light_color = color
initpos = global_transform.origin.y
speed = randf() * 0.01 * (randi() & 1) * -1
translate(Vector3(0, randf() * 0.1, 0))
func _init():
mytype = randi() % (Type.max_pw - 1) + 1
add_to_group("powerup")
|