![]() |
| 複習上次下課前教的音樂撥放 函式庫sound裝妥並將檔案丟進去後才可運行 |
![]() |
| 切換音樂/場景 |
![]() |
| 場景切換(無音樂) |
![]() |
| 拋球球(水果) |
![]() |
| 按鍵觸發的隨機拋球(刷新) 0.98/3是重力加速度 |
![]() |
| 用class新增叫做fruit的函式 |
![]() |
| 文字打擊球 |
![]() |
| 另一個tab的指令 |
球還沒設計計分機制與時間緩停的部分
附上code
Tab1:
Fruit [] fruits;
void setup(){
size(400,300);
fruits=new Fruit[3];
for(int i=0;i<3;i++){
fruits[i] = new Fruit(this);
}
}
void draw(){
background(255,255,0);
for(int i=0;i<3;i++){
fill(255); ellipse(fruits[i].x,fruits[i].y,50,50);
textSize(30);
textAlign(CENTER,CENTER);
fill(0);text(fruits[i].c,fruits[i].x,fruits[i].y);
fruits[i].update();
}
}
void keyPressed(){
for(int i=0;i<3;i++){
if( keyCode==fruits[i].c){
fruits[i].reset();
}
}
}
Tab2:
String line="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
class Fruit{
float x,y,vx,vy;
boolean flying;
char c;
PApplet sketch;
Fruit(PApplet _sketch){
sketch=_sketch;
reset();
}
void reset(){
x=sketch.random(100.0,300.0);
y=300;
vx=sketch.random(-2,+2);
vy=-13;
flying=true;
int i=int(random(26));
c=line.charAt(i);
}
void update(){
x+=vx;
y+=vy;
vy+=0.98/3;
}
}
目標是想做小學的時候玩過的注音快槍手的遊戲
跟今天的課堂作業很像
github連結:https://github.com/asdf2164/20220interaction








沒有留言:
張貼留言