Processingでとりあえず、いろいろとソースを集めてコードを書いたのですが、
寄せ集めただけだからなのか、グローバル変数x,yが存在しませんと出る箇所がります。
PImage image_me;
PImage image_dragon;
PImage image_background;
String game_status="playing";
long t_dragon=0;
int x,y,moveX,moveY;
void setup(){
size(600,600);
background(0);
image_me=loadImage("musi05_d_01.png");
x=width/2;
y=height-image_me.height;
image_dragon=loadImage("dragon.png");
image_background=loadImage("thumb5.png");
game_start();
}
void game_start() {
game_status = "playing";
t_dragon = System.currentTimeMillis();
}
void draw(){
if (game_status.equals("playing"))
update_character_positions();
background(0);
x+=moveX;
if(x<0) x=0; else if(x>width-image_me.width) x=width-image_me.width;
y+=moveY;
if(y<0) y=0; else if(y>height-image_me.height) y=height-image_me.height;
image(image_me,x,y);
image(image_background, 0, 0);
image(image_me, image_me.x, image_me.y);
image(image_dragon, image_dragon.x, image_dragon.y);
if (game_status.equals("game_over")) {
draw_message("GAME OVER!");
}
}
以下のx,yにおいてグローバル変数x,yは存在しませんと出るのですが
どうしたらよいのでしょうか?
void update_character_positions(){
//
// 敵の移動 右は左へ
//
int dt = (int)(System.currentTimeMillis()-t_dragon);
image_dragon.x = (int)(450- dt/1000.0*200);
image_dragon.y = 350;
if (image_dragon.x < -50) {
t_dragon = System.currentTimeMillis(); //左端に来たら右端に戻す
}
//
// 衝突判定
//
double d = Math.sqrt((image_me.x-image_dragon.x)(image_me.x-image_dragon.x) + (image_me.y-image_dragon.y)(image_me.y-image_dragon.y));
if (d < 40)
game_status = "game_over";
}
void draw_message(String message) {
textFont (createFont("MS Gothic", 80, true)); // 文字のフォント
fill(0); // 文字の色
textSize(35); // 文字のサイズ
text(message, 250, 320);
}
void keyPressed(){
println(keyCode);
switch(keyCode){
case 37:
moveX=-3;
break;
case 38:
moveY=-3;
break;
case 39:
moveX=3;
break;
case 40:
moveY=3;
break;
}
}
void keyReleased(){
moveX=0;
moveY=0;
}
あなたの回答
tips
プレビュー