GLBasic forum

Other languages => GLBasic - de => Topic started by: Worebu on 2015-Feb-08

Title: Wieder mal Types
Post by: Worebu on 2015-Feb-08
Hallo Leute,
wollte mir mal Types ein wenig näherbringen und habe dazu ein kleines Projekt gefunden. Allerdings bekomme ich es nicht zum laufen
um mit den Werten zu spielen und mir die Auswirkung anzusschauen. Kann mir jemand helfen un dsagen wo der Fehler liegt?.

Das Projekt ist das hier: http://www.commodore-welt.de/tutorial/tutorial.pdf .

Dank im voraus.

Title: Re: Wieder mal Types
Post by: Ian Price on 2015-Feb-08
Here's an example that I've just put together.

I've commented in the code what each part does. Hopefully by changing values you can understand a bit more.

Title: Re: Wieder mal Types
Post by: Marmor on 2015-Feb-08
great ian , this will help a lot of user
Title: Re: Wieder mal Types
Post by: Worebu on 2015-Feb-08
Thanks very much Ian. That is what i need.
Title: Re: Wieder mal Types
Post by: Schranz0r on 2015-Feb-08
Schön in einen Tutorial genannt/zitiert zu werden :)
Title: Re: Wieder mal Types
Post by: Worebu on 2015-Feb-08
Apropros Tut, läufts ?
Title: Re: Wieder mal Types
Post by: Schranz0r on 2015-Feb-10
Ne aktuell andere Sachen um die Ohren.
Wenn du aber ein Problem hast, helfe ich natürlich gerne.
Title: Re: Wieder mal Types
Post by: Worebu on 2015-Feb-10
Schade das mit dem TUT, aber von deiner Hilfe werde ich gerne bei Zeiten Gebrauch machen.
Title: Re: Wieder mal Types
Post by: erico on 2015-Feb-12
Tried your shooter Ian!
Quite raiden!

I´m keeping it, I have been afraid of functions and types for quite a while.
Your example game is montruously clear to get to the point of how to use both.

Thanks!
Title: Re: Wieder mal Types
Post by: Ian Price on 2015-Feb-13
Cheers.

It's just a simple thing, but can hopefully lead to a better understanding and a cleaner method of working. Functions are just small portions of code that can do something, then hand back control to the main loop.

You could easily enhance that "game" by having the rocks move down the screen (at different speeds etc.) For that you could add a "speed" variable to the rock TYPE so that each rock moves at a constant but different speed, creating a type of parallax.

Eg

Code (glbasic) Select

TYPE Trock
x
y
speed
ENDTYPE


Then adding -

Code (glbasic) Select

FUNCTION create_rock:
...
...
r.speed=RND(3)+1
...
DIMPUSH ro[],r
ENDFUNCTION


and adding the y co-ordinate of each rock

Code (glbasic) Select

FUNCTION render_rock:
...
...
INC r.y, r.speed

// Respawn rock if it goes off the bottom of the screen
IF r.y>480
  create_rock()
DELETE r
ENDIF
...
...
ENDFUNCTION


You could build on those ideas to mkae the rocks bigger or smaller (add a "size" variable to the TYPE), add aliens, power-ups etc. Using the bullet/rock collision code you could make rocks collide with the ship etc. etc.

It's a small start that can lead to bigger and more exciting games.
Title: Re: Wieder mal Types
Post by: Worebu on 2015-Feb-13
Very cool.