Adding a second snake target

Hello!
I’m making a space themed snake game, and I want to add a second smaller target that gives half a point instead of giving one point like the star target already does. Whenever I try to add it by copying the preexisting code for the star target it says the class doesn’t exist. I’m not sure what I’m doing wrong

Code:

Player comet;
Target star;

void setup() 
{
 size(800,800);
 frameRate(48);
  comet = new Player();
  star = new Target();
  textSize(50);
  textAlign(CENTER,CENTER);
}

void draw()
{
  //Drawing the background
  background(5,5,20);

  noFill();
  stroke(255,50);
  strokeWeight(1);
  rect(25, 25, 750, 750, 30);
  
  noFill();
  stroke(255,50);
  strokeWeight(3);
  rect(10, 10, 780, 780, 30);
  
  
  //Score text
  fill(255);
  text("score:" + comet.length/4, 650,50);
  
  comet.move();
  comet.render();
  star.render();
}

class Player 
{
  float xPos, yPos, direction, speed, length;
  ArrayList<Tail> myTail = new ArrayList();


  Player() 
{
  //Targetting point for the Player and the speed/size
    xPos = width/2;
    yPos = height/2;
    direction = 0;
    speed = 3;
    length = 4;
}
  
  
  void render() 
{
    
    for(Tail thisTail: myTail) {
      fill(100,255,255,30);
      thisTail.render();
}
   //Comet base appearance 
    fill(255);
    stroke(255,random(100,150),0);
    strokeWeight(3);
    ellipse(xPos, yPos, 22,20);
    noFill();
    stroke(255,100);
    strokeWeight(2);
}
  
  void move() 
{
  //Prevents the tail from being removed
    myTail.add(new Tail(this));
    if (myTail.size() > length)
      myTail.remove(0);
    //Moving direction
    xPos += sin(direction) * speed;
    yPos += cos(direction) * speed;
    direction = atan2(mouseX-xPos, mouseY-yPos);

}
}

class Tail 
{

  float xPos, yPos;
  

  Tail(Player parent) 
{
    xPos = parent.xPos;
    yPos = parent.yPos;
}
  
  void render() 
{
    ellipse(xPos,yPos,15,15);
}  
}

class Target 
{
  float xPos, yPos;

  Target()
{
    xPos = random(50, width-50);
    yPos = random(50, height-50);
}
//rendering the target
  void render() 
  {
    fill(random(0,255),255,255);
    stroke(134,247,234);
    strokeWeight(1);
    ellipse(xPos,yPos,30,10);
    ellipse(xPos,yPos,10,30);
    collide();
}
  
  void collide() 
{
  //Moving the star when touched by the comet + adding length to the comet
    if (dist(xPos,yPos, comet.xPos,comet.yPos) < 25) 
{
      comet.length += 4;
      xPos = random(50, width-50);
      yPos = random(50, height-50);
      
     
}        
}
}
1 Like

Hello @suspinks0,

I was able to add objects using your existing classes without any modifications to them:

I suggest you review the basics on this.

One tutorial to get you started:

:)