Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
qwerty6
qwerty6's Profile
1
Posts
2
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Writing tron ( how to not crash when going backwards)
[5 Replies]
02-Nov-2010 10:22 AM
Forum:
Programming Questions
I'm not sure how to write my code so that when i'm moving to the right and i press 'a' to go to the left, i don't crash into myself. Thanks.
int x=50;
int y=200;
int direction = RIGHT;
void setup()
{
size(400,400);
background(0);
noFill();
stroke(0,150,150);
rect(20,20,360,360);
}
void draw()
{
human();
}
void human()
{
stroke(255,255,255);
if(get(x,y) != color(0,0,0))
{
fill(255,0,0);
ellipse(150,150,200,200);
stroke(0,255,0);
}
else
{
point(x,y);
if(direction == RIGHT)
{
x++;
}
else if(direction == LEFT)
{
x--;
}
else if(direction == UP)
{
y--;
}
else if( direction == DOWN)
{
y++;
}
}
}
void keyPressed()
{
if (key == 'a')
{
direction= LEFT;
}
if (key == 'd')
{
direction= RIGHT;
}
if (key == 'w')
{
direction= UP;
}
if (key == 's')
{
direction= DOWN;
}
}
«Prev
Next »
Moderate user : qwerty6
Forum