2022年1月17日 星期一

Noteeee [Final] Week19

☂Week19☂


[1/17(一)]

今日是final day!!!


要來跟大家展示我的Doodle Jump💪

在19週展示前,最後加入了(1)背景音(2)計時器(3)失敗畫面

讓我們繼續看下去吧

(1)背景音


















雖然doodle jump這款遊戲原本就無背景音,但為了玩起來更有氣氛,還是決定加了一首輕快又符合此遊戲的bgm! 希望大家覺得這個音樂有搭配到這個遊戲。

(2)計時器

利用以前上課學的,做了一個計時器,但最後很可惜,來不及把最後計下來的時間放到失敗畫面。最後有設計一個比較特別的,就是計時器<500時,就算掉落到起始線,也不會死!  但計時器>500後再掉落,就Game Over了!

(3)失敗畫面





失敗後會出現此圖,素材來自Google大神


💛完整程式碼: 

👉(1)背景音(2)計時器(3)失敗畫面👈

//Doodle Jump製作步驟: (1)jumping主角 (2)跳起來 (3)卡住 (4)畫面捲動
PImage imgBoard01,imgBack,img3;
import ddf.minim.*;//音樂
Minim minim;
AudioPlayer player;
float x=150, y=450, vx=0, vy=0;
boolean jumping=false;
boolean left=false;//左
boolean right=false;//右
boolean alive=true;

float []boardX=new float[11];
float []boardY=new float[11];
int landing=0;//停在哪一個板子上
int second=0;
void setup()
{
    size(300,500);
    fill(#F2D738);
    textSize(45);
    imgBoard01 = loadImage("board01.png");
    imgBack = loadImage("background.png");
    img3 = loadImage("die.png");
    for(int i=0; i<11; i++)
    {
      boardX[i]=random(0,300-67);
      boardY[i]=i*45;
    }
    
     minim = new Minim(this);//加音樂
     player = minim.loadFile("music.mp3");
     player.play();
 
}
float rolling=0;
void draw()
{
  image(imgBack,0,0,300,500);
  ///background(255);
  
  text("Time:"+frameCount, 40,80);
  second=frameCount;
  
  for(int i=0; i<11; i++)
  {
    if(boardY[i]+rolling>500){
      boardY[i]-=495;
      boardX[i]=random(0,300-67);
    }
    //rect(boardX[i],boardY[i], 80, 15); //最原本
    //rect(boardX[i],450-boardY[i]+rolling, 64, 18);//改過(但板子會有邊角)
    image(imgBoard01, boardX[i], boardY[i]+rolling);//再改(板子沒有邊角了,成功)
    //if(boardY[i]+rolling<0) 
    //{
      //boardX[i]=random(0,300-67);
      //boardY[i]=boardY[i]+350;
    //}
  }
  ellipse(x,y,15,15);
  if(left)  x -= 0.8;
  if(right) x += 0.8;
  //x += vx;
  
  if(x< boardX[landing] || boardX[landing]+67<x) jumping=true;//landing=i;//停在哪一個板子上, 超過了,掉下來
  if(x < 0) x+=300;//超過左邊界,從右邊界回來
  if(x > 300) x-=300;//超過右邊界,從左邊界回來
  y += vy; 
  if(jumping) vy += 0.98;//重力加速度(往下的速度)
  if(y>500-18) y=500-18;//地板
  if(vy>=0)
  {//(0)往下,才有可能卡住
    for(int i=0; i<11; i++)
    {
      if(boardX[i] < x && x < boardX[i]+67)//(1)x: 板子的左右邊界符合(主角在板子裡)
      {
        if(y< boardY[i]+rolling && y+vy > boardY[i]+rolling)//(2)y: 上下符合,從板子上,往板子下穿越
        {
          landing=i;
          jumping=false;
          vy=0;
          y = boardY[i]+rolling;//boardY[i];
        }
      }
    }
  }
  
  ///for(int i=0; i<10; i++)
  {
    //image(imgBoard01, boardX[i], 450-boardY[i]+rolling);
    
  }
  //rolling+=1.5;
  if(y<250){
    float diff=250-y;
    rolling += diff;
    y = 250;
  }
  
  if(second>500)//前面時間<500不會死,超過500,且掉到起始線才死!!
  {
    if(y+vy>495) 
    {
      alive=false;
    }
  }
  
  if(alive==false)
  {
    image(img3,0,0,width,height);
  }
}

void keyPressed()
{
  if(keyCode==UP)
  {//(2)跳起來
    vy = -20; jumping=true; //往上的速度,負的越多,跳的越慢
  }
  if(keyCode==LEFT)
  { 
    vx = -0.8; left=true; right=false; //負越多,跑越快
  }
  if(keyCode==RIGHT)
  {
    vx = 0.8;  right=true; left=false;
  }
}


💛期末檢討&心得:
因為時間沒安排好,所以有些東西沒做出來,很可惜! 比如:
1.主角的圖有找到,但圖代替黃球後,整個座標就跑掉了,來不及找問題,所以我才繼續用黃球。
2.計時器最後累積的時間無法顯示在失敗畫面,無法知道自己在此遊戲撐了多久。
3.失敗後,沒有可以重新回到遊戲的按鈕。

這學期很感謝老師的教學,特別是期末遊戲作業,真的幫忙好多😭,太感謝老師耐心的教導了,一開始真的覺得好困難,後來就慢慢做出小遊戲了,自己也有學到東西,很有成就感!!!





WEE13

 東西都差不多了

PImage img,monster,hero,pic1,button;

int N=0;

int condition;

float heroX = 100,heroY = 400;

float monsterX = 150,monsterY = 10;

float []arrowX = new float[100];

float []arrowY = new float[100];

float []arrowVX = new float[100];

float []arrowVY = new float[100];

boolean []arrowFlying = new boolean[100];

boolean gamestart = false;

boolean gameover = false;


void setup(){

  size(300,500);

  

  img = loadImage("background.jpg");

  monster = loadImage("mon.jpg");

  hero = loadImage("bow.jpg");

  pic1 = loadImage("pic1.jpg");

  button = loadImage("button.jpg");

  

  

}



void draw(){

  background(255);

  image(img,0,0);

  image(monster,80,10);

  image(hero,heroX,heroY);

  

  if(keyPressed ){

    if(keyCode == LEFT){

      heroX -= 5;

    }

    if(keyCode == RIGHT){

      heroX += 5;

    }

  }

  

 for(int i=0;i<N;i++){

      arrowY[i] += arrowVY[i];

      ellipse(arrowX[i],arrowY[i],10,10);

  }

}


void mouseClicked(){

  N++;

  arrowX[N-1] = heroX;

  arrowY[N-1] = heroY;

  arrowVX[N-1] = 0;

  arrowVY[N-1] = -3;

}

void mousePressed(){

  gamestart = true;

  if(condition==0){

    image(pic1,0,150);

    image(button,100,200);

  }

  if(mouseButton == LEFT&&dist(300,360,mouseX,mouseY)<60){

    condition = 1;

  }

}

WEEK12

 期末作業

這勿再加上弓箭、按鈕

PImage img,monster,hero,pic1,button;

int N=0;

int condition;

float heroX = 100,heroY = 400;

float monsterX = 150,monsterY = 10;

float []arrowX = new float[100];

float []arrowY = new float[100];

float []arrowVX = new float[100];

float []arrowVY = new float[100];

boolean []arrowFlying = new boolean[100];

boolean gamestart = false;

boolean gameover = false;


void setup(){

  size(300,500);

  

  img = loadImage("background.jpg");

  monster = loadImage("mon.jpg");

  hero = loadImage("bow.jpg");

  pic1 = loadImage("pic1.jpg");

  button = loadImage("button.jpg");

  

  

}



void draw(){

  background(255);

  image(img,0,0);

  image(monster,80,10);

  image(hero,heroX,heroY);

  

  if(keyPressed ){

    if(keyCode == LEFT){

      heroX -= 5;

    }

    if(keyCode == RIGHT){

      heroX += 5;

    }

  }

  

 for(int i=0;i<N;i++){

      arrowY[i] += arrowVY[i];

      ellipse(arrowX[i],arrowY[i],10,10);

  }

}


void mouseClicked(){

  N++;

  arrowX[N-1] = heroX;

  arrowY[N-1] = heroY;

  arrowVX[N-1] = 0;

  arrowVY[N-1] = -3;

}

void mousePressed(){

  gamestart = true;

  if(condition==0){

    image(pic1,0,150);

    image(button,100,200);

  }

  if(mouseButton == LEFT&&dist(300,360,mouseX,mouseY)<60){

    condition = 1;

  }

}


弓箭








按鈕



WEEK11

 還是做期末作業

這次加上圖片

PImage img,monster,hero,pic1,button;

int N=0;

int condition;

float heroX = 100,heroY = 400;

float monsterX = 150,monsterY = 10;

float []arrowX = new float[100];

float []arrowY = new float[100];

float []arrowVX = new float[100];

float []arrowVY = new float[100];

boolean []arrowFlying = new boolean[100];

boolean gamestart = false;

boolean gameover = false;


void setup(){

  size(300,500);

  

  img = loadImage("background.jpg");

  monster = loadImage("mon.jpg");

  hero = loadImage("bow.jpg");

  pic1 = loadImage("pic1.jpg");

  button = loadImage("button.jpg");

  

  

}



void draw(){

  background(255);

  image(img,0,0);

  image(monster,80,10);

  image(hero,heroX,heroY);

  

  if(keyPressed ){

    if(keyCode == LEFT){

      heroX -= 5;

    }

    if(keyCode == RIGHT){

      heroX += 5;

    }

  }

  

 for(int i=0;i<N;i++){

      arrowY[i] += arrowVY[i];

      ellipse(arrowX[i],arrowY[i],10,10);

  }

}


void mouseClicked(){

  N++;

  arrowX[N-1] = heroX;

  arrowY[N-1] = heroY;

  arrowVX[N-1] = 0;

  arrowVY[N-1] = -3;

}

void mousePressed(){

  gamestart = true;

  if(condition==0){

    image(pic1,0,150);

    image(button,100,200);

  }

  if(mouseButton == LEFT&&dist(300,360,mouseX,mouseY)<60){

    condition = 1;

  }

}

背景




主角



怪物








期末作業完成week14

 期末作業完成:






Youtube連結:電流急急棒 - YouTube

程式碼:

PImage ball,maze,gem;

int[] rangeX = {0,125};

int[] rangeY = {480,235};


int ballposX = 30,ballposY = 215;

int offsetX = 0,offsetY = 0;


boolean is_over = false;

boolean is_win = false;


void setup()

{

  size(640,480);

  maze=loadImage("maze.png");

  ball=loadImage("ball.png");

  gem=loadImage("gem.png");

}

void draw()

{

  

  

  background(255);

  imageMode(CENTER); 

  image(maze,320,240);

  image(gem,590,415);

  image(ball,ballposX,ballposY);

  

  if(is_over && !is_win)

  {

    GameOver();

  }

  

  if(is_win)

  {

    Win();

  }

}


void mousePressed()

{

  offsetX = ballposX - mouseX;

  offsetY = ballposY - mouseY;

}


void mouseDragged()

{

  if(!is_over)

  {

    ballposX = offsetX + mouseX;

    ballposY = offsetY + mouseY;

  }

  

  detCollision();

  


}


void GameOver()

{

  textAlign(CENTER);

  textSize(100);

  fill(0);

  text("Game Over",320,240);

}


void Win()

{

  textAlign(CENTER);

  textSize(100);

  fill(0);

  text("Victory",320,240);

}


void detCollision()

{

   //左下

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY-13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY-13 > 235)

  {

    is_over = true;

  }

  

  //左上

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY-13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY-13 < 195)

  {

    is_over = true;

  }

  

  //右上

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY+13 < 395)

  {

    is_over = true;

  }

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  if(ballposX-13 > 515 && ballposX-13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  

  //中上

  if(ballposX+13 > 125 && ballposX+13 < 515 && ballposY-13 < 45)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 515 && ballposY-13 < 45)

  {

    is_over = true;

  }

  

  //中下

  if(ballposX+13 > 125 && ballposX+13 < 640 && ballposY+13 > 435)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 640 && ballposY-13 > 435)

  {

    is_over = true;

  }

  

  //左下2

  if(ballposX+13 > 125 && ballposX+13 < 275 && ballposY+13 > 285)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 275 && ballposY+13 > 285)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 275 && ballposY-13 > 285)

  {

    is_over = true;

  }

  

  //右下2

  if(ballposX+13 > 275 && ballposX+13 < 475 && ballposY+13 > 385)

  {

    is_over = true;

  }

  if(ballposX-13 > 275 && ballposX-13 < 475 && ballposY+13 > 385)

  {

    is_over = true;

  }

  if(ballposX-13 > 275 && ballposX-13 < 475 && ballposY-13 > 385)

  {

    is_over = true;

  }

  

  //右下2上面的

  if(ballposX+13 > 416 && ballposX+13 < 475 && ballposY-13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 416 && ballposX+13 < 475 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX-13 > 416 && ballposX-13 < 475 && ballposY+13 > 235)

  {

    is_over = true;

  }

  

  //中間

  if(ballposX+13 > 165 && ballposX+13 < 376 && ballposY-13 > 85 && ballposY-13 < 245)

  {

    is_over = true;

  }

  if(ballposX+13 > 165 && ballposX+13 < 376 && ballposY+13 > 85 && ballposY+13 < 245)

  {

    is_over = true;

  }

  if(ballposX-13 > 165 && ballposX-13 < 376 && ballposY+13 > 85 && ballposY+13 < 245)

  {

    is_over = true;

  }

  if(ballposX-13 > 165 && ballposX-13 < 376 && ballposY+13 > 85 && ballposY-13 < 245)

  {

    is_over = true;

  }

  

  //中間右

  if(ballposX+13 > 376 && ballposX+13 < 475 && ballposY-13 > 85 && ballposY-13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 376 && ballposX+13 < 475 && ballposY+13 > 85 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 376 && ballposX-13 < 475 && ballposY+13 > 85 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 376 && ballposX-13 < 475 && ballposY+13 > 85 && ballposY-13 < 195)

  {

    is_over = true;

  }

  

  //中間右下

  if(ballposX+13 > 315 && ballposX+13 < 376 && ballposY-13 > 245 && ballposY-13 < 345)

  {

    is_over = true;

  }

  if(ballposX+13 > 315 && ballposX+13 < 376 && ballposY+13 > 245 && ballposY+13 < 345)

  {

    is_over = true;

  }

  if(ballposX-13 > 315 && ballposX-13 < 376 && ballposY+13 > 245 && ballposY+13 < 345)

  {

    is_over = true;

  }

  if(ballposX-13 > 315 && ballposX-13 < 376 && ballposY+13 > 245 && ballposY-13 < 345)

  {

    is_over = true;

  }

  

  //寶石

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  }


WEEK10

 開始做期末作品

PImage img,monster,hero,pic1,button;

int N=0;

int condition;

float heroX = 100,heroY = 400;

float monsterX = 150,monsterY = 10;

float []arrowX = new float[100];

float []arrowY = new float[100];

float []arrowVX = new float[100];

float []arrowVY = new float[100];

boolean []arrowFlying = new boolean[100];

boolean gamestart = false;

boolean gameover = false;


void setup(){

  size(300,500);

  

  img = loadImage("background.jpg");

  monster = loadImage("mon.jpg");

  hero = loadImage("bow.jpg");

  pic1 = loadImage("pic1.jpg");

  button = loadImage("button.jpg");

  

  

}



void draw(){

  background(255);

  image(img,0,0);

  image(monster,80,10);

  image(hero,heroX,heroY);

  

  if(keyPressed ){

    if(keyCode == LEFT){

      heroX -= 5;

    }

    if(keyCode == RIGHT){

      heroX += 5;

    }

  }

  

 for(int i=0;i<N;i++){

      arrowY[i] += arrowVY[i];

      ellipse(arrowX[i],arrowY[i],10,10);

  }

}


void mouseClicked(){

  N++;

  arrowX[N-1] = heroX;

  arrowY[N-1] = heroY;

  arrowVX[N-1] = 0;

  arrowVY[N-1] = -3;

}

void mousePressed(){

  gamestart = true;

  if(condition==0){

    image(pic1,0,150);

    image(button,100,200);

  }

  if(mouseButton == LEFT&&dist(300,360,mouseX,mouseY)<60){

    condition = 1;

  }

}

WEEK6

 學習text

size(500,500);

fill(#1777A2);

textSize(50);

text("HIIII!",50,50);

再來是不同程式碼,座標不同

void setup()

{

  size(500,500);

  fill(#1777A2);

  textSize(50);

}

void draw()

{

    text("HIIII!",50,100);

}


使用frameCount來跑秒,一秒60偵

void setup()

{

  size(500,500);

  fill(#1777A2);

  textSize(50);

}

void draw()

{

  background(255);  

  text("Time:"+frameCount,50,100);

}

再來是按下滑鼠後,會變換文字

PFont font1,font2;
void setup()
{
   size(500,500);
   font1 = createFont("標楷體",100);
   textFont(font1);
   font2 = createFont("微軟正黑體",100);
}
void draw()
{
  background(0);  
  text("中文",100,100); 
  if(mousePressed) textFont(font2);
  else textFont(font1);
}