SyntaxBomb - Indie Coders

Languages & Coding => Blitz Code Archives => User Input => Topic started by: BlitzBot on June 29, 2017, 12:28:41 AM

Title: [bb] Simple Pause Game by _PJ_ [ 1+ years ago ]
Post by: BlitzBot on June 29, 2017, 12:28:41 AM
Title : Simple Pause Game
Author : _PJ_
Posted : 1+ years ago

Description : Using the User32.dll library, GetKeyState(), the Pause/Break key acts like a switch. the switch can then be checked repetitiously in a loop for changes.

The only complication, is that the Pause/Break key 'switch' may already be turned ON prior to running the program, or as a result of exiting a 'paused' game.

This entails an initial setting to reflect the state of the key, and store it as adefault non-paused value.
The code requires a .decls file with the following declaration:

Code: [Select]
.Lib "user32.dll"
GetKeyState% (nVirtKey%) : "GetKeyState"

Place these lines into a text file, and save it as "user32.decls" in the userlibs folder. [/i]

Code :
Code: BlitzBasic
  2. Global b_gam_PAUSESTATE_PAUSED=(Not(GetKeyState(19)))
  5. Function b_cnt_Paused() ;Allows Pause/Break key to toggle Pause mode and returns True if Paused.
  6.         ; Ensure v_cnt_InitialisePause() is called at program initialisation if you use this function!
  7.         Return (GetKeyState(19)=b_gam_PAUSESTATE_PAUSED)        ;$13 = VK_PAUSE
  8. End Function
  10. ; EXAMPLE:
  11. While Not KeyDown(1)
  12.         Cls
  13.         FlushKeys()
  14.         If (b_cnt_Paused())
  15.                 Text 0,0,("Game is paused")
  16.                 Else Text 0,0, ("Game is not paused")
  17.         End If
  18.         Flip
  19. Wend

Comments : none...
SimplePortal 2.3.6 © 2008-2014, SimplePortal