-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
105 lines (84 loc) · 2.31 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
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
const Engine = Matter.Engine;
const World= Matter.World;
const Bodies = Matter.Bodies;
const Constraint = Matter.Constraint;
var engine, world;
var box1, pig1,pig3;
var backgroundImg,platform;
var bird, slingshot;
var gameState = "onSling";
var bg = "sprites/bg1.png";
function preload() {
getBackgroundImage();
}
function setup(){
var canvas = createCanvas(1200,400);
engine = Engine.create();
world = engine.world;
ground = new Ground(600,height,1200,20);
platform = new Ground(150, 305, 300, 170);
box1 = new Box(700,320,70,70);
box2 = new Box(920,320,70,70);
pig1 = new Pig(810, 350);
log1 = new Log(810,260,300, PI/2);
box3 = new Box(700,240,70,70);
box4 = new Box(920,240,70,70);
pig3 = new Pig(810, 220);
log3 = new Log(810,180,300, PI/2);
box5 = new Box(810,160,70,70);
log4 = new Log(760,120,150, PI/7);
log5 = new Log(870,120,150, -PI/7);
bird = new Bird(200,50);
//log6 = new Log(230,180,80, PI/2);
slingshot = new SlingShot(bird.body,{x:200, y:50});
}
function draw(){
if(backgroundImg)
background(backgroundImg);
Engine.update(engine);
//strokeWeight(4);
box1.display();
box2.display();
ground.display();
pig1.display();
log1.display();
box3.display();
box4.display();
pig3.display();
log3.display();
box5.display();
log4.display();
log5.display();
bird.display();
platform.display();
//log6.display();
slingshot.display();
}
function mouseDragged(){
if (gameState!=="launched"){
Matter.Body.setPosition(bird.body, {x: mouseX , y: mouseY});
}
}
function mouseReleased(){
slingshot.fly();
gameState = "launched";
}
function keyPressed(){
if(keyCode === 32){
slingshot.attach(bird.body);
}
}
async function getBackgroundImage(){
var response = await fetch("http://worldtimeapi.org/api/timezone/Asia/Kolkata");
var responseJSON =await response.json();
var dateTime = responseJSON.datetime;
//console.log(responseJSON);
var hour = dateTime.slice(12,13);
if(hour <=6 && hour>=19){
bg = "sprites/bg1.png";
}
else{
bg = "sprites/bg2.jpg";
}
backgroundImg = loadImage(bg);
}