Week06 打字遊戲
week06_1_text_textSize_fill
▼文字大小和填色
▼調整介面讓26個字母可以在同一行,只有大小寫可以輸入
▼ 下載Sound函式庫
week06_6_game_dadada_good_over
▼ 音效
week06_7_keyPressed_da_ENTER_dingdong
▼ 音效
import processing.sound.*; //Sketch->Library打開SoundFile da, dingdong, ouch; void setup(){ size(850,400); textSize(50); da = new SoundFile(this, "da.mp3"); dingdong = new SoundFile(this, "dingdong.mp3"); ouch = new SoundFile(this, "ouch.mp3"); } String line = ""; void draw(){ background(0); text("Input: " + line, 50,100); } void keyPressed(){ if(key >= 'A' && key <= 'Z') { line += key; da.play();} if(key >= 'a' && key <= 'z') { line += key; da.play();} if(key == BACKSPACE && line.length()>0) { line = line.substring( 0, line.length()-1); ouch.play(); } if(key == ENTER){ dingdong.play(); } }
week06_8_game_shoot_word_x_y
▼ if (keyPressed)對文字射出紅色線
void setup(){ size (400,600); textSize(12); } String Q = "hello" , A=""; float x = 100, y=100; void draw(){ background(0); text(Q,x,y); ellipse(200,550,20,20); float dx = (200-x), dy = (550-y), d = sqrt(dx*dx+dy*dy)*3; x += dx / d; y += dy / d; if(keyPressed){ stroke(255,0,0); line(200,550,x,y); } }
week06_9_game_shoot_string_compare_Q_A
▼ charAt(正確字串A的長度 ) //判斷是否與字串Q相同
void setup(){ size (400,600); textSize(12); } String Q = "hello" , A=""; float x = 100, y=100; void draw(){ background(0); fill(#FFFFFF);text(Q,x,y); fill(#FF0000);text(A,x,y); ellipse(200,550,20,20); float dx = (200-x), dy = (550-y), d = sqrt(dx*dx+dy*dy)*3; x += dx / d; y += dy / d; if(keyPressed){ stroke(255,0,0); line(200,550,x,y); } } void keyPressed(){ int i = A.length(); if( key == Q.charAt(i)){ A += key; } }
week06_A_game_shoot_string_compare_Q_A_next_word
▼ 單字隨機出現,拼出所有字母會出現下一個
void setup(){
size(400,600); textSize(20); randomQ(); } void randomQ(){ int i = int(random(QQ.length)); Q = QQ[i]; x = random(0, 300); y = random(0, 100); } String [] QQ ={"void", "setup", "float", "string", "background", "fill"}; String Q = "hello", A = ""; float x =100, y=100; void draw(){ background(0); fill(#FFFFFF); text(Q, x, y); fill(#FF0000); text(A, x, y); ellipse(200,550, 20,20); float dx = (200-x), dy = (550-y), d = sqrt(dx*dx+dy*dy)*3; x += dx/d; y += dy/d; if(keyPressed){ stroke(255,0,0); line(200, 550, x, y); } } void keyPressed(){ int i = A.length(); if( key == Q.charAt(i)){ //相同 A += key; if(Q.equals(A)){ randomQ(); A = ""; } } }
期中作業 10160261林亞萱 10160430林承美
捏臉遊戲
沒有留言:
張貼留言