# Need help in Creating a 2D Serpent, multiple body boss

This topic is 3915 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys I'm working on one of the bosses for my sidescrolling shooting game(2d). And in my game world(this is C++ btw), this is one pointer to a boss object Boss* boss = new AnyBoss(); There are mainly two issues that I have right now 1. How to make the SnakeBoss's body follow the head smoothly. 2. How would the ship collide with the boss's body. To tackle problem #1 1. I have two classes right now, SnakeBoss and SnakeBody. I have a List(vector) of SnakeBody's in class boss. The algorithm for movement is done in the SnakeBoss's move method

SnakeBoss::move(int _x, int _y)
{
prevX = x;
prevY = y;

for (int i = 0; i &lt; MAX_SNAKE_BODIES; i++) //move the bodies
{
if (i == 0)
{
snakeBodies[0]-&gt;move(prevX, prevY); //move the first body
}
else
{
sBodyPrevX = snakeBodies[i -1]-&gt;getPreX();
sBodyPrevY = snakeBodies[i -1]-&gt;getPreY();

snakeBodies-&gt;move(sBodyPrevX, sBodyPrevY);
}

}

Sprite::move(_x, _y); //just move the head
}


This is moving the bodies, but in a very stupid way. It doesn't look like the bodies are actually following the head. Problem #2 Since there is only one pointer for both Boss and Ship in my game, I could easily do collision detection on them using bounding boxes.
if ( ship-&gt;collides(boss) )
{
ship-&gt;takeDamage();
}


However, this time, my boss has several bodies that I need to test collision with. And I can only do it with one. Changing the single boss pointer to an array or list doesn't seem like a good idea. I'd like to hear your suggestions guys. Thanks!

##### Share on other sites
Change the collision code to support multiple collision box enemies, or at least bosses. As for moving the bodies, you could get the same effect you have now by just moving the current tail of the boss to where the head was in the previous frame; I think this is how games used to do it years ago. To get a smoother movement, you can do something like this: move the head first, then for each segment, find the direction to the next segment, and move in that direction such that the distance between segments stays equal to some constant.

diffx = prevbodyx - bodyx
diffy = prevbodyy - bodyy
dist = sqrt(diffx*diffx+diffy*diffy)
diffx = desireddistance * diffx / dist
diffy = desireddistance * diffy / dist
bodyx += diffx
bodyy += diffy

Something like that

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009479
• ### Who's Online (See full list)

There are no registered users currently online

×