【期中作品_封面設計與人物移動篇】
1.滑鼠點下<用mouse>
主要程式碼:
void draw(){
image(start,0,0,850,500);
if(mouseX>290&&mouseX<560&&mouseY>210&&mouseY<290){
cursor(HAND);
if(mousePressed == true && mouseButton == LEFT) {
begin.pause();
startmusic.loop();
state = 1;
k=1;
}
}
else {
cursor(ARROW);
}
}
2.人物左右邊界移動<用If、Else設定邊界>
主要程式碼:
void draw(){
if(xPos < 0) ///left
{
xPos = 0;
k=1;
}
if(xPos > width - img2.width+100){ ///right
xPos = width - img2.width+100;
k=2;
}
while(k==1&&yPos==100){
xPos+=5;
break;
}
while(k==2&&yPos==100){
xPos-=5;
break;
}
if(m==3&&yPos!=100){
yPos-=2;
}
if(keyPressed == true && keyCode == DOWN&&yPos==100){
m=1;
}
if(yPos < 100)
{
yPos = 100;
}
else if(yPos > height - img2.height+20){
yPos = height - img2.height+20;
m=2;
}
}
沒有留言:
張貼留言