Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - PeeJay

Pages: 1 ... 14 15 [16]
226
When passing values to functions, is it possible to have default values, Gernot?

To give a simple example, currently we have to use:

Code: (glbasic) [Select]
DoText(50,50,"No Default Text Allowed","","","","","")
DoText(100,100,"This is ","some text ","to draw.","","","")
DoText(100,150,"This ","is some more.","","","","")
SHOWSCREEN
KEYWAIT

FUNCTION DoText: x,y,a$,b$,c$,d$,e$,f$
a$=a$+b$+c$+d$+e$+f$
PRINT a$,x,y
ENDFUNCTION
but if you replaced that with a system that allowed default values, it becomes:

Code: (glbasic) [Select]
DoText()
DoText(100,100,"This is ","some text ","to draw.")
DoText(100,150,"This ","is some more.")
SHOWSCREEN
KEYWAIT

FUNCTION DoText: x=50,y=50,a$="Default Text",b$="",c$="",d$="",e$="",f$=""
a$=a$+b$+c$+d$+e$+f$
PRINT a$,x,y
ENDFUNCTION
where b$,c$,d$,e$,f$ would automatically by null unless a string was passed to them.
a$ would be "Default Text" unless a string was passed to it.
x and y would be 50 unless values were passed to them.

227
GLBasic - en / Suggestion - more flexible AND
« on: 2008-Jan-02 »
Ah, okay - yeah, that does work - it's only strings that can't be ANDed - you're right

I tried with strings the first time, it didn't compile, so I assumed that the whole "ANDing" bit was non functional. As they say, assumption in the mother of all f*** ups :)

228
GLBasic - en / Suggestion - more flexible AND
« on: 2008-Jan-02 »
Kind of - let me give you a game like example.

Let's say we have a player as position px,py.

He has screen boundaries of minpx, maxpx, minpy, maxpy, and moves 1 pixel at a time.

Control is with the cursor keys.

So this code:

Code: (glbasic) [Select]
px=px+(1 AND KEY(205) AND pxminpx)
py=py+(1 AND KEY(208) AND pyminpy)
would check keypresses, ensure the player is sticking within the boundaries, and update his position, all in 2 lines of code. Hopefully that will give you a better idea of how it can be beneficial?

As I said, it's no biggie - but I do remember back to the days of coding with 1K to play with .... :)

229
GLBasic - en / Suggestion - more flexible AND
« on: 2008-Jan-02 »
Yes and no. If you take my first example, currently you would have to code:

Code: (glbasic) [Select]
x=INTEGER(RND(50))

IF x<25 THEN PRINT 100,100,"Number is less than 25"
IF x=25 THEN PRINT 100,100,"Number is equal to 25"
IF x>25 THEN PRINT 100,100,"Number is more than 25"
but using the more flexible AND, you are can neaten things up to just one line of logical arguments. It becomes less like a boolean operation, and more like a subtext of the IF.

Like I said, it is only a minor suggestion, and only makes for neater coding

230
GLBasic - en / Suggestion - more flexible AND
« on: 2008-Jan-01 »
A minor suggestion, but one that has proved useful in the past - to be able to use AND to do actions depending on whether the operand is true - see example code:

Code: (glbasic) [Select]
x=INTEGER(RND(50))

PRINT 100,100,"Number is "+("less than 25" AND x<25)+("equal to 25" AND x=25)+("more than 25" AND x>25
or

Code: (glbasic) [Select]
x=0+(10 AND something)+(20 AND somethingelse)+(50 AND anotherthing)Just an idea for more efficient coding .....

231
I'm with you on that, Ian. Schranz0r - let me explain - both Ian and myself are both new to GL, and are learning as we go along - but you will have also noticed that we are more than willing to share our code. It is little benefit to either of us to have out code criticised, with no helpful alternatives suggested. I hope you can appreciate this, and perhaps suggest a better method?

232
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-30 »
I couldn't agree more - yours does something mine doesn't - kerning (which is pretty nifty, I must admit!) At some point I might revisit my system, and when I really fancy a headache, tackle word wrap with kerning (as if this game isn't giving me enough headaches :D)

233
This is the routine I am using to draw bitmapped fonts onto the screen. I have also added a function to enable word wrap.

Since the font is a single image, it also demonstrates a very simple way of using ImageStrips.

Code: (glbasic) [Select]
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
//                                                                      //
// Project: Bitmapped Font Printing for GLBasic                         //
//          Example of Imagestrip Usage                                 //
//          Word Wrap Function                                          //
//                                                                      //
// (C)opyright PeeJay December 30th 2007      www.peejays-remakes.co.uk //
//                                                                      //
// Code is free to use for FREEWARE projects only, though credit would  //
// still be welcomed if you decide to use it                            //
//                                                                      //
// Please contact me through my website for conditions on using this    //
// code in shareware, commercial, or other revenue generating projects  //
//                                                                      //
// This code shows an example of how you can use any bitmapped font     //
// without the limitations of the standard GL Basic routines. The font  //
// is stored in an imagestrip. There is also a simple function to allow //
// for a word wrap facility.                                            //
//                                                                      //
// Functions are currently coded for a screen width of 640, and for a   //
// font with individual character size 24x24 (all easily changed!)      //
//                                                                      //
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//

SETSCREEN 640,480,0 // 640x480 Window
LIMITFPS 60 // at 60 frames per second

LOADSPRITE "glfont.png",0

DrawText("PRINTING EXAMPLE",-1,20) // -1 = centralised

DrawText("LEFT",10,80)
DrawText("RIGHT",510,80)

WrapText("THIS TEXT IS AN EXAMPLE OF THE WORD WRAP FUNCTION IN ACTION",104,200,18)

SHOWSCREEN
KEYWAIT
END


FUNCTION DrawText: pjtxt$,pjtx,pjty

// Usage - text$, x co-ordinate (-1 for centralised), y co-ordinate

IF pjtx=-1 THEN pjtx=(640-LEN(pjtxt$)*24)/2
LOCAL pjloop,pjcr
FOR pjloop=0 TO LEN(pjtxt$)-1
pjcr=ASC(MID$(pjtxt$,pjloop,1))-32
VIEWPORT pjtx,pjty,24,24
DRAWSPRITE 0,0-(pjcr*24),0
VIEWPORT 0,0,0,0
pjtx=pjtx+24
NEXT

ENDFUNCTION

FUNCTION WrapText: pjw$,pjwx,pjwy,pjmax

// Usage - text$, x co-ordinate, y co-ordinate, max chars per line

LOCAL pjloop,pjtemp$

WHILE pjw$<>""
IF LEN(pjw$)<(pjmax+1)
DrawText(pjw$,pjwx,pjwy)
pjw$=""
ELSE
pjloop=pjmax
pjtemp$=pjw$
WHILE MID$(pjw$,pjloop,1)<>" "
pjloop=pjloop-1
WEND
DrawText(MID$(pjw$,0,pjloop),pjwx,pjwy)
pjwy=pjwy+24
pjw$=MID$(pjtemp$,pjloop+1,LEN(pjtemp$)-pjloop)
ENDIF
WEND

ENDFUNCTION
You'll also need the font, which is here:

http://www.peejays-remakes.co.uk/gifs/glfont.png

At the moment I have only done the uppercase letters (but only because I couldn't be bothered to add lower case ones to the image!)

Hopefully someone will find it useful!

234
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-30 »
Ooooh, that works - mind you, I did it a totally different way, as I couldn't be bothered with all that GrabSprite malarky :) Now posting my code (and I've added a wordwrap facility too - pretty handy for the game I'm working on!)

235
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-30 »
There is an easy and quick way, Ian - wait until I publish my bitmapped font routine (where the whole font is in one graphic) and you'll see how easily it can be done ;)

236
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-30 »
I've been coding for a while now, Gernot! ;)

I'm writing loads more useful routines while coding for the compo - I'll post some more snippets soon, including a function to draw bitmapped fonts (it's more useful than it sounds!)

237
Code Snippets / Random Maze Generator Function
« on: 2007-Dec-30 »
Great - I'm glad someone has made use of it - I have used it twice myself for my remakes of Maziacs and Fred - buy you can have too much of mazes! :)

238
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-27 »
Another "useful" chunk of code from my BlitzBasic days - this demonstrates how to move a player around a scrolling tilemap, and how to move the player to the edge of the tilemap at the periphery.

Code: (glbasic) [Select]
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
//                                                                      //
// Project: Tile Based Movement Engine Example for GLBasic              //
//                                                                      //
// (C)opyright PeeJay December 13th 2007      www.peejays-remakes.co.uk //
//                                                                      //
// Code is free to use for FREEWARE projects only, though credit would  //
// still be welcomed if you decide to use it                            //
//                                                                      //
// Please contact me through my website for conditions on using this    //
// code in shareware, commercial, or other revenue generating projects  //
//                                                                      //
// This code shows an example of how a player can move around a         //
// scrolling tilemap, and how the player will move towards the edges of //
// the screen when approaching the edge of the map                      //
//                                                                      //
// Use keyboard cursor keys to move - Esc quits                         //
//                                                                      //
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//

SETSCREEN 640,480,0 // 640x480 Window
LIMITFPS 60 // at 60 frames per second

GLOBAL mapx,mapy
GLOBAL px,py
GLOBAL xdir,ydir
GLOBAL tilesize=32
GLOBAL speed=4

DIM level[50][50]

LOCAL loop

FOR loop=0 TO 49
level[0][loop]=1
level[49][loop]=1
level[loop][0]=1
level[loop][49]=1
level[RND(49)][RND(49)]=1
NEXT

mapx=10
mapy=10
px=mapx*tilesize
py=mapy*tilesize

WHILE TRUE

FOR loop=1 TO speed

CheckPlayer()

NEXT

DrawScreen()

WEND

END


FUNCTION CheckPlayer:

LOCAL xdir,ydir

xdir=KEY(205)-KEY(203)
ydir=KEY(208)-KEY(200)

IF WallDetect(px+xdir,py+ydir)=0
px=px+xdir
py=py+ydir
mapx=INTEGER(px/tilesize)
mapy=INTEGER(py/tilesize)
ENDIF

ENDFUNCTION

FUNCTION WallDetect: x,y

LOCAL mx,my,nomove

mx=INTEGER(x/tilesize)
my=INTEGER(y/tilesize)
nomove=0

IF level[mx][my]=1 THEN nomove=1

IF MOD(x,tilesize)>0
IF level[mx+1][my]=1 THEN nomove=1
ENDIF

IF MOD(y,tilesize)>0
IF level[mx][my+1]=1 THEN nomove=1
IF MOD(x,tilesize)>0
IF level[mx+1][my+1]=1 THEN nomove=1
ENDIF
ENDIF

RETURN nomove

ENDFUNCTION

FUNCTION DrawScreen:

startx=mapx-12
endx=startx+25

IF startx<0
startx=0
endx=25
ENDIF

IF endx>49
startx=24
endx=49
ENDIF

starty=mapy-12
endy=starty+25

IF starty<0
starty=0
endy=25
ENDIF

IF endy>49
starty=24
endy=49
ENDIF

IF px<304
scrx=px
ELSEIF px>((49*tilesize)-304)
scrx=304+304-(49*tilesize-px)
ELSE
scrx=304
ENDIF

IF py<224
scry=py
ELSEIF py>((49*tilesize)-224)
scry=224+224-(49*tilesize-py)
ELSE
scry=224
ENDIF

FOR loopy=starty TO endy
FOR loopx=startx TO endx
rectx=scrx-px+(loopx*tilesize)
recty=scry-py+(loopy*tilesize)
IF level[loopx][loopy]=0
DRAWRECT rectx,recty,tilesize,tilesize,RGB(0,0,64)
DRAWRECT rectx+2,recty+2,tilesize-4,tilesize-4,RGB(0,0,128)
ENDIF
IF level[loopx][loopy]=1
DRAWRECT rectx,recty,tilesize,tilesize,RGB(128,0,0)
ENDIF
NEXT
NEXT

DRAWRECT scrx,scry,tilesize,tilesize,RGB(0,128,0)

SHOWSCREEN

ENDFUNCTION

239
Code Snippets / Random Maze Generator Function
« on: 2007-Dec-27 »
This function will produce a random maze of practically any size.

EDIT: Code removed - see bugfix below

240
GLBasic - en / Request - DELAY (millisecs)
« on: 2007-Dec-27 »
Nice simple command to pause program execution for a set length of time.

While I have already written a function to do this:

Code: (glbasic) [Select]
FUNCTION Pause: ms

LOCAL time1,time2
time1=GETTIMERALL()

WHILE TRUE
time2=GETTIMERALL()
IF time2>time1+ms THEN BREAK
WEND

ENDFUNCTION
it would be nice to have it as part of the language.

Pages: 1 ... 14 15 [16]