Created
May 27, 2016 02:02
-
-
Save koluku/0fc4d37e162c674909e76fec4b0f44d5 to your computer and use it in GitHub Desktop.
ブロック崩しの途中 2016-05-27 11:00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PImage img; | |
void setup() { | |
size(400, 580); | |
frameRate(30); | |
img = loadImage("background.jpg"); | |
// block count | |
int [] blockCount = new int[blockItems]; | |
for(int i = 0; i < blockItems; i++) { | |
blockCount[i] = int(random(1, 3)); | |
} | |
} | |
void draw() { | |
if(flag) { | |
background(7,5,10); | |
image(img, 0, height - 266); | |
ball(); | |
racket(); | |
block(); | |
if(x < 0) { | |
x = 0; | |
speedX = reflect(speedX); | |
} | |
if(x > width - ballWidth) { | |
x = width - ballWidth; | |
speedX = reflect(speedX); | |
} | |
if(y < 0){ | |
y = 0; | |
speedY = reflect(speedX); | |
} | |
if(y >= racketY - ballHeight && y <= racketY) { | |
if(x >= mouseX - racketWidth/2 && x <= mouseX + racketWidth/2) { | |
y = racketY - ballHeight; | |
speedY = reflect(speedY); | |
} | |
} | |
x += speedX; | |
y += speedY; | |
if(y > height - ballHeight) { | |
flag = false; | |
} | |
} | |
else { | |
fill(gameoverColor); | |
textSize(20); | |
text("Game Over!", width/2 - 57, height/2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int reflect(int speed) { | |
speed *= -1; | |
return speed; | |
} | |
void ball() { | |
fill(ballColor); | |
ellipse(x, y, ballWidth, ballHeight); | |
} | |
void racket() { | |
fill(racketColor); | |
if(mouseX + racketWidth/2 > width) { | |
rect(width - racketWidth, racketY, racketWidth, racketHeight); | |
} | |
else if(mouseX - racketWidth/2 < 0) { | |
rect(0, racketY, racketWidth, racketHeight); | |
} | |
else { | |
rect(mouseX - racketWidth/2, racketY, racketWidth, racketHeight); | |
} | |
} | |
void block() { | |
for(int i = 0; i < blockLine; i++) { | |
for(int j = 0; j < blockColumn; j++) { | |
rect((blockWidth + 3) * j + 10, (blockHeight + 10) * i + 10, blockWidth, blockHeight); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flag | |
boolean flag = true; | |
// ball | |
int ballWidth = 8; | |
int ballHeight = 8; | |
// ball speed | |
int speedX = 1; | |
int speedY = 2; | |
// ball color | |
int ballColor = 255; | |
// racket | |
int racketWidth = 50; | |
int racketHeight = 10; | |
// racket position | |
// 変数にheight * 75/100を代入すると正確な数値を出力しないことに注意 | |
int racketY = 260; | |
// racket right/left | |
// なぜか機能しないので使用しない | |
// float racketRight = mouseX + racketWidth/2; | |
// float racketLeft = mouseX - racketWidth/2; | |
// racket color | |
int racketColor = 255; | |
// block | |
int blockWidth = 20; | |
int blockHeight = 20; | |
// block items | |
int blockColumn = 8; | |
int blockLine = 2; | |
int blockItems = blockColumn * blockLine; | |
// shoot out ball position | |
int shootoutX = 10; | |
int shootoutY = (blockHeight + 10) * blockLine + 10; | |
// ball position | |
int x = shootoutX; | |
int y = shootoutY; | |
// block color | |
int blockColor = 255; | |
// background color | |
int backgroundColor = 200; | |
int gameoverColor = int(backgroundColor * 0.5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment