2020年3月27日 星期五

今天也還沒玩農場Week04

今天要讓子彈發射

ps.還有學會背景用圖片

ps.ps.最近很想玩大富翁

ps.size的大小要與圖片相同


反正程式如下:

PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int n=0;
void setup()
{
     size(580,438);
     imgBG=loadImage("bk.jpg");
}
void draw()
{
     background(imgBG);
     for(int i=0;i<5;i++)
    {
          circle(x[i],y[i],40);
    }
}
void mousePressed()
{
     if(n>=5)return;                      //////因為陣列只有5,超過5會當機
     x[n]=mouseX;                       //////所以使用if(n>=5)return;這樣就會重複使用子彈
     y[n]=mouseY;
     n++;
}


想要讓子彈往上跑

     


程式如下:


PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int n=0;
void setup()
{
     size(580,438);
     imgBG=loadImage("bk.jpg");
}
void draw()
{
     background(imgBG);
     for(int i=0;i<5;i++)
    {
          circle(x[i],y[i],40);
          y[i]--;                                  ///////可以讓子彈往上跑
    }
}
void mousePressed()
{
     if(n>=5)return;
     x[n]=mouseX;
     y[n]=mouseY;
     n++;
     n=(n+1)%5;
}



現在要用陣列來搞事





程式如下:


int [][]a={
     {1,0,1,0},
     {0,0,0,1},
     {1,1,0,0},
     {0,1,1,0} };
size(400,400);
for(int i=0;i<4;i++)
{
       for(int j=0;j<4;j++)
      {
       if(a[i][j]==1)fill(255,200,120);
       else fill(100,40,35);
       rect(j*100,i*100,100,100);
      }
}

接下來我要讓第一個有點變化,讓球能放大


程式如下:

Pimage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int []r={5,5,5,5,5};
int n=0;
void setup()
{
  size(580,438);
  imgBG=loadImage("bk.jpg");
}
void draw()
{
  background(imgBG);
  for(int i=0;i<5;i++)
  {
    circle(x[i],y[i],r[i]);
  }
  if(mousePressed)r[now]++;
}
int now=0;
void mousePressed()
{
  x[n]=mouseX;
  y[n]=mouseY;
  r[n]=5;
  now=n;
  n=(n+1)%5;
}

沒有留言:

張貼留言