Week17 期末作業---123木頭人☝✌👌👧
解決Bug鬼看了只要動就會死
///一二三木頭人, 3D
import ddf.minim.*;//音樂
Minim minim;//音樂
AudioPlayer player;//音樂
int state=0;// 0:runing, 1:過關
PImage img;
PImage img1;
void setup(){
img = loadImage("1.jpeg");
size(1600,400,P3D);//OpenGL
noStroke();
genRandomTime();
imageMode(CORNER);
minim = new Minim(this);//音樂
player = minim.loadFile("music.mp3");//音樂
player.play();//音樂
}
void genRandomTime(){
time = millis()+random(3000,5000);
}
float time=0;
float angle=-90;
float speed=3;
float vx=0;
int a=0, b=0, x=1450, y=200;
boolean Die=false;
//boolean Win=false;
void draw(){
background(img);
if(Die)
{
background(255,0,0);
textSize(80);//放大字
text("GameOver", 800, 200);
rotate(90);
}
if(state==0){//running
x+=vx;
if(x<190) state=1;
}else if(state==1){
background(52,252,37);
fill(0);
textSize(80);//(4)放大字
text("You WIN!!!", 800, 200);
}
img1=loadImage("G.png");
x+=vx;
if(angle>=90){
//background(255,0,0);
if(testMoving()) Die=true;
}
if(time < millis() ){//animation鬼要動了!!!
//ghostMoving=true;
angle+=speed;
if(angle>=90){//鬼在看你
angle=90;
//background(255,0,0);
//if(testMoving()) Die=true;
time = millis()+3000;//rest
speed = -speed;
}else if(angle<-90){
angle=-90;
genRandomTime();
speed=3;
}
}
ghost(angle);//鬼要看的角度:-90背對沒看,90看到你
image( img1.get(80*a, 100*b, 80,100), x, y);
if(frameCount%30==0) a = (a+1)%3;
}
void ghost(float angle){
fill(237,137,63);
rect(100,200,100,100);//吊帶褲
fill(252,254,4);
rect(100,200,100,30);//衣服
fill(237,137,63);
rect(120,200,20,30);//吊帶
fill(235,218,171);
rect(150,220,18,50);//手
fill(243,233,185);
circle(159, 273, 25);//拳頭
fill(243,233,185);
rect(153,300,25,50);//左腿
fill(243,249,230);
rect(152,330,27,50);//襪子
fill(0);
rect(150,370,30,20);//鞋子
fill(243,233,185);
rect(120,300,25,50);//右腿
fill(243,249,230);
rect(118,330,27,50);//襪子
fill(0);
rect(116,370,30,20);//鞋子
fill(108,54,0);
rect(0,80,60,300);//樹
fill(122,143,58);
circle(20, 50, 180);//葉子
pushMatrix();
lights(); ortho();
translate(150,150);//把整個會轉的頭,移到身體上
rotateY(radians(angle));
fill(246,224,154);//head
sphere(50);//大頭
pushMatrix();
translate(40,-10,50);
fill(0); sphere(10);//黑色的右眼👀
popMatrix();
pushMatrix();
translate(-40,-10,50);
fill(0); sphere(10);//黑色的左眼👀
popMatrix();
popMatrix();
}
boolean testMoving(){
if(vx==0) return false;
else return true;
}
void keyPressed(){
if(keyCode==LEFT) vx=-1;
if(keyCode==UP) { b=1; y--; }///向上飛
if(keyCode==DOWN){ b=0; y++; }///向下走
}
void keyReleased(){
if(keyCode==LEFT) vx=0;
}
///一二三木頭人, 3D
import ddf.minim.*;//音樂
Minim minim;//音樂
AudioPlayer player;//音樂
int state=0;// 0:runing, 1:過關
PImage img;
PImage img1;
void setup(){
img = loadImage("1.jpeg");
size(1600,400,P3D);//OpenGL
noStroke();
genRandomTime();
imageMode(CORNER);
minim = new Minim(this);//音樂
player = minim.loadFile("music.mp3");//音樂
player.play();//音樂
}
void genRandomTime(){
time = millis()+random(1000,1200);
}
float time=0;
float angle=-90;
float speed=3;
float vx=0;
int a=0, b=0, x=1450, y=200;
boolean Die=false;
//boolean Win=false;
void draw(){
background(img);
if(Die)
{
background(255,0,0);
textSize(80);//放大字
text("GameOver", 800, 200);
rotate(90);
}
if(state==0){//running
x+=vx;
if(x<190) state=1;
}else if(state==1){
background(52,252,37);
fill(0);
textSize(80);//(4)放大字
text("You WIN!!!", 800, 200);
angle=0;
}
img1=loadImage("G.png");
x+=vx;
if(angle>=90){
//background(255,0,0);
if(testMoving()) Die=true;
}
if(time < millis() ){//animation鬼要動了!!!
//ghostMoving=true;
angle+=speed;
if(angle>=90){//鬼在看你
angle=90;
//background(255,0,0);
//if(testMoving()) Die=true;
time = millis()+3000;//rest
speed = -speed;
}else if(angle<-90){
angle=-90;
genRandomTime();
speed=3;
}
}
ghost(angle);//鬼要看的角度:-90背對沒看,90看到你
image( img1.get(80*a, 100*b, 80,100), x, y);
if(frameCount%30==0) a = (a+1)%3;
}
void ghost(float angle){
fill(237,137,63);
rect(100,200,100,100);//吊帶褲
fill(252,254,4);
rect(100,200,100,30);//衣服
fill(237,137,63);
rect(120,200,20,30);//吊帶
fill(235,218,171);
rect(150,220,18,50);//手
fill(243,233,185);
circle(159, 273, 25);//拳頭
fill(243,233,185);
rect(153,300,25,50);//左腿
fill(243,249,230);
rect(152,330,27,50);//襪子
fill(0);
rect(150,370,30,20);//鞋子
fill(243,233,185);
rect(120,300,25,50);//右腿
fill(243,249,230);
rect(118,330,27,50);//襪子
fill(0);
rect(116,370,30,20);//鞋子
fill(108,54,0);
rect(0,80,60,300);//樹
fill(122,143,58);
circle(20, 50, 180);//葉子
pushMatrix();
lights(); ortho();
translate(150,150);//把整個會轉的頭,移到身體上
rotateY(radians(angle));
fill(246,224,154);//head
sphere(50);//大頭
pushMatrix();
translate(40,-10,50);
fill(0); sphere(10);//黑色的右眼👀
popMatrix();
pushMatrix();
translate(-40,-10,50);
fill(0); sphere(10);//黑色的左眼👀
popMatrix();
popMatrix();
}
boolean testMoving(){
if(vx==0) return false;
else return true;
}
void keyPressed(){
if(keyCode==LEFT) vx=-1;
if(keyCode==UP) { b=1; y--; }///向上飛
if(keyCode==DOWN){ b=0; y++; }///向下走
}
void keyReleased(){
if(keyCode==LEFT) vx=0;
}

沒有留言:
張貼留言