// week09_01_createFnt_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);
記得先點兩下安裝字型 才能順利createFont
textFont(font2);
text("ㄇㄉㄈㄎ",50,250);
// week09_02_PFomt_outside_void_setp_createFont_void_draw_text
PFont font0,font,font2;
void setup(){
size(500,500);
font0 = createFont("Algerian",50);
font =createFont("標楷體",50);
font2 =createFont("elffont-rock.otf",50);
//println(PFont.list()); //印出現在系統能用的所有字型
}
void draw(){
background(0);
textSize(50);
textFont(font0);
text("Hello",50,50);
textFont(font);
text("中文看到了",50,150);
textFont(font2);
text("ㄇㄉㄈㄎ",50,250);
}
// week09_03_proccessing_sound 聲音相關 使用音樂相關的Library匯式庫
// Sektch-Library-Manager Libraies 找 sound可找到sound函式庫 install
// File-Example, 選libraries核心函式庫 剛剛裝的sound的Soundfile的範例
//以下為精簡版
import processing.sound.*;
SoundFile sound;
void setup(){
size(500,500);
sound = new SoundFile(this,"In Game Music.mp3");
sound.loop();// 一直迴圈撥放
}
void draw(){
}
// week09_04_multiple_sound_files_keyPressed_stop_play
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();//mouse按下時,揮劍的聲音
}
void keyPressed() {
if (key=='1') {
sound2.stop();
sound1.play();
}
}
// week09_05_keyboard_ninja01_background_image_appleX_appleY_appleVX_appleVY_g
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;
appleY += appleVY;
appleVY+= 0.98; //0.98gravity重力加速度(移動的速度,會受到「加速度」影響)
if (appleX >600) {
appleX = 100;
appleY =500;
appleVX =5;
appleVY=-30; //分號分開的四行
}
}
// week09_06_keyboard_ninja02_random
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;
appleVX =random(-8,8);
appleVY =random(-30,-20);
}
void draw() {
background(board);
fill(255, 0, 0);
ellipse(appleX, appleY, 80, 80);
appleX += appleVX;
appleY += appleVY;
appleVY+= 0.98; //0.98gravity重力加速度(移動的速度,會受到「加速度」影響)
if (appleX >600 || appleX <0 || appleY>550) {
randomApple(); //當蘋果出界時,重新設新的蘋果的位置、速度
}
}
// week09_06_keyboard_ninja03_void_randomApple
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,-20);
}
void draw() {
background(board);
fill(255, 0, 0);
ellipse(appleX, appleY, 80, 80);
appleX += appleVX;
appleY += appleVY;
appleVY+= 0.98; //0.98gravity重力加速度(移動的速度,會受到「加速度」影響)
if (appleX >600 || appleX <0 || appleY>550) {
randomApple(); //當蘋果出界時,重新設新的蘋果的位置、速度
}
}
// week09_07_keyboard_ninja04_void_keyPressed_appleKey
PImage board;
void setup() {
size(600, 400);
board = loadImage("board.png");
}
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,400,50);
fill(255, 0, 0);
ellipse(appleX, appleY, 80, 80);
fill(255, 255, 0);
textSize(50);
textAlign(CENTER, CENTER);
text(appleKey, appleX, appleY);
appleX += appleVX;
appleY += appleVY;
appleVY+= 0.98; //0.98gravity重力加速度(移動的速度,會受到「加速度」影響)
if (appleX >600 || appleX <0 || appleY>550) {
randomApple(); //當蘋果出界時,重新設新的蘋果的位置、速度
}
}
// week09_08_keyboard_ninja05_start321_go
PImage board;
void setup() {
size(600, 400);
board = loadImage("board.png");
}
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 (state==0)state=1;
if (state==2) {
if (key == appleKey) {
score+= 100;//答對加分
} else {
score -=200;//答錯扣很多分
}
}
}
int state = 0;
int countdown =64*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, 500);
fill(255, 0, 0);
ellipse(appleX, appleY, 80, 80);
text(appleKey, appleX, appleY);
fill(255, 255, 0);
textSize(50);
textAlign(CENTER, CENTER);
appleX += appleVX;
appleY += appleVY;
appleVY+= 0.98; //0.98gravity重力加速度(移動的速度,會受到「加速度」影響)
if (appleX >600 || appleX <0 || appleY>550) {
randomApple(); //當蘋果出界時,重新設新的蘋果的位置、速度
}
}
}
// week09_09_keyboard_ninja06_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, "");
}
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 (state==0)state=1;
if (state==2) {
if (key == appleKey) {
score+= 100;//答對加分
} else {
score -=200;//答錯扣很多分
}
}
}
int state = 0;
int countdown =64*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, 500);
fill(255, 0, 0);
ellipse(appleX, appleY, 80, 80);
text(appleKey, appleX, appleY);
fill(255, 255, 0);
textSize(50);
textAlign(CENTER, CENTER);
appleX += appleVX;
appleY += appleVY;
appleVY+= 0.98; //0.98gravity重力加速度(移動的速度,會受到「加速度」影響)
if (appleX >600 || appleX <0 || appleY>550) {
randomApple(); //當蘋果出界時,重新設新的蘋果的位置、速度
}
}
}
沒有留言:
張貼留言