Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!timbuk!kilian From: kilian@cray.com (Alan Kilian) Newsgroups: comp.graphics Subject: Re: Graphics -- projectile movement question Message-ID: <165722.22170@timbuk.cray.com> Date: 27 Mar 91 00:52:21 GMT References: <1991Mar26.125744.623@stat.appstate.edu> Lines: 49 In article <1991Mar26.125744.623@stat.appstate.edu>, c_s245010114@stat.appstate.edu writes: > > My question is, what's the best way to devise the arc it will follow using two > pixels as the "bomb?" I will generate a random x-position at the bottom of the > screen and a random angle of elevation. The "speed" will be a fixed value > which I must mess around with. "Gravity" will also be a problem. > > BITNET: C_S245010114@appstate.bitnet Scott E. Schnegelberger > INTERNET: C_S245010114@conrad.appstate.edu Appalachian State University This is easy do do really fast. Here's how: x,y,ox and oy are integers, xv,yv,gravity are floats) x = rand y = 0 (0,0) is at the lower left of the screen xv = rand (X and y velocities in pixels per iteration) yv = rand (Better make yv positive) gravity = .1 (Or something like that) ox = x (Save the initial location) oy = y draw (ox,oy) (draw the initial object) do { ox = x oy = y (Save the position of the object) x = x + xv (Move the object in the X direction) y = y + yv; (Move the object up or down) yv = yv - gravity (add the gravity effect) draw(x,y) (draw the object) erase(ox,oy) (erase the old object) } while (y > 0) That's it. It almost allways goes too fast. you'll need to put a delay loop or have 100 objects flying to get it to slow down. If you're interested, I'll send more things for bouncing off walls and things it's really simple. I'm gone until next Monday April whatever. -- -Alan Kilian kilian@cray.com 612.683.5499 Cray Research, Inc. | If you were plowing a field what would you 655 F Lone Oak Drive | rather use? 2 strong oxen or 1024 chickens? Eagan MN, 55121 | -Seymour Cray (On massivly paralell machines)