Menu

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.

Show posts Menu

Topics - PeeJay

#21
This one should be easy - to be able to have Type elements separated by commas, rather than each on a new line, thus:
Code (glbasic) Select
TYPE enemy
sort,x,y,minx,maxx,miny,maxy,speed
ENDTYPE
#22
Coming from Blitz, I got very used to not having to remember long strings of numbers as to where I had loaded a particular sprite or sound effect, as they were assigned handles instead. As an example, we may have had something like:-
Code (glbasic) Select
Global piano
piano=LoadImage("piano.png")
DrawImage piano,0,0
Obviously, adding this as it stands would mean massive rewrites of code, and upsetting people who are used to the current method, so could I suggest a compromise? What about adding a HANDLE command? Perhaps GL could then just allocate numbers to all the handles and substitute at compile time? This may end something like this:-
Code (glbasic) Select
HANDLE piano
LOADSPRITE "piano.png",piano
DRAWSPRITE piano,0,0
Any thoughts?
#23
Okay, I've been having a play today, and have written a set of functions for manipulating bitmapped fonts, as follows:-

Draw Text (with or without kerning)
Centralise Text (with or without kerning)
Right Justify Text (with or without kerning)

Word Wrap Text (with or without kerning)
Word Wrap and Centralise Text (with or without kerning)
Word Wrap and Right Justify Text (with or without kerning)

Full Justification of Text (kerned only - without kerning would be too ugly!)

All of these can show text at any position on the screen, use any point to justify to, and use any width for word wrap.

As it's a bit big (since I have split everything into separate functions so you can pick and choose what you want to use) I have upped it to zshare - http://www.zshare.net/download/7127057ae41080/ - complete with a load of demo code and a font so you can see it in action.
#24
Not that anyone uses midi any more, but if you PLAYMUSIC "music.mid", you'll get a mouse pointer (in the form of the hourglass) irrespective of what you set SYSTEMPOINTER to.
#25
If you change options in the Editor Oufit, only the current window is updated (if you have more than one gbas file in your project)
#26
I don't know how feasible this is, but it would be handy if you could add an icon that the compiled code would use, rather than the default icon (saves messing around with ResourceHacker!)
#27
Just playing with the multi platform stuff, and while my code will compile to linux, WinCE, GP, when trying to compile to OS/x, I get this:-

Code (glbasic) Select
_______________________________________
*** Configuration: OS-X_UNI ***
precompiling:
GPC - GLBasic Precompiler V.2007.363 - 3D, NET
Wordcount:5136 commands

compile+link:
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Time: 12.4 sec
Build: 0 succeeded
*** 1 FAILED ***
#28
I know the sound / music side is giving you nightmares at the moment, Gernot, but is there any chance of adding this?
#29
Is it possible to add scrolling relative to the mouse position - let me explain ....

I use the middle wheel to scroll through my code. Would it be possible to scroll through the editor code if the mouse is over the editor section, and scroll through the jumps list if the mouse is over the jumps section?
#30
I manage to get around 2 frames per second here if I include USEASBMP in my code. I know my video card is hardly earth shattering (a NVidia FX5500) but that can't be right, surely?
#31
to join MID$ - these commands take the rightmost (or leftmost) characters from a string - very useful for leading zeroes - for example

PRINT "Score: "+RIGHT$("000000"+score,6)

would take the last 6 characters of the string, giving:

Score: 000007
Score: 000042
Score: 012345
#32
I'm sure this is just me being stupid, but I have a problem with the following code that I can't figure out.

It is code to do a collision detection between shots fired and enemies

Code (glbasic) Select
FOREACH en IN enemies[]
LOCAL enemyhit=FALSE
FOREACH sh IN shots[]
IF SPRCOLL (2,sh.x,sh.y,3,en.x,en.y)
DELETE sh
enemyhit=TRUE
ENDIF
NEXT
IF enemyhit=TRUE
DELETE en
ENDIF
NEXT
When run, the shots are being deleted okay, but the enemies are not. Anyone know why?!?
#33
Nothing earth shattering here, but just a little side project I have started working on, and this code might be useful to someone ..... feel free to use and abuse :)

Code (glbasic) Select
SETSCREEN 640,480,1
LIMITFPS 60

TYPE star
x
y
z
ENDTYPE
GLOBAL stars[] AS star

SetupStars()

WHILE TRUE

UpdateStars()
DrawStars()

WEND

END

FUNCTION SetupStars:

LOCAL loop,loop2,num
FOR loop=1 TO 4
IF loop=1 THEN num=6
IF loop=2 THEN num=15
IF loop=3 THEN num=40
IF loop=4 THEN num=100
FOR loop2=1 TO num
LOCAL st AS star
st.x=RND(640)
st.y=RND(480)
st.z=loop
DIMPUSH stars[],st
NEXT
NEXT

ENDFUNCTION

FUNCTION UpdateStars:

FOREACH st IN stars[]
st.y=st.y+(1/st.z)
IF st.y>480
st.x=RND(640)
st.y=st.y-481
ENDIF
NEXT

ENDFUNCTION

FUNCTION DrawStars:

BLACKSCREEN
FOREACH st IN stars[]
LOCAL col=255-(st.z*50)
SETPIXEL st.x,st.y,RGB(col,col,col)
NEXT
SHOWSCREEN

ENDFUNCTION
#34
Is there are a way to delete a file previously created with PutFile? Or rename it?

The project I am working on produces a save game state part way through, but what I hope to do is to do a simple check to test the authenticity of this file (already coded), bring up a warning message if it fails the check (coded), but then either deletes the file, or renames it, so it doesn't go through the file checking procedure again. Does that make sense?

Thanks in advance.
#35
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.
#36
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 .....
#37
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!
#38
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
#39
This function will produce a random maze of practically any size.

EDIT: Code removed - see bugfix below
#40
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.