Public Group

#### Archived

This topic is now archived and is closed to further replies.

# basic function?

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

## Recommended Posts

all right, i got bored one day and decided to design a little snake like game. i got through making the controls and i wanted to make a radial turning style instead of the direction you press is the direction you go. i want to accelerate and decelerate using up and down(which is done) and change direction using left and right(which im still confused on how to do). i went searching for mathematical methods on doing this and i came up with circle slope and things like that. am i on the right track with this, and could somone help me out here? syrm

##### Share on other sites
Can you describe your problem in a bit more detail? How does the snake move?

##### Share on other sites
You have an angle and calculate the vector using tan, sin, or cos. My internet is about to be cut off by comcast for maintenence or i''d tell you more...

Brian J
DL Vacuum - A media file organizer I made | MM

##### Share on other sites
int xoffset[4] = {-1, 0, 1, 0};int yoffset[4] = {0, -1, 0, 1};int direction = 0, playerx = 10, playery = 10;while(!done) {  if(user_pressed_left)   if(--direction < 0)    direction = 3;  if(user_pressed_right)   if(++direction > 3)    direction = 0;  playerx += xoffset[direction];  playery += yoffset[direction]; }

[edited by - smart_idiot on August 10, 2003 6:02:58 AM]

##### Share on other sites
Um... we're still talking just four directions, right? Up, down, left and right?

This is how I did it:

enum{  UP,  RIGHT,  DOWN,  LEFT,}void Snake::ChangeDirection(int direction){  if(direction == RIGHT)  {    m_direction++;    if(m_direction > LEFT)      m_direction = UP;  }  else if(direction == LEFT)  {    m_direction--;    if(m_direction < UP)      m_direction = LEFT;  }  else    //bad direction}

[edited by - SoulSkorpion on August 10, 2003 9:52:31 AM]

##### Share on other sites
I think he means that he wants his snake to form an arc as it turns, like a real snake. You might be able to fake it by drawing a short arc and re-positioning your snake.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633770
• Total Posts
3013760
×