ボール ゲーム
processingで作ったボールゲームです。
使い方
▶▲キーでボールを操作できます。 針に当たると、ボールが割れます。そして、♥が落下します。 地面はランダムに生成されます。針もランダムに出現します。 ♥がなくなってから、針に当たるとGAME OVER。時間が経つごとに画面の動きが速くなります。ボールが遅れて左に吸い込まれると、GAME OVERになるので、注意してください。
スコアは、一度画面を閉じるとリセットされます。続けて遊ぶ時に、一番高いスコアが、HISCOREとして表示されます。
以下がProssecingのソースコードです。
float sc = 3;
PFont font;
PImage[] data = new PImage[256];
PImage ball;
PImage teki;
PImage[] haato = new PImage[5];
PImage menu;
float hy = 1000, hys;
float scs;
float scsc;
float addspeed = 0;
int[][] map = new int[67][32];
float[] ro(float x, float y, float xc, float yc, float theta) {
float[] out = {0, 0};
y = -y;
yc = -yc; // 数学座標と同じ様にするためにy座標値を反転
out[0] = (x - xc) * cos(theta) - (y - yc) * sin(theta) + xc;
out[1] = -1.0 * ( (x - xc) * sin(theta) + (y - yc) * cos(theta) + yc );
return out;
}
class per {
float x;
float y;
float xs;
float ys;
float s;
color c;
}
int ok;
per[] per = new per[100];
void bom(float x, float y) {
for (int i = 0; i < 100; i++) {
if (random(100) < 5) {
per[i].s = random(0, 60);
per[i].x = x;
per[i].y = y;
per[i].xs = random(-5, 5)-10;
per[i].ys = random(-2, 0);
per[i].c = get(int(bx+random(-32, 32)), int(by+12));
}
}
}
float os;
void setup() {
font = loadFont("font10.vlw");
textFont(font, 40);
menu = loadImage("menu.png");
ball = loadImage("ball.png");
teki = loadImage("yurei.png");
data[0] = loadImage("0.png");
data[1] = loadImage("1.png");
data[2] = loadImage("2.png");
data[3] = loadImage("3.png");
for (int i = 0; i < 5; i++) {
haato[i] = loadImage("anime/haato/"+i+".png");
}
size(512, 256);
surface.setSize(int(512*sc), int(256*sc));
frameRate(60);
noStroke();
noSmooth();
noiseDetail(3);
for (int i = 0; i < 100; i++) {
per[i] = new per();
per[i].c = data[2].get(int(random(8)), int(random(4)));
}
}
int oldmilis;
float sad;
int hp = 10;
void tex(String t, float x, float y) {
fill(0);
y += 4;
text(t, 8-2+x, 24-2+y);
text(t, 4-2+x, 24+4-2+y);
text(t, 8-2+x, 24+4-2+y);
fill(255);
text(t, 4-2+x, 24-2+y);
}
float xx;
float s;
float bx, by, bxs, bys;
int score;
boolean h;
boolean jt;
int thp = 0;
int tec;
int nscore;
int muteki;
float ms;
float msin;
float scorex = -1000;
float mslorex = -1000;
float mno = 1;
float[] xy = {0, 0};
float kx, kxs;
boolean t;
int hiscore;
float bs;
float bss;
int y = 5;
int gg;
boolean te;
float bxp, byp;
float tex, tey;
void draw() {
scale(sc);
scs = xx;
background(150, 230, 255);
textFont(font, 11);
if (xx < -8)xx = -8;
for (int i = 0; i < 100; i++) {
if (per[i].s >= 0) {
fill(per[i].c);
rect(per[i].x, per[i].y, 1, 1);
per[i].s -= 3;
per[i].x += per[i].xs;
per[i].x -= xx;
per[i].y += per[i].ys;
per[i].ys += 0.2;
per[i].xs /= 1.05;
}
}
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 65; x++) {
image(data[map[x][31-y]], (x*8)-xx, y*8);
//text(nf(map[x][31-y], 1), (x*8)-xx+1, y*8+10);
for (int k = 0; k < 1; k++) {
if (y < 30) {
if (ok > 0)ok--;
if (ok <= 0) {
for (int i = 1; i < 5; i++) {
if (map[x][31-y] == i) {
if (map[x][31-y-1] == 0) {
int yy = 31-y-1;
if (yy < 31) {
int xx = x;
if (xx > 1 && xx < 64) {
map[xx][yy+1] = 0;
map[xx][yy] = i;
}
}
}
}
}
ok += 6+2;
ok = 12;
}
}
}
}
}
textFont(font, 40);
if (nscore < 66) {
xx += 8;
} else {
mno *= 1.001;
if (keyPressed && kx < 1) {
kxs = 1;
if (kx < 512)muteki = 240;
}
}
if (xx >= 8) {
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 66; x++) {
map[x][y] = map[x+1][y];
ms = 0;
}
}
nscore++;
xx = 0;
int ya = int(noise(s)*16)+4;
//if (ya < y)y -= 2;
//if (ya > y)y += 2;
y = ya;
for (int yy = 0; yy < y; yy++) {
map[65][yy] = 1;
}
map[65][y] = 2;
if (random(100) < hp/3+0.5 ) {
map[65][y+1] = 3;
}
s += 0.03;
if (random(100) < 2) {
s += 0.8;
}
if (random(1000000) < score) {
if (te == false) {
te = true;
}
}
if (kx >= 512) {
bx -= 8;
score++;
}
}
if (kx >= 511) {
mslorex = 0;
//bx += xx;
if (hiscore < score)hiscore = score;
xx += 1+addspeed;
addspeed += 0.0005;
//score = (millis()-oldmilis)/100;
boolean tya = false;
boolean end = false;
int tx = int(bx-bxp);
int ty = int(by-byp);
if (tx < 0)tx = -tx;
if (ty < 0)ty = -ty;
tx /= 8;
ty /= 8;
//println(tx);
if (t || muteki <= 1) {
image(ball, (bx-4)-xx-tx, by-8-ty, 8+(tx*2), 8+(ty*2));
}
if (te) {
image(teki, tex-8, tey);
tex += sin(os)*2;
tey += cos(os)*2;
if (tec < 480) {
float s = atan2(bx-tex, by-tey);
tex += sin(s)/2;
tey += cos(s)/2;
os += 0.1;
//tex -= 1+addspeed;
if (int(tex/8) == int(bx/8) && int(tey/8) == int(by/8)) {
if (muteki <= 1) {
hp--;
muteki = 60;
tec = 480;
}
}
}
if (tex < 0) {
tex = 0;
}
if (tex > 512 || tex < 0 || tey < 0 || tey > 255)te = false;
} else {
tec = 0;
tex = 511;
tey = 1;
}
tec++;
bxp = bx;
byp = by;
t = !t;
if (bx < 16) {
end = true;
}
if (by >= 3 && int(by/8) < 31 && bx > 1 && int(bx/8) < 62) {
if (map[int((bx/8)+1)][31-int(by/8)] != 0 || map[int((bx/8))][31-int(by/8)] != 0 || map[int((bx/8)-1)][31-int(by/8)] != 0 ) {
if (by != int(by/8)*8) {
if (by > int(by/8)*8) {
by = int(by/8)*8;
}
bys = 0.2;
}
tya = true;
if (map[int((bx/8)+1)][31-int(by/8)] == 3 || map[int((bx/8))][31-int(by/8)] == 3) {
if (muteki <= 1) {
hp--;
bxs *= 4;
}
muteki = 60;
}
if (bys > 10 || bxs > 3 || bxs < -3) {
map[int((bx/8)-1)][31-int(by/8)] = 0;
map[int((bx/8)-0)][31-int(by/8)] = 0;
map[int((bx/8)+1)][31-int(by/8)] = 0;
map[int((bx/8)-2)][31-int(by/8)+1] = 0;
map[int((bx/8)-1)][31-int(by/8)+1] = 0;
map[int((bx/8)-0)][31-int(by/8)+1] = 0;
map[int((bx/8)+1)][31-int(by/8)+1] = 0;
map[int((bx/8)+2)][31-int(by/8)+1] = 0;
map[int((bx/8)-3)][31-int(by/8)+2] = 0;
map[int((bx/8)-2)][31-int(by/8)+2] = 0;
map[int((bx/8)-1)][31-int(by/8)+2] = 0;
map[int((bx/8)-0)][31-int(by/8)+2] = 0;
map[int((bx/8)+1)][31-int(by/8)+2] = 0;
map[int((bx/8)+2)][31-int(by/8)+2] = 0;
map[int((bx/8)+3)][31-int(by/8)+2] = 0;
}
bys = -0.001;
}
if (hp < 0)end = true;
if (thp != hp) {
hy = 0;
hys = 0;
}
thp = hp;
for (int i = 0; i < hp; i++) {
int t = int(random(-(8-hp), 8-hp))/4;
image(haato[0], 512-16-(i*16), t);
}
image(haato[0], (512-16-((hp-0)*16)), hy);
hy += hys;
hys += 0.2;
if (muteki > 0) {
muteki--;
}
if (end && muteki <= 0) {
//kx = 0;
kxs = -3;
//bys = -10;
bss += 1;
}
bs += bss;
if (bs > 100)end = true;
bss *= 1.003;
bxs /= 1.02;
int sc = int(bx)-256;
sc /= 30;
if (sc < 0)sc = 0;
xx += sc;
//println(sc);
if (tya)gg = 10;
if (gg >= 0)gg--;
if (keyPressed) {
if (keyCode == RIGHT) {
} else {
if (gg >= 0) {
if (!jt) {
bys += -1;
bxs += 0.1;
//jt = true;
}
}
}
bom(bx, by-bys);
if (bxs < 0.5)bxs = 0.5;
bxs += 0.02+addspeed;
float msc = score;
msc /=1500;
if (bxs > msc+4)bxs = msc+4;
}
if (keyPressed == false) {
jt = false;
}
}
bx += bxs;
if (bx > 512-32)bx = 512-32;
//bx -= scsc;
//bx += xx;
//tex("BALLX:"+nf(int(bx/8), 2, 0), 2+scorex, 2+40);
//tex("BALLY:"+nf(int(by/8), 2, 0), 2+scorex, 2+80);
by += bys;
bys += 0.5;
} else {
bx = 256;
by = -16;
bs = 0;
bss = 0;
}
//if(mousePressed)bom(mouseX,mouseY);
if (kx < 512) {
tex = -8;
thp = 8;
hp = 8;
addspeed = 0;
mslorex = -400;
score = 0;
oldmilis = millis();
//tex("FRATE:"+nf(frameRate,2,2), 2, 2+14);
if (mno > 20)mno = 100000000;
//println(mno);
ms = (sin(msin)/6)/mno;
if (msin > PI*2)msin = 0;
if (kx > 0 && kx < 4) {
mno = 1;
msin = 0;
//mno *= 1.0001;
} else {
mno *= 1.001;
}
if (kx <= 0) {
msin += 0.1;
mno *= 1.01;
} else {
msin -= 0.03;
kxs *= 1.02;
}
int ya = 1;
if (nscore >= 66) {
ya = 2;
}
for (int y = 0; y < 8*ya; y++) {
for (int x = 0; x < 32; x++) {
xy = ro((x*16), y*16, 256, 128, ms);
image(menu.get(x*16-1, y*16-1, 16+2, 16+2), xy[0]+kx, xy[1]);
}
}
}
h = !h;
kx += kxs;
kxs *= 1.01;
if (kx < 0)kx = 0;
if (kx > 512)kx = 512;
scorex = ( mslorex + scorex * 15 )/16;
tex("SCORE :"+nf(score, 5), 2+scorex, 2);
tex("HISCORE:"+nf(hiscore, 5), 2+scorex, 2+28);
}
⇩使用画像です。