-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
146 lines (119 loc) · 3.25 KB
/
Copy pathsketch.js
File metadata and controls
146 lines (119 loc) · 3.25 KB
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
var path,boy,cash,diamonds,jwellery,sword;
var pathImg,boyImg,cashImg,diamondsImg,jwelleryImg,swordImg;
var treasureCollection = 0;
var cashG,diamondsG,jwelleryG,swordGroup;
//Estados do Jogo
var PLAY=1;
var END=0;
var gameState=1;
function preload(){
pathImg = loadImage("Road.png");
boyImg = loadAnimation("Runner-1.png","Runner-2.png");
cashImg = loadImage("cash.png");
diamondsImg = loadImage("diamonds.png");
jwelleryImg = loadImage("jwell.png");
swordImg = loadImage("sword.png");
endImg =loadAnimation("fimdeJogo.png");
}
function setup(){
createCanvas(windowWidth,windowHeight);
// Fundo se movendo
path=createSprite(width/2,200);
path.addImage(pathImg);
path.velocityY = 4;
//criando menino correndo
boy = createSprite(width/2,height-20,20,20);
boy.addAnimation("SahilRunning",boyImg);
boy.scale=0.08;
cashG=new Group();
diamondsG=new Group();
jwelleryG=new Group();
swordGroup=new Group();
}
function draw() {
if(gameState===PLAY){
background(0);
boy.x = World.mouseX;
edges= createEdgeSprites();
boy.collide(edges);
//código para redefinir o fundo
if(path.y > height ){
path.y = height/2;
}
createCash();
createDiamonds();
createJwellery();
createSword();
if (cashG.isTouching(boy)) {
cashG.destroyEach();
treasureCollection=treasureCollection + 50;
}
else if (diamondsG.isTouching(boy)) {
diamondsG.destroyEach();
treasureCollection=treasureCollection + 100;
}else if(jwelleryG.isTouching(boy)) {
jwelleryG.destroyEach();
treasureCollection= treasureCollection + 150;
}else{
if(swordGroup.isTouching(boy)) {
gameState=END;
boy.addAnimation("SahilRunning",endImg);
boy.x=width/2;
boy.y=height/2;
boy.scale=0.6;
cashG.destroyEach();
diamondsG.destroyEach();
jwelleryG.destroyEach();
swordGroup.destroyEach();
cashG.setVelocityYEach(0);
diamondsG.setVelocityYEach(0);
jwelleryG.setVelocityYEach(0);
swordGroup.setVelocityYEach(0);
}
}
drawSprites();
textSize(20);
fill(255);
text("Tesouros: "+ treasureCollection,width-150,30);
}
}
function createCash() {
if (World.frameCount % 200 == 0) {
var cash = createSprite(Math.round(random(50, width-50),40, 10, 10));
cash.addImage(cashImg);
cash.scale=0.12;
cash.velocityY = 5;
cash.lifetime = 200;
cashG.add(cash);
}
}
function createDiamonds() {
if (World.frameCount % 320 == 0) {
var diamonds = createSprite(Math.round(random(50, width-50),40, 10, 10));
diamonds.addImage(diamondsImg);
diamonds.scale=0.03;
diamonds.velocityY = 5;
diamonds.lifetime = 200;
diamondsG.add(diamonds);
}
}
function createJwellery() {
if (World.frameCount % 410 == 0) {
var jwellery = createSprite(Math.round(random(50, width-50),40, 10, 10));
jwellery.addImage(jwelleryImg);
jwellery.scale=0.13;
jwellery.velocityY = 5;
jwellery.lifetime = 200;
jwelleryG.add(jwellery);
}
}
function createSword(){
if (World.frameCount % 530 == 0) {
var sword = createSprite(Math.round(random(50, width-50),40, 10, 10));
sword.addImage(swordImg);
sword.scale=0.1;
sword.velocityY = 4;
sword.lifetime = 200;
swordGroup.add(sword);
}
}