-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
96 lines (77 loc) · 2.21 KB
/
script.js
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
96
let clicked = false;
let fly;
let fly_spritesheet;
let bg, Background;
let Troll;
let bridge = 0;
function preload() {
bg = loadSpriteSheet("assets/bg_spritesheet.png", 600, 600, 2);
fly_spritesheet = loadSpriteSheet('assets/fly_sprites.png', 50, 50, 4);
TrollAnimationIdle = loadAnimation("assets/idle_1.png", "assets/idle_4.png");
twitchLeft = loadAnimation("assets/twitch_left_0000.png", "assets/twitch_left_0011.png");
twitchRight = loadAnimation("assets/twitch_right_0000.png", "assets/twitch_right_0009.png");
eyeroll = loadAnimation("assets/mid_0000.png", "assets/mid_0013.png");
}
function setup() {
const canvas = createCanvas(600, 600);
canvas.parent("sketch");
background(90);
frameRate(15);
Background = createSprite(width / 2, height / 2);
Background.addAnimation("flimmer", bg);
Troll = createSprite(width / 2, height / 2);
Troll.addAnimation("Idle", TrollAnimationIdle);
Troll.addAnimation("twitchleft", twitchLeft, eyeroll);
Troll.addAnimation("twitchright", twitchRight);
Troll.addAnimation("eyeroll", eyeroll);
fly = createSprite(mouseX, mouseY, 50);
fly.addAnimation("buzzing", fly_spritesheet);
fly.visible = false;
}
function draw() {
background(90);
drawSprites();
fly.attractionPoint(4, mouseX, mouseY);
fly.maxSpeed = 20;
if (Troll.animation.getFrame() == Troll.animation.getLastFrame()) {
if (clicked == true) {
if (bridge == 0) {
CheckSquares();
} else {
bridge = bridge - 1;
Troll.changeAnimation("Idle");
}
} else {
Troll.changeAnimation("Idle");
}
}
}
function mouseClicked() {
clicked = !clicked;
if (clicked == false) {
fly.visible = false;
} else {
fly.visible = true;
}
}
function squares() {
if (mouseX > 0 && mouseX < 200) {
return 1;
} else if (mouseX > 200 && mouseX < 400) {
return 2;
} else if (mouseX > 400 && mouseX < 600) {
return 3;
} else { return 0 }
}
function CheckSquares() {
if (squares() == 1) {
Troll.changeAnimation("twitchleft");
} else if (squares() == 2) {
Troll.changeAnimation("eyeroll");
} else if (squares() == 3) {
Troll.changeAnimation("twitchright");
} else {
Troll.changeAnimation("Idle");
}
bridge = 5;
}