-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch.js
75 lines (57 loc) · 1.11 KB
/
sketch.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
//Create variables here
var dog
var foodS
function preload()
{
//load images here
dogImg = loadImage("images/dogImg.png")
dogImg1 = loadImage("images/dogImg1.png")
}
function setup() {
createCanvas(800, 700);
database = firebase.database()
foodref = database.ref('Milk');
foodref.on("value",readStock)
dog = createSprite(400,350,10,10)
dog.addImage("normal",dogImg)
dog.addImage("happy",dogImg1)
dog.scale = 0.5
}
function draw() {
background("white");
drawSprites();
text("Milk bottles left : " + foodS, 200,30)
//add styles here
if(foodS === 0){
text("Ran out of milk!",200,50)
text("Click R to restock ",200,70)
}
}
function writeStock(x){
database.ref('/').set({
Milk : x
})
}
function readStock(data){
foodS = data.val()
}
function keyPressed(){
if(keyCode === UP_ARROW){
if(foodS>0){
dog.changeImage("happy")
foodS = foodS-1
writeStock(foodS)
}
else{
foodS = 0
}
}
if(keyCode === 82 && foodS === 0){
foodS = 20
}
}
function keyReleased(){
if(keyCode === UP_ARROW){
dog.changeImage("normal")
}
}