week08_1_int_page_if_page_0_1
從視窗畫面開始進入遊戲頁面的切換。
PImage img;
void setup() {
size(640, 480);
img = loadImage("640x480.png");
}
int page = 0;
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;
}先在想做出來的地圖上劃分隔線,以利於製作地圖。PImage img;
void setup() {
size(640, 480);
img = loadImage("640x480.png");
}
void draw() {
background(img);
for(int i=0;i<15;i++){
for(int j=0;j<20;j++){
noFill();
rect(j*32, i*32, 32, 32);
}
}
}
week08_03_RPG_PImage_createImage_copy_save現在利用一個紅框的方式去選取地圖的一格方格,選取到的圖片就存取下來。PImage img;
void setup() {
size(640, 480);
img = loadImage("640x480.png");
}
void draw() {
background(img);
for(int i=0;i<15;i++){
for(int j=0;j<20;j++){
noFill();
stroke(0);
rect(j*32, i*32, 32, 32);
}
}
stroke(255,0,0);
rect(J*32, I*32, 32, 32);
}
int I = -1, J = -1;
void mouseMoved(){
I= mouseY/32;
J= mouseX/32;
}
int N = 1;
void mousePressed(){
PImage now = createImage(32, 32, RGB);
now.copy(img, J*32, I*32, 32, 32, 0, 0, 32, 32);
now.save(N+".png");
N++;
}
week08_04_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},
{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,16, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 2, 3,18, 3, 9, 9, 9, 2, 2, 2, 9, 1, 5},
};
PImage img;
PImage [] fimg = new PImage[40];
void setup() {
size(640, 480);
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<floor.length;i++){
for(int j=0;j<20;j++){
int now = floor[i][j];
image(fimg[now], j*32, i*32);
}
}
}
week08_05_RPG_user_move_userJ_userI_keyPressed
繪製完成後,要讓玩家的角色出現並讓角色可以用key去移動,但是會穿牆。
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,16, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 2, 3,18, 3, 9, 9, 9, 2, 2, 2, 9, 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, 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, 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
};
PImage img, user;
PImage [] fimg = new PImage[40];
void setup() {
size(640, 480);
img = loadImage("640x480.png");
user = loadImage("15.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_06_RPG_wall_detection要設置牆壁地形,讓玩家不可以穿透牆壁房門等障礙,切記要確認障礙物的圖檔名稱。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,16, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 2, 3,18, 3, 9, 9, 9, 2, 2, 2, 9, 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, 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, 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
};
PImage img, user;
PImage [] fimg = new PImage[40];
void setup() {
size(640, 480);
img = loadImage("640x480.png");
user = loadImage("15.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(){
int newI = userI, newJ = userJ;
if(keyCode==RIGHT) newJ++;
if(keyCode==LEFT) newJ--;
if(keyCode==UP) newI--;
if(keyCode==DOWN) newI++;
if(floor[newI][newJ]!=4 && floor[newI][newJ]!=5){
userI = newI;
userJ = newJ;
}
}
week08_07_RPG_eat_good我們設置功能讓玩家可以吃掉物件,然後碰到某物件會gameover。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,16, 1, 5},
{4, 1, 1, 1, 5, 4, 1, 2, 3,18, 3, 9, 9, 9, 2, 2, 2, 9, 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, 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, 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 21, 2, 2, 2, 2, 2, 2, 5},
};
PImage img, user;
PImage [] fimg = new PImage[40];
void setup() {
size(640, 480);
img = loadImage("640x480.png");
user = loadImage("15.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);
if(gameOver) background(0, 255, 0);
}
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[newI][newJ]!=4 && floor[newI][newJ]!=5){
userI = newI;
userJ = newJ;
if(floor[userI][userJ]==21) gameOver = true;
floor[userI][userJ] = 2;
}
}


week08_08_RPG_show_info在左側顯示角色的能力值。int [][] floor ={
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1,19, 3,22, 3,22, 9, 2, 2, 2, 9,16, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 2, 3,18, 3, 9, 9, 9, 2, 2, 2, 9, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4,4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 4, 4, 4, 5, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 4, 4, 4, 5, 4, 2, 2, 2, 2, 2, 2, 21, 2, 2, 2, 2, 2, 2, 5},
};
PImage img, user;
PImage [] fimg = new PImage[40];
void setup() {
size(640, 480);
img = loadImage("640x480.png");
user = loadImage("15.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("Hp: "+hp, 16,140);
text("Attack: "+attack, 16,170);
text("Defense: "+defense, 16,200);
text("Magic Defense: "+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, hp= 2693, 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[newI][newJ]!=4 && floor[newI][newJ]!=5){
userI = newI;
userJ = newJ;
if(floor[userI][userJ]==21) gameOver = true;
floor[userI][userJ] = 2;
}
}
week08_09_RPG_attack_magician
設定魔法師的素質設定,讓魔法師可以跟玩家對打。打贏魔法師,
有失去也有獲得。
int [][] floor ={
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 19, 3, 22, 3, 22, 9, 2, 2, 2, 9, 16, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 2, 3, 18, 3, 9, 9, 9, 2, 2, 2, 9, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5},
{4, 4, 4, 4, 5, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5},
{4, 4, 4, 4, 5, 4, 2, 2, 2, 2, 2, 2, 21, 2, 2, 2, 2, 2, 2, 5},
{4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5},
};
PImage img, user;
PImage [] fimg = new PImage[40];
void setup() {
size(640, 480);
img = loadImage("640x480.png");
user = loadImage("15.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("Hp: "+hp, 16, 140);
text("Attack: "+attack, 16, 170);
text("Defense: "+defense, 16, 200);
text("Magic Defense: "+magic, 16, 230);
text("Exp: "+exp, 16, 260);
text("Coins: "+coin, 16, 290);
image(user, userJ*32, userI*32);
if (gameOver==1) background(0, 255, 0);
if (gameOver==2) background(255, 0, 0);
}
int level = 1, hp= 2693, attack = 14, defense = 16, magic=10, exp=72, coin = 72;
int gameOver= 0;
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[newI][newJ]==9) {
if (hp-10<=0) gameOver = 2;
else {
hp -= 10;
coin +=10;
exp += 1;
userI = newI;
userJ = newJ;
floor[userI][userJ]=2;
}
} else if (floor[newI][newJ]!=4 && floor[newI][newJ]!=5) {
userI = newI;
userJ = newJ;
if(floor[newI][newJ]==21) gameOver = 1;
floor[userI][userJ] = 2;
}
}
沒有留言:
張貼留言