game help
in
Programming Questions
•
2 years ago
how do I make it so that you move on to the next level after you kill all the enemies???
this is the code:
- int life=20;
- int level=1;
- float playerYpos=200;
- int playerXpos=30;
- boolean menu=true;
- boolean instruct=false;
- int laserCounter=400;
- PFont font;
- Enemy[]Enemies=new Enemy[level*3];
- void setup(){
- size(800,400);
- smooth();
- for (int i=0;i<Enemies.length;i++){
- Enemies[i]=new Enemy(random(800,1000),random(height), level*10, 3);
- }
- }
- void draw(){
- background(255);
- fill(255,0,0);
- font=loadFont("Corbel-Bold-48.vlw");
- if(menu&&!instruct){
- textFont(font,70);
- text("Play Game",250,100);
- text("Instruct",290,300);
- if(mousePressed&&mouseX>250&&mouseX<580&&mouseY>30&&mouseY<100){
- menu=false;
- }
- if(mousePressed&&mouseX>290&&mouseX<540&&mouseY>230&&mouseY<300){
- instruct=true;
- }
- }
- if(menu&&instruct){
- textSize(27);
- String s="Press up and down arrows to move the ship up and down. The number of enemies is displayed in the bottom right corner. You laser will get stronger every level and so will the enemies. At level 10, there will be a boss. Every time an enemy goes off screen, you will lose a life. You have 20 lives. Lasers must recharge so you can't use them for too long. There are three ways to shoot. Hold space bar to shoot forward or press n for blast cannon. Blast cannons are extremely powerful but you only have four.";
- text(s,50,20,750,375);
- String back="Back";
- text(back,375,375);
- if(mousePressed&&mouseX>375&&mouseX<430&&mouseY<375&&mouseY>350){
- instruct=false;
- }
- }
- if(!menu&&!instruct){
- if(life>=0){
- background(255);
- for (int i=0;i<Enemies.length;i++){
- Enemies[i].display();
- Enemies[i].move();
- player();
- }
- }
- }
- }
- class Enemy{
- float xpos;
- float ypos;
- int health;
- float speed;
- Enemy(float tempXpos, float tempYpos, int tempHealth, float tempSpeed){
- xpos= tempXpos;
- ypos= tempYpos;
- health= tempHealth;
- speed= tempSpeed;
- }
- void display(){
- if(health>0){
- stroke(196,20,20);
- fill(139,30,30);
- beginShape();
- vertex(xpos-16,ypos);
- vertex(xpos,ypos-8);
- vertex(xpos+8,ypos-16);
- vertex(xpos+4,ypos);
- vertex(xpos+8,ypos+16);
- vertex(xpos,ypos+8);
- endShape(CLOSE);
- }
- if(keyPressed){
- if(key==' '){
- if(playerYpos>=ypos-16&&playerYpos<=ypos+16){
- health-=1;
- }
- }
- if(key=='n'){
- health-=100;
- }
- }
- }
- void move(){
- xpos=xpos-speed;
- if(xpos+2<0){
- life-=1;
- xpos=width;
- xpos+=speed;
- }
- }
- }
- void player(){
- if(keyPressed){
- if(keyCode==UP){
- playerYpos-=2;
- }
- if(keyCode==DOWN){
- playerYpos+=2;
- }
- if(key==' '){
- fill(255,0,0);
- stroke(255,0,0);
- for(int i=playerXpos; i<=width; i+=3){
- ellipse(i,playerYpos,5,5);
- }
- }
- if(key=='n'){
- fill(random(255),random(255),random(255));
- for(int i=playerXpos; i<=width; i+=3){
- ellipse(i,playerYpos,50,800);
- }
- }
- }
- beginShape();
- fill(0,30,214);
- stroke(0,236,235);
- vertex(playerXpos+16,playerYpos);
- vertex(playerXpos,playerYpos+8);
- vertex(playerXpos-8,playerYpos+16);
- vertex(playerXpos-4,playerYpos);
- vertex(playerXpos-8,playerYpos-16);
- vertex(playerXpos,playerYpos-8);
- endShape(CLOSE);
- }
1