issue with button in game
in
Programming Questions
•
2 years ago
- int life=20;
- int level=1;
- boolean menu=true;
- boolean instruct=false;
- 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(width+random(30),random(height), level*10, 3);
- }
- }
- void draw(){
- font=loadFont("Corbel-Bold-48.vlw");
- if(menu&&!instruct){
- textFont(font,70);
- text("Play Game",250,100);
- text("Instruct",290,300);
- rectMode(CORNER);
- if(mousePressed&&mouseX>250&&mouseX<320&&mouseY>30&&mouseY<100){
- menu=false;
- }
- }
- if(!menu&&!instruct){
- background(255);
- for (int i=0;i<Enemies.length;i++){
- Enemies[i].display();
- Enemies[i].move();
- }
- }
- }
- 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(){
- stroke(1,1,33);
- fill(72,7,7);
- beginShape();
- vertex(xpos-12,ypos);
- vertex(xpos,ypos-6);
- vertex(xpos+6,ypos-12);
- vertex(xpos+3,ypos);
- vertex(xpos+6,ypos+12);
- vertex(xpos,ypos+6);
- endShape(CLOSE);
- }
- void move(){
- xpos=xpos-speed;
- if(xpos+2<0){
- life-=1;
- }
- }
- }
1