Main Menu

Space Invaders Tutorial

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

Previous topic - Next topic

thaaks

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

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


kevin

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.

thaaks

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  :)

kevin

#3
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

thaaks

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

Big C.

#5
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

kevin

#6

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.

thaaks

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

thaaks

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 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

Big C.

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?)

thaaks

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

thaaks

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

Big C.

I think, there are sufficient offers in the Internet...

PHP and MySQL here for example...

or one version for Perl 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.

thaaks

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) or should I just bite the bullet and upgrade my hosting package?

Thanks for your suggestions,
Tommy

thaaks

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.

Cheers,
Tommy