程式碼:
PImage img;
PImage img2;
int Cat_Size=100,n=0;
float Cat_x,Cat_y,Mouse_x,Mouse_y;
PImage img2;
int Cat_Size=100,n=0;
float Cat_x,Cat_y,Mouse_x,Mouse_y;
void setup()
{
size(500, 500);
img = loadImage("mario04.jpg");
img2= loadImage("char_goomba.png");
Cat_x=50;
Cat_y=0;
Mouse_x=int (random(500));
Mouse_y=int (random(500));
frameRate(20);
}
{
size(500, 500);
img = loadImage("mario04.jpg");
img2= loadImage("char_goomba.png");
Cat_x=50;
Cat_y=0;
Mouse_x=int (random(500));
Mouse_y=int (random(500));
frameRate(20);
}
void draw()
{
background(255);
{
background(255);
image(img,Cat_x,Cat_y,Cat_Size,Cat_Size);
image(img2 ,Mouse_x,Mouse_y,50,50);
image(img2 ,Mouse_x,Mouse_y,50,50);
if ((keyPressed == true) && (key == 'd' )|| (key=='D')) Cat_x=Cat_x+10;
if ((keyPressed == true) && (key == 'a' )|| (key=='A')) Cat_x=Cat_x-10;
if ((keyPressed == true) && (key == 's' )|| (key=='S')) Cat_y= Cat_y+10;
if ((keyPressed == true) && (key == 'w' )|| (key=='W')) Cat_y= Cat_y-10;
if(Cat_x+60+n>Mouse_x && Cat_y+40+n>Mouse_y && Cat_x+60+n<Mouse_x+50 && Cat_y+40+n<Mouse_y+50){
Mouse_x=int (random(300));
Mouse_y=int (random(300));
Cat_Size=Cat_Size+10;
n=n+5;
}
if ((keyPressed == true) && (key == 'a' )|| (key=='A')) Cat_x=Cat_x-10;
if ((keyPressed == true) && (key == 's' )|| (key=='S')) Cat_y= Cat_y+10;
if ((keyPressed == true) && (key == 'w' )|| (key=='W')) Cat_y= Cat_y-10;
if(Cat_x+60+n>Mouse_x && Cat_y+40+n>Mouse_y && Cat_x+60+n<Mouse_x+50 && Cat_y+40+n<Mouse_y+50){
Mouse_x=int (random(300));
Mouse_y=int (random(300));
Cat_Size=Cat_Size+10;
n=n+5;
}
}
心得:
這次的作業我覺得最難,因為要計算馬力歐追到香菇的距離,
光是這點我叫請教了會的同學,也幸好有他們的幫忙,我的作業才順利完成

沒有留言:
張貼留言