Week06 玄的筆記..
1. 爆爆王 簡單版
void setup()
{
size(850,500);
}
int userJ=9,userI=5;
float userX,userY;
int waterN=0;
int[]waterJ=new int[100];
int[]waterI=new int[100];
void draw()
{
background(#92AD28);
noStroke();
for(int i=0;i<10;i++)
{
for(int j=0;j<17;j++)
{
if((j-i)%2==0) fill(#7E9819);
else fill(#92AD28);
rect(j*50,i*50,50,50);
}
}
fill(255,0,0);
ellipse(userJ*50+25,userI*50+25,50,50);
for(int i=0;i<waterN;i++)
{
fill(#93E1F7);
ellipse(waterJ[i]*50+25,waterI[i]*50+25,30,30);
}
}
void keyPressed()
{
if(keyCode==LEFT)userJ--;
if(keyCode==RIGHT)userJ++;
if(keyCode==UP)userI--;
if(keyCode==DOWN)userI++;
if(key==' '){waterI[waterN]=userI; waterJ[waterN]=userJ; waterN++; }
void setup(){
size(500,500);
}
void draw(){
background(255);
fill(0,155,0);ellipse(250,250,300,300);
for(int i=0;i<9;i++){
fill(255); rect(110+i*30,200,30,30);
if(110+i*30<mouseY && mouseY < 110+i*30+30 &&
200 < mouseY && mouseY <200+30){
fill(0);rect(110+i*30,200,30,30);
}
}
for(int i=0;i<9;i++){
fill(255);rect(110+i*30,300,30,30);
if(110+i*30<mouseY && mouseY <100+i*30+30 &&
300 < mouseY && mouseY <300+30){
fill(0);rect(110+i*30,300,30,30);
}
}
}
size(500,500);
}
void draw(){
background(255);
fill(0,155,0);ellipse(250,250,300,300);
for(int i=0;i<9;i++){
fill(255); rect(110+i*30,200,30,30);
if(110+i*30<mouseY && mouseY < 110+i*30+30 &&
200 < mouseY && mouseY <200+30){
fill(0);rect(110+i*30,200,30,30);
}
}
for(int i=0;i<9;i++){
fill(255);rect(110+i*30,300,30,30);
if(110+i*30<mouseY && mouseY <100+i*30+30 &&
300 < mouseY && mouseY <300+30){
fill(0);rect(110+i*30,300,30,30);
}
}
}
遊戲優化 ( 加上random亂數 . Boolean判斷 .遊戲終止)
int bad=0;
int [] all=new int[18];
void setup(){
size(500,500);
bad=int(random(18)); all[bad]=1;
println(bad);
}
boolean bGameOver=false;
void draw(){
if(bGameOver){
background(255,0,0);
return;
}
background(255);
fill(0,155,0);ellipse(250,250,300,300);
for(int i=0;i<9;i++){
if(all[i]==-1) continue;
fill(255); rect(110+i*30,200,30,30);
if(110+i*30<mouseX && mouseX < 110+i*30+30 &&
200 < mouseY && mouseY <200+30){
fill(0);rect(110+i*30,200,30,30);
if(mousePressed && all[i]!=1) all[i]=-1;
if(mousePressed && all[i]==1) bGameOver=true;
}
}
for(int i=0;i<9;i++){
if(all[i+9]==-1) continue;
fill(255);rect(110+i*30,300,30,30);
if(110+i*30<mouseX && mouseX <100+i*30+30 &&
300 < mouseY && mouseY <300+30){
fill(0);rect(110+i*30,300,30,30);
if(mousePressed && all[i+9]!=1) all[i+9]=-1;
if(mousePressed && all[i+9]==1) bGameOver=true;
}
}
}
案下 亂數 設定的牙齒後
沒有留言:
張貼留言