' Only use the modules for commands that we need. ' This results in a smaller EXE Framework BRL.Max2D Import BRL.GLMax2D Import BRL.D3D7Max2D Import BRL.Basic Import BRL.System Import "-lshell32" ' Import shell32.dll for Win32 API Calls below Extern "win32" ' Win32 API Function LoadIcon(hWnd, file:Byte Ptr, index) = "ExtractIconA@12" Function GetActiveWindow() Function GetDesktopWindow() Function GetWindowRect(hWnd, lpRect:Byte Ptr) Function SetWindowText(hWnd, lpString$z) = "SetWindowTextA@8" Function SetWindowPos(hWnd, after, x, y, w, h, flags) Function GetWindowLong(hwnd, nIndex) = "GetWindowLongA@8" Function SetWindowLong(hwnd, index, nIndex) = "SetWindowLongA@12" Function SetClassLong(hWnd, nIndex, dwNewLong) = "SetClassLongA@12" Function GetSystemMenu(hWnd, revert) Function GetMenuItemCount(hMenu) Function RemoveMenu(hMenu, position, flags) Function ShowCursor(bShow) Function GetTickCount() End Extern Type lpRECT ' Type that holds desktop dimensions returned from GetWindowRect() Field l, t, r, b End Type ' WINDOW SETTINGS Const GFX_WIDTH = 640, GFX_HEIGHT = 480 Global BIT_DEPTH, HERTZ Global winMode = True, winVSYNC = True, winRenderer = 1 ' Set for Windowed/60 FPS/OpenGL If winMode = True Then BIT_DEPTH = 0 Else BIT_DEPTH = 32 ' Set to windowed or fullscreen If winVSYNC = 1 Then HERTZ = 60 Else HERTZ = -1 ' Set VSYNC ' Set OpenGL/Direct3D If winRenderer = 1 Then SetGraphicsDriver GLMax2DDriver() Else SetGraphicsDriver D3D7Max2DDriver() Graphics GFX_WIDTH, GFX_HEIGHT, BIT_DEPTH, HERTZ ' Initialize graphics SeedRnd GetTickCount() ' Seed Random SetBlend LIGHTBLEND ' Enable additive Alpha blending ' // Public //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%// Global fpsCount% = 0, fpsCurrent% = 0, fpsTime% = MilliSecs() + 1 Global MyMilliSecs = 0, LastMilliSecs = GetTickCount() If winMode = True Then WindowMode ' Call function that sets up window mode Global o:Obj, objList:TList = New TList ' Type reference and type list Type Obj Field A, R#, Alp# ' Angle, Radius, and Alpha Function Create:Obj() ' Creates a new Obj o:Obj = New Obj o.A = Rand(0, 359); o.R = 0; o.Alp = Rnd(.3, 1) Return o ' Pass it back End Function Method Render() ' Draws the objects Local Del = False ' Delete flag SetColor 0, 255, 0; SetAlpha Alp DrawOval R * Cos(A) + 320, R * Sin(A) + 240, 10, 10 SetColor 255, 255, 255; SetAlpha 1 ' Restore normal settings A:+1; R:+.5 ' Increase angle and radius If R > 50 Then Del = True ' Mark for deletion If Del = True Then objList.Remove o End Method End Type ' // MAIN Repeat Cls fpsCount = fpsCount + 1 If MilliSecs() >= fpsTime Then fpsCurrent = fpsCount; fpsCount = 0; fpsTime = fpsTime + 1000 objList.AddLast obj.Create() ' Create new particles For o:Obj = EachIn objList ' Render particles o.Render Next DrawText "FPS: " + fpsCurrent, 5, 5 FlushMem; Flip Until KeyDown(KEY_ESCAPE) End ' Custom MilliSecs() function that fixes negative MilliSecs() when system uptime is longer than 30 days Function MilliSecs() If GetTickCount() > LastMilliSecs Then MyMilliSecs = MyMilliSecs + (GetTickCount() - LastMilliSecs) If GetTickCount() < LastMilliSecs Then MyMilliSecs = MyMilliSecs + (LastMilliSecs - GetTickCount()) LastMilliSecs = GetTickCount() Return MyMilliSecs End Function ' Function that gives window a title, an icon, and centers it on screen Function WindowMode() Local hWnd% = GetActiveWindow() Local style = GetWindowLong(hWnd, -16) SetWindowLong hWnd, -16, style + $80000 + $20000 Local hMenu = GetSystemMenu(hWnd, 0) Local iMenu = GetMenuItemCount(hMenu) RemoveMenu hMenu, iMenu - 1, $1000 + $400 RemoveMenu hMenu, iMenu - 2, $1000 + $400 SetWindowText hWnd, "My BlitzMax Application" Local icon = LoadIcon(hWnd, "icon.ico", 0) SetClassLong hWnd, -14, icon Local desk_hWnd% = GetDesktopWindow(), l:lpRect = New lpRECT GetWindowRect desk_hWnd, l:lpRECT SetWindowPos hWnd, -2, (l.r / 2) - (GFX_WIDTH / 2), (l.b / 2) - (GFX_HEIGHT / 2), 0, 0, 1 l:lpRECT = Null End Function