-
Notifications
You must be signed in to change notification settings - Fork 0
/
kraken.way
95 lines (75 loc) · 3.94 KB
/
kraken.way
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
type Kraken [position, frame, state, destination, angle]
global int KRAKEN_INCOMING_SOUND = -1
snd_load KRAKEN_INCOMING_SOUND "sounds/kraken-incoming.wav"
global int KRAKEN_DYING_SOUND = -1
snd_load KRAKEN_DYING_SOUND "sounds/kraken-dying.wav"
global int KRAKEN_LAUGHING_SOUND = -1
snd_load KRAKEN_LAUGHING_SOUND "sounds/kraken-laughing.wav"
global array KRAKEN_SPRITE = 4
KRAKEN_SPRITE[0] = Graphics:loadSprite("sprites/kraken.png", 0, 0, 32, 32)
KRAKEN_SPRITE[1] = Graphics:loadSprite("sprites/kraken.png", 32, 0, 64, 32)
KRAKEN_SPRITE[2] = Graphics:loadSprite("sprites/kraken.png", 64, 0, 96, 32)
KRAKEN_SPRITE[3] = Graphics:loadSprite("sprites/kraken.png", 96, 0, 128, 32)
global array KRAKEN_INCOMING_SPRITE = 4
KRAKEN_INCOMING_SPRITE[0] = Graphics:loadSprite("sprites/kraken-incoming.png", 0, 0, 32, 32)
KRAKEN_INCOMING_SPRITE[1] = Graphics:loadSprite("sprites/kraken-incoming.png", 32, 0, 64, 32)
KRAKEN_INCOMING_SPRITE[2] = Graphics:loadSprite("sprites/kraken-incoming.png", 64, 0, 96, 32)
KRAKEN_INCOMING_SPRITE[3] = Graphics:loadSprite("sprites/kraken-incoming.png", 96, 0, 128, 32)
global const int KRAKEN_STATE_IMMERSED = 0
global const int KRAKEN_STATE_INCOMING = 1
global const int KRAKEN_STATE_NORMAL = 2
global const int KRAKEN_STATE_IMMERSING = 3
function Kraken:new() {
Kraken kraken = null
kraken.position = Vector:new()
kraken.destination = Vector:new()
kraken.angle = 0
kraken.frame = 0
kraken.state = KRAKEN_STATE_IMMERSED
return kraken
}
function Kraken:incoming(@kraken) {
kraken.position = Vector:new(Random:rand(8, 216), Random:rand(64, 160))
kraken.destination = Vector:new(Random:rand(8, 216), Random:rand(64, 160))
kraken.angle = Vector:atan2(kraken.position, kraken.destination)
kraken.state = KRAKEN_STATE_INCOMING
snd_action play KRAKEN_INCOMING_SOUND null
List:add(markers, Marker:new(MARKER_TYPE_OYE, kraken.position.x, kraken.position.y - 8))
}
function Kraken:immersing(@kraken) {
kraken.state = KRAKEN_STATE_IMMERSING
kraken.frame = 0
}
function Kraken:dying(@kraken) {
kraken.state = KRAKEN_STATE_IMMERSING
kraken.frame = 0
snd_action play KRAKEN_DYING_SOUND null
List:add(markers, Marker:new(MARKER_TYPE_OUCH, kraken.position.x, kraken.position.y - 12))
List:add(markers, Marker:new(MARKER_TYPE_GAIN, kraken.position.x + 8, kraken.position.y - 4))
}
function Kraken:update(@kraken, mouse) {
kraken.frame = (kraken.frame + 1) % (KRAKEN_SPRITE.length * 2)
if kraken.state == KRAKEN_STATE_NORMAL {
kraken.position.x += Maths:cos(kraken.angle)
kraken.position.y += Maths:sin(kraken.angle)
if kraken.position.x <= kraken.destination.x + 1 && kraken.position.x >= kraken.destination.x - 1 && kraken.position.y <= kraken.destination.y + 1 && kraken.position.y >= kraken.destination.y - 1 {
Kraken:immersing(kraken)
} else if direction && (mouse.x >= ZOOM * (kraken.position.x + 8)) && (mouse.x <= ZOOM * (kraken.position.x + 24)) && (mouse.y >= ZOOM * (kraken.position.y + 8)) && (mouse.y <= ZOOM * (kraken.position.y + 24)) {
Kraken:dying(kraken)
score++
}
} else if kraken.state == KRAKEN_STATE_INCOMING && kraken.frame == 0 {
kraken.state = KRAKEN_STATE_NORMAL
} else if kraken.state == KRAKEN_STATE_IMMERSING && kraken.frame == 0 {
kraken.state = KRAKEN_STATE_IMMERSED
}
}
function Kraken:draw(kraken) {
if kraken.state == KRAKEN_STATE_NORMAL {
Graphics:drawSprite(KRAKEN_SPRITE[kraken.frame / 2], ZOOM * kraken.position.x, ZOOM * kraken.position.y, 0, ZOOM)
} else if kraken.state == KRAKEN_STATE_INCOMING {
Graphics:drawSprite(KRAKEN_INCOMING_SPRITE[kraken.frame / 2], ZOOM * kraken.position.x, ZOOM * kraken.position.y, 0, ZOOM)
} else if kraken.state == KRAKEN_STATE_IMMERSING {
Graphics:drawSprite(KRAKEN_INCOMING_SPRITE[KRAKEN_INCOMING_SPRITE.length - 1 - (kraken.frame / 2)], ZOOM * kraken.position.x, ZOOM * kraken.position.y, 0, ZOOM)
}
}