Muffet from undertale

edited August 2017 in How To...

Hello guys, i would really appreciate if u make me a code with circles (instead of spiders) of the move of the spiders of this video:

It starts at min 1:30

I mean, i think it only create lets say 8 enemies. And the 2nd one is created when the first one has moved lets say 100 pixels.

The 3rd one is created when the 2nd one has moved again 100 pixels, and so on.

But i dont know how can i do that on processing. Please, help me

Answers

  • Have you made already made the code to make a single circle begin, move, and end? Can you share what you have so far?

  • All balls can have same speed and start at same time

    Just give them different x values far outside the screen

  • edited August 2017

    No, they all start on the same value at X.

      void update(){
        x += speed;
        if (x < width/6) {
          this.x = 5*width/6;
          this.y = int(random(1,4)) * height/4;
        }    
      }
    
  • and i dont use circles, i use PImages, but i wont copy that cuz u need to have the image and so on. Just make a single circle or what ever

  • My hint was to use different x values so they appear after another

    Other approach than yours

  • ok. I have already done that. It isnt what i want. have u seen the video? cuz on the video they all start on the same spot

  • I got an idea, but idk if it will work.

    I do actually do this:

      for (int i = 0; i < enemies.length; i++) {
        if (i == 0) enemies[i].run();
        else{
          if (enemies[i-1].x <= 600) enemies[i].run();      
        }
    

    But it is a mess when they all are created.

    So my is to instead of checking the X value on elemnts from a List, making a Queue, and when an enemy reaches left egde, remove it from the queue and add it to the top, and check the X value always from the top element

  • Stop starting new threads

    Of course I saw the video

    My advice is still valid

    Just make different y values and x outside the screen

    They just fly inside the screen from outside the screen

  • Nothing to do with lifo and fifo

  • i dont start any thread xDD

  • class Ball {
      float x, y;
      float dx;
      Ball(){
        if( random(1) < .5){
          x = -30;
          dx = 1;
        } else {
          x = width + 30;
          dx = -1;
        }
        y = 30 + 30 * int(random(3));
      }
      void draw(){
        simulate();
        render();
      }
      void simulate(){
        x+=dx;
        if( x < -30 || x > width + 30 ){
          dx *= -1;
          y = 30 + 30 * int(random(3));
        }
      }
      void render(){
        ellipse(x,y,20,20);
      } 
    }
    
    ArrayList<Ball> balls = new ArrayList();
    
    void setup(){
      size(300,300);
      balls.add( new Ball() );
      balls.add( new Ball() );
      balls.add( new Ball() );
    }
    
    void draw(){
      background(0);
      for( Ball ball : balls ){
        ball.draw();
      }
    }
    
  • edited August 2017

    wait what? u can have a draw on classes?

  • Uuuh that not exactly what i want. I got this, but this is a mess when all the balls are created:

    void draw(){
      for (int i = 0; i < enemies.length; i++) {
        if (i == 0) enemies[i].run();
        else{
          if (enemies[i-1].x <= 600) enemies[i].run();      
        }
        if (enemies[i].collide(heart) && !gameover) {
          println("Game over");
          gameover = true;
        }
      }
    }
    

    And the run makes the show (render) and update(moving, but only checking one edge, for now)

      void update() {
        x += speed;
        if (x < width/6) {
          this.x = 5*width/6;
          this.y = int(random(1,4)) * height/4;
        }
      }
    
  • ah okey, ur draw from the class is not the draw from processing, ok ok ^^

  • Correct: myObject.draw() is not the same thing as draw() -- it isn't a hook/callback and it does not get automatically called by Processing every frame. It is generally a function for rendering that specific object. To avoid confusion you could call it something else, like render().

  • ok ok ty ^^

Sign In or Register to comment.