4628| 1
|
[求助] 各位前辈好我是刚学processing的菜鸟下面这行代码显示不了.... |
[mw_shl_code=java,true]Tunnel oursGame = new Tunnel(0.1); //float a; float x, y; int depth; void setup() { size(1200, 800, P3D); } void draw() { background(0); translate(width/2.0, height/2.0-100, 0); pushMatrix(); translate(0, 200 ,300); lights(); noStroke(); fill(#E3C26E); box(50); popMatrix(); oursGame.display(); oursGame.speedMove(); float anger = atan2(mouseY-100,mouseX-100); rotate(anger); rotate(x); if ((keyPressed)&&(key == 'a')) { x+=0.1; } if ((keyPressed)&&(key == 'd')) { x-=0.1; } translate(0, 0, -80); } class Tunnel{ // default values for a Tunnel color colour = color(0, 255, 0); //int tunnelNumber= 1; float speed; float c; int i; // array of blocks in the tunnel Block[] blocks = new Block[100]; //constructor Tunnel (float tempspeed) { speed = tempspeed; blocks = new Block(0); } //method void display(){ for (int i =blocks.length-1;i > 0; i--) { blocks = blocks[i-1]; } blocks[0] = blocks[blocks.length-1]; }//constructor void speedMove() { translate(0,100, c); c+=speed; } }//tunnel //==================================================== class Block { //default values for 4 blocks float x ; float y ; float z ; float angle ; float roadlocation; float len; // float tempspeed Block(float tempZ ) { angle = (float)random(0, 2*PI); len = random(10,200); //speed = tempspeed; z = tempZ; //set random the angle of the block seconda il centro if ( (( 0<=angle)&&(angle<PI/2)||(PI<=angle)&&(angle<3/2*PI))) { x = -100*sin(angle); y = +100*cos(angle); } if ((( PI/2<=angle)&&(angle<PI)||(3/2*PI<=angle)&&(angle<2*PI))) { x = +100*sin(angle); y = -100*cos(angle); } } //set the random rotate void display() { noStroke(); pointLight( 255, 200, 0, width / 2, height / 2, 400 ); directionalLight(0, 255, 255, 0, -1, 0); println(roadlocation); if ((0<= angle)&&(angle<PI)) { rotate(PI/2-angle); } if ((PI <= angle)&&(angle<2*PI)) { rotate(PI/2+angle); } //4 blocks in a plane for (int i =0; i<4; i++) { pushMatrix(); translate(x, y, 0); fill(200, 122, 255); box(30,30,len); popMatrix(); } } }[/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed