目標一:做出爆爆王
1.製作遊戲場地
程式碼:
void setup()
{
size(850,500);
}
void draw()
{
background(#92AD28);
noStroke(); //背景無線條
for(int x=0;x<17;x++) //X軸座標
{
for(int y=0;y<10;y++) //Y軸座標
{
if((x-y)%2==0)fill(#7E9819);
else fill(#92AD28);
rect(x*50,y*50,50,50); //畫正方形
}
}
}
2.製作可在場地上移動的主角
程式碼:
void setup()
{
size(850,500);
}
int userJ=9,userI=5;
float userX,userY; //設定主角
void draw()
{
background(#92AD28);
noStroke();
for(int x=0;x<17;x++)
{
for(int y=0;y<10;y++)
{
if((x-y)%2==0)fill(#7E9819);
else fill(#92AD28);
rect(x*50,y*50,50,50);
}
}
fill(255,0,0);ellipse(userJ*50+25,userI*50+25,50,50); //把主角畫出來
}
void keyPressed() //設定移動指令
{
if(keyCode==LEFT)userJ--;
if(keyCode==RIGHT)userJ++;
if(keyCode==UP)userI--;
if(keyCode==DOWN)userI++;
}
3.主角可以發射水球
程式碼:
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 x=0;x<17;x++)
{
for(int y=0;y<10;y++)
{
if((x-y)%2==0)fill(#7E9819);
else fill(#92AD28);
rect(x*50,y*50,50,50);
}
}
fill(255,0,0);ellipse(userJ*50+25,userI*50+25,50,50);
for(int i=0;i<waterN;i++) //把水球畫出來
{
fill(#93E1E7);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++;} //按空白鍵發射水球
}
沒有留言:
張貼留言