News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Space Invaders Tutorial

Started by thaaks, April 18, 2006, 03:33:47 PM

Previous topic - Next topic

Big C.

yeah... i loving your first tut and how it grows...  :)

I would have another optimization suggestion for you:

The bullet of the ship appears with the pressing onto the control key to the fore, therefore before / on your ship and begins his way through the Aliens upper game edge.

What you think about that if the bullet already appears behind the ship and shows the shooting standby thus, in order to appear behind the ship then according to his target reaching again, then his way goes.

(needs a transparant ship image)

Big C.

thaaks

It's done! Part one of the tutorial is complete. Collision detection is in and so is scoring, some simple high score mechanism, increasing game difficulty and the option to restart the game.

Jump here to have a read!
At the end of the tutorial you can download the complete source code.

Have fun with it and please give some feedback.

Ideas for the second part of the tutorial are:
- game states to handle transitions between splash screen, main menu or title, the game, the high score list and so on,
- animations for sprites,
- sound and music,
- some effects (explosions).

Do you want to see more? Tell me  ;)

Cheers,
Tommy

stef

Hi Thaaks/Tommy!

Thx for your tutorial. Must still deal with it.
But I would like to see more B)  !!


Greetings
stef

thaaks

Thanks, stef!

I will continue the tutorial with a second part for sure.
Right now I spend most of my coding spare time to proceed with my RetroRemakes compo entry. After the compo is over I think I'll find the time to go ahead with the tutorial part 2 :rolleyes:

Or maybe I'll start it to relax a bit in between coding - who knows...
But school holidays are ahead so I will also spend some time with my kids - summer is just a bad time for coding  :D

Cheers,
Tommy

kevin

#19
Revised Source Code  

   This is such a great tutorial, but the code was out of date.     So I've refreshed the code so that's it's not only be compatible with PlayBasic V1.62 (and above) but utilize some features there weren't available when the tutorial was originally written.

   Download is the attached to this post.



edwinbmiller

#20
I have version 1.63m playbasic had to do a global replace of list() with temp().
in other words replace list array with new name of temp in order to get the demo space invaders
to compile and run correctly. list() must be a key word or have special meaning to the compiler
can find no docs on it though. anyone know why using this array name is an issue for 1.63m???
this comment applys to the original space invaders code as extracted from his web page not
the updated code attached as a zip in one of the messages in this thread ( he already made
the equivelent changes already on that code). He needs to update the writeup on his site to
make the changes also to the array name.


kevin

 PB1.63 and above have native linked LIST support.

thaaks

Hi Kevin,
I've been very quiet on the PlayBasic side of life but I just decided to overhaul my Space Invaders Tutorial - I still get around 100 hits a month on this tutorial so I thought it's worth updating it to help new users of PlayBasic.
I downloaded your updated source code and started my updated PlayBasic (1.71g). The code doesn't work anymore - seems like index 0 is no longer allowed for arrays.

So I don't just want to fix the code but also update it to the most recent PB features and reading your previous post I must ask: What do you mean with native linked list support?
I found the help for GetFirstSprite() and GetNextSprite() where you mention native linked lists but the Space Invaders Tutorial shows linked lists for types. Is there also native support for type lists?

Anyway, looking at all the screenshots and tutorials I am impressed about your progress with PB! Hats off!
I'm urged to have a deeper look into the new sprite and particle stuff and will surely hang around in the forums for a while now ;)
Can you recommend usage of PB 1.71g or should I better use some 1.6x version? I would prefer using 1.7x (HW acceleration, here I come!)...

I will post here as soon as the tutorial is up to date!

Cheers,
Tommy

Big C.

WB Tommy,  :)

QuoteIs there also native support for type lists?
==>Have a look at the Types List example in the Projects\example\Arrays_&_types folders.

QuoteCan you recommend usage of PB 1.71g or should I better use some 1.6x version?
read this or see here

Big C.

kevin

#24
QuoteI downloaded your updated source code and started my updated PlayBasic (1.71g). The code doesn't work anymore - seems like index 0 is no longer allowed for arrays.

  There's a logic error in you're bullet collision code, it's transparent in  V1.63 and bellow as they apparently allow addressing sprites that don't exist through SpriteOverlap and SpriteHit.  But that hole has been plugged!

  See here..

PlayBASIC Code: [Select]
Psub UpdateBullets()
Local i, j, nrBullets, nrAliens
nrBullets = GetArrayElements(Bullets().TBullet, 1)
For i = 0 To nrBullets
If Bullets(i).inUse
Bullets(i).y# = Bullets(i).y# + Bullets(i).dy
If (Bullets(i).y# > SCREEN_HEIGHT) Or (Bullets(i).y# + Bullets(i).h) < 0
DestroyBullet(i)
Else
; check for bullet collisions
; first check alien bullets with player
If Bullets(i).playerShot = False And SpritesOverlap(Bullets(i).spriteNo, Player.spriteNo)
GameOver = True
ElseIf Bullets(i).playerShot = True
; this is a player bullet - check against all aliens
nrAliens = GetArrayElements(Aliens().TAlien, 1)
For j = 0 To nrAliens
If Aliens(j).inUse
If SpritesOverlap(Bullets(i).spriteNo, Aliens(j).spriteNo)
; destroy the bullet and the alien
DestroyBullet(i) ; Here you're killing the bullet, but don't exit the loop. So when the
; loop continues the bullet sprite no longer exists (ie. it'll be checking a null sprite)
DestroyAlien(j)
Score = Score + ALIEN_KILL_SCORE
exitfor j ; we should exit this inner loop here.

EndIf
EndIf
Next
EndIf
If Bullets(i).inUse
PositionSprite Bullets(i).spriteNo, Bullets(i).x#, Bullets(i).y#
EndIf
EndIf
EndIf
Next
EndPsub




  Although, you really should be using SpriteHIT() !  



QuoteSo I don't just want to fix the code but also update it to the most recent PB features and reading your previous post I must ask: What do you mean with native linked list support?
I found the help for GetFirstSprite() and GetNextSprite() where you mention native linked lists but the Space Invaders Tutorial shows linked lists for types. Is there also native support for type lists?

  See  Linked Lists    



QuoteCan you recommend usage of PB 1.71g or should I better use some 1.6x version? I would prefer using 1.7x (HW acceleration, here I come!)...

  PB 1.63 and bellow are hardware accelerated also!   In terms of this example I don't really see the point of lifting the requirements above 1.63.  

thaaks

Thanks Kevin and Big C.,
just as usual lightning fast answers  ;D

Last night I saw the problem with the SpritesOverlap and the spriteno being 0. But I didn't see why this occurred. After reading Kevin's answer it's pretty obvious  ::)

I will use the new native linked lists for aliens and bullets and clean up the code and my writing. Those linked lists of typed pointers look very promising!

Regarding the PB version issue: should I go back reinstalling the latest 1.63 patch? Can I just unzip or install the latest patch over the 1.71g patch in my programs\playbasic folder???

Or is there a recommended way to cleanup my local mess (patched and patched and patched version of PB) and just setup a fresh final 1.63 version?
Maybe I should have two installations of PlayBasic?! Any known issues about having two different PlayBasic versions on your hard disk?

BTW: Seems like the debugger in 1.71g just dies after hitting F6 in the IDE. Debugging and tracing (F7) works!?

Cheers,
Tommy



thaaks

Okay, I'm back to PB 1.63r.

If anyone wants to reinstall PB on their machine here's what I did:
1. Renamed c:\program files\PlayBasic to c:\program files\PlayBasic.away
2. Install the PlayBasicV1089c_Retail_Setup.exe
3. Install the PlayBasicV163m_Retail_Patch.exe
4. Install the PlayBasicV163r_Retail_Patch.zip

Keep your registration key at hand, load a project and run it...

So now I'm starting to revamp the tutorial.

Later,
Tommy

thaaks

The Space Invaders tutorial is updated!
It now works with PlayBasic 1.63r, uses native lists, pixel perfect collisions, collision classes, SpriteHit() and uses SpriteLocals.

Go and have a read here!

Feedback appreciated!

Good night,
Tommy

Big C.

Hi Tommy,

i've downloaded and try (with PB V1.71g) u sourcecode again...  A great work, but I have found two things... see hardcopys...

I thing u want 8 aliens on 5 rows, but with these codesnippet u got one row


  ; let's have 5 rows of 8 aliens each
  For y = 1 To 1 ; 5


on the second hardcopy i thing u want to center the text... to solve this problem i would change the following codesnippet

from

  CenterText SCREEN_WIDTH/2 - (w/2), ypos, msg$


to

  CenterText (SCREEN_WIDTH/2) , ypos, msg$


cheers Big C.  ;D


[attachment deleted by admin]

thaaks

Big C.,
you got me  :-[

Shouldn't create zip files late at night...

The first "bug" (8 aliens on 1 instead of 5 rows) crept in while fixing the last bug. I simply forgot to undo the change.

The second one was a stupid copy/paste bug...

Thanks for telling me, will fix it tonight or tomorrow night!

Cheers,
TommyError Missing Closing Square Bracket