小朋友下樓梯~終於結束了
import processing.sound.*;
SoundFile soundfile;
SoundFile scare;
PImage imgB;
PImage imgB2;
PImage imgt;
PImage imgp;
PImage imgpl;
PImage imgpr;
float []boardX=new float[9];
float []boardY=new float[9];
float []wallX1=new float[15];
float []wallY1=new float[15];
float []wallX2=new float[15];
float []wallY2=new float[15];
float px;
float py,vx=0, vy=0.2;
float pyn;
int score;
boolean left=false;//左
boolean right=false;//右
int landing=0;
int condition=0;
float rolling=0;
void setup(){
size(720,540);
fill(0,0,0);
textSize(40);
imgB=loadImage("b1.jpg");
imgB2=loadImage("b2.png");
imgt=loadImage("t.png");
imgp=loadImage("p.png");
px=random(30,400-40);
py=random(55,100);
soundfile=new SoundFile(this,"BGM.mp3");
scare=new SoundFile(this,"小朋友下樓梯音效.mp3");
score=0;
for(int i=0;i<9;i++)
{
boardX[i]=random(30,450-14-200);
boardY[i]=i*45+80;
}
for(int i=0;i<15;i++)
{
wallX1[i]=0;
wallY1[i]=i*30+50;
}
for(int i=0;i<15;i++)
{
wallX2[i]=410;
wallY2[i]=i*30+50;
}
soundfile.play();
soundfile.loop();
}
void mousePressed() {
if (mouseButton == LEFT&&mouseX>=500&&mouseX<=650&&mouseY>=250&&mouseY<=390){
condition=1;
score=0;
}
if(condition==1){
if (mouseButton == LEFT&&mouseX>=500&&mouseX<=650&&mouseY>=400&&mouseY<=490){
condition=0;
}
}
}
void keyPressed()
{
if(keyCode==LEFT)
{
px += -20;
}
if(keyCode==RIGHT)
{
px += 20;
}
}
void draw(){
if(condition==0){
background(225);
rect(10,45,400,450);
text("PLAY", 500,300);
text("STOP", 500,400);
}
else if(condition==1){
background(225);
rect(10,45,400,450);
text("PLAY", 500,300);
text("STOP", 500,400);
image(imgp,px-vx,py-vy);
if(py-vy<495&&py-vy>30) {
score+=1;
text("Score:"+score/60, 450,100);
}
else {
scare.play();
text("Score:"+score/60+"\n"+"GameOver", 450,100);
condition=2;
py=random(55,100);
}
for(int i=0;i<15;i++){
image(imgB,wallX1[i],wallY1[i]-rolling);
image(imgB,wallX2[i],wallY2[i]-rolling);
if(wallY1[i]-rolling<45)
{
wallY1[i]+=450;
wallY2[i]+=450;
}
}
for(int i=0;i<9;i++){
image(imgB2,boardX[i],boardY[i]+80-rolling);
if(boardY[i]-rolling<0){
boardX[i]=random(15,400-15-95);
boardY[i]=boardY[i]+400;
}
py += vy;
for(int k=0; k<9; k++)
{
if(boardX[k] < px && px < boardX[k]+95)
{
if(py<boardY[k]+80-rolling && py>boardY[k]+80-rolling-16)
{
landing=k;
py=boardY[k]-26+80-rolling;
}
}
}
}
image(imgt,10,45);
rolling+=1.1;
}
else if(condition==2){
background(225);
rect(10,45,400,450);
text("PLAY", 500,300);
text("STOP", 500,400);
text("Score:"+score/60+"\n"+"GameOver", 450,100);
}
}
沒有留言:
張貼留言