# Adding a second snake target

**URL:** <https://discourse.processing.org/t/adding-a-second-snake-target/43449>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 11, 2023, 10:08pm UTC](https://discourse.processing.org/t/adding-a-second-snake-target/43449 "2023-12-11T22:08:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![suspinks0](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@suspinks0](https://discourse.processing.org/u/suspinks0)\
**Post date:** [December 11, 2023, 10:08pm UTC](https://discourse.processing.org/t/adding-a-second-snake-target/43449/1 "2023-12-11T22:08:19Z")

</div>

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:

```auto
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);
      
     
}        
}
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 12, 2023, 12:24pm UTC](https://discourse.processing.org/t/adding-a-second-snake-target/43449/2 "2023-12-12T12:24:12Z")

</div>

Hello @suspinks0,

> [@suspinks0](#):
>
> I want to add a second smaller target that gives half a point instead of giving one point like the star target already does.

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

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/0/8/0868f8618d8e6cb954cf0d46ff47afceb44f845e.png)

I suggest you review the basics on this.

One tutorial to get you started:

> **[Objects](https://processing.org/tutorials/objects/)**
>
> The basics of object-oriented programming.

`:)`
