• Print

Author Topic: UnseenGDK (Game Development Kit) For QB64  (Read 16988 times)

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
UnseenGDK (Game Development Kit) For QB64
« on: October 03, 2010, 06:45:45 PM »
Here's the very start of my UnseenGFX (will become) UnseenGameDevKit for QB64. Does not do a great deal yet, but with it you can create and position spheres of various sizes and colors. (CodeGuy wrote the sphere code) i edited it.

I have left a lot of rem lines in the code, so i wont go into detail here, but let me know what you think.

Can i do this without the CALL for each sub?

i.e CreateObjectSphere rather than CALL CreateObjectSphere

« Last Edit: December 28, 2010, 08:24:10 PM by unseenmachine »
UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #1 on: October 03, 2010, 06:48:45 PM »
WHAT code? ???
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #2 on: October 03, 2010, 07:06:57 PM »
oops!!LOL!

here it is, with MoveObject added now to.

Code: [Select]
'Unseen Grapics and Game Library for Qb64 - By John Onyon a.k.a Unseen Machine
'
'NOT ALL CODE BY MAIN AUTHOR - AUTHOR CREDITS IN RELEVANT FUNCTIONS
'
'All functions are free for public use as long as you give credit.

SCREEN _NEWIMAGE(400, 400, 32)

'Sprites/objects all have these settings, Put this code at the start of your program.
TYPE aSprite

  num AS INTEGER 'the sprite/object number
  SpriteType AS STRING * 8 'the type of sprite/object
  xsize AS INTEGER 'width of sprite
  ysize AS INTEGER 'height of sprite
  zsize AS INTEGER 'Depth of sprite used for collision checking
  image AS LONG 'the image of the sprite

  'These set centre of the object.
  xpos AS INTEGER 'sprite/object x postion
  ypos AS INTEGER 'sprite/object y position
  zpos AS INTEGER 'sprite/object z postiton

  'Color values for sprite
  r AS INTEGER 'sprite/object red value
  g AS INTEGER 'sprite/object green value
  b AS INTEGER 'sprite/object blue value
  a AS INTEGER 'sprite/object alpha value

END TYPE
DIM SHARED sprite(1 TO 1000) AS aSprite

'######################### MAIN PROGRAM MODULE #########################

'Create you game objects.
CALL CreateObjectSphere(1, 50, 0, 250, 0)
CALL PositionObject(1, 100, 100, 1)
CALL MoveObject(1, 10, 10, 0)
CALL PositionObject(1, sprite(1).xpos, sprite(1).ypos, 1)

'FUNCTION/SUB COMMANDS
'
'CreateObjectSphere (num%, xsize%, r%, g%, b%)'
'PositionObject (num%, xpos%,ypos%,scale%)
'MoveObject (num%,xdistance%,ydistance%,zdistance%)


'Put the relevant functions you want to call at the end of your program.
'########################################################################

SUB CreateObjectSphere (num%, xsize%, r%, g%, b%)

'CREDITS - Sphere code by CodeGuy - Edited for purpose by Unseen Machine

sprite(num%).num = num%
sprite(num%).image = _NEWIMAGE(xsize%, xsize%, 32)
_DONTBLEND sprite(num%).image
_DEST sprite(num%).image
FOR y = 0 TO (xsize% - 1)
  FOR x = 0 TO (xsize% - 1)
    alpha = SQR((x - (xsize% / 2)) ^ 2 + (y - (xsize% / 2)) ^ 2) / (xsize% / 2)
    IF alpha < 0 THEN alpha = 0
    alpha = (1 - alpha * alpha) 'parabolic curve
    PSET (x, y), _RGBA32(r%, g%, b%, alpha * 255)
  NEXT
NEXT
_BLEND sprite(num%).image
_DEST 0 'return to the screen

sprite(num%).xsize = xsize%
sprite(num%).ysize = xsize%
sprite(num%).zsize = xsize%

END SUB

'########################################################################

SUB PositionObject (num%, xpos%, ypos%, scale%)

_PUTIMAGE (xpos% - (scale% / 2), ypos% - (scale% / 2))-(xpos% + (sprite(num%).xsize + (scale% / 2)), ypos% + (sprite(num%).ysize% + (scale% / 2))), sprite(num%).image
sprite(num%).xpos = xpos%
sprite(num%).ypos = ypos%
sprite(num%).zpos = zpos%

END SUB

'########################################################################

SUB MoveObject (num%, xdistance%, ydistance%, zdistance%)

sprite(num%).xpos = sprite(num%).xpos + xdistance%
sprite(num%).ypos = sprite(num%).ypos + ydistance%
sprite(num%).zpos = sprite(num%).zpos + zdistance%

END SUB

'########################################################################
UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

DarthWho

  • Hero Member
  • *****
  • Posts: 3853
  • Timelord of the Sith
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #3 on: October 03, 2010, 07:51:41 PM »
give me a couple days and i will give you a sphere algorithm that can be more easily manipulated to produce more interesting shapes.
Rassilon: My lord Doctor; My lord Master; My lord DarthWho
The Doctor and the master at the same time :WHAT!?!?!

FastMath 1.1.0 released: http://dl.dropbox.com/u/12359848/fastmath.h

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #4 on: October 03, 2010, 08:22:46 PM »
I need a rotating cube algo please!!!! Then i need to figure out a way to texture objects.

I have not totally tested them yet, but i have implemented these now too

'MakeAnimatedSprite (num%, xsize%, ysize%, spritecnt%, filename$)
'PlayAnimatedSprite (num%, xpos%, ypos%, startframe%, endframe%, timelapse)
'PlaySound (filename$, volume)

All of this is all in aid of making it simple and fun to make games and applications. If i see some good stuff from the monkies (look forward to spheres from darthy) i might make it the DKM QB64GDK (Game dev kit).

I thought it might be nice for Galleon to have a massive library for him to give out when he gets it into schools, stuff like this would make the learning curve easier for those not so adept at programming, making it a better teaching tool. Also, the more stuff pre-programmed the better i say!!!


UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

DarthWho

  • Hero Member
  • *****
  • Posts: 3853
  • Timelord of the Sith
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #5 on: October 03, 2010, 08:28:54 PM »
Well i will put work into all of that then but it will delay things further
Rassilon: My lord Doctor; My lord Master; My lord DarthWho
The Doctor and the master at the same time :WHAT!?!?!

FastMath 1.1.0 released: http://dl.dropbox.com/u/12359848/fastmath.h

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #6 on: October 03, 2010, 09:09:38 PM »
Take your time, no mad rush. Have a look on the qbasic.com challnge page there is a thread on rotating cubes, someone figured it out already, i need a universal version of that when you get time, remmeber school comes first!!!
UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #7 on: October 03, 2010, 09:47:01 PM »
DarthWHO...why dont you make the Physick engine part? you seem to be quite adept at that sort of math. Also, maybe you could make a water physics engine that can be applied to any image? We could make rippling ponds with a transparant water texture that way. Oh, what can be done by DKM? I reckon pretty much anything!!!
UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #8 on: October 04, 2010, 12:18:32 AM »
Clippy...

What am i doing wrong?

Code: [Select]

msx% = _GetMx(mx%)
msy% = _GetMy(my%)
PRINT "MOUSE INFORMATION : MX :", msx%, " MY : ", msy%

'########################################################################
'#######################   Function library   ###########################
'########################################################################
FUNCTION _GetMx (mx%)
DO WHILE _MOUSEINPUT
  mx% = _MOUSEX
LOOP
END FUNCTION

'########################################################################
FUNCTION _GetMy (my%)
DO WHILE _MOUSEINPUT
  my% = _MOUSEY
LOOP
END FUNCTION

'########################################################################
UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

DarthWho

  • Hero Member
  • *****
  • Posts: 3853
  • Timelord of the Sith
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #9 on: October 04, 2010, 05:22:24 AM »
quite true Unseen school does always come first but then again where is the harm in using spare time to code a physics engine when you are taking a physics class?
Rassilon: My lord Doctor; My lord Master; My lord DarthWho
The Doctor and the master at the same time :WHAT!?!?!

FastMath 1.1.0 released: http://dl.dropbox.com/u/12359848/fastmath.h

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #10 on: October 04, 2010, 06:28:44 AM »
you would be better off getting the mouse x and y in a single loop. or doing do... loop until MouseInput<>0
my suggestion is:
sub GetMouseX(mx)
do
mx=_MOUSEX
loop until _MOUSEINPUT <> 0
end sub
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

unseenmachine

  • Hero Member
  • *****
  • Posts: 3285
  • A fish, a fish, a fishy o!
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #11 on: October 04, 2010, 10:07:33 AM »
So could someone show me a proper use for Functions then please? I am getting a little frustrated with them!!

UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

Cyperium

  • Hero Member
  • *****
  • Posts: 3285
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #12 on: October 04, 2010, 10:48:09 AM »
The loop doesn't have to be executed if _MOUSEINPUT is 0 so I suggest

mousewheel = 0
DO WHILE _MOUSEINPUT
mousewheel = mousewheel + _MOUSEWHEEL
xmouse = _MOUSEX
ymouse = _MOUSEY
buttonl = _MOUSEBUTTON(1)
buttonr = _MOUSEBUTTON(2)
LOOP

To be executed in the main loop.
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #13 on: October 04, 2010, 10:48:38 AM »
if you INSIST on making separate subs to get _mousex and _mousey, this way, the loop is ALWAYS run at least once, whereas with
do while _mouseinput
x=_mousex
loop
if the mouse is idle (no buttons pressed, no apparent mouse cursor movement), the code inside the loop never gets executed.
short demo showing difference between do while and do... loop while
Code: [Select]
DO
    GetMouseX x
    GetMouseY y
    LOCATE 1, 1
    PRINT USING "(####:####)"; x; y;
    GetMouseWhilex a
    GetMouseWhileY b
    PRINT USING "(####:####)"; a; b;
LOOP


SUB GetMouseX (x)
DO
    x = _MOUSEX
LOOP UNTIL _MOUSEINPUT = 0
END SUB
SUB GetMouseY (Y)
DO
    Y = _MOUSEY
LOOP UNTIL _MOUSEINPUT = 0
END SUB

SUB GetMouseWhileY (z)
DO WHILE _MOUSEINPUT
    z = _MOUSEX
LOOP
END SUB

SUB GetMouseWhilex (u)
DO WHILE _MOUSEINPUT
    u = _MOUSEY
LOOP
END SUB
« Last Edit: October 04, 2010, 01:12:25 PM by codeguy »
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Hey Clippy, i've got it cracked noe, and just to show off.
« Reply #14 on: October 04, 2010, 12:01:29 PM »
Quote
Code: [Select]
SUB CreateObjectSphere (num%, xsize%, r%, g%, b%)

'CREDITS - Sphere code by CodeGuy - Edited for purpose by Unseen Machine

sprite(num%).num = num%
sprite(num%).image = _NEWIMAGE(xsize%, xsize%, 32)
_DONTBLEND sprite(num%).image
_DEST sprite(num%).image
FOR y = 0 TO (xsize% - 1)
  FOR x = 0 TO (xsize% - 1)
    alpha = SQR((x - (xsize% / 2)) ^ 2 + (y - (xsize% / 2)) ^ 2) / (xsize% / 2)
    IF alpha < 0 THEN alpha = 0
    alpha = (1 - alpha * alpha) 'parabolic curve
    PSET (x, y), _RGBA32(r%, g%, b%, alpha * 255)
  NEXT
NEXT
_BLEND sprite(num%).image
_DEST 0 'return to the screen

sprite(num%).xsize = xsize%
sprite(num%).ysize = xsize%
sprite(num%).zsize = xsize%

END SUB
actually, this code is Zom-B's and i borrowed it. i personally would have used trig functions as they are actually faster than Zom-B's method on my computer (weird, eh?). just wanted to make sure the right person got the right credit. i borrowed this code. and i doubt if ANYONE else has beaten me to the punch on nspace, which i strongly request to have made unavailable for commercial use.
« Last Edit: October 04, 2010, 12:33:27 PM by codeguy »
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

  • Print