Jump to content
  • Advertisement

Archived

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

syrmakleftis

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!