Bridges-Python  3.4.4
Bridges(Python API)
Public Member Functions | Public Attributes | List of all members
bridges.non_blocking_game3D.NonBlockingGame3D Class Reference
Inheritance diagram for bridges.non_blocking_game3D.NonBlockingGame3D:
bridges.gamebase3D.GameBase3D

Detailed Description

brief This class provides the features necessary to implement simple non blocking games.

The games that can be created out of NonBlockingGame are based on a simple board grid of at most 1024 cells (e.g., 32x32, or any combinations less than 1024 cells). Each cell has a background color, and a colored symbol.

This class is used by having another class derive from it and implement the two functions: initialize() and GameLoop(). initialize() is called exactly once, on the first frame of the game. It is used to make first time initializations of the game state (such as setting the board in its initial position, for instance in chess). However, GameLoop() is called at every frame of the game. The game starts when the function start() is called on the object you created.

This game does not do anything, but it is the minimal code that will run a game. Note that the constructor of my_game passes 3 parameters to the constructor of NonBlockingGame(). These three parameters are the classic parameters that the constructor of bridges::Bridges takes (e.g., assignmentID, username, apikey).

To change the board, two functions are used. setBGColor() change the background color of a particular cell. It takes three parameters, the first two identify the cell of the board to change, and the last one is a color from a color palette provided by NamedColor. drawSymbol() takes four parameters, the first two identify the cell of the board to change, the third is a symbol from a symbol palette provided by NamedSymbol, the fourth is the color that symbol shold be drawn in and provided by NamedColor.

For instance, a very simple initialize() could look like: code{.py} def initialize(): set_bg_color(0, 0, NamedColor.lightsalmon);

draw_symbol(0, 0, NamedSymbol.sword, NamedColor.blue);
endcode

Note that the size of the board is set by default at 10x10 and that drawing on a cell that does not exist will lead to an error. One can specify a gameboard of a different size by passing additional parameters to the NonBlockingGame constructor. However, the game can not be more than 1024 cells in total, so a 15x15 board is possible, a 32x32 board is the largest square board possible, and a rectangular 64x16 rectangular board is also possible. But a 100x20 board would be 2000 cells and is not possible. For instance a board of 16 rows and 64 columns can be created defining the my_game constructor as:

code{.py}

my_game = NonBlockingGame (1, "myuserid", "myapikey", 16, 64)
endcode

The bridges game engine will call the GameLoop() function at each frame of the game. You can write this function to modify the state of the game board using setBGColor() and drawSymbol(). For instance, the following GameLoop() will color the board randomly one cell at a time.

code{.py} def game_oop(): set_BG_Color(rand()%10, rand()%10, NamedColor.lightsalmon); endcode

The gameLoop can also probe the state of some keys of the keyboard using functions key_up(), key_left(),

key_down(), key_right(), key_w(), key_a(), key_s(),

key_d(), key_space(), and key_q(). These functions return a boolean that indicate whether the key is pressed at that frame or not. For instance, the following code will only color the board randomly when the up arrow is pressed.

code{.py} def gameLoop(): if key_up()

set_bg_color(rand()%10, rand()%10, NamedColor.lightsalmon);
endcode
Author
Erik Saule
Date
72119

NonBlockingGame tutorial at: https://bridgesuncc.github.io/tutorials/NonBlockingGame.html

Public Member Functions

def __init__ (self, assid, login, apikey)
 PROTECTED constructor prevents the object from being directly created. More...
 
def fps (self)
 Get the frame rate at which the game running. More...
 
def fps (self, frames)
 Set the frame rate at which the game running. More...
 
def sleep_timer (self, timems=None)
 
def control_framerate (self)
 
def start (self)
 Call this function from main to start game. More...
 
def key_left (self)
 Is left currently pressed? More...
 
def key_right (self)
 Is right currently pressed? More...
 
def key_up (self)
 Is up currently pressed? More...
 
def key_down (self)
 Is down currently pressed? More...
 
def key_q (self)
 Is q currently pressed? More...
 
def key_space (self)
 Is space currently pressed? More...
 
def key_w (self)
 Is w currently pressed? More...
 
def key_a (self)
 Is a currently pressed? More...
 
def key_s (self)
 Is s currently pressed? More...
 
def key_d (self)
 Is right currently pressed? More...
 
- Public Member Functions inherited from bridges.gamebase3D.GameBase3D
def game_base_init (self, id, log, key)
 Initializes the gamebase object. More...
 
def close (self)
 close the socket connection (and game) More...
 
def register_keypress (self, kl)
 
def initialize (self)
 
def game_loop (self)
 
def quit (self)
 calling this function causes the game to end. More...
 
def set_title (self, title)
 sets title of game More...
 
def set_description (self, desc)
 sets description of the game More...
 
def render (self)
 renders the scene More...
 

Public Attributes

 time_of_last_frame
 
 ih
 
 game_started
 
- Public Attributes inherited from bridges.gamebase3D.GameBase3D
 firsttime
 
 bridges
 
 sock
 
 scene
 
 game_started
 

Additional Inherited Members

- Static Public Attributes inherited from bridges.gamebase3D.GameBase3D
bool debug = True
 

Constructor & Destructor Documentation

◆ __init__()

def bridges.non_blocking_game3D.NonBlockingGame3D.__init__ (   self,
  assid,
  login,
  apikey 
)

PROTECTED constructor prevents the object from being directly created.

Since GameBase is meant to be a purely internal class, that seems appropriate.

Parameters
assidassignment number
loginuser name
apikeyauthentication id
rowsheight of game grid
colswidth of game grid
Returns
None

Reimplemented from bridges.gamebase3D.GameBase3D.

Member Function Documentation

◆ control_framerate()

def bridges.non_blocking_game3D.NonBlockingGame3D.control_framerate (   self)

◆ fps() [1/2]

def bridges.non_blocking_game3D.NonBlockingGame3D.fps (   self)

Get the frame rate at which the game running.

Returns
The target framerate. The game could be somewhat slower depending on how computationally expensive the gameloop is and on the speed of the network

◆ fps() [2/2]

def bridges.non_blocking_game3D.NonBlockingGame3D.fps (   self,
  frames 
)

Set the frame rate at which the game running.

Parameters
framesframe rate to be set.

◆ key_a()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_a (   self)

Is a currently pressed?

Returns
true if a is currently pressed

◆ key_d()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_d (   self)

Is right currently pressed?

Returns
true d right is currently pressed

◆ key_down()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_down (   self)

Is down currently pressed?

Returns
true if down is currently pressed

◆ key_left()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_left (   self)

Is left currently pressed?

Returns
true if left is currently pressed

◆ key_q()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_q (   self)

Is q currently pressed?

Returns
true if q is currently pressed

◆ key_right()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_right (   self)

Is right currently pressed?

Returns
true if right is currently pressed

◆ key_s()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_s (   self)

Is s currently pressed?

Returns
true if s is currently pressed

◆ key_space()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_space (   self)

Is space currently pressed?

Returns
true if space is currently pressed

◆ key_up()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_up (   self)

Is up currently pressed?

Returns
true if up is currently pressed

◆ key_w()

def bridges.non_blocking_game3D.NonBlockingGame3D.key_w (   self)

Is w currently pressed?

Returns
true if w is currently pressed

◆ sleep_timer()

def bridges.non_blocking_game3D.NonBlockingGame3D.sleep_timer (   self,
  timems = None 
)

◆ start()

def bridges.non_blocking_game3D.NonBlockingGame3D.start (   self)

Call this function from main to start game.

Reimplemented from bridges.gamebase3D.GameBase3D.

Member Data Documentation

◆ game_started

bridges.non_blocking_game3D.NonBlockingGame3D.game_started

◆ ih

bridges.non_blocking_game3D.NonBlockingGame3D.ih

◆ time_of_last_frame

bridges.non_blocking_game3D.NonBlockingGame3D.time_of_last_frame

The documentation for this class was generated from the following file: