PDA

View Full Version : AirDogs 1942, a TBDI sample game



Michael Hartlef
02-09-2007, 10:57
Hi folks,

after 3 weeks part time work, I proud to show off a little 2 player game.

I have to say thank you to Petr Schreiber for providing the TopDown3D
sources as they helped a lot during the development.

The game is called AirDogs 1942 and is a WW2 dogfighting game. It's not 100% finished
but allready fun to play. My son and I enjoy it very much.

The controls are simple:

JoyY to go faster or slower, or UP and Down
JoyX to turn
Button 1 to shot
Button 2 to select

If no joystick is connected, you ADWS and space or LEFT,RIGHT,UP,DOWN,L

Once the bundle functionality is working again, I will create an exe for it.

Like allways, comments are welcome.

Take care
Michael

EDIT on June 7th, 2008: Updated the code with bug fixes and singler player code by Petr Schreiber. Also the menu buttons have a better size now so the FPS isn't dropping down anymore.

Petr Schreiber
02-09-2007, 12:03
Mike,

this is perfect !
Finally my joypad got some use :)

Really good, nice and clean look ... fantastic !

I tried to use my PC steering wheel and joypad to control planes and it worked perfectly.


Good work!,
Petr

Michael Hartlef
02-09-2007, 12:10
Steering wheel, not that is something. Thanks for the nice words. :)

ErosOlmi
02-09-2007, 12:12
:o FANTASTIC !
Thanks a lot to you for this astonishing example and for your new TBDI module. Tell me when you will be ready for official release.
Also a big thanks to your son, that I imagine he was your beta tester ;D

I will play with my son too and will give you back impressions.

A big :-*

Michael Hartlef
02-09-2007, 12:25
I can tell you, he had a blast.

The game isn't 100% finished because I was suffering from headaches and neckpains a lot this week. But the publisher made me releasing it. ;D

I will work further on it, as I have some ideas.

Single player mode, different planes, options, maaaayyyyybe network playing.

It's a simple game but you can do a lot with it.

ErosOlmi
02-09-2007, 12:31
It's a simple game but you can do a lot with it.


Well, not so simple. All is present: presentation, interface, multiple controllers plus keyboards, graphics, sprites, sounds. An impressive job, Mike.
Code is perfectly organized, clear. A joy to have a look for study purposes.

Petr Schreiber
02-09-2007, 12:33
Mike,

I hope my work on new TBGL will go ok as till now,
when released, it will simplify even more whole source of AirDogs ;)

Just after playing Airdogs I finished attaching camera to entity which was making problems before,
so your game has brainhealing efffect too :)


Bye,
Petr

Michael Hartlef
02-09-2007, 12:37
Code is perfectly organized, clear. A joy to have a look for study purposes.


That was another goal I had. Writing a playable game in that short period and still having a codebase that is reusable and readable. Overall I put around 30-40 hours into it. It also helped me to figure out how fast and far I could come in a given timeframe.


has brainhealing efffect too

I'm glad I could help out here. :) I can't wait till you release it.

kryton9
02-09-2007, 21:59
Thanks Mike, as Eros said, you did a complete job, I really liked it from start to finish. A beautiful splashscreen, a nice menu, sound, sprites, action, and scenery, plus wide support of input. Excellent, thanks so much for the hard work and release!!!

Michael Hartlef
03-09-2007, 05:40
You're welcome.

ErosOlmi
04-09-2007, 17:18
Mike,

I had some time today to test AirDogs 1942 game.
I tested on my laptop that has no any DI devices so consider it a non ideal situation. Here my observations:

if I change
dim xRes as long = 640
dim yRes as long = 480
to
dim xRes as long = 1024
dim yRes as long = 768
initial menu is not centered (or redimensioned). The same happen if TBGL window is redimensioned at runtime by manual operation.


if TBGL window is redimensione at runtime while paying game (let say you start from 640x480 and than make TBGL bigger) the new game playground is not considered by planes that continue to see previous logical size.


Using up/down arrows while in initial menu takes more than 2 second to to move current active menu. Maybe it can me related to the fact I've no DI devices. While inside RenderMenu function I get only 1 FPS.




I will test more maybe this evening when home. I will have joystick.

Ciao
Eros

Michael Hartlef
04-09-2007, 18:37
1) The game is not ment to be played at bigger resolutions.
2) Because of the lag, could it be that you have vertical sync off?

ErosOlmi
04-09-2007, 18:48
All other TBGL scripts run as expected at big FPS.

Also AirDogs 1942 works as expected once inside the game. It is just the menu that has this problem. As soon as I'm inside the game, it is perfect!

ErosOlmi
04-09-2007, 18:57
I limited the problematic part. If I comment the following commented part in RenderMenu function all run at high speed.



...
tbgl_PushMatrix
tbgl_Translate 320, 100, 0
for j = 1 to 5
if j = actmenu then
tbgl_Color 255,255,255
else
tbgl_color 200,200,200
end if
' tbgl_BindTexture %mnplate+j ' Sets texture #1 as actual
' tbgl_BeginPoly %GL_QUADS
' tbgl_TexCoord2D 0, 0
' tbgl_Vertex -64, -20+j*46, 0

' tbgl_TexCoord2D 1, 0
' tbgl_Vertex 64, -20+j*46, 0
'
' tbgl_TexCoord2D 1, 1
' tbgl_Vertex 64, 20+j*46, 0
'
' tbgl_TexCoord2D 0, 1
' tbgl_Vertex -64, 20+j*46, 0
' tbgl_EndPoly
next
tbgl_PopMatrix
TBGL_ResetMatrix
tbgl_drawframe
...


But of course menu items are not on screen.

Going home now. I will test more later.

Ciao
Eros

Petr Schreiber
04-09-2007, 19:03
Eros,

1 FPS is a bit scary.
Such a low FPS you should not get even in case OpenGL falls to software mode on your dual core monster.
Try to comment out TBDI commands, maybe some device lags it ? ( but this is highly unprobable ).

Here is slightly more optimized ( still not to maxx ) RenderMenu procedure:


'*-------------------------------------------------------*
'* drawMenu *
'*-------------------------------------------------------*
sub RenderMenu()
local pressed as long
local jx as long

pressed = %FALSE

tbgl_GetAsyncKeyState(-1) ' Resets keys status before checking

tbgl_UseAlphaTest 1
tbgl_AlphaFunc %tbGL_GREATER, 0.5
tbgl_UseDepth 0 ' No depth - it's useless for smokes, it will look better without it
tbgl_Uselighting 0 ' No light
tbgl_usetexture 1 ' Texturing on

while IsWindow(hWnd)

'FPSCount = TBGL_GetFramerate 'help_CalcFramerate

' *******************************
' * RENDERING THE SCENE *
' *******************************
tbgl_RenderMatrix2D
tbgl_ClearFrame

tbgl_BindTexture %mnPlate ' Sets texture #1 as actual

tbgl_PushMatrix
tbgl_backColor 0, 67,171
tbgl_Color 255,255,255
tbgl_Translate 320, 240, 0

' We will map player texture to square polygon

tbgl_BeginPoly %GL_QUADS
tbgl_TexCoord2D 0, 0
tbgl_Vertex -128, -128, 0

tbgl_TexCoord2D 1, 0
tbgl_Vertex 128, -128, 0

tbgl_TexCoord2D 1, 1
tbgl_Vertex 128, 128, 0

tbgl_TexCoord2D 0, 1
tbgl_Vertex -128, 128, 0
tbgl_EndPoly

tbgl_PopMatrix

tbgl_PushMatrix
tbgl_Translate 320, 100, 0
for j = 1 to 5
if j = actmenu then
tbgl_Color 255,255,255
else
tbgl_color 200,200,200
end if
tbgl_BindTexture %mnplate+j ' Sets texture #1 as actual
tbgl_BeginPoly %GL_QUADS
tbgl_TexCoord2D 0, 0
tbgl_Vertex -64, -20+j*46

tbgl_TexCoord2D 1, 0
tbgl_Vertex 64, -20+j*46

tbgl_TexCoord2D 1, 1
tbgl_Vertex 64, 20+j*46

tbgl_TexCoord2D 0, 1
tbgl_Vertex -64, 20+j*46
tbgl_EndPoly
next
tbgl_PopMatrix

tbgl_drawframe

if tbgl_getwindowkeyonce(hWnd,%VK_DOWN) THEN actmenu = actmenu - 1
if tbgl_getwindowkeyonce(hWnd,%VK_UP) THEN actmenu = actmenu + 1

jx = tbdi_joyY(0)
if Pressed = %TRUE and jx > -10 and jx < 10 then
pressed = %FALSE
end if
if Pressed = %FALSE and jx < -10 then
pressed = %TRUE
actmenu = actmenu + 1
end if
if Pressed = %FALSE and jx > 10 then
pressed = %TRUE
actmenu = actmenu - 1
end if

If actmenu = 6 then actmenu = 1
If actmenu = 0 then actmenu = 5
if TBDI_JoyButton(0,2) <> 0 then exit while
if GetAsyncKeyState(%VK_RETURN) THEN exit while
wend

end sub


This code runs 400 FPS on my PC with onboard GeForce 6150, your Radeon is much faster !


Bye,
Petr

Michael Hartlef
04-09-2007, 19:09
Where did you enhance it?

Petr Schreiber
04-09-2007, 19:10
Eros,

I found the problem !

Menu items textures are not sized in power of two - 128x40! Me and Mike have 3D card with correct OpenGL 2.0 implementation - non power of two textures cause no trouble.
It seems your release of ATi drivers does not do non-power of two textures on hardware.

My excuse ;D : TBGL manual says only power of two textures are allowed.

So just copy attached modified textures ( 128x64 ) to your AirDogs \ Textures.
You should get no hurt in quality ( as I stretched them vertically, program will map them on smaller height ) and I am almost 100% sure you won't get 1 FPS anymore.


Bye,
Petr

Petr Schreiber
04-09-2007, 19:12
Mike,

just little change - state controlling variables are moved before loop, there is no need to request alpha testing ( for example ) in every iteration. Once you set the state, it is set on until you switch it off.
In fact my change was just cosmetic, on todays hardware it makes not so big difference.

But this was not cause of the problem, that were NPOT textures.


Bye,
Petr

Michael Hartlef
04-09-2007, 19:15
Ok, I thought the power of two counts only for the X axxis.

Petr Schreiber
04-09-2007, 19:21
Sadly not,

I will accent it more in TBGL helpfile.

Fastest are square shaped textures ( 512x512, ... ), rectangular textures with power of two sides ( 512x256, ... ) are similar in speed too.

Non power of two are part of OpenGL natively ( not just via extension ) from OpenGL 2.0.
They are more comfortable then the previous mentioned, but they generally *should* be slowest.

This does not apply on my PC as it seems to perform well all 3 cases, but power of two textures are slightly easier to filter when you think of it.


Bye,
Petr

Michael Hartlef
04-09-2007, 19:27
Thanks for the explanation. I'll make the modifications soon.

ErosOlmi
04-09-2007, 22:08
Perfect! All working fine now. Frame rate is very high.

Mike, this is also a perfect example demonstrating how TBGL can also do 2D games.

Ciao
Eros

ErosOlmi
04-09-2007, 22:42
Mike,

for fun I set %MaxShots to 20 and get Runtime error at line 603. Line 603 is



for j = 1 to %maxShots


but should be



for j = 1 to %MaxSmoke


Also, because you are generating random numbers in your script, add a RANDOMIZE (http://www.thinbasic.com/public/products/thinBasic/help/html/randomize.htm) command at the beginning, so random generator will generate different sequences.

Ciao
Eros

ErosOlmi
04-09-2007, 23:37
Mike,

I've made a little variation adding specific and different turning angles and speed to every plane. See attached file with full source code.
Mainly, tPlayer UDT is the following:


Type tPlayer
X as double
Y as double
dir as double
damage as double
speed as double
img as long
vic as long
TurnLeft as long
TurnRight as long
SpeedUp as long
SpeedDown as long
end type
Than tPlayer setup inside SetupPlayers sub is something like:


Player(1).x = 90
Player(1).y = yres/2
Player(1).dir = 0
Player(1).speed = 2
Player(1).img = 1
Player(1).TurnLeft = rnd(60, 200) '---Generate random turning angle
Player(1).TurnRight = Player(1).TurnLeft '---Put the same as left but can be different
Player(1).SpeedUp = rnd(3,7) '---Generate random max speed
Player(1).SpeedDown = 1 '---Min speed is always 1

Player(2).x = xres-90
Player(2).y = yres/2
Player(2).dir = 180
Player(2).speed = 2
Player(2).img = 2
Player(2).TurnLeft = rnd(60, 200) '---Generate random turning angle
Player(2).TurnRight = Player(2).TurnLeft '---Put the same as left but can be different
Player(2).SpeedUp = rnd(3,7) '---Generate random max speed
Player(2).SpeedDown = 1 '---Min speed is always 1

New parameters are than used inside CheckKeyInput and CheckJoyInput subs.
Consider that a possible evolution is to add some bonus (positive or negative) during game execution that will change turn angle and speed for every plane.

Hope you will like.
Ciao
Eros

Michael Hartlef
05-09-2007, 05:29
Mike,

for fun I set %MaxShots to 20 and get Runtime error at line 603. Line 603 is



for j = 1 to %maxShots


but should be



for j = 1 to %MaxSmoke


Also, because you are generating random numbers in your script, add a RANDOMIZE (http://www.thinbasic.com/public/products/thinBasic/help/html/randomize.htm) command at the beginning, so random generator will generate different sequences.

Ciao
Eros



Thanks Eros, I saw that yesterday too.

And thanks for the mod, I plan on having several different planes to choose from for the player. With different values. But your mod could be a RANDOM plane. Good idea!

ErosOlmi
05-09-2007, 07:30
Thanks Eros, I saw that yesterday too.

And thanks for the mod, I plan on having several different planes to choose from for the player. With different values. But your mod could be a RANDOM plane. Good idea!


Perfect Mike.

Remeber to keep updated first post of this thread with your latest version of AirDogs 1942. When I will finish filling new thinBasic web site with initial minimum content, I would like to make a dedicated gaming area and AirDogs 1942 is a perfect choice to start with, if you like the idea.

Ciao
Eros

Michael Hartlef
05-09-2007, 09:01
Don't forget TopDown3D. :)

Michael Clease
05-09-2007, 09:05
I cant get it to run it complains about "%TBGL_Tex_ANISO" have i missed a TBGL update?

Petr Schreiber
05-09-2007, 10:23
Abraxas,

yes you did :)
You can wait till next thinBASIC preview release ( I think quite soon ) or grab it here (http://community.thinbasic.com/index.php?topic=1138.msg7750#msg7750).
It features mentioned anisotropic filtering and color masking for BMPs; more mini-patch than real new version.


Bye,
Petr

ErosOlmi
05-09-2007, 10:38
Don't forget TopDown3D. :)

Of course, how can I forget all the Bonus Pack examples all of you have created.
Ideas for the web are a lot, time a little less :D

ErosOlmi
05-09-2007, 10:41
... have i missed a TBGL update?

Yes Abraxas.
Sorry about that. I would have released an updated preview version with latest TBGL included but I have to finish some other changes and make some final tests before I can do it.

Ciao
Eros

Michael Hartlef
05-09-2007, 13:21
I cant get it to run it complains about "%TBGL_Tex_ANISO" have i missed a TBGL update?




Sorry, I should have stated it in the first place! :-\

Randall
05-09-2007, 18:50
Hello All,

I am brand new to thinBasic, and experienced this same error. Michael Hartlef was very kind to point me to the updated TBGL module via a PM. Thank you again Michael.

This experience raised a question in my mind.

While reviewing the documentation for thinBasic. I noticed the pre-parsing directive #MINVERSION, which I assume is for the core module of thinBasic.

Is there an equivalent function for other modules? For example, is there functionality that says this script needs TBGL module x.x.x at minimum to run?

I'm completely new here, so maybe I don't understand #MINVERSION or how the modules work. If so, please excuse my ignorance.

By the way, I'm very impressed by what I have seen in the language, the web site, and especially the forum members and contributors.

Nice job, guys!

Thank you,

Randall

ErosOlmi
05-09-2007, 19:59
Hi Randall,

welcome to thinBasic community :)
To give you some indications about thinBasic version. We publish 2 versions: stable and preview.
Stable is an official version released after some time of internal and mainly forum users tests.
After we release a stable version we start a new development phase we call preview version. In this phase we fix some bugs, add new functionalities, listen to thinBasic user need and continuously release new preview under the same version number. In this way you do not have to wait ages to get latest fix or features but quite immediately.

That said, when we release a new version (stable or preview) all exe, dll and modules (modules are just nothing more than special dlls) have the same version number. Currently you can download thinBasic stable version 1.4.0.0 and thinBasic preview version 1.4.0.1. But remember: thinBasic preview version change continuosly as you can see here: http://community.thinbasic.com/index.php?topic=985.0

Now to #MINVERSION command. It's purpose is exactly what you described. It stops script execution if installed thinBasic is not the minimum version script author has indicated. But it checks only thinBasic core engine and official thinBasic modules. TBGL and TBDI are not thinBasic official modules but modules developed by (respectively) Petr and Mike. So #MINVERSION will not check their version.

More, AirDogs 1942 is an ongoing experimental script made by Mike to test new TBDI module features (multi direct input devices handling) so this thread is an ongoing experimental project. While Mike was developing AirDogs 1942 he asked Petr about the possibility to have transparent BMPs and Petr immediately developed the new anisotropic filtering and colour masking features. Again new features developed while AirDogs 1942 was in the middle of the development. But we have not yet included all those new features in thinBasic preview so ...

So, to make the story short, there are some movements here thanks to the passion of the users populating thinBasic forum (did I already thank you guy? :D ). Maybe a little confusing at first but I hope you will start to like the way we develop.

Ciao
Eros

PS: do not forget to give us some info about you: what are you searching, what do you program for, what type of script do you prefer, if you need something inparticular, or just have some ideas to implement thinBasic and thinBasic tools. We will listen to you and try to make our best to add what you need to thinBasic.

oops: maybe to much long this reply, isn't it? ;D

Michael Hartlef
05-09-2007, 20:33
Hi Randall,

again welcome on board. :) If you are into game programming then I suggest you to really look into thinBASIC. You won't be dissapointed. Like Eros said, if you need something or have an idea, let us know. We might be able to come up with a new functionality quickly.

Eros, you described thinBASIC and us here to the point. Thank you! :)

kryton9
05-09-2007, 21:18
Welcome aboard! thinBasic is already an awesome language and each week it just gets better and better. There is much underway that is going to just add to what can be done in thinBasic easily. Even under development our tests are coming out so much better than I ever thought possible at this stage. Whatever we throw at thinBasic it can handle so far and is always improving on all aspects. So I hope you enjoy it as much as the rest of us. The development team here is best I have ever seen, they work hard to make all our wished true!

Petr Schreiber
05-09-2007, 21:33
Welcome Randall,

TBGL does not provide any version checking so far.
As typical users will target "stable" most, the #MINVERSION should be enough.

For example stable of actual preview ( 1.4.0.1 ) will contain new TBGL ( 0.2.0.1, that you had to download ) out of the box. It is good to keep in touch with latest thinBASIC version, as there is always some added functionality or improve in speed.

Hope you will like thinBASIC, it is very dynamically developed language with very friendly community and developers.


Bye,
Petr

Randall
06-09-2007, 02:23
I got it working ! Very cool ! Thanks Michael !

I don't have a game-pad or joy-stick, so I just used the keyboard in single player mode, but it's pretty cool there is a module for these types of input devices.

And thank you all for the warm welcome!

I'm not a game programmer, not even much of a programmer, but I enjoy learning new languages. I'll poke around the forums and ask a few questions as I try to learn thinBasic.

I am intrigued by the architecture of thinBasic and it's extensibility through user contributed modules. Perhaps some day , far in the future, I could contribute such a module. :)

Randall

ErosOlmi
06-09-2007, 02:27
Perfect Randall.

In any case your presence here is already a great contribution for us. Be sure.

Ciao
Eros

kryton9
06-09-2007, 04:54
Randall, take a look at the SDK section on the forums or in your thinBasic installation, in there you will find all the languages currently you can write modules in. It is a pretty nice list already.

Petr Schreiber
25-11-2007, 15:09
Hi,

here is mini update which removes dependancy on UI module and adds at least text response for all menu items.
I am thinking of rewriting this game to entity system, making it "3D 2D" would remove dependnacy on resolution and maybe even more clear code.

Apply like a patch to the original installation.


Petr

Michael Hartlef
25-11-2007, 17:06
Hi Petr, thanks fopr your work. Everyone is free to use it like they want. I working on stuff too for it.

Petr Schreiber
07-06-2008, 12:21
Hi,

here is just main script update, which makes singleplayer finally possible!

You play as player 1 ( W,S,A,D,C ) and player 2 tries to get you. Currently it is very basic, but could serve as base for further tweaks.


Petr

Michael Hartlef
07-06-2008, 13:16
Thanks man, I will include your single playert code into my current one, as there are some quirks in other code pieces I allready fixed but not posted. Thanks again man.

Petr Schreiber
07-06-2008, 13:30
Thanks Mike,

looking forward to latest version!
It is very nice game :)


Petr

Michael Hartlef
07-06-2008, 13:45
Done Petr. :) Get it from the first topic.

Petr Schreiber
07-06-2008, 14:18
Thanks Mike,

I can hear you added some new audio :)


Petr

kryton9
07-06-2008, 17:35
Great update guys!!

On mine, Winston Churchill keeps talking through out the game even in the battle. Wasn't sure if planned this way or not, but wanted to mention it.

Now back to some more airDogs play, thanks again guys!