HELP - Simple Game in Processing
              in 
             Programming Questions 
              •  
              6 months ago    
            
 
           
             Hello fellow programmers, I am currently studying at university and for my coursework I was asked to create an Alien, and then later on, a simple game which would include my previously drawn creature in some way. 
            
            
I have made a very simple shooting game which I thought could work. White balls are falling from the top of the screen and at the bottom there is a ship which shoots these down. Now, I have made this prototype without my Alien, and now I am struggling to import it into the game. I wanted to use my Alien instead of the white balls but this proved difficult so I decided to make the green "triangle ship" at the bottom to be my alien. I also need some kind of scoring system and possibly lives. I have spent many hours today trying to figure this out but no luck so I'm begging for your help. This coursework is due in 2 days time and it would be perfect if my Alien was in the game. The Alien uses a class, this is the code for the main body and all the methods, please ignore the movement and the bouncing part of the program as it is not needed for the game.
            
 
            
           I have made a very simple shooting game which I thought could work. White balls are falling from the top of the screen and at the bottom there is a ship which shoots these down. Now, I have made this prototype without my Alien, and now I am struggling to import it into the game. I wanted to use my Alien instead of the white balls but this proved difficult so I decided to make the green "triangle ship" at the bottom to be my alien. I also need some kind of scoring system and possibly lives. I have spent many hours today trying to figure this out but no luck so I'm begging for your help. This coursework is due in 2 days time and it would be perfect if my Alien was in the game. The Alien uses a class, this is the code for the main body and all the methods, please ignore the movement and the bouncing part of the program as it is not needed for the game.
- Alien myAlien; //Class
 void setup(){
 size(700,700); //Window Size
 myAlien = new Alien(350,175,250,250,3,3); //Changeable Parameters
 }
 void draw(){
 background(255);//Space Background
 stroke(0);
 myAlien.draw_Face(); //draws alien
 myAlien.draw_left_ear(); //draws left ear
 myAlien.draw_right_ear();//draws right ear
 myAlien.draw_body();//draws the body
 myAlien.draw_eye();//draws the eye
 myAlien.draw_eye_ball();//draws the eyeball
 myAlien.draw_mouth();//draws the mouth
 myAlien.draw_nose();//draws the nose
 myAlien.movement_of_alien();//calculates movement
 myAlien.alien_bounce();//bouncing
             Methods etc:
             
             
             
 
           - class Alien {
 
 //Variables
 int bodyXLocation;
 int bodyYLocation;
 int bodyWidth;
 int bodyHeight;
 int eyeWidth;
 int eyeHeight;
 int eyeXLocation;
 int eyeYLocation;
 int eyeballWidth;
 int eyeballHeight;
 int eyeballXlocation;
 int eyeballYlocation;
 int earleftWidth;
 int earleftHeight;
 int earleftXlocation;
 int earleftYlocation;
 int earrightWidth;
 int earrightHeight;
 int earrightXlocation;
 int earrightYlocation;
 int mouthXlocation;
 int mouthYlocation;
 int mouthHeight;
 int mouthWidth;
 int noseXlocation;
 int noseYlocation;
 int noseHeight;
 int noseWidth;
 int speedXLocation;
 int speedYLocation;
 Alien(int tempX, int tempY, int tempWidth, int tempHeight, int tempXSpeed, int tempYSpeed) {
 bodyXLocation = tempX;
 bodyYLocation = tempY;
 bodyWidth = tempWidth;
 bodyHeight = tempHeight;
 speedXLocation = tempXSpeed;
 speedYLocation = tempYSpeed;
 //Changeable Parameters
 }
 //This method draws the alien
 void draw_Face() {
 this.draw_left_ear();
 this.draw_right_ear();
 this.draw_body();
 this.draw_eye();
 this.draw_eye_ball();
 this.draw_mouth();
 this.draw_nose();
 this.alien_bounce();
 }
 void draw_left_ear() {
 fill(255,0,0);
 earleftXlocation = bodyXLocation - 50;
 earleftYlocation = bodyYLocation - 50;
 earleftWidth = bodyWidth / 5;
 earleftHeight = bodyHeight - 50;
 ellipse(earleftXlocation,earleftYlocation,earleftWidth,earleftHeight);
 }
 void draw_right_ear() {
 earrightWidth = bodyWidth / 4;
 earrightHeight = bodyHeight - 50;
 earrightXlocation = bodyXLocation + 50;
 earrightYlocation = bodyYLocation - 50;
 ellipse(earrightXlocation,earrightYlocation,earrightWidth,earrightHeight);
 }
 void draw_body() {
 fill(0,255,0);
 ellipse(bodyXLocation,bodyYLocation,bodyWidth,bodyHeight);
 }
 void draw_eye() {
 int offSet = bodyWidth / 17;
 eyeXLocation = bodyXLocation - offSet;
 eyeYLocation = bodyYLocation - (bodyHeight / 4);
 eyeWidth = bodyHeight / 5;
 eyeHeight = bodyWidth / 5;
 ellipse(eyeXLocation,eyeYLocation,eyeWidth,eyeHeight);
 }
 void draw_eye_ball() {
 fill(255,0,0);
 int eyeballoffset = bodyWidth / 10;
 eyeballXlocation = bodyXLocation - eyeballoffset;
 eyeballXlocation = bodyXLocation - 8;
 eyeballYlocation = bodyYLocation - 60;
 eyeballWidth = bodyHeight / 10;
 eyeballHeight = bodyWidth / 10;
 ellipse(eyeballXlocation,eyeballYlocation,eyeballWidth,eyeballHeight);
 }
 void draw_mouth() {
 fill(255,0,0);
 mouthXlocation = bodyXLocation;
 mouthYlocation = bodyYLocation + 75;
 mouthWidth = bodyWidth - 150;
 mouthHeight = bodyHeight - 190;
 ellipse(mouthXlocation,mouthYlocation,mouthWidth,mouthHeight);
 }
 void draw_nose() {
 fill(0,0,255);
 noseXlocation = bodyXLocation - 5;
 noseYlocation = bodyYLocation + 3;
 noseWidth = bodyWidth - 200;
 noseHeight = bodyHeight - 200;
 ellipse(noseXlocation,noseYlocation,noseWidth,noseHeight);
 }
 void movement_of_alien() {
 
 //Movement
 bodyXLocation = bodyXLocation + speedXLocation;
 bodyYLocation = bodyYLocation + speedYLocation;
 this.alien_bounce();//Links to Alien_Bounce
 }
 void alien_bounce() {
 
 //Bouncing
 if(bodyXLocation > width - (bodyWidth / 2 )) {
 speedXLocation = speedXLocation * -1;
 }
 if(bodyXLocation < 0 + (bodyWidth / 2 )) {
 speedXLocation = speedXLocation * -1;
 }
 if(bodyYLocation > height - (bodyHeight / 2 )) {
 speedYLocation = speedYLocation * -1;
 }
 if(bodyYLocation < 0 + (bodyHeight / 2 )) {
 speedYLocation = speedYLocation * -1;
 }
 }
 } //End Of Class Alien
              And finally the code for the game:
              
              
              
            -   //PImage bg;
 PFont fontA;
 int sphereDiameter = 10;
 boolean shoot = false;
 
 int randx()
 {
 return int(random(600));
 }
 
 int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
 int[] sphereYCoords = { 0, 0, 0, 0, 0 };
 
 void setup()
 {
 //bg = loadImage("SpaceBG.png");
 size(600,620);
 }
 
 void draw()
 {
 background(0);
 fill(color(0,255,0));
 stroke(color(0,255,0));
 triangle(mouseX-8, 580, mouseX+8, 580, mouseX, 565);
 fill(color(255,0,0));
 stroke(color(255,0,0));
 
 if(shoot==true)
 {
 sphereKiller(mouseX);
 shoot = false;
 }
 
 sphereDropper();
 gameEnder();
 }
 
 void mousePressed()
 {
 shoot = true;
 }
 
 void sphereDropper()
 {
 stroke(255);
 fill(255);
 for (int i=0; i<5; i++)
 {
 ellipse(sphereXCoords[i], sphereYCoords[i]++,
 sphereDiameter, sphereDiameter);
 }
 }
 
 void sphereKiller(int shotX)
 {
 boolean hit = false;
 for (int i = 0; i < 5; i++)
 {
 if((shotX >= (sphereXCoords[i]-sphereDiameter/2)) &&
 (shotX <= (sphereXCoords[i]+sphereDiameter/2)))
 {
 hit = true;
 line(mouseX, 565, mouseX, sphereYCoords[i]);
 ellipse(sphereXCoords[i], sphereYCoords[i],
 sphereDiameter+25, sphereDiameter+25);
 sphereXCoords[i] = randx();
 sphereYCoords[i] = 0;
 }
 }
 
 if(hit == false)
 {
 line(mouseX, 565, mouseX, 0);
 }
 
 }
 
 void gameEnder()
 {
 for (int i=0; i< 5; i++)
 {
 if(sphereYCoords[i]==600)
 {
 fill(color(255,0,0));
 noLoop();
 }
 }
 }
               So here it is, please help me out on this. 
               
All best, Pharrel
              
             All best, Pharrel
 
              
              1  
            
 
            
 
 
           
 
             
              
             