BASIC

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

Pages: 1 ... 262 263 [264]
3946
This function allows you to load in a single image/sprite that contains a multiple of same size images (tiles etc.) and then spits out sprites ready to be used - this negates the need for lots and lots of similar image files within a folder and makes everything tidier and easier.

This code is public domain and may be used freely, although a thankyou would be nice.

USAGE -

AnimImage( graphic file name$, the required sprite start#, number of tiles/images, tile width, tile height]

Code: GLBasic [Select]
// Get tiles
FUNCTION AnimImage: name$, start_num, num_sprites, width, height

LOADSPRITE name$,1000

DRAWRECT 0,0,640,480,RGB(255,0,128)

DRAWSPRITE 1000,0,0

GETSPRITESIZE 1000,sizex,sizey

n=start_num
x=0
y=0

WHILE n<start_num+num_sprites

GRABSPRITE n,x,y,width,height

n=n+1

x=x+width

IF x>sizex-width
 x=0
 y=y+height
ENDIF

IF KEY(1) THEN RETURN

WEND

ENDFUNCTION

3947
Nice :)

3948
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-30 »
It doesn't matter how you get things to work, as long as they do! :D

I don't suppose for a second that my version is cleaner or greener than anyone elses, but it's mine and it works, so the job's a good one :)

3949
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-30 »
I originally tried a GrabSprite routine, but the masking didn't appear to work properly - neither of the mask colours came through. Admittedly I didn't spend a lot of time playing with it - I've been busy with other routines and doing the level editor and getting the game working properly :)

What I actually meant (about LoadSpriteAnim) though is that it should be an automated and included command and not just a function.

[EDIT] Sorted :D

Here's my Bitmap Font function (for fonts 6x9)

Code: GLBasic [Select]
GLOBAL width=6, height=9

LOADSPRITE "gfx/font.png",1000

DRAWRECT 0,0,640,480,RGB(255,0,128)

DRAWSPRITE 1000,0,0

n=1
x=0
y=0

WHILE n<97

GRABSPRITE n,x,y,width,height

n=n+1

x=x+width

IF x>186
 x=0
 y=y+9
ENDIF

WEND


WHILE TRUE

DRAWRECT 0,0,640,480,RGB(255,255,255)

txt(100,100,"Ian Price was here!")

SHOWSCREEN

WEND


// Display bitmap Text
FUNCTION txt: x, y, ss$
 xpos=0

  FOR i=0 TO LEN(ss$)-1
   cr=(ASC(MID$(ss$,i,1))-31)

    DRAWSPRITE cr,x+(xpos*width),y

    // Kern text
    IF cr=42 OR cr=74 THEN x=x-4
    IF cr=9 OR cr=10 OR cr=77 THEN x=x-3
    IF cr=1 OR cr=18 OR cr=75 THEN x=x-2
    IF cr=85 THEN x=x-1

     xpos=xpos+1
  NEXT
ENDFUNCTION
Values relate to sprite image number of individual letters, with a full 96 character font (as seen below).



**** Incidently, this could be used for animated sprites too :D

3950
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-30 »
I've got a bitmap font running too - uses pretty much the same code I used in my Blitz (inc Max) and PlayBasic games. The basic core of the language is very similar to pretty much all Basic languages really, only the names of the commands have been changed to protect the innocent :P

I just wish there was a proper LoadSpriteAnim command that allowed easy and quick loading of tilemaps/multiple images to put into sprites. :( Gernot...

3951
Code Snippets / Random Maze Generator Function
« on: 2007-Dec-28 »
:)

3952
Code Snippets / Tilemap Based Movement Engine
« on: 2007-Dec-28 »
Nice one PeJay :)

3953
GLBasic - en / Rand(Min,Max)??
« on: 2007-Dec-24 »
Quote from: Schranz0r
Hmm Gernot i think RND(0,9) for example, could be better then RND(9).
So you can do RND(5,10),  5 MIN 10 MAX....
Should be easier to use...

@ iprice

you can use that:

negativ and positiv values!

ex.: RAND(-10,10) or RAND(10,20) or something like ;)

Code: GLBasic [Select]
FUNCTION RAND: minimum, maximum

        RETURN minimum + RND(-minimum + maximum)
       
ENDFUNCTION
That's very similar to the function I came up with :)

3954
GLBasic - en / Rand(Min,Max)??
« on: 2007-Dec-24 »
I know that GLBasic supports random numbers in the form of RND(Max), but this always returns a value between 0 and the Max value.

Is there a command like RAND(Min, Max), where the command returns a value between (and inclusive of) the two values?

I have only skimmed through the Index, so maybe I missed a similar command. Does it exist, and if not, can it be added?

[EDIT] BTW I created a function to do this, but a built in command could be useful to newcomers.

Pages: 1 ... 262 263 [264]