2024年11月4日 星期一

WEEK09-翁逸豪

 WEEK09-0

int i;
void setup() {
  size(600, 800);
  i=int(random(10, 14));
  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]!=9) {
              if (a<aU||a>aD) {
                if (b<bL||b>bR) {
                  num[a][b]=9;
                  for (int A=a-1; A<=a+1; A++) {
                    for (int B=b-1; B<=b+1; B++) {
                      if (A>=0&&A<num.length&&B>=0&&B<num[A].length) {
                        if (num[A][B]!=9) {
                          num[A][B]+=1;
                        }
                      }
                    }
                  }
                  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;
  }
}
快完成的期中作業

WEEK09-1

size(500,500);
background(0);
textSize(50);
text("Hello",50,50);
PFont font = createFont("標楷體",50);
textFont(font);
text("中文看到了",50,150);
PFont font2 = createFont("elffont-rock.otf",50);
textFont(font2);
text("ㄇㄉㄈㄎ",50,250);
新增字體

WEEK09-2

PFont font0,font,font2;
void setup(){
size(500,500);
font0 = createFont("Arial",50);
font = createFont("標楷體",50);
font2 = createFont("elffont-rock.otf",50);
}
void draw(){
background(0);
textSize(50);

textFont(font0);
text("Hello",50,50);

textFont(font);
text("中文看到了",50,150);

textFont(font2);
text("ㄇㄉㄈㄎ",50,250);
}
將字體宣告在setup

WEEK09-3

import processing.sound.*;//使用外掛
SoundFile sound;
void setup(){
  size(500,500);
  sound = new SoundFile(this,"In Game Music.mp3");
  //sound.play();//撥放一次
  sound.loop();
}
void draw(){

}
撥放音樂

WEEK09-4

import processing.sound.*;
SoundFile sound1,sound2,hit;
void setup(){
  size(500,500);
  sound1=new SoundFile(this ,"In Game Music.mp3");
  sound2=new SoundFile(this ,"Intro Song_Final.mp3");
  hit = new SoundFile(this,"sword slash.mp3");
  sound2.play();
}
void draw(){
  background(255);
}
void mousePressed(){
  hit.play();
}
void keyPressed(){
  if(key=='1'){
    sound2.stop();
    sound1.play();
  }
  else{
    sound1.stop();
    sound2.play();
  }
}
滑鼠播放音效,按鍵撥放音樂

WEEK09-5

PImage board;
void setup(){
  size(600,400);
  board = loadImage("board.png");
}
float appleX=100,appleY=500,appleVX=5,appleVY=-30;
void draw(){
  background(board);
  fill(255,0,0);
  ellipse(appleX,appleY,80,80);
  appleX+=appleVX;//按照運動速度,X往右移
  appleY+=appleVY;//按照運動速度,Y也會移動
  appleVY+=0.98;//0.98重力加速度(移動的速度會受到加速度影響)
  if(appleX>600){//當蘋果太右邊時,重設蘋果位置與速度
    appleX=random(100,400);appleY=500;appleVX=random(3,6);appleVY=-30;
  }
}
丟右蘋果

WEEK09-6

PImage board;
void setup(){
  size(600,400);
  board = loadImage("board.png");
}
float appleX=100,appleY=500,appleVX=5,appleVY=-30;
void randomApple(){
  appleX=random(100,500);
  appleY=500;
  if(appleX<300)appleVX=random(0,8);
  else appleVX=random(-8,0);
  appleVY=random(-30,-25);
}
void draw(){
  background(board);
  fill(255,0,0);
  ellipse(appleX,appleY,80,80);
  appleX+=appleVX;//按照運動速度,X往右移
  appleY+=appleVY;//按照運動速度,Y也會移動
  appleVY+=0.98;//0.98重力加速度(移動的速度會受到加速度影響)
  if(appleX>600||appleX<0||appleY>550){//當蘋果太右邊時,重設蘋果位置與速度
    randomApple();
  }
}
隨機丟蘋果

WEEK09-7

PImage board;
void setup(){
  size(600,400);
  board = loadImage("board.png");
  textSize(50);
  textAlign(CENTER,CENTER);
  randomApple();
}
float appleX=100,appleY=500,appleVX=5,appleVY=-30;
char applekey;
void randomApple(){
  appleX=random(100,500);
  appleY=500;
  if(appleX<300)appleVX=random(0,8);
  else appleVX=random(-8,0);
  appleVY=random(-30,-25);
  applekey = (char)('a'+int(random(26)));
}
int score=0;
void keyPressed(){
  if(key==applekey){
    score+=100;
  }
  else{
    score-=200;
  }
}
void draw(){
  background(board);
  text("Score:"+score,450,50);
  fill(255,0,0);
  ellipse(appleX,appleY,80,80);
  fill(255,255,0);
  text(applekey,appleX,appleY);
  appleX+=appleVX;//按照運動速度,X往右移
  appleY+=appleVY;//按照運動速度,Y也會移動
  appleVY+=0.98;//0.98重力加速度(移動的速度會受到加速度影響)
  if(appleX>600||appleX<0||appleY>550){//當蘋果太右邊時,重設蘋果位置與速度
    randomApple();
  }
}
按下蘋果上面的文字會有分數變動

WEEK09-8

......
int score=0;
void keyPressed() {
  if (state==0)state=1;
  if (state==2) {
    if (key==applekey) {
      score+=100;
    } else {
      score-=200;
    }
  }
}
int state = 0;
int countdown=60*4;
void draw() {
  background(board);
  if (state==0) {
    fill(255, 255, 0);
    textSize(50);
    text("Press Any Key To Start", 300, 200);
  } else if (state==1) {
    textSize(100);
    countdown--;
    if(countdown>60*3)text("3",300,200);
    else if(countdown>60*2)text("2",300,200);
    else if(countdown>60*1)text("1",300,200);
    else if(countdown>0)text("GO",300,200);
    else state=2;
  } else {
    textSize(50);
    text("Score:"+score, 450, 50);
    fill(255, 0, 0);
    ellipse(appleX, appleY, 80, 80);
    fill(255, 255, 0);
    text(applekey, appleX, appleY);
    appleX+=appleVX;//按照運動速度,X往右移
    appleY+=appleVY;//按照運動速度,Y也會移動
    appleVY+=0.98;//0.98重力加速度(移動的速度會受到加速度影響)
    if (appleX>600||appleX<0||appleY>550) {//當蘋果太右邊時,重設蘋果位置與速度
      randomApple();
    }
  }
}
倒數321GO!

WEEK09-9

import processing.sound.*;
SoundFile sound1, sound2, sound3;
PImage board;
void setup() {
  size(600, 400);
  board = loadImage("board.png");

  textAlign(CENTER, CENTER);
  randomApple();
  sound1 = new SoundFile(this, "Intro Song_Final.mp3");
  sound2 = new SoundFile(this, "Gong.mp3");
  sound3 = new SoundFile(this, "In Game Music.mp3");
  sound1.play();
}
float appleX, appleY, appleVX, appleVY;
char applekey;
void randomApple() {
  appleX=random(100, 500);
  appleY=500;
  if (appleX<300)appleVX=random(0, 8);
  else appleVX=random(-8, 0);
  appleVY=random(-30, -25);
  applekey = (char)('a'+int(random(26)));
}
int score=0;
void keyPressed() {
  if (state==0)state=1;
  if (state==2) {
    if (key==applekey) {
      score+=100;
    } else {
      score-=200;
    }
  }
}
int state = 0;
int countdown=60*4;
void draw() {
  background(board);
  if (state==0) {
    fill(255, 255, 0);
    textSize(50);
    text("Press Any Key To Start", 300, 200);
  } else if (state==1) {
    textSize(100);
    countdown--;
    if (countdown%60==0) {
      sound2.stop();
      sound2.play();
    }
    if (countdown>60*3)text("3", 300, 200);
    else if (countdown>60*2)text("2", 300, 200);
    else if (countdown>60*1)text("1", 300, 200);
    else if (countdown>0)text("GO", 300, 200);
    else {
      state=2;
      sound2.stop();
      sound3.loop();
    }
  } else {
    textSize(50);
    text("Score:"+score, 450, 50);
    fill(255, 0, 0);
    ellipse(appleX, appleY, 80, 80);
    fill(255, 255, 0);
    text(applekey, appleX, appleY);
    appleX+=appleVX;//按照運動速度,X往右移
    appleY+=appleVY;//按照運動速度,Y也會移動
    appleVY+=0.98;//0.98重力加速度(移動的速度會受到加速度影響)
    if (appleX>600||appleX<0||appleY>550) {//當蘋果太右邊時,重設蘋果位置與速度
      randomApple();
    }
  }
}
加入音樂

沒有留言:

張貼留言