Week08
//week08_1_int_page_if_page_0_1
PImage img;
void setup() {
size(640, 480);
img=loadImage("640x480.png");
}
int page = 0;//0:開場畫面 1:第一關 2:第二關
void draw() {
if (page==0) {
background(0);
textSize(70);
textAlign(CENTER, CENTER);
text("Opening", 320, 240);
} else if (page==1) {
background(img);
}
}
void mousePressed() {
if (page==0) page=1;
}
//week08_03_RPG_PImage_createImage_copy_save
PImage img;
void setup() {
size(640, 480); //15格=480,480/15=32小圖
img=loadImage("640x480.png");
}
void draw() {
background(img);
for (int i=0; i<15; i++) { //高度480 對應y座標
for (int j=0; j<20; j++) { //寬度640 對應x座標
noFill();
stroke(0);
rect(j*32, i*32, 32, 32); //小格子是32x32
}
}
stroke(255,0,0);
rect(J*32, I*32, 32, 32);
}
int I = -1, J = -1;
void mouseMoved(){
I= mouseY/32; //小心 Y
J= mouseX/32; //小心X
}
void mousePressed() {
PImage now = createImage(32, 32, RGB);
now.copy(img, J*32, I*32, 32, 32, 0, 0, 32, 32);
now.save("1.png");
}
//week08_4_RPG_2d_array_floor_map
int [][] floor = {
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 9,3, 10,3, 17,9, 1, 1, 1, 9, 1,16, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 9,3, 10,3, 17,9, 1, 1, 1, 9, 1,16, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 9,3, 10,3, 17,9, 1, 1, 1, 9, 1,16, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 9,3, 10,3, 17,9, 1, 1, 1, 9, 1,16, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5}, //有20個數字
{4, 1, 1, 1, 5, 4, 1, 9,3, 10,3, 17,9, 1, 1, 1, 9, 1,16, 5}, //有20個數字
};
PImage img;
PImage [] fimg = new PImage[40];
void setup(){
size(640,480); //15格=480, 480/15=32 小圓
img = loadImage("640x480.png");
for(int i=1;i<=22;i++) fimg[i] = loadImage(i+".png");
}
void draw(){
//background(img);
for(int i=0;i<15;i++){
for(int j=0;j<20;j++){
int now = floor[i][j];
image(fimg[now],j*32,i*32);
}
}
}
///week08_5_RPG_user_move_userJ_keyPressed
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 19, 3, 22, 3, 22, 9, 2, 2, 2, 9, 13, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
};
PImage img, user;
PImage [] fimg = new PImage[40];
void setup(){
size(640,480);
img = loadImage("640x480.png");
user = loadImage("25.png");//勇者
for(int i=1; i<=22; i++) fimg[i] = loadImage(i+".png");
}
int userI = 12, userJ = 15;
void draw(){
//background(img);
for(int i=0; i<floor.length; i++){
for(int j=0; j<20; j++){
int now = floor[i][j];
image(fimg[now], j*32, i*32);
}
}
image(user, userJ*32, userI*32);
}
void keyPressed(){
if(keyCode==RIGHT) userJ++;
if(keyCode==LEFT) userJ--;
if(keyCode==UP) userI--;
if(keyCode==DOWN) userI++;
}
// week08_8_RPG_show_info
int [][] floor = {
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 19, 3, 22, 3, 22, 9, 2, 2, 2, 9, 13, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
{3, 1, 1, 1, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 9, 5},
};
PImage img, user;
PImage [] fimg = new PImage[40];
void setup(){
size(640,480);
img = loadImage("640x480.png");
user = loadImage("25.png");//勇者
for(int i=1; i<=22; i++) fimg[i] = loadImage(i+".png");
}
int userI = 12, userJ = 15;
void draw(){
//background(img);
for(int i=0; i<floor.length; i++){
for(int j=0; j<20; j++){
int now = floor[i][j];
image(fimg[now], j*32, i*32);
}
}
image(user, 16, 16);//左邊上面的圖
textSize(30);
text("Level: "+ level, 16, 90);
textSize(20);
text("Live: "+ live, 16, 140);
text("Attack: "+ attack, 16, 170);
text("Defense: "+ defense, 16, 200);
text("Magic: "+ magic,16,230);
text("Exp: "+ exp, 16, 260);
text("Coins: "+ coin, 16, 290);
image(user, userJ*32, userI*32);
if(GameOver)background(0,255,0);
}
int level = 1, live = 2639, attack = 14, defense =16, magic = 10, exp = 72, coin = 72;
boolean gameOver = false;
void keyPressed(){
int newI = userI, newJ = userJ;
if(keyCode==RIGHT) newJ++;
if(keyCode==LEFT) newJ--;
if(keyCode==UP) newI--;
if(keyCode==DOWN) newI++;
if(floor[new][new]! = 1 && floor[new][new]!=3){
userI = newI;
userJ = newJ;
if(floor[userI][userJ]==21) gameover = true;
floor[userI][userJ] = 2;
}
}
沒有留言:
張貼留言