-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
154 lines (127 loc) · 3.32 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
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
149
150
151
152
153
154
var bow , arrow, background, redB, pinkB, greenB ,blueB ,arrowGroup;
var bowImage, arrowImage, green_balloonImage, red_balloonImage, pink_balloonImage ,blue_balloonImage, backgroundImage;
var score =0;
function preload(){
backgroundImage = loadImage("background0.png");
arrowImage = loadImage("arrow0.png");
bowImage = loadImage("bow0.png");
red_balloonImage = loadImage("red_balloon0.png");
green_balloonImage = loadImage("green_balloon0.png");
pink_balloonImage = loadImage("pink_balloon0.png");
blue_balloonImage = loadImage("blue_balloon0.png");
}
function setup() {
createCanvas(400, 400);
//creating background
scene = createSprite(0,0,400,400);
scene.addImage(backgroundImage);
scene.scale = 2.5
// creating bow to shoot arrow
bow = createSprite(380,220,20,50);
bow.addImage(bowImage);
bow.scale = 1;
score = 0
redB= new Group();
greenB= new Group();
blueB= new Group();
pinkB= new Group();
arrowGroup= new Group();
}
function draw() {
background(0);
// moving ground
scene.velocityX = -3
if (scene.x < 0){
scene.x = scene.width/2;
}
//moving bow
bow.y = World.mouseY
// release arrow when space key is pressed
if (keyDown("space")) {
createArrow();
}
//creating continous enemies
var select_balloon = Math.round(random(1,4));
if (World.frameCount % 100 == 0) {
if (select_balloon == 1) {
redBalloon();
} else if (select_balloon == 2) {
greenBalloon();
} else if (select_balloon == 3) {
blueBalloon();
} else {
pinkBalloon();
}
}
if (arrowGroup.isTouching(redB)) {
redB.destroyEach();
//redB.destroy();
//redB.Each();
//ballon.destroyEach();
arrowGroup.destroyEach();
score=score+1;
}
if (arrowGroup.isTouching(greenB)) {
greenB.destroyEach();
arrowGroup.destroyEach();
score=score+3;
}
if (arrowGroup.isTouching(blueB)) {
blueB.destroyEach();
arrowGroup.destroyEach();
score=score+2;
}
if (arrowGroup.isTouching(pinkB)) {
pinkB.destroyEach();
arrowGroup.destroyEach();
score=score+1;
}
drawSprites();
text("Score: "+ score, 300,50);
}
function redBalloon() {
var red = createSprite(0,Math.round(random(20, 370)), 10, 10);
red.addImage(red_balloonImage);
red.velocityX = 3;
red.lifetime = 150;
red.scale = 0.1;
redB.add(red);
}
function blueBalloon() {
var blue = createSprite(0,Math.round(random(20, 370)), 10, 10);
blue.addImage(blue_balloonImage);
blue.velocityX = 3;
blue.lifetime = 150;
blue.scale = 0.1;
blueB.add(blue);
}
function greenBalloon() {
var green = createSprite(0,Math.round(random(20, 370)), 10, 10);
green.addImage(green_balloonImage);
green.velocityX = 3;
green.lifetime = 150;
green.scale = 0.1;
greenB.add(green);
}
function pinkBalloon() {
var pink = createSprite(0,Math.round(random(20, 370)), 10, 10);
pink.addImage(pink_balloonImage);
pink.velocityX = 3;
pink.lifetime = 150;
pink.scale = 1
pinkB.add(pink);
}
// Creating arrows for bow
function createArrow() {
var arrow= createSprite(100, 100, 60, 10);
arrow.addImage(arrowImage);
arrow.x = 360;
arrow.y=bow.y;
arrow.velocityX = -4;
arrow.lifetime = 100;
arrow.scale = 0.3;
//arrowGroup.addGroup(arrow);
//arrow.add(arrowGroup);
//arrowGroup.add();
arrowGroup.add(arrow);
}