-
Notifications
You must be signed in to change notification settings - Fork 0
/
boat.way
77 lines (59 loc) · 2.61 KB
/
boat.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
type Boat [position, frame]
global const int BOAT_WIDTH = 16
global const int BOAT_HEIGHT = 16
global const int BOAT_SPEED = 2
global const int BOAT_STATE_NONE = 0
global const int BOAT_STATE_SAFE = 1
global const int BOAT_STATE_DESTROY = 2
global int BOAT_SOUND = -1
snd_load BOAT_SOUND "sounds/boat.wav"
global array boatSprite = 6
boatSprite[0] = Graphics:loadSprite("sprites/boat.png", 0, 0, BOAT_WIDTH, BOAT_HEIGHT)
boatSprite[1] = Graphics:loadSprite("sprites/boat.png", BOAT_WIDTH, 0, BOAT_WIDTH * 2, BOAT_HEIGHT)
boatSprite[2] = Graphics:loadSprite("sprites/boat.png", BOAT_WIDTH * 2, 0, BOAT_WIDTH * 3, BOAT_HEIGHT)
boatSprite[3] = Graphics:loadSprite("sprites/boat.png", BOAT_WIDTH * 3, 0, BOAT_WIDTH * 4, BOAT_HEIGHT)
boatSprite[4] = Graphics:loadSprite("sprites/boat.png", BOAT_WIDTH * 4, 0, BOAT_WIDTH * 5, BOAT_HEIGHT)
boatSprite[5] = Graphics:loadSprite("sprites/boat.png", BOAT_WIDTH * 5, 0, BOAT_WIDTH * 6, BOAT_HEIGHT)
function Boat:new() {
Boat boat = null
boat.position = Vector:new(Random:rand(BOAT_WIDTH / 2, WIDTH - BOAT_WIDTH - BOAT_WIDTH / 2), 62)
boat.frame = 0
snd_action play BOAT_SOUND null
return boat
}
function Boat:update(@boat, mouse) {
if direction {
Vector center = Vector:new(ZOOM * (boat.position.x + BOAT_WIDTH / 2), ZOOM * (boat.position.y + BOAT_HEIGHT / 2))
int distance = Vector:distance(center, mouse)
if distance < ZOOM * BOAT_WIDTH * 1.5 {
if mouse.x < center.x {
boat.position.x--
} else if mouse.x > center.x {
boat.position.x++
}
}
}
boat.position.y++
if boat.frame < boatSprite.length - 1 {
boat.frame = (boat.position.y - 64) / 14
}
if boat.position.y > HEIGHT {
return BOAT_STATE_SAFE
}
int i = 0
while i < rocks.size {
if boat.position.x + BOAT_WIDTH < 0 || boat.position.x > WIDTH || Boat:collideWithRock(boat, rocks.elements[i]) || Boat:collideWithKraken(boat, kraken) {
return BOAT_STATE_DESTROY
}
i++
}
return BOAT_STATE_NONE
}
function Boat:collideWithRock(boat, rock) {
int rockX = rock.x * ROCK_WIDTH
int rockY = rock.y * ROCK_HEIGHT
return (boat.position.x + 12 >= rockX) && (boat.position.x <= rockX + 12) && (boat.position.y + 8 >= rockY) && (boat.position.y <= rockY + 12)
}
function Boat:collideWithKraken(boat, kraken) {
return (kraken.state == KRAKEN_STATE_NORMAL) && (boat.position.x + 4 >= kraken.position.x) && (boat.position.x <= kraken.position.x + 24) && (boat.position.y + 4 >= kraken.position.y) && (boat.position.y <= kraken.position.y + 24)
}