Skip to content

Commit 753ebbc

Browse files
committed
Formatting/style fixes
1 parent 316cf5e commit 753ebbc

File tree

3 files changed

+43
-53
lines changed

3 files changed

+43
-53
lines changed

bird.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
class Bird {
77
constructor() {
8-
this.y = height/2;
8+
this.y = height / 2;
99
this.x = 64;
1010

1111
this.gravity = 0.6;
1212
this.lift = -15;
1313
this.velocity = 0;
14-
15-
this.icon = loadImage("graphics/train.png");
14+
15+
this.icon = birdSprite;
1616
this.width = 64;
1717
this.height = 64;
1818
}
@@ -21,7 +21,7 @@ class Bird {
2121
// draw the icon CENTERED around the X and Y coords of the bird object
2222
image(this.icon, this.x - (this.width / 2), this.y - (this.height / 2), this.width, this.height);
2323
}
24-
24+
2525
up() {
2626
this.velocity += this.lift;
2727
}
@@ -30,16 +30,15 @@ class Bird {
3030
this.velocity += this.gravity;
3131
this.velocity *= 0.9;
3232
this.y += this.velocity;
33-
34-
if (this.y >= height - this.height/2) {
35-
this.y = height - this.height/2;
33+
34+
if (this.y >= height - this.height / 2) {
35+
this.y = height - this.height / 2;
3636
this.velocity = 0;
3737
}
3838

39-
if (this.y <= this.height/2) {
40-
this.y = this.height/2;
39+
if (this.y <= this.height / 2) {
40+
this.y = this.height / 2;
4141
this.velocity = 0;
4242
}
4343
}
4444
}
45-

pipe.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
class Pipe {
77
constructor() {
88
this.spacing = 110;
9-
this.top = random(height/6, 3/4*height);
9+
this.top = random(height / 6, 3 / 4 * height);
1010
this.bottom = this.top + this.spacing;
1111

1212
this.x = width;
1313
this.w = 20;
1414
this.speed = 2;
1515

16-
this.passed=false;
16+
this.passed = false;
1717
this.highlight = false;
1818
}
1919

2020
hits(bird) {
21-
if (bird.y - (bird.height / 2) < this.top || bird.y+(bird.height / 2) > this.bottom) {
22-
if (bird.x +(bird.width / 2)> this.x + this.w && bird.x - (bird.width / 2) < this.x) {
21+
if (bird.y - (bird.height / 2) < this.top || bird.y + (bird.height / 2) > this.bottom) {
22+
if (bird.x + (bird.width / 2) > this.x + this.w && bird.x - (bird.width / 2) < this.x) {
2323
this.highlight = true;
24-
this.passed=true;
24+
this.passed = true;
2525
return true;
2626
}
2727
}
@@ -31,16 +31,16 @@ class Pipe {
3131

3232
//this function is used to calculate scores and checks if we've went through the pipes
3333
pass(bird) {
34-
if (bird.x > this.x && !this.passed) {
35-
this.passed=true;
36-
return true;
37-
}
38-
return false;
34+
if (bird.x > this.x && !this.passed) {
35+
this.passed = true;
36+
return true;
37+
}
38+
return false;
3939
}
40-
40+
4141
show() {
42-
image(pipeBodySprite,this.x,0,this.w,this.top);
43-
image(pipeBodySprite,this.x,this.bottom,this.w,height);
42+
image(pipeBodySprite, this.x, 0, this.w, this.top);
43+
image(pipeBodySprite, this.x, this.bottom, this.w, height);
4444
}
4545

4646
update() {

sketch.js

+21-30
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,33 @@
55

66
var bird;
77
var pipes = [];
8-
var score=0;
9-
var maxScore=0;
10-
11-
var pipeSprite,pipBodySprite;
8+
var score = 0;
9+
var maxScore = 0;
10+
var birdIcon;
11+
var pipeBodySprite;
12+
var bgImg;
13+
var bgX = 0;
1214

1315
function preload() {
14-
15-
pipeBodySprite = loadImage("./graphics/pipe_body.png");
16-
16+
pipeBodySprite = loadImage("./graphics/pipe_body.png");
17+
birdSprite = loadImage("graphics/train.png");
18+
bgImg = loadImage("graphics/background.png");
1719
}
1820

19-
var bgImg;
20-
var bgX = 0;
21-
2221
function setup() {
2322
createCanvas(600, 600);
2423
bird = new Bird();
2524
pipes.push(new Pipe());
26-
bgImg = loadImage("graphics/background.png");
2725
}
2826

2927
function draw() {
30-
3128
background(0);
32-
3329
// Draw our background image, then move it at the same speed as the pipes
3430
image(bgImg, bgX, 0, bgImg.width, height);
3531
bgX -= pipes[0].speed;
3632

3733
// this handles the "infinite loop" by checking if the right
38-
// edge of the image would be on the screen, if it is draw a
34+
// edge of the image would be on the screen, if it is draw a
3935
// second copy of the image right next to it
4036
// once the second image gets to the 0 point, we can reset bgX to
4137
// 0 and go back to drawing just one image.
@@ -54,17 +50,14 @@ function draw() {
5450
console.log("YAY");
5551
score++;
5652
}
57-
53+
5854
if (pipes[i].hits(bird)) {
5955
gameover();
6056
}
6157

62-
6358
if (pipes[i].offscreen()) {
6459
pipes.splice(i, 1);
6560
}
66-
67-
6861
}
6962

7063
bird.update();
@@ -74,26 +67,24 @@ function draw() {
7467
pipes.push(new Pipe());
7568
}
7669

77-
7870
showScores();
7971
}
8072

8173
function showScores() {
82-
textSize(32);
83-
text("score: "+score,1,32 );
84-
text("record: "+maxScore,1,64 );
74+
textSize(32);
75+
text("score: " + score, 1, 32);
76+
text("record: " + maxScore, 1, 64);
8577
}
8678

8779
function gameover() {
88-
console.log("HIT");
89-
textSize(64);
90-
text('HIT',width/2,height/2);
91-
maxScore=max(score,maxScore);
92-
score=0;
80+
console.log("HIT");
81+
textSize(64);
82+
text("HIT", width / 2, height / 2);
83+
maxScore = max(score, maxScore);
84+
score = 0;
9385
}
9486
function keyPressed() {
95-
if (key == ' ') {
87+
if (key == " ") {
9688
bird.up();
97-
//console.log("SPACE");
9889
}
99-
}
90+
}

0 commit comments

Comments
 (0)