• fullscreen
  • AmmoUp.pde
  • Block.pde
  • Slalom2D_Aug_19_09.pde
  • public class AmmoUp extends Block
    {
      public AmmoUp(color c)
      {
        super(c);
      }
    
      public void act()
      {
        if(r*2>=height&&x+r>centerX-shipWidth/2&&x-r<centerX+shipWidth/2)//if you crash into the block
        {
          super.makeNew(c);
          if(ammo<5)
          {
            ammo++;
            msg("ammo++",5);
          }
          score+=ptsPerPad;
        }
        else if(x-r>width||x+r<0||r*2>height+1)//if the block leaves the screen
          super.makeNew(c);
    
        float top = centerY+r;
        float top2 = centerY-r;
        float bottom = centerY+2*r;
        float bottom2 = centerY-2*r;
        fill(c);
        quad(x-r,top,x+r,top,x+2*r,bottom,x-2*r,bottom);//makes a trapezoid
        quad(x-r,top2,x+r,top2,x+2*r,bottom2,x-2*r,bottom2);//makes an upside-down trapezoid
      }
    }
    
    public class Block
    {
      protected int x;//the X value of the CENTER of the block
      public float r;//the side length of the block
      protected color c;//the color of the block
    
      public Block(color c)
      {
        makeNew(c);
      }
    
      private void makeNew(color fillColor)//create a new block
      {
        x = (int)random(width);
        r = startingRadius;
        c = fillColor;
      }
    
      public void act()
      {
        if(r*2>=height&&x+r>centerX-shipWidth/2&&x-r<centerX+shipWidth/2)//if you crashed into the block
          crash();
        else if(x-r>width||x+r<0||r*2>height)//if the block leaves the screen
          makeNew(c);
    
        fill(c);
        triangle(x-r, centerY+r, x, centerY-triangleHeight*r, x+r, centerY+r);//draws the block to the screen
    
        if(mousePressed&&get(mouseX,mouseY)==c)//if you shoot the block
          shot();
      }
    
      public void move()
      {
        r+=r*speed/100;
        x+=(x-mouseX)*speed/100;
      }
    
      private void shot()
      {
        if(ammo<=0)
        {
          msg("NO AMMO!",20);
          return;
        }
    
        makeNew(c);
        ammo--;
    
        if(2*r>height-400)
          msg("Close one!",8);
        else
          msg("Good shot!",7);
      }
    }
    
    import ddf.minim.signals.*;
    import ddf.minim.*;
    import ddf.minim.analysis.*;
    import ddf.minim.effects.*;
    
    Minim minim; 
    AudioPlayer song; 
    
    /**
     * Slalom, By Rafael Cosman.
     * 
     * Your navigation was broken by some space junk around the primitive planet earth.
     * There seems to be some super-glue sticking the pedal to the floor, and there is no way to slow down.
     * Your only hope is to dodge the random obelisks for 5 tricky levels.
     * Mouse side to side to steer.
     * You can shoot the obstacles and can reload by passing over the reload pads.
     */
    /*
    THINGS TO DO:
     music, sound efx
     bombs?
     color themed blocks
     more boosters
     extra points for close saves?
     */
    Block[] blocks = new Block[500];
    
    class Stage
    {
      public String message;
      public color skyColor;
      public int scoreNeeded;
      public float startingSpeed;
      public int numBlocks;
      public int ammoUps;
    
      public void initialize()
      {
        ammoColor = color(random(180,255),random(0,80),random(80,180));
        scoreColor = color(random(0,80),random(30,120),random(150,255));
        completeColor = color(random(255),random(255),random(255));//for the progress bar
        incompleteColor = color(random(255),random(255),random(255));//for the progress bar
        msgColor = color(random(200,255),random(0,80),random(0,80));
        mountainColor = color(random(5,250));
        triangleHeight = random(.5,10);
        
        msg("LEVEL: "+lvl+"\n"+message,50);
        speed = startingSpeed;
        ammo = max(ammo,3);
    
        for(int n=0;n<numBlocks;n++)//for each block
          blocks[n] = new Block(color(random(255),random(255),random(255)));//creates the blocks with random color
        for(int n=numBlocks;n<numBlocks+ammoUps;n++)
          blocks[n] = new AmmoUp(color(255,0,0,100));//creates the boosts
        for(int n=numBlocks+ammoUps;n<blocks.length;n++)
          blocks[n] = null;//clears the rest of the array
      }
    }
    
    Stage[] level = new Stage[7];//how many stages there are in the game plus 2?
    
    color groundColor;
    color ammoColor;
    color scoreColor;
    color completeColor;//for the progress bar
    color incompleteColor;//for the progress bar
    color msgColor;
    color mountainColor;
    
    int lives;
    int[] mntRnd;
    final float startingRadius = 2;//the size of stuff when it appears
    int ammo;
    final int ptsPerPad = 100;//the number of pts recieved for each booster pad
    float speed;
    final int shipWidth = 50;
    int centerX;//the X value of the center of the screen
    int centerY;//the Y value of the center of the screen
    int score;//your total score
    int lvl;//the current level
    final int textY = 40;//the Y value of all the info at the top of the screen
    String msg;
    int msgTime;//the duration of the message
    float triangleHeight;
    
    void crash()//if you died
    {
      lives--;
      delay(1000);//waits a second
      msg("Score: "+score,30);//shows your score
      score = level[lvl].scoreNeeded;//resets your score
      level[lvl].initialize();//resets the level
      
      if(lives<0)
      {
        setup();
        lvl = 0;
      }
    }
    
    void setup()
    {
      frameRate(40);
      
      lives = 2;
      mntRnd = new int[100];
      ammo = 3;
      score = -200;
      lvl = 0;
      
      //mountains
      for(int n=0;n<100;n++)
        mntRnd[n] = (int)random(100);
    
      // always start Minim first
      minim = new Minim(this); 
      // load a file into an AudioSnippet
      // it must be in this sketches data folder
      //song = minim.loadFile("song.mp3",512);/********************************************************/
      //song.play();
    
      // The font must be located in the sketch's
      // "data" directory to load successfully
      textFont(loadFont("Bauhaus93-48.vlw"));
      
      size(800,500);
      centerX = width/2;
      
      smooth();
      cursor(CROSS);//makes the mouse arrow into a cross-hairs
    
      for(int n=0;n<level.length;n++)
        level[n] = new Stage();
        
      level[0].message = "Slalom, by Rafael Cosman";
      level[0].skyColor = color(255,200,200);
      level[0].scoreNeeded = 0;
      level[0].startingSpeed = 5.5;
      level[0].numBlocks = 0;
      level[0].ammoUps = 0;
    
      //LEVEL 1
      level[1].message = "Just dodge.";
      level[1].skyColor = color(255,200,200);
      level[1].scoreNeeded = 0;
      level[1].startingSpeed = 5.5;
      level[1].numBlocks = 30;
      level[1].ammoUps = 0;
    
      //LEVEL 2
      level[2].message = "Click to shoot!";
      level[2].skyColor = color(0,0,255);
      level[2].scoreNeeded = 500;
      level[2].startingSpeed = 3.5;
      level[2].numBlocks = 120;
      level[2].ammoUps = 10;
    
      //LEVEL 3
      level[3].message = "Ready to go FAST?";
      level[3].skyColor = color(200,20,80);
      level[3].scoreNeeded = 2500;
      level[3].startingSpeed = 7;
      level[3].numBlocks = 30;
      level[3].ammoUps = 5;
    
      //LEVEL 4
      level[4].message = "You still alive?";
      level[4].skyColor = color(0);
      level[4].scoreNeeded = 5000;
      level[4].startingSpeed = 6;
      level[4].numBlocks = 130;
      level[4].ammoUps = 10;
    
      //LEVEL 5
      level[5].message = "LAST LEVEL!";
      level[5].skyColor = color(255,200,200);
      level[5].scoreNeeded = 7000;
      level[5].startingSpeed = 10;
      level[5].numBlocks = 30;
      level[5].ammoUps = 5;
    
      //WIN!!!
      level[6].message = "YOU WIN!!!";
      level[6].scoreNeeded = 10000;//score needed to win the game
      
      level[0].initialize();
    }
    
    void msg(String message, int time)
    {
      msg = message;
      msgTime = time;
    }
    
    void showIntro()
    {
      msg("Slalom, by Rafael Cosman",2);
      if(mousePressed)
        score=0;
    }
    
    void showGround()
    {
      fill(groundColor);
      rect(-width,centerY,width*3,height);
    }
    
    void showMountains()
    {  
      fill(mountainColor);
      int mntNum=0;
      for(int d=-width;d<width;d+=mntRnd[mntNum])
      {
        mntNum++;
        triangle(centerX+d, centerY, centerX+2*d, centerY-2*abs(d), centerX+4*d, centerY);
      }
    }
    
    void showBlocks()
    {
      for(int n=0;blocks[n]!=null;n++)//for each block
        blocks[n].move();
    
      float increment = 2;
    
      for(int size=0;size<height*2;size+=increment)//for each size
        for(int n=0;blocks[n]!=null;n++)//for each block
          if(blocks[n].r > size && blocks[n].r <= size+increment)//if the radius is inbetween size and size+decrement
              blocks[n].act();
    }
    
    void showMsg()
    {
      textAlign(CENTER);
      fill(msgColor);
      float msgY = centerY+msgTime*2;
      if(msgTime>0)
        text(msg,centerX,msgY);
      msgTime--;
    }
    
    void showShip()
    {
      fill(100,200,250);
      ellipse(centerX,height-20,shipWidth/2,shipWidth/2);
      line(centerX-shipWidth/2,height-5,centerX-shipWidth/3,height-50);
      line(centerX+shipWidth/2,height-5,centerX+shipWidth/3,height-50);
      fill(200,200,60);
      ellipse(centerX,height-20,shipWidth,5);
      line(centerX,height-20,centerX,height-80);
      fill(100,200,200);
      ellipse(centerX,height-80,5,5);
      fill(255,0,0);
      triangle(centerX-shipWidth/3+3,height-50,centerX-shipWidth/3-3,height-50,centerX-shipWidth/3+2,height-60);
      triangle(centerX+shipWidth/3+3,height-50,centerX+shipWidth/3-3,height-50,centerX+shipWidth/3-2,height-60);
    }
    
    void showAmmo()
    {
      textAlign(LEFT);
      int ammoSize = 25;
      fill(ammoColor);//the color of the ammo
      if(ammo<=0)
        text("NO ammo!",0,textY);
      else if(ammo>=5)//5 is the max ammo
        text("MAX ammo",0,textY);
      else
        for(int a=ammo;a>0;a--)//for each ammo
          ellipse(2*a*ammoSize,textY-ammoSize/2,ammoSize,ammoSize);//shows how much ammo you have
    }
    
    void showStats()
    {
      showAmmo();  
      showBar();
      showLives();
    
      fill(scoreColor);//the color of the text
      textAlign(RIGHT);
      text(nf(score,5)+" pts",width,textY);//shows the score
    
      fill(speed*20,255-speed*20,100-speed*20);//goes from green to orange to red
      if(speed>10)
        fill((score*20)%255,0,0);//flashes red/black
      textAlign(CENTER);
      text("Mach "+nfc(speed,2),width/2,textY);//show the speed
    }
    
    void showBar()
    {
      int barTop = textY+20;
      int barHeight = height-textY-60;
      int barX = width-60;
      fill(incompleteColor);
      rect(barX,barTop,30,barHeight);
    
      if(lvl+1<level.length)//if you haven't won already
      {
        float h = map(score,level[lvl].scoreNeeded,level[lvl+1].scoreNeeded,barHeight+barTop,barTop);
        fill(completeColor);
        rect(barX,h,30,barHeight-h+60);
      }
    }
    
    void showLives()
    {
      textAlign(LEFT);
      fill(255-lives*80,lives*80,0);
      if(lives>0)
        text("Lives: "+lives,20,height);
      else
        text("Lives: "+lives+"!",20,height);
    }
    
    void efx()
    {
      //adds a slight tint when you go fast
      fill(255,0,0,speed*2);
      rect(0,0,width,height);
    
      //shakes the screen when you go fast
      float shake = speed/3;
      if(speed>10)
        centerY+=random(-shake,shake);
    }
    
    void draw()
    {
      if(mouseX < 0)
        mouseX = 0;
      if(mouseX > width-100)
        mouseX = width-100;
      
      centerY = height-(mouseY+height/2)/2;
      centerX += (mouseX-centerX)/50;
    
      efx();
    
      pushMatrix();//stores the settings
      float angle = ((float)mouseX-centerX)/width;
      rotate(angle);
      translate(0,-sin(angle)/2*width);
      if(lvl<level.length-1&&score>level[lvl+1].scoreNeeded)//if you beat the stage
      {
        groundColor = color(random(0,200),random(50,255),random(0,200));
        lvl++;//go to the next level
        lives++;
        level[lvl].initialize();//begin the level
      }
      background(level[lvl].skyColor);
      showGround();
      showMountains();
      showBlocks();  
      showMsg();
      showShip();  
      if(score<=0)
        showIntro();
      popMatrix();//restores the previous settings
      showStats();
    
      speed*=1.0008;//increases the speed
      score++;//gives you pts for survivng
    }
    

    code

    tweaks (0)

    license

    advertisement

    Rafael Cosman

    Slalom

    Add to Faves Me Likey@! 14
    You must login/register to add this sketch to your favorites.

    Slalom, By Rafael Cosman.
    Your navigation was broken by some space junk around the primitive planet earth.
    There seems to be some super-glue sticking the pedal to the floor, and there is no way to slow down.
    Your only hope is to dodge the random spikes for 5 tricky levels.
    - Mouse side to side to steer.
    - You can shoot the obstacles and can reload by passing over the reload pads.

    dotlassie
    20 Aug 2009
    It's quite too fast to me :)
    Rafael Cosman
    20 Aug 2009
    You think I should slow it down?
    I guess you can setup a standard speed by using frameRate(). If not, every computer will try to run it as fast as it can.
    Rafael Cosman
    21 Aug 2009
    Ok, I called frameRate(50). Thanks for the advice.
    I'm now working on a completely different program, something to simulate evolution of unicellular organisms. Ill try to get it up within the next week.
    Rafael Cosman
    23 Aug 2009
    Fixed an exploit which allows you to cheat through levels. Made game slightly easier.
    ExcepciĆ³n: java.lang.ClassNotFoundException: Slalom2D_Aug_19_09.class
    cargar: clase Slalom2D_Aug_19_09.class no encontrada.
    :(
    I can't get click to shoot working.. when I click it stalls for a little.
    Chris Ball
    11 May 2010
    Hey rafael I'm gonna add sound! :)
    dramathis
    20 May 2011
    Can anyone help me about my school homework.? Because i haven't got enough information about processing. Waiting your reply.This is very important for me
    Rafael Cosman
    20 May 2011
    Sure. What do you need?
    dramathis
    20 May 2011
    Firstly ,thank you very much.

    I have got a final homework at school about processing. I am not good at processing so this will be so helpfull for me.

    HOMEWORK

    *// Think of school with a 5 classes. Classes have got chairs board or things, stuffs like that(not need to be same as). There is 5 days ( monday(m), tuesday(t),wednesday(w),thursday(h),friday(f)).

    And. There will be buttons.Days are shows on the buttons.

    Each class will be have number for associate with days and classes.

    EXAMPLE;

    When i press button 'm';
    give me the number of classes which ones have lecture monday.

    When i press button 't';
    give me the number of classes which ones have lecture tuesday.

    When i press button 'w';
    give me the number of classes which ones have lecture wednesday.

    When i press button 'h';
    give me the number of classes which ones have lecture thursday.

    When i press button 'f';
    give me the number of classes which ones have lecture friday.

    Drawings will be in 3D , moving ,classes can be entered into.



    dramathis
    21 May 2011
    moving ,classes can be entered into.

    3D model of a school, with chairs and desks and floors and walls will be draw like this;

    http://www.openprocessing.org/visuals/?visualID=25255


    Displays 5 buttons, labeled with the days of the work week (button)

    message box appears when a button is clicked. (message box)

    When I click button 'f'

    Message box will show me number of classes which classes have lecture on friday.

    every class has a number .
    Gerard Geer
    15 Jun 2011
    COOL! Hmm, you might like my sketch too, Rafael: http://www.openprocessing.org/visuals/?visualID=14726
    Kate Eisenbraun
    17 Aug 2012
    FRRIGGIN SPIKES
    You need to login/register to comment.