Archived

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

syrmakleftis

basic function?

Recommended Posts

syrmakleftis    122
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
smart_idiot    1298

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
SoulSkorpion    238
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
monkey_32606    101
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