'\\ UnseenGDK Core v1.2 - Updated September 2012 '// Created By John Onyon a.k.a Unseen Machine '// Optimistation by CodeGuy '// ScanKeys% function by Cypherium '// Image rotation function by Galleon '############################################################################################ '########################################################################################################################## '// Typdef's '########################################################################################################################## SUB GDK_Start TYPE Sprite File AS LONG Width AS INTEGER Height AS INTEGER Alpha AS LONG IsVisible AS INTEGER XFrameCount AS INTEGER YFrameCount AS INTEGER TotalFrameCount AS INTEGER RotationX AS INTEGER RotationY AS INTEGER Scale AS SINGLE END TYPE TYPE Vector X AS SINGLE Y AS SINGLE Speed AS SINGLE Rotation AS DOUBLE Accel AS SINGLE Decel AS SINGLE END TYPE TYPE Rectangle X AS INTEGER Y AS INTEGER Width AS INTEGER Height AS INTEGER CollisionX AS INTEGER CollisionY AS INTEGER CollisionXX AS INTEGER CollisionYY AS INTEGER END TYPE TYPE BoundingCircle X AS INTEGER Y AS INTEGER Radius AS INTEGER END TYPE TYPE MouseState Mx AS INTEGER My AS INTEGER LMB AS INTEGER RMB AS INTEGER END TYPE TYPE KeyBoardState Left AS LONG Right AS LONG Down AS LONG Up AS LONG CTRL AS LONG SHIFT AS LONG ALT AS LONG SPACE AS LONG ENTER AS LONG ESC AS LONG Num1 AS LONG Num2 AS LONG Num3 AS LONG Num4 AS LONG Num5 AS LONG Num6 AS LONG Num7 AS LONG Num8 AS LONG Num9 AS LONG Num0 AS LONG PLUS AS LONG MINUS AS LONG BACKSPACE AS LONG TAB AS LONG A AS LONG B AS LONG C AS LONG D AS LONG E AS LONG F AS LONG G AS LONG H AS LONG I AS LONG J AS LONG K AS LONG L AS LONG M AS LONG N AS LONG O AS LONG P AS LONG Q AS LONG R AS LONG S AS LONG T AS LONG U AS LONG V AS LONG W AS LONG X AS LONG Y AS LONG Z AS LONG END TYPE TYPE GameObject Sprite AS Sprite Vector AS Vector Rect AS Rectangle END TYPE TYPE ANIMATION Frame AS INTEGER StartFrame AS INTEGER ResetFrame AS INTEGER Timer AS DOUBLE Time AS DOUBLE END TYPE TYPE SpriteX File AS LONG '// Handle to the file Width AS INTEGER '// Width of the entire spritesheet Height AS INTEGER '// Height of the entire spritesheet XFrames AS INTEGER '// Number of frames on x axis - For Equally spaced spritesheets only. YFrames AS INTEGER '// Number of frames on y axis - For Equally spaced spritesheets only. TotalFrames AS INTEGER FrameWidth AS INTEGER '// For Equally spaced spritesheets only. FrameHeight AS INTEGER '// For Equally spaced spritesheets only. RotX AS INTEGER '// Rotation point on x axis for a single sprite from an equally spaced sprite sheet. RotY AS INTEGER '// Rotation point on y axis for a single sprite from an equally spaced sprite sheet. ScaleX AS INTEGER '// Scale on x axis ScaleY AS INTEGER '// Scale on y axis Alpha AS LONG '// Tranparent colour IsVisible AS INTEGER '// Detrmines if sprite is drawn or not = 0 no, <> 0 = yes IsEqual AS INTEGER '// 0 = False (non equally spaced sprite sheet),sprite spacing cannot be/is not calculated, <> 0 = true, END TYPE TYPE Path Vector AS Vector NumPoints AS INTEGER CurrentPoint AS INTEGER LastVector AS Vector HitTargetX AS INTEGER HitTargetY AS INTEGER Reverse AS INTEGER IsReversing AS INTEGER END TYPE TYPE PathPoint X AS INTEGER Y AS INTEGER Speed AS INTEGER END TYPE END SUB SUB GDK_Particles_Init TYPE Emitter X AS INTEGER Y AS INTEGER SpawnRate AS INTEGER SpawnAngleMin AS SINGLE SpawnAngleMax AS SINGLE SpawnMaxVelocity AS SINGLE SpawnMinVelocity AS SINGLE MaxLifeTime AS DOUBLE MinLifeTime AS DOUBLE AccelMax AS SINGLE DecelMax AS SINGLE AccelMin AS SINGLE DecelMIn AS SINGLE Gravity AS SINGLE END TYPE TYPE Particle InitialCLR AS LONG CurrentCLR AS LONG ClrChange AS LONG ClrChangeMode AS INTEGER Vector AS Vector BirthTime AS DOUBLE LifeTime AS DOUBLE Exists AS INTEGER Accel AS SINGLE Decel AS SINGLE Gravity AS SINGLE END TYPE END SUB SUB GDK_TileEngine_Init TYPE Tileset File AS LONG Width AS INTEGER Height AS INTEGER THeight AS INTEGER TWidth AS INTEGER XTiles AS INTEGER YTiles AS INTEGER Alpha AS LONG XOffset AS INTEGER YOffset AS INTEGER Scale AS SINGLE END TYPE TYPE XY X AS INTEGER Y AS INTEGER END TYPE TYPE Tile RECT AS Rectangle Tile AS INTEGER END TYPE END SUB SUB GDK_TileEngineX_Init TYPE TilesetX File AS LONG Width AS INTEGER Height AS INTEGER THeight AS INTEGER TWidth AS INTEGER XTiles AS INTEGER YTiles AS INTEGER Alpha AS LONG XOffset AS INTEGER YOffset AS INTEGER Scale AS SINGLE Spacing AS INTEGER END TYPE TYPE XY2 X AS INTEGER Y AS INTEGER RealRect AS Rectangle END TYPE END SUB '########################################################################################################################## '// Collision detection '########################################################################################################################## SUB GDK_Rectangle_New (RectRef AS Rectangle, x%, y%, Width%, Height%) RectRef.X = x% RectRef.Y = y% RectRef.Width = Width% RectRef.Height = Height% END SUB '// Returns -1 for true, 0 for false FUNCTION GDK_Rectangle_Intersect (RectangleRef1 AS Rectangle, RectangleRef2 AS Rectangle) IF RectangleRef1.X <= RectangleRef2.X + RectangleRef2.Width THEN IF RectangleRef1.X + RectangleRef1.Width >= RectangleRef2.X THEN IF RectangleRef1.Y <= RectangleRef2.Y + RectangleRef2.Height THEN IF RectangleRef1.Y + RectangleRef1.Height >= RectangleRef2.Y THEN GDK_Rectangle_Intersect = -1 END IF END IF END IF ELSE GDK_Rectangle_Intersect = 0 END IF END FUNCTION SUB GDK_Rectangle_GetCollisionArea (RectRef1 AS Rectangle, RectRef2 AS Rectangle) IF RectRef1.X < RectRef2.X THEN RectRef2.CollisionX = 0 RectRef1.CollisionX = RectRef2.X - RectRef1.X IF RectRef2.Width + RectRef1.CollisionX < RectRef1.Width THEN RectRef2.CollisionXX = RectRef2.Width RectRef1.CollisionXX = RectRef1.CollisionX + RectRef2.Width ELSE RectRef1.CollisionXX = RectRef1.Width RectRef2.CollisionXX = (RectRef1.X + RectRef1.Width) - RectRef2.X END IF ELSEIF RectRef1.X > RectRef2.X THEN RectRef1.CollisionX = 0 RectRef2.CollisionX = RectRef1.X - RectRef2.X IF RectRef2.Width - RectRef2.CollisionX < RectRef1.Width THEN RectRef1.CollisionXX = (RectRef1.CollisionX + RectRef2.Width) - RectRef2.CollisionX RectRef2.CollisionXX = RectRef2.Width ELSE RectRef1.CollisionXX = RectRef1.Width RectRef2.CollisionXX = RectRef2.CollisionX + RectRef1.Width END IF ELSEIF RectRef1.X = RectRef2.X THEN RectRef1.CollisionX = 0 RectRef2.CollisionX = 0 IF RectRef1.Width < RectRef2.Width THEN ColWidth% = RectRef1.Width ELSE ColWidth% = RectRef2.Width END IF RectRef1.CollisionXX = ColWidth% RectRef2.CollisionXX = ColWidth% END IF IF RectRef1.Y < RectRef2.Y THEN RectRef2.CollisionY = 0 RectRef1.CollisionY = RectRef2.Y - RectRef1.Y IF RectRef2.Height + RectRef1.CollisionY < RectRef1.Height THEN RectRef2.CollisionYY = RectRef2.Height RectRef1.CollisionYY = RectRef1.CollisionY + RectRef2.Height ELSE RectRef1.CollisionYY = RectRef1.Height RectRef2.CollisionYY = (RectRef1.Y + RectRef1.Height) - RectRef2.Y END IF ELSEIF RectRef1.Y > RectRef2.Y THEN RectRef1.CollisionY = 0 RectRef2.CollisionY = RectRef1.Y - RectRef2.Y IF RectRef2.Height - RectRef2.CollisionY < RectRef1.Height THEN RectRef1.CollisionYY = (RectRef1.CollisionY + RectRef2.Height) - RectRef2.CollisionY RectRef2.CollisionYY = RectRef2.Height ELSE RectRef1.CollisionYY = RectRef1.Height RectRef2.CollisionYY = RectRef2.CollisionY + RectRef1.Height END IF ELSEIF RectRef1.Y = RectRef2.Y THEN RectRef1.CollisionY = 0 RectRef2.CollisionY = 0 IF RectRef1.Height < RectRef2.Height THEN ColHeight% = RectRef1.Height ELSE ColHeight% = RectRef2.Height END IF RectRef1.CollisionYY = ColHeight% RectRef2.CollisionYY = ColHeight% END IF END SUB SUB GDK_Rectangle_AutoSize (Sprite AS Sprite, Vector AS Vector, Rect AS Rectangle) DIM pX(3) AS SINGLE, pY(3) AS SINGLE, W AS LONG, H AS LONG, I AS LONG, X AS LONG, Y AS LONG, X2 AS LONG, Y2 AS LONG, PointX AS LONG, PointY AS LONG X = Vector.X Y = Vector.Y W = (Sprite.Width / Sprite.XFrameCount) H = (Sprite.Height / Sprite.YFrameCount) PointX = Sprite.RotationX PointY = Sprite.RotationY pX(0) = -PointX pY(0) = -PointY pX(1) = -PointX pY(1) = -PointY + H - 1 pX(2) = -PointX + W - 1 pY(2) = -PointY + H - 1 pX(3) = -PointX + W - 1 pY(3) = -PointY 'Set dest screen points SINr = SIN(Vector.Rotation) COSr = COS(Vector.Rotation) 'Precalculate SIN & COS of angle FOR I = 0 TO 3 pX(I) = pX(I) * Sprite.Scale pY(I) = pY(I) * Sprite.Scale 'Scale X2 = pX(I) * COSr + SINr * pY(I) pY(I) = pY(I) * COSr - pX(I) * SINr pX(I) = X2 'Rotate Dest Points pX(I) = pX(I) + X pY(I) = pY(I) + Y 'Translate Dest Points IF I = 0 THEN MinX% = pX(I) MinY% = pY(I) MaxX% = pX(I) MaxY% = pY(I) ELSE IF pX(I) < MinX% THEN MinX% = pX(I) IF pX(I) > MaxX% THEN MaxX% = pX(I) IF pY(I) < MinY% THEN MinY% = pY(I) IF pY(I) > MaxY% THEN MaxY% = pY(I) END IF NEXT Rect.X = MinX% Rect.Y = MinY% Rect.Width = MaxX% - MinX% Rect.Height = MaxY% - MinY% END SUB FUNCTION GDK_BoundingCircle_Intersect (Circ1 AS BoundingCircle, Circ2 AS BoundingCircle) LRAD% = Circ1.Radius + Circ2.Radius CDist! = GDK_Distance(Circ1.X, Circ1.Y, Circ2.X, Circ2.Y) IF CDist! > LRAD% THEN GDK_BoundingCircle_Intersect = 0 ELSE GDK_BoundingCircle_Intersect = -1 END IF END FUNCTION '########################################################################################################################## '//Vector stuff '########################################################################################################################## SUB GDK_Vector_New (Vector AS Vector, X%, Y%, Speed!, Rotation#) Vector.X = X% Vector.Y = Y% Vector.Speed = Speed! Vector.Rotation = Rotation# END SUB SUB GDK_Vector_SetPosition (Vector AS Vector, X%, Y%) Vector.X = X% Vector.Y = Y% END SUB SUB GDK_Vector_SetRotation (Vector AS Vector, Rotation#) Vector.Rotation = Rotation# END SUB SUB GDK_Vector_SetSpeed (Vector AS Vector, Speed!) Vector.Speed = Speed! END SUB SUB GDK_Vector_Update (Vector AS Vector) IF Vector.Decel > 0 THEN IF Vector.Accel > 0 THEN Vector.Accel = Vector.Accel - Vector.Decel ELSE IF Vector.Speed > (Vector.Decel) THEN Vector.Speed = Vector.Speed - Vector.Decel ELSE Vector.Speed = 0 END IF END IF IF Vector.Accel > 0 THEN Vector.Speed = Vector.Speed + Vector.Accel GDK_Vector_Move Vector END SUB SUB GDK_Vector_SetAccelDecel (Vector AS Vector, Accel!, Decel!) Vector.Accel = Accel! Vector.Decel = Decel! END SUB SUB GDK_Vector_Move (Vector AS Vector) Vector.X = Vector.X - SIN(Vector.Rotation) * Vector.Speed Vector.Y = Vector.Y - COS(Vector.Rotation) * Vector.Speed END SUB '########################################################################################################################## '// Sprite stuff '########################################################################################################################## SUB GDK_Sprite_New (SpriteFile AS Sprite, FileSource$, XFrameCount%, YFrameCount%, TotalFrameCount%, Scale!) SpriteFile.File = _LOADIMAGE(FileSource$) SpriteFile.Width = _WIDTH(SpriteFile.File) SpriteFile.Height = _HEIGHT(SpriteFile.File) SpriteFile.XFrameCount = XFrameCount% SpriteFile.YFrameCount = YFrameCount% SpriteFile.TotalFrameCount = TotalFrameCount% SpriteFile.Scale = Scale! END SUB SUB GDK_Sprite_SetRotationPoint (SpriteFile AS Sprite, X%, Y%) SpriteFile.RotationX = X% SpriteFile.RotationY = Y% END SUB SUB GDK_Sprite_SetVisibility (SpriteFile AS Sprite, OnOff%) SpriteFile.IsVisible = OnOff% END SUB SUB GDK_Sprite_SetAlpha (SpriteFile AS Sprite, Alpha&) SpriteFile.Alpha = Alpha& END SUB SUB GDK_Sprite_DrawXY (Sprite AS Sprite, X%, Y%, Rotation!, AnimationFrame%) DIM tempvect AS Vector GDK_Vector_New tempvect, X%, Y%, 0, Rotation! GDK_Sprite_Draw Sprite, tempvect, AnimationFrame% END SUB SUB GDK_Sprite_Hide (Handle AS Sprite) Handle.IsVisible = 0 END SUB SUB GDK_Sprite_Show (Handle AS Sprite) Handle.IsVisible = -1 END SUB SUB GDK_Sprite_Free (SpriteFile AS Sprite) _FREEIMAGE (SpriteFile.File) SpriteFile.IsVisible = 0 END SUB SUB GDK_Sprite_Clone (SourceSprite AS Sprite, DestSprite AS Sprite) DestSprite = SourceSprite END SUB SUB GDK_Sprite_Clone_X (SourceSprite AS Sprite, DestSprite() AS Sprite, FirstClone%, NumberOfClones%) FOR CloneCount% = FirstClone% TO FirstClone% + NumberOfClones% - 1 DestSprite(CloneCount%) = SourceSprite NEXT END SUB SUB GDK_Sprite_Draw (SpriteFile AS Sprite, DestVector AS Vector, Frame%) _CLEARCOLOR SpriteFile.Alpha, SpriteFile.File IF SpriteFile.IsVisible THEN IF Frame% = 0 THEN '// Draw the entire image. IF DestVector.Rotation = 0 THEN _PUTIMAGE (DestVector.X - (SpriteFile.RotationX * SpriteFile.Scale), DestVector.Y - (SpriteFile.RotationY * SpriteFile.Scale))-((DestVector.X - (SpriteFile.RotationX * SpriteFile.Scale)) + (SpriteFile.Width * SpriteFile.Scale), (DestVector.Y - (SpriteFile.RotationY * SpriteFile.Scale)) + (SpriteFile.Height * SpriteFile.Scale)), SpriteFile.File ELSE GDK_Sprite_Rotate SpriteFile, SpriteFile.RotationX * SpriteFile.Scale, SpriteFile.RotationY * SpriteFile.Scale, DestVector, SpriteFile.Scale END IF ELSE '// Draw a specific frame. FrameXSize% = SpriteFile.Width / SpriteFile.XFrameCount FrameYSize% = SpriteFile.Height / SpriteFile.YFrameCount FrameCnt% = 0 FrameYStart% = 0 FOR j% = 1 TO SpriteFile.YFrameCount FrameXStart% = 0 FOR i% = 1 TO SpriteFile.XFrameCount FrameCnt% = FrameCnt% + 1 IF FrameCnt% = Frame% THEN IF DestVector.Rotation <> 0 THEN DIM TmpImage AS Sprite TmpImage.File = _NEWIMAGE(FrameXSize%, FrameYSize%, 32) _PUTIMAGE (0, 0), SpriteFile.File, TmpImage.File, (FrameXStart%, FrameYStart%)-(FrameXStart% + FrameXSize%, FrameYStart% + FrameYSize%) '//GDK_Sprite_Rotate tmpimage, SpriteFile.RotationX, SpriteFile.RotationY, DestVector, SpriteFile.Scale Rotate_Scale_AroundPoint DestVector.X, DestVector.Y, TmpImage.File, -GDK_RadianToDegree(DestVector.Rotation), SpriteFile.Scale, SpriteFile.Scale, SpriteFile.RotationX, SpriteFile.RotationY _FREEIMAGE TmpImage.File ELSE _PUTIMAGE (DestVector.X - (SpriteFile.RotationX * SpriteFile.Scale), DestVector.Y - (SpriteFile.RotationY * SpriteFile.Scale))-((DestVector.X - (SpriteFile.RotationX * SpriteFile.Scale)) + (FrameXSize% * SpriteFile.Scale), (DestVector.Y - (SpriteFile.RotationY * SpriteFile.Scale)) + (FrameYSize% * SpriteFile.Scale)), SpriteFile.File, , (FrameXStart%, FrameYStart%)-(FrameXStart% + FrameXSize% -1, FrameYStart% + FrameYSize%) END IF EXIT FOR END IF FrameXStart% = FrameXStart% + FrameXSize% NEXT FrameYStart% = FrameYStart% + FrameYSize% NEXT END IF END IF END SUB SUB GDK_Sprite_Rotate (TypeRef AS Sprite, sx!, sy!, Vector AS Vector, Scale!) _SOURCE TypeRef.File w% = _WIDTH(_SOURCE) h% = _HEIGHT(_SOURCE) cs! = COS(Vector.Rotation) sn! = SIN(Vector.Rotation) calculateMinMax cs!, sn!, sx!, sy!, Scale!, x1, y1, x2, y2 mask# = 2 ^ 32 - 1 '* (used to make sure integer and not < 0 at the same time), cool, eh? FOR y = y1 TO y2 FOR x = x1 TO x2 xx = ((x * cs! - y * sn!) / Scale! + sx!) AND mask# yy = ((x * sn! + y * cs!) / Scale! + sy!) AND mask# IF xx >= w% OR yy >= h% THEN p& = 0 ' Make transparent if outside image ELSE p& = POINT(xx, yy) END IF IF p& <> TypeRef.Alpha THEN PSET (x + INT(Vector.X), y + INT(Vector.Y)), p& NEXT NEXT END SUB SUB calculateMinMax (cs!, sn!, sx!, sy!, zoom!, x1, y1, x2, y2) lt! = -sx! up! = -sy! rt! = _WIDTH(_SOURCE) - sx! dn! = _HEIGHT(_SOURCE) - sy! ulX! = (up! * sn! + lt! * cs!) * zoom! ulY! = (up! * cs! - lt! * sn!) * zoom! dlX! = (dn! * sn! + lt! * cs!) * zoom! dlY! = (dn! * cs! - lt! * sn!) * zoom! urX! = (up! * sn! + rt! * cs!) * zoom! urY! = (up! * cs! - rt! * sn!) * zoom! drX! = (dn! * sn! + rt! * cs!) * zoom! drY! = (dn! * cs! - rt! * sn!) * zoom! x1 = INT(min(min(ulX!, dlX!), min(urX!, drX!))) ' INT(x) = floor(x) y1 = INT(min(min(ulY!, dlY!), min(urY!, drY!))) x2 = -INT(-max(max(ulX!, dlX!), max(urX!, drX!))) ' -INT(-x)) = ceil(x) y2 = -INT(-max(max(ulY!, dlY!), max(urY!, drY!))) END SUB FUNCTION min! (a!, b!) min! = a! + (a! - b!) * (b! < a!) END FUNCTION FUNCTION max! (a!, b!) max! = a! + (a! - b!) * (b! > a!) END FUNCTION '########################################################################################################################## '// SCREEN Stuff! '########################################################################################################################## SUB GDK_Screen_MatchRes (ScreenHandle&, clr%, fs%) ScreenHandle& = _NEWIMAGE(_WIDTH(_SCREENIMAGE), _HEIGHT(_SCREENIMAGE), clr%) SCREEN ScreenHandle& IF fs% = 1 THEN _FULLSCREEN IF fs% = 0 THEN _FULLSCREEN _OFF END SUB SUB GDK_Screen_SetRes (ScreenHandle&, width%, height%, clr%, fs%) ScreenHandle& = _NEWIMAGE(width%, height%, clr%) SCREEN _NEWIMAGE(width%, height%, clr%) IF fs% = 1 THEN _FULLSCREEN IF fs% = 0 THEN _FULLSCREEN _OFF END SUB FUNCTION GDK_WindowHeight% GDK_WindowHeight% = _HEIGHT(0) END FUNCTION FUNCTION GDK_WindowWidth% GDK_WindowWidth% = _WIDTH(0) END FUNCTION FUNCTION GDK_ScreenWidth% GDK_ScreenWidth% = _WIDTH(_SCREENIMAGE) END FUNCTION FUNCTION GDK_ScreenHeight% GDK_ScreenHeight% = _HEIGHT(_SCREENIMAGE) END FUNCTION SUB GDK_ToggleFullScreen IF _FULLSCREEN THEN _FULLSCREEN _OFF ELSE _FULLSCREEN END SUB SUB GDK_Screen_Store (ImageHandle&) ImageHandle& = _COPYIMAGE(0) END SUB SUB GDK_Screen_Restore (ImageHandle&) _PUTIMAGE (0, 0), ImageHandle& END SUB SUB GDK_Screen_FadeIn (Time#) TmpScrnImage& = _COPYIMAGE(0) FOR i% = 255 TO 0 STEP -5 _PUTIMAGE , TmpScrnImage& LINE (0, 0)-(_WIDTH(0), _HEIGHT(0)), _RGBA(0, 0, 0, i%), BF _DELAY (Time# / 51) _DISPLAY NEXT END SUB SUB GDK_Screen_FadeOut (Time#) TmpScrnImage& = _COPYIMAGE(0) FOR i% = 0 TO 255 STEP 5 _PUTIMAGE , TmpScrnImage& LINE (0, 0)-(_WIDTH(0), _HEIGHT(0)), _RGBA(0, 0, 0, i%), BF _DELAY (Time# / 51) _DISPLAY NEXT END SUB '########################################################################################################################## '// User input subs and functions. '########################################################################################################################## SUB GDK_Keyboard_GetState (KeyboardRef AS KeyBoardState) FOR x% = 1 TO 88 'read each key scancode from array IF x% = 1 THEN KeyboardRef.ESC = scankey%(x%) IF x% = 2 THEN KeyboardRef.Num1 = scankey%(x%) IF x% = 3 THEN KeyboardRef.Num2 = scankey%(x%) IF x% = 4 THEN KeyboardRef.Num3 = scankey%(x%) IF x% = 5 THEN KeyboardRef.Num4 = scankey%(x%) IF x% = 6 THEN KeyboardRef.Num5 = scankey%(x%) IF x% = 7 THEN KeyboardRef.Num6 = scankey%(x%) IF x% = 8 THEN KeyboardRef.Num7 = scankey%(x%) IF x% = 9 THEN KeyboardRef.Num8 = scankey%(x%) IF x% = 10 THEN KeyboardRef.Num9 = scankey%(x%) IF x% = 11 THEN KeyboardRef.Num0 = scankey%(x%) IF x% = 12 THEN KeyboardRef.PLUS = scankey%(x%) IF x% = 13 THEN KeyboardRef.MINUS = scankey%(x%) IF x% = 14 THEN KeyboardRef.BACKSPACE = scankey%(x%) IF x% = 15 THEN KeyboardRef.TAB = scankey%(x%) IF x% = 30 THEN KeyboardRef.A = scankey%(x%) IF x% = 48 THEN KeyboardRef.B = scankey%(x%) IF x% = 46 THEN KeyboardRef.C = scankey%(x%) IF x% = 32 THEN KeyboardRef.D = scankey%(x%) IF x% = 18 THEN KeyboardRef.E = scankey%(x%) IF x% = 33 THEN KeyboardRef.F = scankey%(x%) IF x% = 34 THEN KeyboardRef.G = scankey%(x%) IF x% = 35 THEN KeyboardRef.H = scankey%(x%) IF x% = 23 THEN KeyboardRef.I = scankey%(x%) IF x% = 36 THEN KeyboardRef.J = scankey%(x%) IF x% = 37 THEN KeyboardRef.K = scankey%(x%) IF x% = 38 THEN KeyboardRef.L = scankey%(x%) IF x% = 50 THEN KeyboardRef.M = scankey%(x%) IF x% = 49 THEN KeyboardRef.N = scankey%(x%) IF x% = 24 THEN KeyboardRef.O = scankey%(x%) IF x% = 25 THEN KeyboardRef.P = scankey%(x%) IF x% = 16 THEN KeyboardRef.Q = scankey%(x%) IF x% = 19 THEN KeyboardRef.R = scankey%(x%) IF x% = 31 THEN KeyboardRef.S = scankey%(x%) IF x% = 20 THEN KeyboardRef.T = scankey%(x%) IF x% = 22 THEN KeyboardRef.U = scankey%(x%) IF x% = 47 THEN KeyboardRef.V = scankey%(x%) IF x% = 17 THEN KeyboardRef.W = scankey%(x%) IF x% = 45 THEN KeyboardRef.X = scankey%(x%) IF x% = 21 THEN KeyboardRef.Y = scankey%(x%) IF x% = 44 THEN KeyboardRef.Z = scankey%(x%) IF x% = 72 THEN KeyboardRef.Up = scankey%(x%) IF x% = 75 THEN KeyboardRef.Left = scankey%(x%) IF x% = 77 THEN KeyboardRef.Right = scankey%(x%) IF x% = 80 THEN KeyboardRef.Down = scankey%(x%) IF x% = 28 THEN KeyboardRef.ENTER = scankey%(x%) IF x% = 57 THEN KeyboardRef.SPACE = scankey%(x%) IF x% = 29 THEN KeyboardRef.CTRL = scankey%(x%) IF x% = 56 THEN KeyboardRef.ALT = scankey%(x%) IF x% = 42 THEN KeyboardRef.SHIFT = scankey%(x%) NEXT END SUB FUNCTION scankey% (scancode%) '//Created by clippy! STATIC Ready%, keyflags%() IF NOT Ready% THEN REDIM keyflags%(0 TO 127): Ready% = -1 'the keyboard states i% = INP(&H60) IF (i% AND 128) THEN keyflags%(i% XOR 128) = 0 IF (i% AND 128) = 0 THEN keyflags%(i%) = -1 WHILE INKEY$ <> "": WEND scankey% = keyflags%(scancode%) END FUNCTION SUB GDK_Mouse_GetState (MouseRef AS MouseState) DO MouseRef.Mx = _MOUSEX MouseRef.My = _MOUSEY MouseRef.LMB = _MOUSEBUTTON(1) MouseRef.RMB = _MOUSEBUTTON(2) LOOP WHILE _MOUSEINPUT END SUB '########################################################################################################################## '// Graphics Manipulation subs and functions '########################################################################################################################## '// Sprite Specific routines '########################################################################################################################## SUB GDK_ApplyMonoFilter (TypeRef AS Sprite) _SOURCE TypeRef.File _DONTBLEND TypeRef.File _DEST TypeRef.File w% = TypeRef.Width h% = TypeRef.Height FOR i% = 0 TO w% FOR j% = 0 TO h% m& = POINT(i%, j%) IF m& <> TypeRef.Alpha THEN clrsum% = (INT((_BLUE(m&) / 100) * 11) + INT((_RED(m&) / 100) * 39) + INT((_GREEN(m&) / 100) * 50)) IF clrsum% > 0 AND clrsum% < 255 THEN IF m& <> _RGB(clrsum%, clrsum%, clrsum%) THEN PSET (i%, j%), _RGB(clrsum%, clrsum%, clrsum%) END IF END IF NEXT NEXT _BLEND TypeRef.File _DEST 0 END SUB SUB GDK_ApplyColorFilter (TypeRef AS Sprite, r%, g%, b%, a%) _SOURCE TypeRef.File _DONTBLEND TypeRef.File _DEST TypeRef.File w% = TypeRef.Width h% = TypeRef.Height FOR i% = 0 TO w% FOR j% = 0 TO h% m& = POINT(i%, j%) IF m& <> TypeRef.Alpha THEN PSET (i%, j%), _RGBA(_RED(m&) + r%, _GREEN(m&) + g%, _BLUE(m&) + b%, _ALPHA(m&) + a%) END IF NEXT NEXT _BLEND TypeRef.File _DEST 0 END SUB SUB GDK_ReplaceColor (TypeRef AS Sprite, OldColor&, NewColor&) tmpimg& = _COPYIMAGE(TypeRef.File) _CLEARCOLOR OldColor&, tmpimg& _DEST TypeRef.File PAINT (0, 0), NewColor& _PUTIMAGE (0, 0), tmpimg& _FREEIMAGE tmpimg& _DEST 0 END SUB SUB GDK_ChangeColorValue (TypeRef AS Sprite, Color$, Value%) _SOURCE TypeRef.File _DONTBLEND TypeRef.File _DEST TypeRef.File w% = TypeRef.Width h% = TypeRef.Height FOR i% = 0 TO w% FOR j% = 0 TO h% m& = POINT(i%, j%) IF m& <> TypeRef.Alpha THEN SELECT CASE UCASE$(Color$) CASE "R" PSET (i%, j%), _RGBA(_RED(m&) + Value%, _GREEN(m&), _BLUE(m&), _ALPHA(m&)) CASE "G" PSET (i%, j%), _RGBA(_RED(m&), _GREEN(m&) + Value%, _BLUE(m&), _ALPHA(m&)) CASE "B" PSET (i%, j%), _RGBA(_RED(m&), _GREEN(m&), _BLUE(m&) + Value%, _ALPHA(m&)) CASE "A" PSET (i%, j%), _RGBA(_RED(m&), _GREEN(m&), _BLUE(m&), _ALPHA(m&) + Value%) END SELECT END IF NEXT NEXT _BLEND TypeRef.File _DEST 0 END SUB '########################################################################################################################## '// Non Sprite Specific functions '########################################################################################################################## SUB GDK_Sphere (X%, Y%, Radius%, R%, G%, B%) FOR py% = 0 TO (Radius% - 1) FOR px% = 0 TO (Radius% - 1) alpha = SQR((px% - (Radius% / 2)) ^ 2 + (py% - (Radius% / 2)) ^ 2) / (Radius% / 2) IF alpha < 0 THEN alpha = 0 alpha = (1 - alpha * alpha) 'parabolic curve PSET (X% + px%, Y% + py%), _RGBA32(R%, G%, B%, alpha * 255) NEXT NEXT END SUB '########################################################################################################################## '//Particle engine v.02 '########################################################################################################################## SUB GDK_Emitter_New (EmitRef AS Emitter, x%, y%, SpawnRate%, AngleMin!, AngleMax!, VelMin!, VelMax!, MinLifeTime#, MaxLifeTime#) EmitRef.X = x% EmitRef.Y = y% EmitRef.SpawnRate = SpawnRate% EmitRef.SpawnAngleMin = AngleMin! EmitRef.SpawnAngleMax = AngleMax! EmitRef.SpawnMaxVelocity = VelMax! EmitRef.SpawnMinVelocity = VelMin! EmitRef.MaxLifeTime = MaxLifeTime# EmitRef.MinLifeTime = MinLifeTime# END SUB SUB GDK_Emitter_SetGravity (EmitRef AS Emitter, Gravity!) EmitRef.Gravity = Gravity! END SUB SUB GDK_Emitter_SetAccelDecel (EmitRef AS Emitter, AccelMin!, AccelMax!, DecelMin!, DecelMax!) EmitRef.AccelMin = AccelMin! EmitRef.AccelMax = AccelMax! EmitRef.DecelMIn = DecelMin! EmitRef.DecelMax! = DecelMax! END SUB SUB GDK_Particles_Spawn (EmitRef AS Emitter, PartRef() AS Particle, ParticleMax%, InitialColor&, ColorChange&, ChangeMode%) SuccessfulSpawns% = 0 FOR i% = 0 TO ParticleMax% IF NOT PartRef(i%).Exists THEN PartRef(i%).Vector.X = EmitRef.X PartRef(i%).Vector.Y = EmitRef.Y PartRef(i%).Exists = -1 PartRef(i%).Vector.Rotation = (RND * EmitRef.SpawnAngleMax) + EmitRef.SpawnAngleMin PartRef(i%).Vector.Speed = (RND * EmitRef.SpawnMaxVelocity) + EmitRef.SpawnMinVelocity PartRef(i%).LifeTime = (RND * EmitRef.MaxLifeTime) + EmitRef.MinLifeTime PartRef(i%).InitialCLR = InitialColor& PartRef(i%).CurrentCLR = InitialColor& PartRef(i%).ClrChange = ColorChange& PartRef(i%).BirthTime = TIMER(.001) PartRef(i%).ClrChangeMode = ChangeMode% IF EmitRef.AccelMax > 0 THEN PartRef(i%).Accel = (RND * EmitRef.AccelMax) + EmitRef.AccelMin END IF IF EmitRef.DecelMax > 0 THEN PartRef(i%).Decel = (RND * EmitRef.DecelMax) + EmitRef.DecelMIn END IF SuccessfulSpawns% = SuccessfulSpawns% + 1 IF SuccessfulSpawns% = EmitRef.SpawnRate THEN EXIT FOR END IF NEXT END SUB SUB GDK_Particles_Update (PartRef() AS Particle, ParticleMax%) FOR i% = 0 TO ParticleMax% IF PartRef(i%).Exists THEN IF TIMER(.001) - PartRef(i%).BirthTime >= PartRef(i%).LifeTime THEN PartRef(i%).Exists = 0 ELSE IF PartRef(i%).Vector.Speed > 0 THEN IF PartRef(i%).Decel > 0 THEN IF PartRef(i%).Accel > 0 THEN PartRef(i%).Accel = PartRef(i%).Accel - PartRef(i%).Decel ELSE PartRef(i%).Vector.Speed = PartRef(i%).Vector.Speed - PartRef(i%).Decel END IF END IF IF PartRef(i%).Accel > 0 THEN PartRef(i%).Vector.Speed = PartRef(i%).Vector.Speed + PartRef(i%).Accel IF PartRef(i%).ClrChangeMode = 1 THEN PartRef(i%).CurrentCLR = PartRef(i%).CurrentCLR - PartRef(i%).ClrChange ELSE PartRef(i%).CurrentCLR = PartRef(i%).CurrentCLR + PartRef(i%).ClrChange END IF GDK_Vector_Move PartRef(i%).Vector END IF END IF END IF NEXT END SUB SUB GDK_Particles_Draw (PartRef() AS Particle, ParticleMax%) FOR i% = 0 TO ParticleMax% IF PartRef(i%).Exists THEN PSET (PartRef(i%).Vector.X, PartRef(i%).Vector.Y), PartRef(i%).CurrentCLR END IF NEXT END SUB '########################################################################################################################## '// MATH FUNCTIONS '########################################################################################################################## FUNCTION GDK_Distance! (X%, Y%, XX%, YY%) xd% = XX% - X% yd% = YY% - Y% GDK_Distance! = SQR((xd% * xd%) + (yd% * yd%)) END FUNCTION FUNCTION GDK_RadianToDegree! (Radians!) GDK_RadianToDegree! = Radians! * (180 / (4 * ATN(1))) END FUNCTION FUNCTION GDK_DegreeToRadian! (Degrees!) GDK_DegreeToRadian! = Degrees! * ((4 * ATN(1)) / 180) END FUNCTION SUB GDK_MathX DECLARE LIBRARY FUNCTION atan2# (BYVAL y#, BYVAL x#) FUNCTION acos# (BYVAL x#) FUNCTION asin# (BYVAL x#) FUNCTION cosh# (BYVAL x#) FUNCTION sinh# (BYVAL x#) FUNCTION tanh# (BYVAL x#) FUNCTION pow# (BYVAL base#, BYVAL exponent#) END DECLARE END SUB '########################################################################################################################## '// Tile engine '########################################################################################################################## SUB GDK_TileMap_Load (Level() AS Tile, XTiles%, YTiles%) FOR j% = 0 TO YTiles% - 1 FOR i% = 0 TO XTiles% - 1 READ tile% Level(i%, j%).Tile = tile% NEXT NEXT END SUB SUB GDK_Tiles_Draw (TileRef AS Tileset, XYRef() AS XY, Level() AS Tile, X%, Y%, XCnt%, YCnt%, XMax%, YMax%) Tx% = X% Ty% = Y% sx% = _WIDTH(_DEST) sy% = _HEIGHT(_DEST) FOR j% = YCnt% TO YMax% - 1 FOR i% = XCnt% TO XMax% - 1 IF Tx% < sx% THEN IF Level(i%, j%).Tile > 0 THEN GDK_Tile_Draw TileRef, Level(i%, j%).Tile, XYRef(), Tx%, Ty% GDK_Rectangle_New Level(i%, j%).RECT, Tx%, Ty%, TileRef.TWidth * TileRef.Scale, TileRef.THeight * TileRef.Scale END IF Tx% = Tx% + (TileRef.TWidth * TileRef.Scale) ELSE EXIT FOR END IF NEXT Tx% = X% IF Ty% < sy% THEN Ty% = Ty% + (TileRef.THeight * TileRef.Scale) ELSE EXIT FOR NEXT END SUB SUB GDK_Tileset_New (TileRef AS Tileset, File$, XYRef() AS XY, XTiles%, YTiles%, Alpha&, XOffset%, YOffset%) TileRef.XTiles = XTiles% TileRef.YTiles = YTiles% TileRef.Alpha = Alpha& TileRef.File = _LOADIMAGE(File$, 32) TileRef.Width = _WIDTH(TileRef.File) TileRef.Height = _HEIGHT(TileRef.File) TileRef.TWidth = (TileRef.Width / TileRef.XTiles) - XOffset% TileRef.THeight = (TileRef.Height / TileRef.YTiles) - YOffset% FOR j% = 1 TO YTiles% FOR i% = 1 TO XTiles% Count% = Count% + 1 XYRef(Count%).X = (i% - 1) * (TileRef.Width / XTiles%) + XOffset% XYRef(Count%).Y = (j% - 1) * (TileRef.Height / YTiles%) + YOffset% NEXT NEXT _CLEARCOLOR Alpha&, TileRef.File TileRef.Scale = 1 END SUB SUB GDK_Tile_Draw (TileRef AS Tileset, TileNum%, XYRef() AS XY, x%, y%) _PUTIMAGE (x%, y%)-(x% + (TileRef.TWidth * TileRef.Scale), y% + (TileRef.THeight * TileRef.Scale)), TileRef.File, , (XYRef(TileNum%).X, XYRef(TileNum%).Y)-(XYRef(TileNum%).X + TileRef.TWidth - 1, XYRef(TileNum%).Y + TileRef.THeight - 1) END SUB '########################################################################################################################## '// GameObject Subs and Functions - SUper fast prototyping commands for games '########################################################################################################################## SUB GDK_GameObject_New (Handle AS GameObject, File$, XframeCount%, YFrameCount%, X%, Y%, Speed!, Rotation!) GDK_Sprite_New Handle.Sprite, File$, XframeCount%, YFrameCount%, XframeCount% * YFrameCount%, 1 GDK_Vector_New Handle.Vector, X%, Y%, Speed!, Rotation! GDK_Rectangle_New Handle.Rect, X%, Y%, Handle.Sprite.Width / XframeCount%, Handle.Sprite.Height / YFrameCount% GDK_Sprite_SetVisibility Handle.Sprite, -1 GDK_Sprite_SetAlpha Handle.Sprite, _RGB(255, 0, 255) END SUB SUB GDK_GameObject_Draw (GameObject AS GameObject, AnimationFrame%) GDK_Sprite_Draw GameObject.Sprite, GameObject.Vector, AnimationFrame% END SUB SUB GDK_GameObject_Update (Handle AS GameObject) GDK_Vector_Update Handle.Vector GDK_Rectangle_AutoSize Handle.Sprite, Handle.Vector, Handle.Rect END SUB SUB GDK_GameObject_Rotate (Handle AS GameObject, Rot!) Handle.Vector.Rotation = Handle.Vector.Rotation + Rot! END SUB SUB GDK_GameObject_Hide (Handle AS GameObject) Handle.Sprite.IsVisible = 0 END SUB SUB GDK_GameObject_Show (Handle AS GameObject) Handle.Sprite.IsVisible = -1 END SUB FUNCTION GDK_GameObject_Intersect (Handle AS GameObject, Handle2 AS GameObject) IF GDK_Rectangle_Intersect(Handle.Rect, Handle2.Rect) THEN GDK_GameObjectIntersect = -1 ELSE GDK_GameObjectIntersect = 0 END IF END SUB '########################################################################################################################## '################################################### GDK v1.1 Update ###################################################### '########################################################################################################################## '########################################################################################################################## '// Animation routines - Taken from GDK_GL '########################################################################################################################## SUB GDK_ANIMATION_NEW (Anim AS ANIMATION, Frame%, StartFrame%, ResetFrame%, AnimTime#, AnimTimer#) Anim.Frame = Frame% Anim.StartFrame = StartFrame% Anim.ResetFrame = ResetFrame% Anim.Time = AnimTime# Anim.Timer = AnimTimer# END SUB SUB GDK_ANIMATION_UPDATE (Anim AS ANIMATION) IF Anim.Frame < Anim.StartFrame OR Anim.Frame > Anim.ResetFrame THEN Anim.Frame = Anim.StartFrame Anim.Timer = TIMER(.001) ELSE IF TIMER(.001) - Anim.Timer >= Anim.Time THEN IF Anim.Frame = Anim.ResetFrame THEN Anim.Frame = Anim.StartFrame ELSE Anim.Frame = Anim.Frame + 1 END IF Anim.Timer = TIMER(.001) END IF END IF END SUB '########################################################################################################################## '// SpriteX Functions '########################################################################################################################## SUB GDK_SpriteX_New (Sprite AS SpriteX, File$, Rect() AS Rectangle, XFrames%, YFrames%, MaxFrames%, Spacing%) Sprite.File = _LOADIMAGE(File$, 32) Sprite.Width = _WIDTH(Sprite.File) Sprite.Height = _HEIGHT(Sprite.File) Sprite.IsEqual = Spacing% Sprite.ScaleX = 1 Sprite.ScaleY = 1 Sprite.TotalFrames = MaxFrames% IF Spacing% THEN '// Is an equally spaced sprite sheet, if x or y frames count > 1 calculate posisitons into rect array Sprite.FrameWidth = Sprite.Width / XFrames% Sprite.FrameHeight = Sprite.Height / YFrames% IF XFrames% > 1 OR YFrames% > 1 THEN FOR Y% = 1 TO YFrames% FOR X% = 1 TO XFrames% IF X% > 1 THEN Px% = Px% + Sprite.FrameWidth Rect(RectCnt%).X = Px% Rect(RectCnt%).Y = Py% Rect(RectCnt%).Width = Sprite.FrameWidth Rect(RectCnt%).Height = Sprite.FrameHeight RectCnt% = RectCnt% + 1 NEXT Py% = Py% + Sprite.FrameHeight Px% = 0 NEXT ELSE Rect(RectCnt%).X = 0 Rect(RectCnt%).Y = 0 Rect(RectCnt%).Width = Sprite.FrameWidth Rect(RectCnt%).Height = Sprite.FrameHeight END IF END IF END SUB SUB GDK_SpriteX_Clone (SourceSprite AS SpriteX, DestSprite AS SpriteX) DestSprite = SourceSprite END SUB SUB GDK_SpriteX_Clone_X (SourceSprite AS SpriteX, DestSprite() AS SpriteX, FirstClone%, NumberOfClones%) FOR CloneCount% = FirstClone% TO FirstClone% + NumberOfClones% - 1 DestSprite(CloneCount%) = SourceSprite NEXT END SUB SUB GDK_SpriteX_Set_Scale (Sprite AS SpriteX, XScale%, YScale%) Sprite.ScaleX = XScale% Sprite.ScaleY = YScale% END SUB SUB GDK_SpriteX_SetRotationPoint (Sprite AS SpriteX, X%, Y%) Sprite.RotX = X% Sprite.RotY = Y% END SUB SUB GDK_SpriteX_SetVisibility (Sprite AS SpriteX, OnOff%) Sprite.IsVisible = OnOff% END SUB SUB GDK_SpriteX_SetAlpha (Sprite AS SpriteX, Alpha&) Sprite.Alpha = Alpha& END SUB SUB GDK_SpriteX_DrawXY (Sprite AS SpriteX, Rect() AS Rectangle, X%, Y%, Rotation!, AnimationFrame%) DIM TempVect AS Vector GDK_Vector_New TempVect, X%, Y%, 0, Rotation! GDK_SpriteX_Draw Sprite, TempVect, Rect(), AnimationFrame% END SUB SUB GDK_SpriteX_Draw (Sprite AS SpriteX, DestVector AS Vector, Rect() AS Rectangle, Frame%) _CLEARCOLOR Sprite.Alpha, Sprite.File IF Sprite.IsVisible THEN IF Frame% = 0 THEN '// Draw the entire image. IF DestVector.Rotation = 0 THEN _PUTIMAGE (DestVector.X - (Sprite.RotX * Sprite.ScaleX), DestVector.Y - (Sprite.RotY * Sprite.ScaleY))-((DestVector.X - (Sprite.RotX * Sprite.ScaleX)) + (Sprite.Width * Sprite.ScaleX), (DestVector.Y - (Sprite.RotY * Sprite.ScaleY)) + (Sprite.Height * Sprite.ScaleY)), Sprite.File ELSE Rotate_Scale_AroundPoint DestVector.X, DestVector.Y, Sprite.File, DestVector.Rotation, Sprite.ScaleX, Sprite.ScaleY, Sprite.RotX, Sprite.RotY END IF ELSE '// Draw a specific frame. IF DestVector.Rotation = 0 THEN _PUTIMAGE (DestVector.X - (Sprite.RotX * Sprite.ScaleX), DestVector.Y - (Sprite.RotY * Sprite.ScaleY))-((DestVector.X - (Sprite.RotX * Sprite.ScaleX)) + (Sprite.FrameWidth * Sprite.ScaleX), (DestVector.Y - (Sprite.RotY * Sprite.ScaleY)) + (Sprite.FrameHeight * Sprite.ScaleY)), Sprite.File, , (Rect(Frame% - 1).X, Rect(Frame% - 1).Y)-(Rect(Frame% - 1).X + Rect(Frame% - 1).Width, Rect(Frame% - 1).Y + Rect(Frame% - 1).Height) ELSE DIM TmpImage AS LONG TmpImage = _NEWIMAGE(Sprite.FrameWidth * Sprite.ScaleX, Sprite.FrameHeight * Sprite.ScaleY, 32) OldDest& = _DEST _DEST TmpImage _PUTIMAGE (0, 0)-(Sprite.FrameWidth * Sprite.ScaleX, Sprite.FrameHeight * Sprite.ScaleY), Sprite.File, , (Rect(Frame% - 1).X, Rect(Frame% - 1).Y)-(Rect(Frame% - 1).X + Rect(Frame% - 1).Width, Rect(Frame% - 1).Y + Rect(Frame% - 1).Height) _DEST OldDest& Rotate_Scale_AroundPoint DestVector.X, DestVector.Y, TmpImage, DestVector.Rotation, Sprite.ScaleX, Sprite.ScaleY, Sprite.RotX, Sprite.RotY _FREEIMAGE TmpImage END IF END IF END IF END SUB SUB GDK_SpriteX_Hide (Handle AS SpriteX) Handle.IsVisible = 0 END SUB SUB GDK_SpriteX_Show (Handle AS SpriteX) Handle.IsVisible = -1 END SUB '########################################################################################################################## '// Image ROTATION/ZOOM FUNCTION BY GALLEON '########################################################################################################################## SUB Rotate_Scale_AroundPoint (X AS LONG, Y AS LONG, Image AS LONG, Rotation AS SINGLE, ScaleX AS SINGLE, ScaleY AS SINGLE, PointX AS LONG, PointY AS LONG) DEFSNG A-Z DIM pX(3) AS SINGLE: DIM pY(3) AS SINGLE DIM W AS LONG, H AS LONG, I AS LONG, X2 AS LONG, Y2 AS LONG W = _WIDTH(Image): H = _HEIGHT(Image) pX(0) = -PointX: pY(0) = -PointY: pX(1) = -PointX: pY(1) = -PointY + H - 1: pX(2) = -PointX + W - 1: pY(2) = -PointY + H - 1: pX(3) = -PointX + W - 1: pY(3) = -PointY 'Set dest screen points Radians = -Rotation / 57.29578: SINr = SIN(Radians): COSr = COS(Radians) 'Precalculate SIN & COS of angle FOR I = 0 TO 3 pX(I) = pX(I) * ScaleX: pY(I) = pY(I) * ScaleY 'Scale X2 = pX(I) * COSr + SINr * pY(I): pY(I) = pY(I) * COSr - pX(I) * SINr: pX(I) = X2 'Rotate Dest Points pX(I) = pX(I) + X: pY(I) = pY(I) + Y 'Translate Dest Points NEXT _MAPTRIANGLE (0, 0)-(0, H - 1)-(W - 1, H - 1), Image TO(pX(0), pY(0))-(pX(1), pY(1))-(pX(2), pY(2)) _MAPTRIANGLE (0, 0)-(W - 1, 0)-(W - 1, H - 1), Image TO(pX(0), pY(0))-(pX(3), pY(3))-(pX(2), pY(2)) END SUB '########################################################################################################################## '########################################################################################################################## '// Tile Engine Patch 1 '########################################################################################################################## SUB GDK_TileMap_Load_FromFile (GameFile$, Level() AS Tile, YTiles%) X& = FREEFILE OPEN GameFile$ FOR INPUT AS #X& FOR i% = 0 TO YTiles% - 1 LINE INPUT #X&, DataLine$ Cnt% = 0 FOR j% = 0 TO LEN(DataLine$) IF INSTR(j%, DataLine$, ",") > 0 THEN Level(Cnt%, i%).Tile = VAL(MID$(DataLine$, j%, INSTR(j%, DataLine$, ",") - j%)) j% = INSTR(j%, DataLine$, ",") Cnt% = Cnt% + 1 ELSE Level(Cnt%, i%).Tile = VAL(MID$(DataLine$, j%)) END IF NEXT NEXT CLOSE #X& END SUB SUB GDK_Tileset_SetScale (TileRef AS Tileset, Scale!) TileRef.Scale = Scale! END SUB '########################################################################################################################## SUB GDK_TilesetX_New (TileRef AS TilesetX, File$, XYRef() AS XY2, XTiles%, YTiles%, Alpha&, XOffset%, YOffset%) TileRef.XTiles = XTiles% TileRef.YTiles = YTiles% TileRef.Alpha = Alpha& TileRef.File = _LOADIMAGE(File$, 32) TileRef.Width = _WIDTH(TileRef.File) TileRef.Height = _HEIGHT(TileRef.File) TileRef.Scale = 1 _CLEARCOLOR Alpha&, TileRef.File TileRef.TWidth = (TileRef.Width / TileRef.XTiles) - XOffset% TileRef.THeight = (TileRef.Height / TileRef.YTiles) - YOffset% OldSource& = _SOURCE _SOURCE TileRef.File FOR j% = 1 TO YTiles% FOR i% = 1 TO XTiles% Count% = Count% + 1 XYRef(Count%).X = (i% - 1) * (TileRef.Width / XTiles%) + XOffset% XYRef(Count%).Y = (j% - 1) * (TileRef.Height / YTiles%) + YOffset% '// Get RealRect (actual pixel area) data for the tile '// This is relative to the tiles XY position FirstY% = TileRef.TWidth FirstX% = TileRef.THeight LastY% = 0 LastX% = 0 H% = TileRef.TWidth - 1 W% = TileRef.THeight - 1 FOR k% = 0 TO H% FOR l% = 0 TO W% RealK% = k% + j% - 1 RealL% = l% + i% - 1 C& = POINT(RealL%, RealK%) IF C& <> TileRef.Alpha THEN IF l% < FirstX% THEN FirstX% = l% IF l% > LastX% THEN LastX% = l% IF k% < FirstY% THEN FirstY% = k% IF k% > LastY% THEN LastY% = k% END IF NEXT NEXT XYRef(Count%).RealRect.X = FirstX% XYRef(Count%).RealRect.Y = FirstY% XYRef(Count%).RealRect.Width = LastX% - FirstX% XYRef(Count%).RealRect.Height = LastY% - FirstY% NEXT NEXT _SOURCE OldSource& END SUB '########################################################################################################################## SUB GDK_TileX_Draw (TileRef AS TilesetX, TileNum%, XYRef() AS XY2, x%, y%) _PUTIMAGE (x%, y%)-(x% + (TileRef.TWidth * TileRef.Scale), y% + (TileRef.THeight * TileRef.Scale)), TileRef.File, , (XYRef(TileNum%).X, XYRef(TileNum%).Y)-(XYRef(TileNum%).X + TileRef.TWidth - 1, XYRef(TileNum%).Y + TileRef.THeight - 1) END SUB '########################################################################################################################## SUB GDK_TilesX_Draw (TileRef AS TilesetX, XYRef() AS XY2, Level() AS Tile, X%, Y%, XCnt%, YCnt%, XMax%, YMax%) Tx% = X% Ty% = Y% sx% = _WIDTH(_DEST) sy% = _HEIGHT(_DEST) FOR j% = YCnt% TO YMax% - 1 FOR i% = XCnt% TO XMax% - 1 IF Tx% < sx% THEN IF Level(i%, j%).Tile > 0 THEN GDK_TileX_Draw TileRef, Level(i%, j%).Tile, XYRef(), Tx%, Ty% GDK_Rectangle_New Level(i%, j%).RECT, Tx% + XYRef(Level(i%, j%).Tile).RealRect.X, Ty% + XYRef(Level(i%, j%).Tile).RealRect.Y, XYRef(Level(i%, j%).Tile).RealRect.Width * TileRef.Scale, XYRef(Level(i%, j%).Tile).RealRect.Height * TileRef.Scale END IF Tx% = Tx% + (TileRef.TWidth * TileRef.Scale) ELSE EXIT FOR END IF NEXT Tx% = X% IF Ty% < sy% THEN Ty% = Ty% + (TileRef.THeight * TileRef.Scale) ELSE EXIT FOR NEXT END SUB '########################################################################################################################## SUB GDK_TilesetX_SetScale (TileRef AS TilesetX, Scale!) TileRef.Scale = Scale! END SUB '########################################################################################################################## '// Path based movement v.01 '########################################################################################################################## SUB GDK_Path_New (Path AS Path, PathPoint() AS PathPoint, NumPoints%, Reverse%) FOR i% = 0 TO NumPoints% - 1 READ PathPoint(i%).X, PathPoint(i%).Y, PathPoint(i%).Speed NEXT Path.Vector.Rotation = -atan2(PathPoint(0).Y - PathPoint(1).Y, PathPoint(0).X - PathPoint(1).X) + (2 * ATN(1)) Path.Vector.X = PathPoint(0).X Path.Vector.Y = PathPoint(0).Y Path.LastVector = Path.Vector Path.NumPoints = NumPoints% Path.Reverse = Reverse% END SUB '########################################################################################################################## SUB GDK_Path_Update (Path AS Path, PathPoint() AS PathPoint) Path.LastVector = Path.Vector Path.Vector.Speed = PathPoint(Path.CurrentPoint).Speed GDK_Vector_Update Path.Vector IF Path.IsReversing THEN IF Path.CurrentPoint > 0 THEN IF NOT Path.HitTargetX THEN IF IsWithinRange(PathPoint(Path.CurrentPoint - 1).X, Path.LastVector.X, Path.Vector.X) THEN Path.HitTargetX = -1 IF NOT Path.HitTargetY THEN IF IsWithinRange(PathPoint(Path.CurrentPoint - 1).Y, Path.LastVector.Y, Path.Vector.Y) THEN Path.HitTargetY = -1 IF Path.HitTargetX AND Path.HitTargetY THEN IF Path.CurrentPoint > 1 THEN Path.CurrentPoint = Path.CurrentPoint - 1 Path.Vector.Rotation = -atan2(Path.Vector.Y - PathPoint(Path.CurrentPoint - 1).Y, Path.Vector.X - PathPoint(Path.CurrentPoint - 1).X) + (2 * ATN(1)) ELSE '// First point Path.CurrentPoint = 0 IF Path.Reverse THEN Path.IsReversing = 0 Path.Vector.Rotation = -atan2(Path.Vector.Y - PathPoint(Path.CurrentPoint + 1).Y, Path.Vector.X - PathPoint(Path.CurrentPoint + 1).X) + (2 * ATN(1)) END IF END IF Path.HitTargetX = 0 Path.HitTargetY = 0 END IF END IF ELSE IF Path.CurrentPoint < Path.NumPoints - 1 THEN IF NOT Path.HitTargetX THEN IF IsWithinRange(PathPoint(Path.CurrentPoint + 1).X, Path.LastVector.X, Path.Vector.X) THEN Path.HitTargetX = -1 IF NOT Path.HitTargetY THEN IF IsWithinRange(PathPoint(Path.CurrentPoint + 1).Y, Path.LastVector.Y, Path.Vector.Y) THEN Path.HitTargetY = -1 IF Path.HitTargetX AND Path.HitTargetY THEN IF Path.CurrentPoint < Path.NumPoints - 2 THEN Path.CurrentPoint = Path.CurrentPoint + 1 Path.Vector.Rotation = -atan2(Path.Vector.Y - PathPoint(Path.CurrentPoint + 1).Y, Path.Vector.X - PathPoint(Path.CurrentPoint + 1).X) + (2 * ATN(1)) ELSE '// Last point Path.CurrentPoint = Path.NumPoints - 1 IF Path.Reverse THEN Path.IsReversing = -1 Path.Vector.Rotation = -atan2(Path.Vector.Y - PathPoint(Path.CurrentPoint - 1).Y, Path.Vector.X - PathPoint(Path.CurrentPoint - 1).X) + (2 * ATN(1)) END IF END IF Path.HitTargetX = 0 Path.HitTargetY = 0 END IF END IF END IF END SUB '########################################################################################################################## FUNCTION IsWithinRange% (Target%, MinRange%, MaxRange%) IF Target% >= MinRange% AND Target% <= MaxRange% THEN IsWithinRange% = -1 ELSEIF Target% <= MinRange% AND Target% >= MaxRange% THEN IsWithinRange% = -1 ELSE IsWithinRange% = 0 END IF END FUNCTION '########################################################################################################################## '########################################################################################################################## '########################################################################################################################## '########################################################################################################################## '########################################################################################################################## '########################################################################################################################## '##########################################################################################################################