week09
week09_01_createFont_loadFont_textFont
1.字型的改變(例子:精靈文)
2.不能寫在draw裡面,會一直重建字型浪費記憶體
程式碼
//week09_01_createFont_loadFont_textFont
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_02_Font_outside_setup_createFont
1.完成01優化
程式碼
//week09_02_Font_outside_setup_createFont
PFont font0,font,font2;
void setup(){
size(500,500);
font0 = createFont("Ariel",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);
}
week09_03_processing_sound
程式碼
//week09_03_processing_sound
//sketch-manager-libraries-搜尋sound
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_04_multiple_sound_files_keyPressed_stop_play
程式碼
//week09_04_multiple_sound_files_keyPressed_stop_play
import processing.sound.*;
SoundFile sound1, sound2, hit;
void setup(){
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_05_keyboard_ninja_XYVXVY
1.新增背景
2.做出蘋果,給位置,給速度、加速度
3.嘗試變化
程式碼
//week09_05_keyboard_ninja_XYVXVY
PImage board;
void setup(){
size(600,400);
board = loadImage("board.png");
}
float appleX = 100,appleY = 500,appleVX = 3,appleVY = -30;
void draw(){
background(board);
fill(255,0,0);
ellipse(appleX,appleY,80,80);
appleX += appleVX;//照著運動的速度,X往右移動
appleY += appleVY;//照著運動的速度,Y也會移動
appleVY += 0.98;//重力加速度
if(appleX>600) {
appleX = 100; appleY = 500; appleVX = 5; appleVY = -30;
}//當蘋果太右邊,重設新的蘋果位置、速度
}
week09_06_keyboard_ninja_02_void_randomapple
1.讓位置random
程式碼
//week09_06_keyboard_ninja_02_void_randomapple
PImage board;
void setup(){
size(600,400);
board = loadImage("board.png");
}
float appleX = 100,appleY = 500,appleVX = 3,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;//重力加速度
if(appleX>600 || appleX<0 || appleY>550){
randomApple();
}//當蘋果太右邊,重設新的蘋果位置、速度
}
week09_07_keyboard_ninja_03_keypressed_applekey
1.加上分數系統
2.繡上英文字母
程式碼
//week09_07_keyboard_ninja_03_keypressed_applekey
PImage board;
void setup(){
size(600,400);
board = loadImage("board.png");
randomApple();
}
float appleX = 100,appleY = 500,appleVX = 3,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'+random(26));
}
int score = 0;
void keyPressed(){
if(key==appleKey) {
score += 100;
} else {
score -=50;
}
}
void draw(){
background(board);
text("Score:"+score,400,60);
fill(255,0,0);
ellipse(appleX,appleY,80,80);
fill(255,255,0);
textSize(50);
textAlign(CENTER,CENTER);
text(appleKey,appleX,appleY);
appleX += appleVX;//照著運動的速度,X往右移動
appleY += appleVY;//照著運動的速度,Y也會移動
appleVY += 0.98;//重力加速度
if(appleX>600 || appleX<0 || appleY>550){
randomApple();
}//當蘋果太右邊,重設新的蘋果位置、速度
}
week09_07_keyboard_ninja_03_keypressed_applekey
1.做開始介面
程式碼
//week09_07_keyboard_ninja_03_keypressed_applekey
PImage board;
void setup(){
size(600,400);
board = loadImage("board.png");
randomApple();
}
float appleX = 100,appleY = 500,appleVX = 3,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'+random(26));
}
int score = 0;
void keyPressed(){
if(state==0) state = 1;
if(state==2) {
if(key==appleKey) {
score += 100;
} else {
score -=10;
}
}
}
int state = 0;
int countdown = 60*4;
void draw(){
background(board);
textSize(50);
textAlign(CENTER,CENTER);
fill(255,255,0);
if(state==0) 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 {
text("Score:"+score,400,60);
fill(255,0,0);
ellipse(appleX,appleY,80,80);
fill(255,255,0);
textSize(50);
textAlign(CENTER,CENTER);
text(appleKey,appleX,appleY);
appleX += appleVX;//照著運動的速度,X往右移動
appleY += appleVY;//照著運動的速度,Y也會移動
appleVY += 0.98;//重力加速度
if(appleX>600 || appleX<0 || appleY>550){
randomApple();
}//當蘋果太右邊,重設新的蘋果位置、速度
}
}
week09_09_keyboard_ninja_05_add_music
程式碼
//week09_09_keyboard_ninja_05_add_music
import processing.sound.*;
SoundFile sound1,sound2,sound3;
PImage board;
void setup(){
size(600,400);
board = loadImage("board.png");
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 = 100,appleY = 500,appleVX = 3,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'+random(26));
}
int score = 0;
void keyPressed(){
if(state==0) state = 1;
if(state==2) {
if(key==appleKey) {
score += 100;
} else {
score -=10;
}
}
}
int state = 0;
int countdown = 60*4;
void draw(){
background(board);
textSize(50);
textAlign(CENTER,CENTER);
fill(255,255,0);
if(state==0) 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 {
text("Score:"+score,400,60);
fill(255,0,0);
ellipse(appleX,appleY,80,80);
fill(255,255,0);
textSize(50);
textAlign(CENTER,CENTER);
text(appleKey,appleX,appleY);
appleX += appleVX;//照著運動的速度,X往右移動
appleY += appleVY;//照著運動的速度,Y也會移動
appleVY += 0.98;//重力加速度
if(appleX>600 || appleX<0 || appleY>550){
randomApple();
}//當蘋果太右邊,重設新的蘋果位置、速度
}
}







沒有留言:
張貼留言