Zuvio 複習
Part1: C/C++瘋狂程設---進階(除2)、進階(gcd)
Part2:玩電玩、學程式、圖片、去背、方向鍵、移動
![]() |
Part2 |
左邊的那個程式就是拿來操控它的
程式放在下面:
PImage img0, img1, img2;
//先定義
void setup(){
size(400,400); //先設定400*400
img0 = loadImage("user0.png");
img1 = loadImage("user1.png");
img2 = loadImage("user2.png");
}
int userX=250, userY=250;
void draw(){
background(128); //把背景設定灰色
if(keyPressed && keyCode==LEFT){
image(img0, mouseX, mouseY);
userX--;
}else if(keyPressed && keyCode==RIGHT){
image(img2, mouseX, mouseY);
userX++;
}else image(img1, mouseX, mouseY);
//上面是設定說按了左右鍵可以切換圖片
}
程式碼如下:
PImage img;
void setup(){
size(190, 265);
img=loadImage("map.jpg");
}
int userX=95, userY=132;
void draw(){
background(img);
ellipse(userX, userY, 20, 20);
if(keyPressed&&keyCode==UP)userY--;
if(keyPressed&&keyCode==RIGHT)userX++;
if(keyPressed&&keyCode==DOWN)userY++;
if(keyPressed&&keyCode==LEFT)userX--;
}
之後也有教可以射子彈的程式是從(掉雪球的程式演變的)
程式如下:
for(int i=0; i<n; i++){
if(bulletFlyiing[i]==1){
ellipse(bulletX[i], bulletY[i], 5, 10);
bulletY[i]-=2;
}
}
void mousePressed(){
bulletX[n]=userX;
}
PImage img0, img1, img2;
//先定義
void setup(){
size(400,400); //先設定400*400
img0 = loadImage("user0.png");
img1 = loadImage("user1.png");
img2 = loadImage("user2.png");
}
int userX=250, userY=250;
void draw(){
background(128); //把背景設定灰色
if(keyPressed && keyCode==LEFT){
image(img0, mouseX, mouseY);
userX--;
}else if(keyPressed && keyCode==RIGHT){
image(img2, mouseX, mouseY);
userX++;
}else image(img1, mouseX, mouseY);
//上面是設定說按了左右鍵可以切換圖片
}
![]() |
part2 上下左右 |
程式碼如下:
PImage img;
void setup(){
size(190, 265);
img=loadImage("map.jpg");
}
int userX=95, userY=132;
void draw(){
background(img);
ellipse(userX, userY, 20, 20);
if(keyPressed&&keyCode==UP)userY--;
if(keyPressed&&keyCode==RIGHT)userX++;
if(keyPressed&&keyCode==DOWN)userY++;
if(keyPressed&&keyCode==LEFT)userX--;
}
之後也有教可以射子彈的程式是從(掉雪球的程式演變的)
程式如下:
for(int i=0; i<n; i++){
if(bulletFlyiing[i]==1){
ellipse(bulletX[i], bulletY[i], 5, 10);
bulletY[i]-=2;
}
}
void mousePressed(){
bulletX[n]=userX;
}
沒有留言:
張貼留言