UnderwareDESIGN

PlayBASIC => Resources => Tutorials => Topic started by: thaaks on April 18, 2006, 03:33:47 PM

Title: Space Invaders Tutorial
Post by: thaaks on April 18, 2006, 03:33:47 PM
I will use this thread to tell you about the progress on my simple Space Invaders tutorial.
You can have a look here if you want to:
Space Invaders Tutorial (http://www.haaks.net/spaceinvaders1/index.html)

It's not done yet but progressing nicely.

I started explaining dynamic lists which will be used for the aliens and bullets later on.
It's (of course) based on some code I "stole" from Kevin's PlayBlaster demo. I also used this mechanism in Astrobreak.

I created a little "dynamic list" template which you can reuse with some global "find and replace" for your own needs.

Please tell me what you think of the tutorial in this thread.
Is it too low level? Too detailed? Too complicated?

Feedback appreciated!

Thanks,
Tommy



Go Here For Updated Version Of the Tutorials Source Code (http://www.underwaredesign.com/forums/index.php?topic=1275.msg14083#msg14083)

Title: Space Invaders Tutorial
Post by: kevin on April 19, 2006, 09:44:05 AM
While, i only skimmed through it yesterday morning, it's looking pretty good.   There's a few tidbit of codes here and there that could be trimmed down i guess.. but ya get that.


QuoteI created a little "dynamic list" template which you can reuse with some global "find and replace" for your own needs.

That's one way, another is to inherit the game list types from a parent list type.  Then you can use it on the kids.
Title: Space Invaders Tutorial
Post by: thaaks on April 19, 2006, 10:35:27 AM
QuoteThat's one way, another is to inherit the game list types from a parent list type.  Then you can use it on the kids.

Holy cow - does that mean that I could use the parent list type as the function parameter for all list functions and reuse the same code for all kid type arrays without changing the code (at least for the getfreeyadda(list().TList) and deleteyadda(list().TList, index) and deleteallyadda(list().TList) functions)?

That would be soooo cool - must give it a try tonight.

Tommy goes off humming a little happy tune  :)
Title: Space Invaders Tutorial
Post by: kevin on April 19, 2006, 11:08:50 AM
Yep, so if all the character arrays (aliens/bullets/particles/explosions etc) are children of your parent type.  Then you can roll a set of generic (for the entire family) Create/delete/getfree's/ position etc style function layers which you can use across all of them.  

Have a look at the Inherited types example in the Projects\example\Arrays_&_types folders

More recently there's also a linked list library that works the same way.  Which has been made into a Slib recently also.  

Here's the older version.
Linked Lists Example (http://www.underwaredesign.com/forums/index.php?topic=1026.0)
Title: Space Invaders Tutorial
Post by: thaaks on April 19, 2006, 11:39:30 AM
Wow, that's great and will shrink coding efforts a big deal.
I will modify my tutorial to use inherited types.

Did you do some speed comparison between linked lists and the array functions (FindArrayCell) to detect free elements?
What is faster?

I think codewise they don't differ very much and both are good to explain.

If I only knew that a few months before  :rolleyes:

Thanks,
Tommy
Title: Space Invaders Tutorial
Post by: Big C. on April 19, 2006, 11:43:25 AM
Hi, their both aces

linked Lists or dynamic Lists in PB are a difficult topic, anyway for me...

and I notice here, that professionals are at the work... that is also good so, but I wanted honestly said a command set that there is for example in Purebasic (perfectly moved) or also in BlitzBasic (complicated, but understandable).

The principle is already clear to me, I find only the handling complicated and I have me both explanations Tommys Tutorial, as also Kevins source code already more than once read through and/or worked through. For my Asteroidclone, i worked on, I use first once a Mix of types, arrays, dim commands and a good portion of mathematics. With my result I am already satisfied and I will see, weather I reach my personal target.

I added once the Help from Purebasic on the topic for information... Powerful Command Collection  B)
QuotePureBasic - LinkedList

Overview

Linked Lists are structures for storing data which are dynamically allocated depending of your need. It is a list of elements (the data you want to store) and each element is fully independant of the others. You can add as many elements you want (or as many as will fit into the memory of your computer), insert elements at the position you need, delete some other and more. This kind of data management is very useful as it's one of the best ways to handle data when you do not know how many elements you will need to store, or if you are often changing how many elements there are.

Before you can work with LinkedLists, you must declare them first. This could be done with the keyword NewList. For saving the contents are also often used structures.

To specifically search the contents of a LinkedList, using of loops is recommended: For : Next, ForEach : Next, Repeat : Until or While : Wend.
Command Index

AddElement
ChangeCurrentElement
ClearList
CountList
DeleteElement
FirstElement
InsertElement
LastElement
ListIndex
NextElement
PreviousElement
ResetList
SelectElement
SwapElements
Big C.

P.S. request not with me chide... It is only my opinion and I will occupy myself also still more intensively with the topic. Promised.  However who knows, maybe can Kevin us in version 1.50 or more highly surprise..  :D
Title: Space Invaders Tutorial
Post by: kevin on April 19, 2006, 12:29:28 PM

Tommy,

QuoteDid you do some speed comparison between linked lists and the array functions (FindArrayCell) to detect free elements?
What is faster?

 No idea.  Doing linear searches should be faster, on a small data set. Slower on big ones.    But it's not like pulling a free item from the free list requires a lot of operations.   While it'd more expensive,  it's not really worth worrying about.
Title: Space Invaders Tutorial
Post by: thaaks on April 19, 2006, 01:52:06 PM
Big C,

assuming that the speed of the PlayBasic VM is increasing, there is no need for builtin commands. An slib will just serve you fine. Looking at your PureBasic command list I am totally sure that all those commands can easily be implemented using an slib for linked lists and some inherited types.
Many languages only have a small command set and are mostly built from libraries (Smalltalk for example knows 7 keywords. The rest is libraries. Even if-then-else and loops and case statements are done as libraries...Ruby is similar.).
And if the runtime engine is fast and optimizing you won't realize a speed difference. For example Java gets 80% the speed of a C++ program as long as it is pure number crunching. If OO features are used, C++ is slow as hell compared to Java. Tested in some c't (german computer magazine) two years ago.

Kevin,

I will just go for the array and the builtin array functions. This way I need to change only minor things in my tutorial. And I agree, speed issues should be ignorable. If we deal with ten thousands of elements (where a speed difference could be measured) we would run into a whole set of other problems  :D

Thanks for the interesting informations,
Tommy
Title: Space Invaders Tutorial
Post by: thaaks on April 23, 2006, 03:28:26 PM
Hi all,
the tutorial is updated.
The game now explains(?) and uses type inheritance and dynamically growing arrays.

You can move the player ship and the aliens already approach you. If they reach the bottom (and they will as you can't shoot yet) the game ends.

I like the code so far, it's very readable, nicely split in functions and psubs and not too long.

Next things to add will be bullets and collisions and death of aliens and player.
At the end of the first part of the tutorial I will add simple scoring.

I added a voting (http://www.haaks.net/tinc?key=pfzIuqA0) to find out if a translation is required. Big C., only click once, okay?  :P
If I get some requests I'll do a german translation. If other languages are requested please post here. Also if you would be willing to do a translation into your native language once the first part (or the following parts) are finished. I will gladly host the translations on my site.

Again, feedback appreciated. As you might see, I already changed some bits of the tutorial, simplifying code, adding explanations and so on.

Cheers,
Tommy
Title: Space Invaders Tutorial
Post by: Big C. on April 24, 2006, 04:09:12 PM
Tommy,

now I am, however, offended...  :P

for that I voted now like 2 times... however only, because I wanted to give one my voice and one around test, whether you have a reloading barrier... Unfortunately no, therefore... I can now immediately... no... promised... I do not become... large Red Indian word of honor...  ;)

A annotation to the Tutorial:
If I try out your source code, I get a compiler-error then because the graphics are missing. I use yours that you implement in your Tutorial, then the pictures have as a jpg extension and not png... (the shot image is missing still)... Maybe another corresponding tip might be recorded!?

Big C.

Post addition:  I believe, you do not have to take yourself the trouble (my English becomes again better also from day to day, but do you know, how I do paraphrase P.S. in the English?)
Title: Space Invaders Tutorial
Post by: thaaks on April 24, 2006, 04:58:00 PM
Oh rats, those cheap voting tools you get from ISPs for free  :angry:

For the jpgs - another rats. My web publishing tool doesn't keep the file format I add the images with. I will complain. Sigh. And I will update the tutorial accordingly...

And good to know that your english gets better, feel free to contact me if you have any questions.

Cheers,
Tommy

PS: PS is the same in english although you might want to use p.s.: It's latin for post scriptum.

PPS: A nice web page to help you is dict.leo.org - a nice translation web page, even for phrases and such.
And if you install the Google toolbar you can switch on automatic translation of the words your mouse is over! Also pretty helpful.

PPPS: The default translation language of the google toolbar is spanish - that might confuse you. Switch to german  :D
Title: Space Invaders Tutorial
Post by: thaaks on April 25, 2006, 04:05:11 PM
Shooting bullets is in (at least for the player).
Now you can download the project including sources and images as a zip file at the bottom of the tutorial page.

Big C., thanks for pointing me to this bug. And I removed the shitty voting code.

Just curious: Is there free web voting available that I can add to my page by inserting some script code?

Cheers,
Tommy
Title: Space Invaders Tutorial
Post by: Big C. on April 25, 2006, 04:43:32 PM
I think, there are sufficient offers in the Internet...

PHP and MySQL (http://www.php-homepage.de/scripts/Umfragen.html) here for example...

or one version for Perl (http://www.cgi-world.de/cgi-bin/index.cgi?action=software&do=show&b=evs) maybe... or you write your own script.

But considers, a representative statement will be difficult to reach. You can only complicate the multiple voting, but you can not prevent them..
QuoteBig C., thanks for pointing me to this bug.
with pleasure happen...  :)

Big C.
Title: Space Invaders Tutorial
Post by: thaaks on April 25, 2006, 05:43:43 PM
The problem with my web hoster ("1 und 1") is that I'm not allowed to write my own scripts...
I can call existing scripts (like their web counter or voting script) or include JavaScript in my web page code but that's pretty much it.

I could upgrade my hosting package but that would be 3 Euros a month on top just to get some more web space, one MySQL DB and PHP scripting...that would make 7 Euros a month and 84 Euros (around 90 US-$) a year for hosting. Hmpf.

I think I'll just wait a while. And if the visitor counter reaches 1000 and I have more than one game and a half finished tutorial I will think about it again :D

Or does anyone have experience with free remote web polls (which can be found here for example:Remote hosted voting scripts (http://www.scripts.com/remotely-hosted-scripts/poll-and-voting-scripts/)) or should I just bite the bullet and upgrade my hosting package?

Thanks for your suggestions,
Tommy
Title: Space Invaders Tutorial
Post by: thaaks on May 02, 2006, 03:40:00 PM
Okay, the tutorial is updated a little bit.
I added alien shooting and started collision detection. The setup is in and shows the three most used kinds of collision areas:
- circle collison area for the player ship,
- rectangle collision area for the aliens,
- shape collision area for the bullets.

Missing is the real collision detection code - that's coming next. Then I'll add some finishing touches (score, hiscore, next level when all aliens are killed, increasing difficulty per level).
These are mainly a few added lines and then I declare the first part of the tutorial finished.

Hope to get there real soon  :D

Have a read over here (http://www.haaks.net/spaceinvaders1/index.html).

Cheers,
Tommy
Title: Space Invaders Tutorial
Post by: Big C. on May 02, 2006, 04:01:53 PM
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.
Title: Space Invaders Tutorial
Post by: thaaks on May 03, 2006, 04:36:58 PM
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 (http://www.haaks.net/spaceinvaders1/index.html) 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
Title: Space Invaders Tutorial
Post by: stef on June 21, 2006, 01:14:48 PM
Hi Thaaks/Tommy!

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


Greetings
stef
Title: Space Invaders Tutorial
Post by: thaaks on June 21, 2006, 02:26:22 PM
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
Title: Re: Space Invaders Tutorial
Post by: kevin on August 01, 2007, 03:42:17 PM
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.


Title: Re: Space Invaders Tutorial
Post by: edwinbmiller on January 21, 2008, 07:43:59 AM
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.

Title: Re: Space Invaders Tutorial
Post by: kevin on January 21, 2008, 07:53:14 AM
 PB1.63 and above have native linked LIST support.
Title: Re: Space Invaders Tutorial
Post by: thaaks on January 29, 2008, 03:02:06 PM
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
Title: Re: Space Invaders Tutorial
Post by: Big C. on January 29, 2008, 05:11:30 PM
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 (http://www.underwaredesign.com/forums/index.php?topic=338.msg14180#msg14180) or see here (http://www.underwaredesign.com/forums/index.php?topic=338.msg15170#msg15170)

Big C.
Title: Re: Space Invaders Tutorial
Post by: kevin on January 30, 2008, 12:08:08 AM
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..

[pbcode]

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

[/pbcode]

  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 (http://www.underwaredesign.com/forums/index.php?topic=2052.0)    



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.  
Title: Re: Space Invaders Tutorial
Post by: thaaks on January 30, 2008, 02:17:41 AM
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


Title: Re: Space Invaders Tutorial
Post by: thaaks on January 30, 2008, 04:33:13 PM
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
Title: Re: Space Invaders Tutorial
Post by: thaaks on February 10, 2008, 05:19:01 PM
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 (http://www.haaks.net/spaceinvaders1/index.html)!

Feedback appreciated!

Good night,
Tommy
Title: Re: Space Invaders Tutorial
Post by: Big C. on February 11, 2008, 07:02:33 AM
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]
Title: Re: Space Invaders Tutorial
Post by: thaaks on February 11, 2008, 07:45:28 AM
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,
Tommy
Title: Re: Space Invaders Tutorial
Post by: Big C. on February 11, 2008, 08:54:22 AM
sry tommy... one more pic... I got this after i was killed by the aliens and i restart the game with space... this pic is repeatable...

but i've no hint for u why  ???

Big C.

[attachment deleted by admin]
Title: Re: Space Invaders Tutorial
Post by: thaaks on February 11, 2008, 10:24:29 AM
Damned! That was the bug I thought that was fixed...

Sometimes it happens that although there is still one alien left the aliencounter in UpdateAliens() finds zero aliens and so a bunch of new aliens is created for the next level. And this single alien somehow survives...

I even delete all aliens in a PSub iterating over the Aliens() list when I start the next level...

Hmm, beats me.

Will investigate...
Title: Re: Space Invaders Tutorial
Post by: thaaks on February 12, 2008, 04:43:09 AM
Still searching for the bug.
It does not happen for bullets so I assume it's somewhere in my alien code.

If I shoot the "last but one" alien my UpdateAliens() method is convinced that there is no alien left anymore...
so either my UpdateAliens() code does something bad or the way I destroy dead aliens.

I will give it another try tonight to find the buggy code...
Title: Re: Space Invaders Tutorial
Post by: kevin on February 13, 2008, 07:56:16 PM
 You have to be careful with flushing a list within a For/Next, as it's possible for the current link to be stepped over. So a while structure is probably a better solution for fall back compatibly (PB1.59)


function DestroyAllAliens()
ResetList Aliens()
While EndofList(aliens())=false
    DestroyAlien(Aliens())
                    StepList Aliens()
endwhile
EndFunction

Title: Re: Space Invaders Tutorial
Post by: thaaks on February 14, 2008, 04:36:53 AM
Is this a general recommendation?
I would change the sample code and the tutorial to use the while loop and give some explanation.

But I got the impression that the "For Each Next" loop is the proper way to deal with native type linked lists. And you do use and recommend it in your linked list/sprite hit game framework too (http://www.underwaredesign.com/forums/index.php?topic=2259.0 (http://www.underwaredesign.com/forums/index.php?topic=2259.0))...

And of course it's much simpler and more user friendly than the manual link list control...

So: What to use? "For Each Next" or "While with manual list control" as mentioned in your other thread http://www.underwaredesign.com/forums/index.php?topic=2273.0 (http://www.underwaredesign.com/forums/index.php?topic=2273.0)?

Currently the tutorial assumes a PB version 1.63...

Cheers,
Tommy
Title: Re: Space Invaders Tutorial
Post by: kevin on February 14, 2008, 07:31:35 PM
     
QuoteBut I got the impression that the "For Each Next" loop is the proper way to deal with native type linked lists. And you do use and recommend it in your linked list/sprite hit game framework too (http://www.underwaredesign.com/forums/index.php?topic=2259.0)...

        That example was merely to demonstrate that you don't need to search for sprites upon collisions, you can use a reverse look ups.     In  terms of maintaining a list,  If you look around the forums you'll see there's any number of ways to creating them.   From Cell links, UDT pointers, etc etc.   Take your pick.         

        The ForEach/Next behavior is only noticeable in your example because of the how the program is structured.   But that I mean, the code relies upon the all objects being reclaimed within the DeleteAllAliens(), DeleteAllBullets().    Those functions could just as easily flip the state of the objects (to DEAD and release the sprite) and allow them to be freed during the next frames of the games refresh (since they'll be at the end of the list).

         Or it could collect garage during main.  Which removes the potential step over problem from the update functions.   

         
             Repeat
                     UpdateAliens()
                     UpdateBullets()
                     UpdatePlayer()             
                     RenderScene()
                     CollectGarbage()
             until GameState=GameOver
         
   

         or...or.... etc

         It doesn't fuss me what approach is used really.  As long as i don't have to give user support for it ! :)


       
QuoteCurrently the tutorial assumes a PB version 1.63...

          Why ? - There are sites still offering PB1.62 demo. 
Title: Re: Space Invaders Tutorial
Post by: thaaks on February 15, 2008, 04:22:28 AM
Quote from: kevin on February 14, 2008, 07:31:35 PM
         Or it could collect garage during main.  Which removes the potential step over problem from the update functions.
         
             Repeat
                     UpdateAliens()
                     UpdateBullets()
                     UpdatePlayer()             
                     RenderScene()
                     CollectGarbage()
             until GameState=GameOver
         
   
I like that idea and will work that approach into the tutorial and the source code.

Quote
          Why ? - There are sites still offering PB1.62 demo. 

Simply because you mentioned here (http://www.underwaredesign.com/forums/index.php?topic=1275.msg15163#msg15163) that native link lists are available in version 1.63 and above  ::)

If they are already working for 1.62 then I'm fine and change the code accordingly.
Title: Re: Space Invaders Tutorial
Post by: kevin on February 15, 2008, 10:35:41 PM

    For clarification sake,  Lists were added in the 1.59 -> 1.60 update.    I don't recall if the implementation changed since then, apart from the 1.63t2 revision the other day. 

   While the tutorials runs as is under 1.63t2,  for compatibility sake (since there's lots of editions of 1.63 even)  it'd be better to structure the code in such a way that it'll operate correctly both from the latest release and older editions.   Since i'd assume that all version of PB from 1.59 to 1.63t include skipping behavior from within a ForEach/next structure.

    Other things you could look at are using inheritance for the object types.    This way you could rescue the size of the code and even remove some list bound functions.

    Also  I notice that scene is rendering through a camera, but the Z depths appear to be same for all objects in the scene ?   To correctly bias the draw order, the objects need to be on different z levels.   If there all at the same Z then it's almost pot luck if they're in order.

Title: Re: Space Invaders Tutorial
Post by: kevin on February 17, 2008, 09:30:05 AM

Here's a rehash of the code
Title: Re: Space Invaders Tutorial
Post by: thaaks on February 17, 2008, 10:49:03 AM
Thanks  ;)

Looks pretty similar to what I have currently as a WIP. But you did some more code refactorings (MakeSprite() for example and the Hide stuff) which I like and will put into the tutorial if you don't mind.

And of course calling the CollectGarbage() every frame simplifies the list handling a lot.

Thanks for your help and efforts!

Cheers,
Tommy
Title: Re: Space Invaders Tutorial
Post by: kevin on February 17, 2008, 11:03:41 AM

   The removing objects outside of the updating  post displaying, ensures the visual logic errors don't occur. While not a big issue in a frame Dependant examples like this, it's critical in games where  logic and rendering aren't interleaved.  (ie time based)
Title: Space Invaders Tutorial update is finished!
Post by: thaaks on February 19, 2008, 03:03:10 PM
Okay, I declare the tutorial finished  ;D

Here's the direct link: Space Invaders Tutorial (http://www.haaks.net/spaceinvaders1/index.html)

If you detect bugs (I am sure Big C. will dig through the code until he finds something  ;)) please tell me so I can fix it.

Have fun with it,

Tommy
Title: Re: Space Invaders Tutorial
Post by: ATLUS on May 20, 2008, 10:57:11 AM
Big Thx for tutorial!!!!!!!!!!!!
Title: Re: Space Invaders Tutorial
Post by: thaaks on May 20, 2008, 02:38:36 PM
You're welcome  ;D