I'm really not one for introductions, it's basic but it could go many directions.
BEGIN{ unshift(@INC,"../blib"); } # in case OpenGL is built but not i +nstalled BEGIN{ unshift(@INC,"../blib/arch"); } # 5.002 gamma needs this BEGIN{ unshift(@INC,"../blib/lib"); } # 5.002 gamma needs this use OpenGL; use Term::ReadKey; use warnings; glpOpenWindow; glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-300,300,-300,300,-30,30); glColor3f(1,0,0); sub drawplane{ glBegin(GL_POLYGON); @pos=($_[0],$_[1]); my $rot = $_[2]*0.0174; my @point1=($pos[0],$pos[1]); my @point2=($point1[0]+(cos($rot+90)*10),$point1[1]+(sin($rot+90)*10)) +; my @point3=($point2[0]+(cos($rot+45)*6),$point2[1]+(sin($rot+45)*6)); my @point4=($point3[0]+(cos($rot)*4),$point3[1]+(sin($rot)*4)); my @point5=($point4[0]-(cos($rot+225)*8),$point4[1]-(sin($rot+225)*8)) +; glVertex2f($point1[0],$point1[1]); glVertex2f($point2[0],$point2[1]); glVertex2f($point3[0],$point3[1]); glVertex2f($point4[0],$point4[1]); glVertex2f($point5[0],$point5[1]); @point1=($pos[0],$pos[1]); @point2=($point1[0]+(cos($rot-90)*10),$point1[1]+(sin($rot-90)*10)); @point3=($point2[0]+(cos($rot-45)*6),$point2[1]+(sin($rot-45)*6)); @point4=($point3[0]+(cos($rot)*4),$point3[1]+(sin($rot)*4)); @point5=($point4[0]-(cos($rot-225)*8),$point4[1]-(sin($rot-225)*8)); glVertex2f($point1[0],$point1[1]); glVertex2f($point2[0],$point2[1]); glVertex2f($point3[0],$point3[1]); glVertex2f($point4[0],$point4[1]); glVertex2f($point5[0],$point5[1]); glEnd(); glpFlush(); } @pos=(0,0); $dir=0; $forwardspeed=0; $turnspeed=0; ReadMode 4; # Turn off controls keys @direction=(0,0); while (1==1){ if (defined ($key = ReadKey(-1))){if($key eq'a'){if($turnspeed<2){$tur +nspeed+=.7};};if($key eq'd'){if($turnspeed>-2){$turnspeed-=.7}} if($k +ey eq'w'){ if ($forwardspeed <.05){$forwardspeed+=.015} }} $dir+=$turnspeed; glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); if ($forwardspeed >0){$forwardspeed/=1.05;} $turnspeed/=1.05; @direction=(($direction[0]/1.01)+(cos($dir*0.0174)*$forwardspeed),($di +rection[1]/1.01)+(sin($dir*0.0174)*$forwardspeed)); @pos=($pos[0]+$direction[0],$pos[1]+$direction[1]); drawplane($pos[0],$pos[1],$dir%360); select(undef,undef,undef, .02); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I made a pilotable ship!
by zentara (Cardinal) on Mar 20, 2012 at 15:36 UTC | |
|
Re: I made a pilotable ship!
by Anonymous Monk on Mar 20, 2012 at 17:24 UTC |