Java Processing Projectile Motion

时间:2013-04-03 21:14:07

标签: java processing angle

我正在努力为我的作业创造一个像野蛮的野鸟,但我在角度和射弹运动方面遇到了麻烦。我给它重力*时间模块,但它似乎没有进行弹丸运动可能是什么问题?

float gravity = 9.75;
float time = 0;
float speedx=20;
float speedy=440;

int speed = 0;
int angle = 0;

String veloc = "";



void setup(){
size(800,600);
}


 void keyPressed() {
  if( key >= '0' && key <= '9' ){
    veloc+=char(key);
    if( abs( int( veloc ) ) > 1000 ){
        speed = int(veloc.substring(0,2));  
        angle = int(veloc.substring(2,4));
        println("Speed is " + speed + " m/sec");
        println("Angle is " + angle + " degree");
        time = time + 1;
    }
  } 
}





void draw() {



  background(129,201,255);
  strokeWeight(0);
fill(64,152,3);
rect(0,200,800,600);

fill(188,133,61);
rect(400,375,150,30);
rect(400,500,150,30);
rect(400,275,150,30);



rect(400,400,30,120);
rect(520,400,30,120);
rect(400,275,30,120);
rect(520,275,30,120);

PImage slingshot;
slingshot = loadImage("slingshot.png");
image(slingshot, 30, 450);


PImage pig;
pig = loadImage("pig.png");
image(pig, 460, 253);
image(pig, 410, 253);
image(pig, 510, 253);
image(pig, 435, 353);
image(pig, 485, 353);
image(pig, 435, 478);
image(pig, 485, 478);

text("Please Type a Magnitude (0-99) and an Angle (0-99). E.g. 1045 , Speed = 10, Angle = 45", 120, 30);



  PImage bird;
  bird = loadImage("bird.png");
  image(bird, speedx, speedy);

  speedx = speedx + (speed * cos(angle));
  speedy = speedy + (speed * -sin(angle)) + gravity*time;

}

1 个答案:

答案 0 :(得分:0)

你没有明确说明你想要解决的问题,所以我建议你只看https://en.wikipedia.org/wiki/Trajectory_of_a_projectile,其中列出了关于弹道轨迹如何工作的总和知识(包括适用于愤怒的小鸟军械的那些并且只是实现这些功能。它们非常简单,而且几乎不言自明。