-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
148 lines (135 loc) · 3.85 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var toppings;
var heldTopping;
var table;
var pizza;
var gameOverImage;
var cameraImage;
function setup() {
createCanvas(800, 600);
table = loadImage("images/table.jpg");
pizza = new Topping("images/pizza.png", -100, 0);
gameOverImage = loadImage("images/gameover.png");
cameraImage = new Topping("images/camera.png", 10, 500);
toppings = [];
heldTopping = null;
addSlice();
toppings.push(new Topping("images/mushroom1.png", 400, 10));
toppings.push(new Topping("images/mushroom2.png", 500, 10));
toppings.push(new Topping("images/mushroom3.png", 600, 10));
toppings.push(new Topping("images/bacon1.png", 450, 100));
toppings.push(new Topping("images/bacon2.png", 400, 150));
toppings.push(new Topping("images/tshirt.png", 250, 350));
toppings[toppings.length - 1].setSpecial(addClothes);
toppings.push(new Topping("images/bread.png", 350, 400));
toppings[toppings.length - 1].setSpecial(addBurger);
toppings.push(new Topping("images/cheese.png", 450, 270));
toppings.push(new Topping("images/ham.png", 500, 200));
toppings[toppings.length - 1].setSpecial(addVesuvio);
toppings.push(new Topping("images/lettuce.png", 50, 370));
toppings[toppings.length - 1].setSpecial(addBurger);
toppings.push(new Topping("images/pineapple.png", 620, 250));
toppings[toppings.length - 1].setSpecial(gameOver);
toppings.push(new Topping("images/gummybears.png", 100, 400));
toppings.push(new Topping("images/nescartridge.png", 400, 550));
toppings[toppings.length - 1].setSpecial(pizzaGame);
}
function draw() {
var toppingIsHovered = false;
for (let index = toppings.length - 1; index >= 0; index--) {
if (toppings[index].isHovered()) {
toppingIsHovered = true;
break;
}
}
if (cameraImage.isHovered() && heldTopping === null && !youLost) {
cursor(HAND);
} else if ((toppingIsHovered || heldTopping !== null) && !youLost) {
cursor(MOVE);
} else {
cursor(ARROW);
}
if (heldTopping !== null && !youLost) {
heldTopping.move(mouseX - pmouseX, mouseY - pmouseY);
}
if (youLost) {
if (lostTimer < 1) {
lostTimer += 1 / frameRate();
}
tint(255, 255 * (1 - lostTimer), 255 * (1 - lostTimer));
}
image(table, 0, 0);
pizza.draw();
for (let index = 0; index < toppings.length; index++) {
toppings[index].draw();
}
cameraImage.draw();
if (heldTopping !== null) {
heldTopping.draw();
}
if (youLost) {
tint(255, 255, 255, 255 * lostTimer);
image(gameOverImage, 0, 0);
}
}
function mousePressed() {
if (youLost) {
return;
} else if (mouseButton === LEFT && cameraImage.isHovered()) {
saveCanvas("pizza", "png");
} else if (mouseButton === LEFT) {
for (let index = toppings.length - 1; index >= 0; index--) {
if (toppings[index].isHovered()) {
heldTopping = toppings[index];
toppings.splice(index, 1);
break;
}
}
}
}
function mouseReleased() {
if (youLost) {
return;
} else if (mouseButton === LEFT && heldTopping !== null) {
if (pizza.isHovered()) {
if (heldTopping.getHasSpecial()) {
heldTopping.runSpecial();
}
pizzaIsEmpty = false;
}
toppings.push(heldTopping);
heldTopping = null;
}
}
//specials
var pizzaIsEmpty = true;
function addVesuvio() {
if (pizzaIsEmpty) {
toppings.push(new Topping("images/vesuvio.png", -100, 0));
}
}
function addSlice() {
toppings.push(new Topping("images/slice.png", 450, 200));
toppings[toppings.length - 1].setSpecial(addSlice);
}
var hasHalfBurger = false;
function addBurger() {
if (hasHalfBurger) {
toppings.push(new Topping("images/burger.png", 400, 200));
} else {
hasHalfBurger = true;
}
}
var youLost = false;
var lostTimer;
function gameOver() {
youLost = true;
lostTimer = 0;
}
function addClothes() {
toppings.push(new Topping("images/bikini.png", 450, 100));
toppings.push(new Topping("images/blackdress.png", 450, 100));
toppings.push(new Topping("images/reddress.png", 550, 100));
}
function pizzaGame() {
window.open("https://pizzagame.party/", "_blank");
}