Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
uranustooth
uranustooth's Profile
1
Posts
1
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
Hidden code
[2 Replies]
06-Dec-2011 12:00 PM
Forum:
Programming Questions
so i am working on a game demo for school but when my object moves up by pressing 'w' it stops halfway up
here is my code:
float x = 100;
float y = 100;
float gravity = 0.1;
float vy = 0;
float f = 0;
void setup () {
size (1000, 500);
smooth();
strokeWeight (0);
}
void draw() {
background (#05B6FA);
fill (#554627);
rect(0, 450, 1000, 50);
fill (#34FF08);
rect(50, 200, 1000, 250);
fill (#20740E);
rect( 200, 375, 100, 50);
fill(#20740E);
rect(225, 400, 50, 50);
move ();
if (keyPressed==true) {
if (key=='a'&&x>0) {
x-=3;
}
if (key=='d' &&x<width) {
x+=3;
}
if (key=='w' &&y>=0) {
y-=4;
vy=0;
}
}
translate (x, y);
//body//
fill (#6306B7);
rect (18, 338, 14, 8);
fill (#6306B7);
rect (18, 330, 4, 16);
fill (#6306B7);
rect (28, 330, 4, 16);
fill (#FFF300);
rect (22, 330, 6, 8);
// arms//
fill(#FFF300);
rect (14, 330, 4, 10);
fill(225);
rect(14, 338, 4, 4);
// head//
fill (#FFE298);
rect (20, 320, 10, 10);
//eyes//
fill(0);
rect(26, 324, 3, 2);
//hair//
fill (0);
rect(16, 315, 4, 4);
fill(0);
rect(12, 320, 8, 4);
fill(#5D4023);
rect(26, 328, 4, 2);
//hat//
fill(#FFF700);
rect(20, 318, 14, 2);
fill(#FFF700);
rect (20, 314, 8, 4);
if (keyPressed==true) {
if (key=='a') {
fill (0);
rect (22, 346, 6, 4);
fill(#FFF300);
rect (32, 330, 4, 10);
fill (225);
rect (32, 338, 4, 4);
}
if (key=='d') {
fill (0);
rect (22, 346, 6, 4);
fill(#FFF300);
rect (32, 330, 4, 10);
fill (225);
rect (32, 338, 4, 4);
}
if (key=='w') {
fill(#FFF300);
rect (32, 320, 4, 10);
fill (225);
rect (32, 316, 4, 4);
fill(0);
rect(18, 346, 6, 4);
fill (0);
rect (26, 346, 6, 4);
}
}
if (keyPressed==false) {
if (key=='a') {
fill(0);
rect(18, 346, 6, 4);
fill(0);
rect(26, 346, 6, 4);
fill(#FFF300);
rect (32, 330, 4, 10);
fill (225);
rect (32, 338, 4, 4);
}
if (key=='d') {
fill(0);
rect(18, 346, 6, 4);
fill (0);
rect (26, 346, 6, 4);
fill(#FFF300);
rect (32, 330, 4, 10);
fill (225);
rect (32, 338, 4, 4);
}
if (key=='w') {
fill(#FFF300);
rect (32, 330, 4, 10);
fill (225);
rect (32, 338, 4, 4);
}
}
}
void move () {
vy += gravity;
y += vy;
if (y>=100) {
y=100;
}
}
«Prev
Next »
Moderate user : uranustooth
Forum