GLBasic forum

Main forum => Announcements => Topic started by: Kitty Hello on 2007-Apr-05

Title: Super-TYPEs
Post by: Kitty Hello on 2007-Apr-05
With the next update (soon, soon!) you will be able to write a shooting spaceship as easy as this:

Code (glbasic) Select
// --------------------------------- //
// Project: Blaster
// Start: Thursday, April 05, 2007
// IDE Version: 4.145

// A SHOT type. It's just the position in this sample
TYPE SHOT
x
y
ENDTYPE

// a SHOT for adding new ones later
LOCAL newshot AS SHOT

// The SHOTs array. Here the shots get inserted
LOCAL shots[] AS SHOT

playerx = 320
WHILE TRUE
// Player Movement
INC playerx, KEY(205)-KEY(203)
// Limit to borders
playerx=MAX(MIN(playerx,600),40)

// Space bar and some time since last shot?
IF KEY(57) AND delay // Prepare a shot
newshot.x = playerx
newshot.y = 400
// And stuff into the array
DIMPUSH shots[], newshot
// Get a time when the next shot can be fired
delay = GETTIMERALL() + 100
ENDIF

// Loop through all shots
FOREACH pop IN shots[]
// Move shot up
DEC pop.y, 1
// If shot reaches upper screen, remove it and continue
IF pop.y<0 THEN DELETE pop

// Draw the shot
PRINT "|", pop.x, pop.y
NEXT

// Draw "player"
PRINT "A", playerx, 400

// some status
PRINT "Shots: "+BOUNDS(shots[], 0), 0,0
SHOWSCREEN
WEND
Title: Super-TYPEs
Post by: Lazarus on 2007-Apr-05
Sweet. 8)
Title: Super-TYPEs
Post by: bigsofty on 2007-Apr-05
"FOREACH"... yay... no more BOUNDS in my FOR loops ;)
"DIMPUSH"... array as a stack?
"DELETE" ... pop off of stack?


Looks very cool, types are turning out to be REALLY powerful in GLBasic!
Title: Super-TYPEs
Post by: bigsofty on 2007-Apr-09
These are great... cut my code in half and its now much more readable! :)