Loading...
Logo
Processing Forum
elterado's Profile
4 Posts
8 Responses
0 Followers

Activity Trend

Last 30 days

Loading Chart...

Show:
Private Message
    Hi there! I recently submitted a question regarding help with a snake game and I received some amazing help. I was hoping that someone would be able to help walk me through my final two hiccups of the assignment. With the last lot I got some amazing, magical code assistance but for the assignment I've got to keep it as it is given we've only learnt so much and we're not meant to go ahead.

    At the moment I'm trying to create some in boundaries inside of the game rather then just having the walls of the game itself.  So instead of dying like the snake does when it hits the walls of the game, I was hoping to have the snake stop on impact with these boundaries so it couldn't enter the area. (I've got fences and trees in my background for the game)
    I'm using the following lines of code to test this which I then call in the actual drawing of the boundaries (this way I can have boundary1();, boundary(2);, etc.

    1. "void boundries()
    2. {
    3.   noFill();
    4.   noStroke();
    5.   rectMode(CORNER);
    6.   if (inside(x1, y1, x2, y2))
    7.   {
    8.    // println("Inside!");
    9.   }
    10.   else {
    11.     //println("Outside!");
    12.   }
    13.   noFill();
    14.   noStroke();
    15.   rect(x1, y1, x2, y2);
    16. }
    17. // a simple boolean function that will return true if the mouse is inside the two points
    18. boolean inside(int x1, int y1, int x2, int y2)
    19. {
    20.   // This is broken up for speed.
    21.   // instead of doing four checks and then getting a false we check each one and can get a faster fail
    22.   if (px > x1)
    23.   {
    24.     if ( px < x2)
    25.     {
    26.       if ( py > y1)
    27.       {
    28.         if ( py < y2)
    29.         {
    30.           return true;
    31.         }
    32.       }
    33.     }
    34.   }
    35.   return false;
    36. }

    the second issue I'm having is in regards to resetting my snake after finishing the game. My teacher has told me to use append and shorten in order to achieve this, but I can only seem to shorten the array by 1 through using shorten. My snake starts off at 6 in length, and for every rupee it consumes the snake body grows one. When the game ends (say I have 10 rupees) and the body length is 16, when I reset the game my snake starts at 15 rather then 6.

    my line for append is-
    1.  snakePosX = append(snakePosX, snakePosX[snakePosX.length-1]+1);
    2.  snakePosY = append(snakePosY, snakePosY[snakePosY.length-1]+1);
    and for shorten it is -


    1.   snakePosX =shorten(snakePosX);
    2.   snakePosY =shorten(snakePosY);

    I realise shorten would have to be elaborated somehow, but I seem to be getting a multitude of issues whenever I try to involve the array in any form or even mention .length.

    I'd post the full code, but I'm a little paranoid of people in my degree finding it while searching for help like I am now, haha! Any help would be super appreciated though.
    Hi there!

    I'm 10 weeks into my programming subject for games design and I've ran into a bit of an issue for one of the assignments- we've been told we can recreate the classic game 'snake', and given my teacher is convinced that my talents lie more in the art side of things, he's requested me to use PImages to represent the snake head and body- which, I don't mind given I like making things pretty- but I've never been good with arrays to begin with, and now the idea of making a image array is scaring me horrendously. I've tried emailing the lecturer for help, but he continues to go over my head with his explanations.

    The main idea is to get an image loaded as a head of the snake, and then another image that will act as the snakes body as it continues to eat fruit, gradually increasing. (Which is another part I haven't been able to wrap my head around, the idea of spawning fruit from an image)


    I was hoping that would be kind enough to point me in the right direction?  

    I've loaded images into processing before, but never had to actually use them as an active part of the code. If need be, I can email the code to you- I just haven't uploaded it on here as 1. it's a little embarrassing, and 2. I've got quite a few tabs going at this rate.
    Hello!

    I've been working on a code for my programming class (I'm currently studying to be a concept designer, but unfortunately this is mandatory!) and I've ran into a bit of an issue-
    in the final product, we're supposed to have the puck bounce around and change colours on impact to each coloured wall (there's four walls acting as boundaries which are all different colours), but have a trail as well.
    In previous versions we just had to get the puck to change colour and return to the original colour, which I was able to do with help from you lovely people. However, I'm puzzled as to why after putting in the code for the trail, the puck will no longer change colours?

    Also, I was curious if anyone could help me with the hit count- i can't seem to get it to count actual impacts. :(

    (I apologize for the messy code- I'm not very good at this!)

    The current code I'm working on is:

    // Variables
    float halfX, halfY, vx, vy, startX, startY, speedx, speedy, wholeX, wholeY, d=18, r=9, quartX, quartY, halfX2, halfY2; // Puck's position, velocity, and radius
    color c; // Puck's color
    color p; //pink
    color b; //blue
    color g; //green
    color yellow = color(252, 255, 183);
    color pink = color(255, 193, 193);
    color bblue = color(222, 241, 255);
    color ggreen = color(222, 255, 227);
    color midgrey = color(175);
    color white = color(255);
    color lightgrey = color(245);
    color ballcolour = color(245, 245, 245);


    float x, y, mx, my;

    int num = 15;
    float[] posx = new float[num];
    float[] posy = new float[num];


    int bar=16; // Thickness of side bars
    int hit= 0; //hit count

    void setup ()
    {

      size(400, 300);

      mx = 10;
      my = 5;

      // Initial position, velocity, and color of the puck

      //had to bring in halfX2 and halfY2 because everytime I used halfY and halfX, the circles for the background decided to move.
      halfY2 = height/2;
      halfX2 = width/2;
      x = width*0.5;
      y = height/2.666;
      wholeX = width;
      wholeY = height;
      halfX = width/2;
      halfY = height/2;
      speedx = 2.2;
      speedy = 1.5;
      c = color(245);
      startX = 0;
      startY = 0;
      quartX = width/4;
      quartY = height/4;


      // Static drawing settings
      smooth();
      strokeWeight(4);
      stroke(midgrey);
    }

    void draw()
    {
      background(white);
      // Lines
      line (quartX, startY, quartX, wholeY);
      line (3*quartX, startY, 3*quartX, wholeY);
      fill(lightgrey);
      // Centre circle
      ellipse(halfX2, halfY2, wholeX/6, wholeX/6);
      // Shooters circles
      ellipse(0, halfY2, wholeX/3, wholeX/3);
      ellipse(wholeX, halfY2, wholeX/3, wholeX/3);
     
       
      // Borders
      fill(yellow); // Yellow - left
      rect(startX, startY, bar, wholeY);
      fill(pink); // Pink - right
      rect(wholeX-bar, startY, bar, wholeY);
      fill(bblue); // Blue - bottom
      rect(startX, wholeY-bar, wholeX, bar);
      fill(ggreen); // Green - top
      rect(startX, startY, wholeX, bar);
     
      //PADDLES

      if (halfY >wholeY-bar*2-r*4|| halfY<bar+r) {
        speedy= speedy * -1;
      }

      halfX+=speedx;
      halfY+=speedy;

    rect(quartX-bar*3, halfY, quartX/3, wholeY/6);

    rect(quartX*3+bar, halfY, quartX/3, wholeY/6);
     

      //BALL & FADE
      for (int i = num - 1; i > 0; i --) {

        posx[i] = posx[i-1];
        posy[i] = posy[i-1];
      }

      //1st element.
      posx[0] = x;
      posy[0] = y;



      // ball position.
      x += mx;
      y += my;



      //boundries
      if (x < 0 + bar + d|| x > width-bar-d) {
        mx = -mx;
      }
      if (y < 0 + bar+d|| y > height-bar-d) {
        my = -my;
      }


      // and draw the trail
      for (int i = 0; i < num; i++) {
       

        fill(245, 245 - (245/num)*i);

        // Draw puck

        ellipse(posx[i], posy[i], d, d);

     //draw paddles
     

        // Determine puck color
        //right wall.

        if (posx[i]>wholeX-bar-d) {
          fill(pink);
          println("turn pink!");
        }
        //left wall.
        if (posx[i]<bar+d) {
          fill(yellow);
          println("turn yellow!");
        }
        //bottom wall.
        if (posy[i]>wholeY-bar-d) {
          fill(bblue);
          println("turn blue!");
        }
        //top wall.
        if (posy[i]<bar+d) {
          fill(ggreen);
          println("turn green!");
        }




    //hit count
    //can't seem to get it to work in manner of increasing rather then
    //just showing the hit.

    int hitsx = 0;
    //startX, startY, bar, wholeY
    if(posx[i] > 0 + bar + d) {
    hitsx += 1;
    }
    println("hitsx: " + hitsx);


    int hitsy = 0;

    if(posy[i] > 0 + bar+d) {
    hitsy += 1;
    }
    println("hitsy: " + hitsy);







        //colour change back.

        //colour stops changing eventually.

        // if 200(ball) is more then 100 and 200 is less then 300 = grey.
        // else if (halfX>quartX&&halfX<3*quartX) {
        //  c=color(lightgrey);
      }
      // if 150(ball) is more then 75 and 150 is less then 225 = grey.
      // else if (halfY>quartY&&halfY<3*quartY) {
      //   c=color(lightgrey);
    }


    Previous code:
    // Variables
    float halfX, halfY, vx, vy, startX, startY, speedx, speedy, wholeX, wholeY, r=18, x, y, quartX, quartY, halfX2, halfY2; // Puck's position, velocity, and radius
    color c; // Puck's color
    color p; //pink
    color b; //blue
    color g; //green
    color yellow = color(252, 255, 183);
    color pink = color(255, 193, 193);
    color bblue = color(222, 241, 255);
    color ggreen = color(222, 255, 227);
    color midgrey = color(175);
    color white = color(255);
    color lightgrey = color(245);
    color ballcolour = color(245, 245, 245);


    int bar=16; // Thickness of side bars

    void setup ()
    {

      size(400, 300);

      // Initial position, velocity, and color of the puck

      //had to bring in halfX2 and halfY2 because everytime I used halfY and halfX, the circles for the background decided to move.
      halfY2 = height/2;
      halfX2 = width/2;
      x = width*0.5;
      y = height/2.666;
      wholeX = width;
      wholeY = height;
      halfX = width/2;
      halfY = height/2;
      speedx = 2.2;
      speedy = 1.5;
      c = color(245);
      startX = 0;
      startY = 0;
      quartX = width/4;
      quartY = height/4;


      // Static drawing settings
      smooth();
      strokeWeight(4);
      stroke(midgrey);
    }

    void draw()
    {
      background(white);
      // Lines
      line (quartX, startY, quartX, wholeY);
      line (3*quartX, startY, 3*quartX, wholeY);
      fill(lightgrey);
      // Centre circle
      ellipse(halfX2, halfY2, wholeX/6, wholeX/6);
      // Shooters circles
      ellipse(0, halfY2, wholeX/3, wholeX/3);
      ellipse(wholeX, halfY2, wholeX/3, wholeX/3);

      // Borders
      fill(yellow); // Yellow - left
      rect(startX, startY, bar, wholeY);
      fill(pink); // Pink - right
      rect(wholeX-bar, startY, bar, wholeY);
      fill(bblue); // Blue - bottom
      rect(startX, wholeY-bar, wholeX, bar);
      fill(ggreen); // Green - top
      rect(startX, startY, wholeX, bar);


      // Draw puck
      fill(c);
      ellipse(halfX, halfY, 2*r, 2*r);

    //keeps ball inside wall boundries.

      if ( halfX >wholeX-bar-r || halfX<bar+r) {
        speedx = speedx * -1;
      }


      if (halfY >wholeY-bar-r|| halfY<bar+r) {
        speedy= speedy * -1;
      }


      halfX+=speedx;
      halfY+=speedy;



      // Determine puck color
      //colour sops changing eventually.

    //right wall.
    // if halfX(ball)[200] is more then 400 minus the bar width (16) minus the ball size (18) ball colour = pink.
      if (halfX>wholeX-bar-r) {
        c= color(pink);
      }
      //left wall.
    // if halfX(ball)[200] is less then the bar width (16) plus the ball size (18) ball colour = yellow.
      if (halfX<bar+r) {
        c= color(yellow);
      }
      //bottom wall.
      // if halfY (ball[150]) is more then 300 minus the bar width, minus the ball size ball colour= blue.
      if (halfY>wholeY-bar-r) {
        c= color(bblue);
      }
      //top wall.
      //if halfY (ball [150]) is less then the bar width (16)plus the ball size (18) ball colour = green.
      if (halfY<bar+r) {
        c= color(ggreen);
      }
     
      //colour change back.
      // if 200(ball) is more then 100 and 200 is less then 300 = grey.
      else if (halfX>quartX&&halfX<3*quartX) {
         c=color(lightgrey);
      }
      // if 150(ball) is more then 75 and 150 is less then 225 = grey.
      else if (halfY>quartY&&halfY<3*quartY) {
         c=color(lightgrey);
      }


    }
      //This puck wouldn't stay within the four walls, would only bounce back off two and go into the coloured zones on the top and left walls.     
      //      // Draw puck
      //      fill(c);
      //      ellipse(x, y, 2*r, 2*r);


    any help would be greatly appreciated!
    Hello! I'm really, really new to Processing and for my games programming class we've been enlisted to create a 'bouncing puck' type code that'll see the puck bounce off four walls and change colour when coming into contact with each one, then return to white when it's in the middle, change colour when it hits another and so on. So far I've got a moving puck and a layout- but I can't seem to get the colour to change no matter how much I fiddle with the code, and I've also ran into an issue regarding my boundaries- on two off the walls (the bottom and right wall) the puck will 'bounce off' rather then going into the walls like it does on the top one and the left. I was wondering if anyone knew how I could fix it so the puck would bounce off all the walls rather then two?

    We were given some codes that were meant to help us, but no matter what I do it doesn't seem to want to work.

    My code currently looks like this;

    //ints!
    int posX, posY, rad;
    int lineX;

    //colours!
    color lightgrey = color(245, 245, 245);
    color midgrey = color(175, 175, 175);
    color white = color(255);
    color yellow = color(252, 255, 183);
    color pink = color(255, 193, 193);
    color bblue = color(222, 241, 255);
    color ggreen = color(222, 255, 227);

    //floats!
    float halfY = height/2;
    float halfX = width/2;
    float wholeX = width;
    float wholeY = height;
    float xspeed = 2;
    float yspeed = 2;
    float x = width*0.5;
    float y = height/2.666;
    float x1 = 1;
    float y1 = 1;
    float r = height*0.8;
    float quartY = height/4;
    float quartY2 = height/1.333;
    float circx = width*0.1666;
    float rect1 = width*0.9333;
    float rect2 = height*0.05;
    float rect3 = height*0.95;



    void setup ()
    {
      println ("s2893849");
      println ("Tori Maslen"); 

      smooth();

      size(300, 400);

      //declaring
      posX = 0;
      posY = height/2;
      rad = 10;
      xspeed = 2.2;
      yspeed = 1.5;
      r = height*0.09;
      wholeX = width;
      wholeY = height;
      halfY = height/2;
      halfX = width/2;
      x = width*0.5;
      y = height/2.666;
      x1 = 1;
      y1 = 1;
      quartY = height/4;
      quartY2 = height/1.333;
      circx = width*0.1666;
      rect1 = width*0.9333;
      rect2 = height*0.05;
      rect3 = height*0.95;
    }

    void draw()
    {
      //background setup
      background(white);
      strokeWeight(4);
      stroke(midgrey);
      //find the middle.
      //line (X, posY, wholeX, posY);
      //netball court segments.
      line (X, quartY, wholeX, quartY);
      line (X, quartY2, wholeX, quartY2);
      //println(quartY2);
      fill(lightgrey);

      //centre circle.
      ellipse(halfX, halfY, circx, circx);
      //shooters circles.
      ellipse(halfX, Y, circx*2, circx*2);
      ellipse(halfX, wholeY, circx*2, circx*2);

      //borders.
        strokeWeight(4);
        fill(yellow);
        rect(x1, y1, rect2, wholeY);
        fill(pink);
        rect(rect1, y1, rect2, wholeY);
        fill(bblue);
        rect(x1, rect3, wholeX, rect2);
        fill(ggreen);
        rect(x1, y1, wholeX, rect2);



      x = x + xspeed;
      y = y + yspeed;

      if ((x > 260) || (x < 0))
      {

        xspeed = xspeed * -1;
      }


      if ((y > 360) || (y < 0))
      {

     
        yspeed = yspeed * -1;
      }
     
      //setting up the 'puck'.
      stroke(midgrey);
      strokeWeight(4);
      fill(lightgrey);
     

        
      if  (y >= 100 || y1 < 400)
         {
        fill (45);
         }

      else if (posY<60)
        {
        fill(pink); //green
        }

        else if (posY > 70)
        {
          fill(0, 0, 255); //blue
        }
      else
      {
        fill (255); //white
      }

      ellipse(x, y, r, r);

      posX++;;

      if (posX > width)
      {
        posX = 0;
      }
    }