We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Objects and, animations and, 2D arrays... Oh My!
Page Index Toggle Pages: 1
Objects and, animations and, 2D arrays... Oh My! (Read 359 times)
Objects and, animations and, 2D arrays... Oh My!
Apr 19th, 2010, 7:14pm
 
Hi everyone. Fair warning I am a total programming newb.

As such, I foolishly dove head first into object oriented programming with 2 dimensional arrays thrown in for flavor… with no idea whatsoever how hard it was going to be…

This is a simple balloon popping game.  Once the balloon is popped a three frame long gif sequence is supposed to play as the balloon falls…

As it stands popping a balloon will cause the game to crash…

Also, I've been trying to figure out where to use the remove() function, so that a balloon instance will be removed if it either rises above or falls below the margins of the stage.

Any thoughts on this would be appreciated...

http://sulley.dm.ucf.edu/~ch638148/Hidden/


[quote]

   PImage bkg;
   PImage gsight;
   PImage blln[] = new PImage[5];
   int numframes = 3;
   int numclrs = 5;
   int clrs = 0;
   int frame = 0;
   PImage[][] pop = new PImage[numclrs][numframes];
   float hit = 1;
   int score = 1;
   int numballoon = 1;
   float ballscale;
   ArrayList balloonList = new ArrayList();
   boolean drawyn = true;
   PFont scorefont;
   
   
     void setup()
     {
     size(500,500);
     frameRate(30);
     bkg = loadImage("sky_2.jpg");
     blln[0] = loadImage("b_balloon.gif");
     blln[1] = loadImage("g_balloon.gif");
     blln[2] = loadImage("p_balloon.gif");
     blln[3] = loadImage("r_balloon.gif");
     blln[4] = loadImage("y_balloon.gif");
     
     PImage pop[][] = {
               {loadImage("b_balloon0000.gif"),loadImage("b_balloon0001.gif"),loadImage("b_bal
loon0002.gif")},
               {loadImage("g_balloon0000.gif"),loadImage("g_balloon0001.gif"),loadImage("g_bal
loon0002.gif")},
               {loadImage("p_balloon0000.gif"),loadImage("p_balloon0001.gif"),loadImage("p_bal
loon0002.gif")},
               {loadImage("r_balloon0000.gif"),loadImage("r_balloon0001.gif"),loadImage("r_bal
loon0002.gif")},
               {loadImage("y_balloon0000.gif"),loadImage("y_balloon0001.gif"),loadImage("y_bal
loon0002.gif")}
               };
     
     blln[0].resize(90,90);
     blln[1].resize(90,90);
     blln[2].resize(90,90);
     blln[3].resize(90,90);
     blln[4].resize(90,90);
     
     pop[0][0].resize(90,90);
     pop[0][1].resize(90,90);
     pop[0][2].resize(90,90);
     
     pop[1][0].resize(90,90);
     pop[1][1].resize(90,90);
     pop[1][2].resize(90,90);
     
     pop[2][0].resize(90,90);
     pop[2][1].resize(90,90);
     pop[2][2].resize(90,90);
     
     pop[3][0].resize(90,90);
     pop[3][1].resize(90,90);
     pop[3][2].resize(90,90);
     
     pop[4][0].resize(90,90);
     pop[4][1].resize(90,90);
     pop[4][2].resize(90,90);
     
     gsight = loadImage("gun_sight.png");
     scorefont = loadFont("HoboStd-36.vlw");
     drawAll();
     
     }
     
   void skymaker(color mycolor, color mycolor2)
     {
   
     for(float i = 0.00; i<height;i++)
       {
         int rfill=int((i/height)*(red(mycolor) - red(mycolor2))+red(mycolor2));
         int gfill=int((i/height)*(green(mycolor) - green(mycolor2))+green(mycolor2));
         int bfill=int((i/height)*(blue(mycolor) - blue(mycolor2))+blue(mycolor2));
         color fillcolor = color(rfill,gfill,bfill);
         fill(fillcolor);
         noStroke();
         rect(0,i,width,1);
       }
     }
     
   //--------------------------------------balloon class
   class Balloon
   {
       boolean popped;
       float x;
       float y;
       int speed;
       float lr = random(-1,1);
       int clrs = round(random(0,4));
       Balloon()
       {
        popped = false;
        float xrand = random(20, 500-blln[clrs].width);
        speed = round(random(2,4));
        x = xrand;
        y = 500;
       
       }
     
   
     void drawBalloon()
       {
         
         if(this.popped==true)
           {
           this.fall();
             for(int clrs =0; clrs<=4; clrs++)
               {
                 for(int frame=0; frame<=2; frame++)
                  {
                  image(pop[clrs][frame], x, y);
                  }
               }
            //println("I'm Hit!");
           }
           else
           {
            this.rise();
           
            image(blln[clrs],x,y);
           
         //println("I'm Drawing!");
           }
           
       }
       
       boolean overBalloon(int width, int height)
       {
         if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height)
         {
           return true;
         }
           else
         {
           return false;
         }
       }  
       
     
     void chkOver()
       {
         if(overBalloon(100, 100))
         {
         popped = true;
         numballoon = round(random(1, sqrt(hit)));
         
         drawyn=true;
         if (score>100)
           {
           hit = 0;
           }
         else if(score>50)
           {
           hit = (hit+0.10);
           }
         else if(score>5)
           {
           hit= (hit+0.10);
           }
         else
           {
           hit = hit;
           }
         
         score = (score +1);
         //println();
         text("+1",x + 5, y+10);
         }
       }
   
       
   
     void rise()
       {
         y = y-speed;  
         //println(x);      
       }
     
     void fall()
       {
         y = y + 20;
         //println(y);
         
       }
       
     
   
   
   }
   
   
   
   //--------------------------------gunsight class
   
   
   
   
   
   
   
   //---------------------------------balloon shoot
   void drawAll()
   {
   int any = round(hit);
   //println(balloonList);
     for(int i = 0; i<any; i++)
       {
       balloonList.add(new Balloon());
       }
       drawyn = false;
   }
   
   void draw()
   {
     
     
      //println(balloonList.size()
Page Index Toggle Pages: 1