2018-9-27 19:57:51 [显示全部楼层]
4116浏览
查看: 4116|回复: 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]

lcb163  见习技师

发表于 2019-1-15 11:56:39

回帖奖励 +1 创造力

能运行,没有报错,结果只有一个正方形。各位前辈好我是刚学processing的菜鸟下面这行代码显示不了....图1
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail