basic function?
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
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
Brian J
DL Vacuum - A media file organizer I made | MM
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]
Um... we're still talking just four directions, right? Up, down, left and right?
This is how I did it:
[edited by - SoulSkorpion on August 10, 2003 9:52:31 AM]
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]
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement