001.
void setup() {
size(500, 500);
}
void draw() {
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);
}
----------------------------------------------------------------------------------------------
002.
PFont font0,font,font2;
void setup() {
size(500, 500);
font0 = createFont("Cascadia Code", 50);
font = createFont("微軟正黑體", 50);
font2 = createFont("elffont-rock.otf", 50);
}
void draw() {
background(0);
textSize(50);
//PFont font0 = createFont("Ariel", 50);
textFont(font0);
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);
}
----------------------------------------------------------------------------------------------------
003.
sketch->library->sound
-----------------------
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();
}
void keyPressed() {
if (key=='1') {
sound2.stop();
sound1.play();
}.
if (key=='2') {
sound1.stop();
sound2.play();
}
}
------------------------------------------------------------------
004.
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<30) 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;
appleY += appleVY;
appleVY+= 0.98;
if (appleX>600 ||appleX<0 || appleY>550) {
randomApple();
}
}
-------------------------------------------------------------------------------------
005.
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<30) 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 (key==appleKey)
{
score += 100;
} else
{
score -= 10;
}
}
int state = 0;
int countdown = 60*4;
void draw()
{
background(board);
textSize(50);
textAlign(CENTER, CENTER);
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, 50);
fill(255, 0, 0);
ellipse(appleX, appleY, 80, 80);
fill(255, 255, 0);
text(appleKey, appleX, appleY);
appleX += appleVX;
appleY += appleVY;
appleVY+= 0.98;
if (appleX>600 ||appleX<0 || appleY>550) {
randomApple();
}
}
}
沒有留言:
張貼留言