0

我正在尝试为我的家庭作业创建一个类似愤怒的小鸟的游戏,但我在角度和弹丸运动方面遇到了麻烦。我给它重力*时间模块,但它似乎没有进行抛射运动,可能是什么问题?

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;

}
4

1 回答 1

0

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

于 2013-04-04T17:16:49.360 回答