ผมเขียนขึ้นมา 1 เกมส์ ยิงเลเซอร์โดนบล็อกแล้วจะได้ 1 คะแนนและบล็อกจะหายไป
แต่ปัญหา มีตรงที่ว่ายิงเลเซอร์ได้ครั้งเดียว อยากจะถามว่าต้องใส่คำสั่งเพิ่มตรงไหนบ้างครับ
PImage img;
float RDX,RDY,C1,C2,C3;
float RDX1,RDX2,RDX3,RDX4,RDX5,RDX6,RDX7,RDX8,RDX9,RDY1,RDY2,RDY3,RDY4,RDY5,RDY6,RDY7,RDY8,RDY9;
float sp = 10;
float block=1;
float boun=1;
float misslePath = 300;
float sunEdge = 565;
float x1 = 300;
float y1 = 400;
float x2 = 305;
float y2 = 400;
float cannonEdge = 120;
float n;
float no;
float yl = -1;
float xl = 1;
void setup(){
size(600,480);
smooth ();
noStroke ();
img = loadImage("a2.jpg");
}
void draw(){
imageMode(CENTER);
image(img, 300, 240);
/////////missile///////
go();
rect(x1,y1,80,60);
///////////end//////////////
/////////////////////randommany/////////////
stroke(255);
strokeWeight(2);
fill(255);
//////////////////////////end////////////////////////
////////////////////////random//////////////////////
fill(C1,C2,C3);
rect(RDX,RDY,30,30);
rect(RDX1,RDY1,30,30);
rect(RDX2,RDY2,30,30);
rect(RDX3,RDY3,30,30);
rect(RDX4,RDY4,30,30);
rect(RDX5,RDY5,30,30);
rect(RDX6,RDY6,30,30);
rect(RDX7,RDY7,30,30);
rect(RDX8,RDY8,30,30);
rect(RDX9,RDY9,30,30);
/////////////////////////end//////////////////////////////
////////////////////////text score///////////////////
fill(#12F9FF);
textSize(20);
text(n,50,50);
//////////////end//////////////////
////////////////////////////////////if number//////////////////////////
if(n >=10){
fill(#E9FF03);
textSize(40);
text("WINNER",200,300);
stop();
}
if(block==1){
if(boun==1){
RDX=random(50,500);
RDY=random(30,300);
RDX1=random(50,500);
RDY1=random(30,300);
RDX2=random(50,500);
RDY2=random(30,300);
RDX3=random(50,500);
RDY3=random(30,300);
RDX4=random(50,500);
RDY4=random(30,300);
RDX5=random(50,500);
RDY5=random(30,300);
RDX6=random(50,500);
RDY6=random(30,300);
RDX7=random(50,500);
RDY7=random(30,300);
RDX8=random(50,500);
RDY8=random(30,300);
RDX9=random(50,500);
RDY9=random(30,300);
C1=random(0,255);
C2=random(0,255);
C3=random(0,255);
boun=0;
}
}
}
//////////////////////////////////////////////attack////////////////////////////ss
void attack(){
fill (#12FF03); // draw missle
rectMode (CENTER);
noStroke();
fill(#4D240B);
rect (x2,misslePath,10,20);
misslePath = misslePath -sp;
if(misslePath>=RDY&& misslePath<=RDY+30 && misslePath>=RDX && misslePath<=RDX+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY1&& misslePath<=RDY1+30 && misslePath>=RDX1 && misslePath<=RDX1+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY2&& misslePath<=RDY2+30 && misslePath>=RDX2 && misslePath<=RDX2+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY3&& misslePath<=RDY3+30 && misslePath>=RDX3 && misslePath<=RDX3+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY4&& misslePath<=RDY4+30 && misslePath>=RDX4 && misslePath<=RDX4+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY5&& misslePath<=RDY5+30 && misslePath>=RDX5 && misslePath<=RDX5+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY6&& misslePath<=RDY6+30 && misslePath>=RDX6 && misslePath<=RDX6+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY7&& misslePath<=RDY7+30 && misslePath>=RDX7 && misslePath<=RDX7+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY8&& misslePath<=RDY8+30 && misslePath>=RDX8 && misslePath<=RDX8+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY9&& misslePath<=RDY9+30 && misslePath>=RDX9 && misslePath<=RDX9+30){
boun=1;
n++;
misslePath = 480;
////////////////////////////////////////////////end///////////////////////////////
if(misslePath >= width+10){
misslePath = 300;
return;
}
return;
}
}
///////////////////////111////////////////////////////////control///////////////////
void keyPressed(){
if(key==CODED){
if(keyCode==LEFT){
noFill();
x1=x1-10;
x2=x2-10;
}
if(keyCode==RIGHT){
x1=x1+10;
x2=x2+10;
}
}
loop();
}
///////////////////////////////////////////////////////end/////////////////////
void go(){
text("Start Game",250,400);
if(key == 's'){
image(img, 300, 240);
attack();
}
}
โปรแกรม Processing ช่วยด้วย ครับ
แต่ปัญหา มีตรงที่ว่ายิงเลเซอร์ได้ครั้งเดียว อยากจะถามว่าต้องใส่คำสั่งเพิ่มตรงไหนบ้างครับ
PImage img;
float RDX,RDY,C1,C2,C3;
float RDX1,RDX2,RDX3,RDX4,RDX5,RDX6,RDX7,RDX8,RDX9,RDY1,RDY2,RDY3,RDY4,RDY5,RDY6,RDY7,RDY8,RDY9;
float sp = 10;
float block=1;
float boun=1;
float misslePath = 300;
float sunEdge = 565;
float x1 = 300;
float y1 = 400;
float x2 = 305;
float y2 = 400;
float cannonEdge = 120;
float n;
float no;
float yl = -1;
float xl = 1;
void setup(){
size(600,480);
smooth ();
noStroke ();
img = loadImage("a2.jpg");
}
void draw(){
imageMode(CENTER);
image(img, 300, 240);
/////////missile///////
go();
rect(x1,y1,80,60);
///////////end//////////////
/////////////////////randommany/////////////
stroke(255);
strokeWeight(2);
fill(255);
//////////////////////////end////////////////////////
////////////////////////random//////////////////////
fill(C1,C2,C3);
rect(RDX,RDY,30,30);
rect(RDX1,RDY1,30,30);
rect(RDX2,RDY2,30,30);
rect(RDX3,RDY3,30,30);
rect(RDX4,RDY4,30,30);
rect(RDX5,RDY5,30,30);
rect(RDX6,RDY6,30,30);
rect(RDX7,RDY7,30,30);
rect(RDX8,RDY8,30,30);
rect(RDX9,RDY9,30,30);
/////////////////////////end//////////////////////////////
////////////////////////text score///////////////////
fill(#12F9FF);
textSize(20);
text(n,50,50);
//////////////end//////////////////
////////////////////////////////////if number//////////////////////////
if(n >=10){
fill(#E9FF03);
textSize(40);
text("WINNER",200,300);
stop();
}
if(block==1){
if(boun==1){
RDX=random(50,500);
RDY=random(30,300);
RDX1=random(50,500);
RDY1=random(30,300);
RDX2=random(50,500);
RDY2=random(30,300);
RDX3=random(50,500);
RDY3=random(30,300);
RDX4=random(50,500);
RDY4=random(30,300);
RDX5=random(50,500);
RDY5=random(30,300);
RDX6=random(50,500);
RDY6=random(30,300);
RDX7=random(50,500);
RDY7=random(30,300);
RDX8=random(50,500);
RDY8=random(30,300);
RDX9=random(50,500);
RDY9=random(30,300);
C1=random(0,255);
C2=random(0,255);
C3=random(0,255);
boun=0;
}
}
}
//////////////////////////////////////////////attack////////////////////////////ss
void attack(){
fill (#12FF03); // draw missle
rectMode (CENTER);
noStroke();
fill(#4D240B);
rect (x2,misslePath,10,20);
misslePath = misslePath -sp;
if(misslePath>=RDY&& misslePath<=RDY+30 && misslePath>=RDX && misslePath<=RDX+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY1&& misslePath<=RDY1+30 && misslePath>=RDX1 && misslePath<=RDX1+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY2&& misslePath<=RDY2+30 && misslePath>=RDX2 && misslePath<=RDX2+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY3&& misslePath<=RDY3+30 && misslePath>=RDX3 && misslePath<=RDX3+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY4&& misslePath<=RDY4+30 && misslePath>=RDX4 && misslePath<=RDX4+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY5&& misslePath<=RDY5+30 && misslePath>=RDX5 && misslePath<=RDX5+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY6&& misslePath<=RDY6+30 && misslePath>=RDX6 && misslePath<=RDX6+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY7&& misslePath<=RDY7+30 && misslePath>=RDX7 && misslePath<=RDX7+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY8&& misslePath<=RDY8+30 && misslePath>=RDX8 && misslePath<=RDX8+30){
boun=1;
n++;
misslePath = 480;
}
if(misslePath>=RDY9&& misslePath<=RDY9+30 && misslePath>=RDX9 && misslePath<=RDX9+30){
boun=1;
n++;
misslePath = 480;
////////////////////////////////////////////////end///////////////////////////////
if(misslePath >= width+10){
misslePath = 300;
return;
}
return;
}
}
///////////////////////111////////////////////////////////control///////////////////
void keyPressed(){
if(key==CODED){
if(keyCode==LEFT){
noFill();
x1=x1-10;
x2=x2-10;
}
if(keyCode==RIGHT){
x1=x1+10;
x2=x2+10;
}
}
loop();
}
///////////////////////////////////////////////////////end/////////////////////
void go(){
text("Start Game",250,400);
if(key == 's'){
image(img, 300, 240);
attack();
}
}