2024年10月28日 星期一

WEEK08-翁逸豪

 WEEK08-0

int i;
void setup() {
  size(600, 800);
  i=int(random(8, 11));
  textSize(50);
  textAlign(CENTER, CENTER);
}
int [][]num=new int[8][6];
int [][]press=new int[8][6];
int ClickCount=0;
void draw() {

  for (int j=0; j<6; j++)
  {
    for (int k=0; k<8; k++)
    {
      fill(255);
      rect(j*100, k*100, 100, 100);
      if (press[k][j]==2) {
        fill(0);
        text("X", 50+j*100, 50+k*100);
      }
      if (press[k][j]==1) {
        if (ClickCount==1) {
          int aU=k-1, aD=k+1,bL=j-1, bR=j+1;
          if (aU<0)aU+=1;
          if (aD>7)aD-=1;
          if (bL<0)bL+=1;
          if (bR>5)bR-=1;
          num[k][j]=0;
          fill(0);
          text(""+num[k][j], 50+j*100, 50+k*100);
          while (i!=0) {
            int a=int(random(0, 8));
            int b=int(random(0, 6));
            if (num[a][b]==0) {
              if (a<aU||a>aD) {
                if (b<bL||b>bR) {
                  num[a][b]=9;
                  i--;
                }
              }
            }
          }
        } else {
          fill(0);
          text(""+num[k][j], 50+j*100, 50+k*100);
        }
      }
    }
  }
}
void mousePressed() {
  if (mouseButton==LEFT)
  {
    int x=mouseY/100, y=mouseX/100;
    if (press[x][y]<1)press[x][y]=1;
    ClickCount+=1;
  }
  if (mouseButton==RIGHT)
  {
    int x=mouseY/100, y=mouseX/100;
    if (press[x][y]==0)press[x][y]=2;
    else if (press[x][y]==2)press[x][y]=0;
  }
}
未完成的期中作業

WEEK08-1

PImage img;
void setup(){
  size(640,480);
  img=loadImage("640x480.png");
}
int page=0;
void draw(){
  if(page==0){
    background(0);
    textSize(70);
    textAlign(CENTER,CENTER);
    text("Opening",320,240);
  }
  else if(page==1){
    background(img);
  }
}
void mousePressed(){
  if(page==0)page=1;
}
切換頁面

WEEK08-2

PImage img;
void setup(){
  size(640,480);
  img=loadImage("640x480.png");
}
void draw(){
  background(img);
  for(int i=0;i<15;i++){
    for(int j=0;j<20;j++){
      noFill();
      rect(j*32,i*32,32,32);
    }
  }
}
畫方格

WEEK08-3

PImage img;
void setup(){
  size(640,480);
  img=loadImage("640x480.png");
}
void draw(){
  background(img);
  for(int i=0;i<15;i++){
    for(int j=0;j<20;j++){
      noFill();
      stroke(0);
      rect(j*32,i*32,32,32);
    }
  }
  stroke(255,0,0);
  rect(J*32,I*32,32,32);
}
int I=-1,J=-1;
void mouseMoved(){
  I=mouseY/32;
  J=mouseX/32;
}
int PNUM=0;
void mousePressed(){
  PImage now=createImage(32,32,RGB);
  now.copy(img,J*32,I*32,32,32,0,0,32,32);
  image(now,0,0,320,320);
  now.save(PNUM+".png");
  PNUM++;
}
滑鼠移動到的方格以紅框框顯示,按下滑鼠後儲存該格圖片

WEEK08-4

int [][]floor={
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 19, 3, 22, 3, 22, 9, 2, 2, 2, 9, 2, 16, 5},
};
PImage img;
PImage []fimg=new PImage[40];
void setup() {
  size(640, 480);
  img=loadImage("640x480.png");
  for(int i=1;i<=22;i++)fimg[i]=loadImage(i+".png");
}
void draw() {
  //background(img);
  for (int i=0; i<3; i++) {
    for (int j=0; j<20; j++) {
      int now=floor[i][j];
      image(fimg[now],j*32,i*32);
    }
  }
}
用小格畫地圖

WEEK08-5

int [][]floor={
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 19, 3, 22, 3, 22, 9, 2, 2, 2, 9, 16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 22, 9, 2, 2, 2, 9, 16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 22, 9, 2, 2, 2, 9, 16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 22, 9, 2, 2, 2, 9, 16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 22, 9, 2, 2, 2, 9, 16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 22, 9, 2, 2, 2, 9, 16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 2, 2, 2, 9, 9, 9, 2, 2, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 21, 3, 18, 3, 9, 9, 9, 2, 2, 20, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
};
PImage img, user;
PImage []fimg=new PImage[40];
void setup() {
  size(640, 480);
  img=loadImage("640x480.png");
  user=loadImage("15.png");
  for (int i=1; i<=22; i++)fimg[i]=loadImage(i+".png");
}
int userI=12, userJ=15;
void draw() {
  //background(img);
  for (int i=0; i<floor.length; i++) {
    for (int j=0; j<20; j++) {
      int now=floor[i][j];
      image(fimg[now], j*32, i*32);
    }
  }
  image(user, userJ*32, userI*32);
}
void keyPressed() {
  if (keyCode==RIGHT)userJ++;
  if (keyCode==LEFT)userJ--;
  if (keyCode==UP)userI--;
  if (keyCode==DOWN)userI++;
}
畫地圖,玩家可以操作角色

WEEK08-6

int [][]floor={
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,19, 3,22, 3,22, 9, 2, 2, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3,18, 3,22, 9, 2, 2, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,11, 3, 9, 3,22, 9, 2, 3, 3, 6, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 6, 2, 3,22, 9, 2, 3, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,11, 3, 2, 3, 3, 3, 3, 3, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,18, 3, 2, 2,22, 9, 2, 2, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,17, 3, 3, 2, 9, 9, 9, 2, 2, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,16,12, 3, 2, 9, 9, 9, 2, 2, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 3, 3, 3, 2, 9, 9, 9, 2, 3, 6, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 2, 3, 2, 9, 9, 9, 2, 2, 2, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,20,23, 2, 2, 9, 9, 9, 2, 3,21, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
};
PImage img, user;
PImage []fimg=new PImage[40];
void setup() {
  size(640, 480);
  img=loadImage("640x480.png");
  user=loadImage("15.png");
  for (int i=1; i<=25; i++)fimg[i]=loadImage(i+".png");
}
int userI=11, userJ=16;
void draw() {
  //background(img);
  for (int i=0; i<floor.length; i++) {
    for (int j=0; j<20; j++) {
      int now=floor[i][j];
      image(fimg[now], j*32, i*32);
    }
  }
  image(user, userJ*32, userI*32);
}
void keyPressed() {
  int newI=userI,newJ=userJ;
  if (keyCode==RIGHT)newJ++;
  if (keyCode==LEFT)newJ--;
  if (keyCode==UP)newI--;
  if (keyCode==DOWN)newI++;
  if(floor[newI][newJ]!=1&&floor[newI][newJ]!=3){
    userI=newI;
    userJ=newJ;
  }
}
有牆壁

WEEK08-7

int [][]floor={
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,19, 3,22, 3,22, 9, 2, 2, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3,18, 3,22, 9, 2, 2, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,11, 3, 9, 3,22, 9, 2, 3, 3, 6, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 6, 2, 3,22, 9, 2, 3, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,11, 3, 2, 3, 3, 3, 3, 3, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,18, 3, 2, 2,22, 9, 2, 2, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,17, 3, 3,25, 3, 3, 3, 3, 3, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,16,12, 3,25, 3, 2, 2, 2, 2, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 3, 3, 3,24, 3, 2, 3, 2, 3, 6, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,20,23, 2, 2, 2, 2, 3, 2, 3,21, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
};
PImage img, user;
PImage []fimg=new PImage[40];
void setup() {
  size(640, 480);
  img=loadImage("640x480.png");
  user=loadImage("15.png");
  for (int i=1; i<=25; i++)fimg[i]=loadImage(i+".png");
}
int userI=11, userJ=16;
void draw() {
  //background(img);
  for (int i=0; i<floor.length; i++) {
    for (int j=0; j<20; j++) {
      int now=floor[i][j];
      image(fimg[now], j*32, i*32);
    }
  }
  image(user, userJ*32, userI*32);
  if(gameOver)background(0,255,0);
}
boolean gameOver = false;
void keyPressed() {
  int newI=userI,newJ=userJ;
  if (keyCode==RIGHT)newJ++;
  if (keyCode==LEFT)newJ--;
  if (keyCode==UP)newI--;
  if (keyCode==DOWN)newI++;
  if(floor[newI][newJ]!=1&&floor[newI][newJ]!=3){
    userI=newI;
    userJ=newJ;
    if(floor[newI][newJ]==21||floor[newI][newJ]==20)gameOver=true;
    floor[userI][userJ]=2;
  }
}
經過吃掉,到樓梯換頁面

WEEK08-8

int [][]floor={
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,19, 3,22, 3,22, 9, 2, 2, 2, 9,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 3,18, 3, 9, 9, 9, 2, 2, 2, 9, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,11, 3, 9, 3,26,16,26, 3, 3, 6, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 6, 2, 3,19,26,16, 3,10,13,10, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,11, 3, 2, 3, 3, 3, 3, 3, 2,10,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,18, 3, 2, 2,24, 10, 2, 2, 2,27,10, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,17, 3, 3,25, 3, 3, 3, 3, 2,10,10, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,16,12, 3,25, 3, 2, 2, 2,13,14,16, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 3, 3, 3,24, 3, 2, 3, 2, 3, 6, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 2, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1,20,23, 2, 2, 2, 2, 3, 2, 3,21, 3, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
  {4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
};
PImage img, user;
PImage []fimg=new PImage[40];
void setup() {
  size(640, 480);
  img=loadImage("640x480.png");
  user=loadImage("15.png");
  for (int i=1; i<=27; i++)fimg[i]=loadImage(i+".png");
}
int userI=11, userJ=16;
void draw() {
  //background(img);
  for (int i=0; i<floor.length; i++) {
    for (int j=0; j<20; j++) {
      int now=floor[i][j];
      image(fimg[now], j*32, i*32);
    }
  }
  image(user, 16, 16);
  textSize(30);
  text("Level: "+level, 16, 90);
  textSize(20);
  text("Live: "+live, 16, 140);
  text("Attack: "+att, 16, 170);
  text("Defense: "+def, 16, 200);
  text("MagicDef: "+mdef, 16, 230);
  text("Exp: "+exp, 16, 260);
  text("Coins: "+coin, 16, 290);
  image(user, userJ*32, userI*32);
  if (gameOver==1)background(0, 255, 0);
  if (gameOver==2)background(255, 0, 0);
}
int level = 1, live=2693, att=14, def=16,mdef=10,exp=72,coin=72;
int gameOver = 0;
void keyPressed() {
  int newI=userI, newJ=userJ;
  if (keyCode==RIGHT)newJ++;
  if (keyCode==LEFT)newJ--;
  if (keyCode==UP)newI--;
  if (keyCode==DOWN)newI++;
  if(floor[newI][newJ]==9){
    if(live-10<=0)gameOver = 2;
    else{
      live-=10;
      coin+=10;
      exp+=1;
      userI=newI;
      userJ=newJ;
      floor[userI][userJ]=2;
    }
  }
  else if (floor[newI][newJ]!=1&&floor[newI][newJ]!=3) {
    userI=newI;
    userJ=newJ;
    if (floor[newI][newJ]==21||floor[newI][newJ]==20)gameOver=1;
    floor[userI][userJ]=2;
  }
}
攻擊魔法師的話,會改變數值(live、exp、coin)


沒有留言:

張貼留言