BIP basic code?

BlitzMax Forums/BlitzMax Programming/BIP basic code?

Rimmsy(Posted 2006) [#1]
I'm trying to write a small multiplayer version of the amiga classic, BIP:




(The best screenshots I could find). The problem is I'm trying to understand the concept of lift and gravity on the little plane. The game is a 2d single screen side on view.

In the original you had power buttons (up and down) which you used to control what little power you had. When you flew straight left and right you didn't lose any altitude but when you pointed your nose up a little you lost speed. when you pointed your nose down you gained speed. This way you could stall and do some cool power dives.

My problem is I'm not sure how to code this. It's not a physically correct game, it's arcade; so it's not vitally important to work with kilos, proper gravity, wind, etc. Has anyone done anything similar or any idea how it might work code wise?


Who was John Galt?(Posted 2006) [#2]
Ahh Rimmsy I absolutely loved this game, too. I can give you a hand when I get home later.


Rimmsy(Posted 2006) [#3]
Cheers, matey. I'm going to attempt multiplayer via the internet when I get the thing going and make it publicly available. I used to love playing this game for hours on end. Awesome.


ImaginaryHuman(Posted 2006) [#4]
I have very fond memories of this game on the Amiga, it was a real favorite for multiplayer fun. So simple, so cool. :-) Looking forward to seeing this remake.

The `falling out of the sky` thing might be that when the engine revs get below a certain point there isn't enough forward motion to counteract the gravity. After all, you have to figure in the `lift` effect (antigravity) of the way a plane's wings work. When there is enough velocity forward there is lift counteracting any gravity. I remember the fun of `stalling` the plane and having it fall out of the sky, only to get itself re-started again at the last moment before hitting the ground - but only if you were pointed straight down. :-D


Rimmsy(Posted 2006) [#5]
Here's what I've got so far. The source is hastily put together from bits of mark's gnet example and other bits and bobs. I'm just trying to get a rough feeling for what goes where at the moment.

www.birdinsky.com/downloads/bip.zip


Who was John Galt?(Posted 2006) [#6]
Right Rimmsy - first off I don't have all the answers here - you'll have to do some experimenting and a lot of playtesting (which should be fun!) to get things tweaked right, but here's a starter for ten. I don't know how much u know already so....

Define your plane's x and y position, and split its speed into two components, the x and y parts:

x#=100.0;
y#=100.0;
vx#=0.0;
vy#=0.0;

Every loop you add the velocity components to the planes position - this gives it the tendency to keep moving in the same direction...

x:+vx
y:+vy

To start with the plane has no velocity - its speed will be effected by the forces on it - engine thrust, lift, gravity, wind resistance.

You might try-
engine_thrust#=constant*engine_speed# ;player controls engine speed)
lift#=constant2*airspeed#
gravity#=another constant
wind resistance=constant3*airspeed#

These calculation give you the size of the forces on the plane but dont account for the directions of the forces. I'm finger waving with some of them - you might try lift_mag#=constant*airspeed#^2 or something - see what feels best, and you'll have to fiddle with the constants.

You need to define the way the aircraft is pointing...
angle#=0.0

This is in degrees anticlockwise from right, assuming your plane starts upright facing right.

forward_unit_x#=cos(angle)
forward_unit_y#=sin(angle)

up_unit_x#=cos(angle+90.0)
up_unit_y#=cos(angle+90.0)
etc...
back.... (angle+180.0)
down... (angle+270.0)

You use these variables to get your forces pointing in the right direction - here up means where the pilot would be looking if he put his head back 90 degrees, not the 'landscape' up. Use these to calculate how much of each force is along x and how much is along y. For example, lift is directed 'up' from the planes wing, so:

lift_force_x#=lift_mag*up_unit_x
lift_force_y#=lift_mag*up_unit_y

gravity always points landscape down, (y direction)
gravity_force_y#=gravity

Each loop you need to add all the x components of each force to get the total x force, and likewise all the ys.

Then
vx=vx+const*total_force_x
vy=vy+const*total_force_y

This should be enough to give you your basic flight movement. I would start off just getting the thing to move in a straight line without gravity or lift to. It might need some stuff adding... and I'm sorry if this is too confusing or assumes you know less than you do - I don't know what background you have.


Who was John Galt?(Posted 2006) [#7]
Ahh damn - you know more than I assumed... wish I hadnt written all that now! I was writing that before the demo was posted.

I'm liking the demo already!!!

At the mo its acting more like a rocket - instead of thrusting when you press forward, you need an engine speed that is modified by pressing forward/back. Use the engine speed to work out a thrust.

Keep up the good work and be sure to post another demo when you've done a bit more.


ImaginaryHuman(Posted 2006) [#8]
Rimmsy - I think that second screenshot up there is not the original game. The original only ever had the hut, that other one obviously seems to be a remake.


Rimmsy(Posted 2006) [#9]
Yeah, it's apparently a remake in allergo but I can't find the source. I'm going to make use of this o'reilly physics book I bought years ago.

Thanks for the tips nomen. It's getting there. I'll upload the new version tomorrow and maybe a front end to the host/join selection so we can have a game.


Rimmsy(Posted 2006) [#10]
No, I can't seem to find any code that's easy for me to understand/translate. I'm getting annoyed because I can't visualise the code to do this. Has anyone done anything similar? You got anything like this nomen?


Perturbatio(Posted 2006) [#11]
just so you know, that Allegro one doesn't match my recollection of the gameplay at all.


Who was John Galt?(Posted 2006) [#12]
I haven't done anything like this before. You need a lift force up from the wing (at right angles to the body of the plane), and like I said a constant engine speed which controls the thrust generated, and a wind resistance pointed backwards from the direction of motion. That should get you there with some tweaking.


Perturbatio(Posted 2006) [#13]
Rimmsy, it's nothing spectacular and far from perfect (gravity just ain't right), but it's my first attempt at using vectors for anything worthwhile so it pleases me :)



The crappy plane image:



AndyBoy_UK(Posted 2006) [#14]
Oh good choice people, as soon as this baby is ready, you let me know as I have an old score to settle with my sister on this game from when we were kids, but she lives miles away now.

:)

A


Rimmsy(Posted 2006) [#15]
Cool code, perty. I'm attempting to change the move() method to something like this:

lift:vector = how much lift you get compared to wing angle of attack. this should be something like 1.0/90 * pitch so that if you're facing right (0) there is no lift, -10 there is a little bit of lift, -45 perfect lift. 

gravity:vector = done. always pointing down

drag:vector = 180 from plane's pitch. more drag with speed. I suppose this could be linked to the lift vector, so if your pitch is -90 (pointed straight up) then your drag would be super (causing a stall).

thrust:vector = movement in the pitch direction related to engine power (here, speed)

Position = AddVec2D(Position, thrust)
Position = AddVec2D(Position, drag)
Position = AddVec2D(Position, lift)
Position = AddVec2D(Position, gravity)


I'm not sure of the calculations for this lift, drag and thrust. The thrust should just be:
thrust.x=Cos(Pitch)*speed - Sin(Pitch)*speed
thrust.y=Sin(Pitch)*speed - Cos(Pitch)*speed

Simple enough... The lift? You've made an excellent start on this. at least I could fly the thing around and it didn't feel like space invaders. Swift, I know you've done something like this before, you got any ideas?


Perturbatio(Posted 2006) [#16]
The rest of my vector module if you need it:
(my site appears to be down at the moment so I'm posting source).