HomeTurtlegraficsGPanelRoboticsGameGrid WebTigerPython
 Python - Online
Deutsch   English   

Dokumentation GameGrid

Import: from gamegrid import *

Class GameGrid (global functions when makeGameGrid() is called)

Method Aktion
makeGameGrid(nbHorzCells, nbVertCells, cellSize, color)
creates a game window with given number of horizontal and vertical cells, given cell size and visible grid lines with given color and a navigation bar
makeGameGrid(nbHorzCells, nbVertCells, cellSize, color, bgImagePath)
creates a game window with given number of horizontal and vertical cells, given cell size and visible grid lines with given color, and a navigation bar and a background image
makeGameGrid(nbHorzCells, nbVertCells, cellSize, None, bgImagePath, False)
creates a game window with given number of horizontal and vertical cells, given cell size and visible grid lines with given color, and a background image, but no navigation bar
act() invoked in every simulation cycle after all Actor.act()
addActor(actor, location) adds an actor to the game grid and shows it in the game window at given location
delay(time) stops execution for the given time (in millisecs)
doPause() stops the simulation cycling
doStep() executes one single simulation cycle
doReset() sets all actors to start position/direction
doRun() starts the simulation cycling
getActors(Actor class) returns all actors of given class (Python list)
getBgColor() returns the background color
getKeyCode() returns the code of the most recent key press
getOneActorAt(location, Actor class) returns the actor of the class in the given cell (None if none)
getRandomEmptyLocation() returns a random empty location
getRandomLocation() returns a random location
isAtBorder(location) returns True, if the cell ist at the border of the game window
isEmpty(location) returns True, if the cell is empty
isInGrid(location) returns True, if the cell is inside the game window
toLocation(x, y) returns the cell that contains the pixel coordinates (x, y)
refresh() renders the image double buffer on the screen (automatically for most operations)
removeActor(actor) removes an actor from the game grid
removeActorsAt(location)  removes all actors from the game grid at given location
removeAllActors() removes all actors from the game grid
show() makes a game window visible
setBgColor(color) sets the background color
setSimulationPeriod (milisec) sets the simulation period
setTitle(text) sets the game window title

Class Actor
Actor(spritepath) creates an actor with given sprite image
Actor(True, spritepath) creates a rotatable actor with given sprite image
Actor(spritepath, nbSprites) creates an actor with several sprite images (index _0, _1,... e.g.fish_0.gif , fish_1.gif,... )
Actor(True, spritepath, nbSprites) creates an rotatable actor with several sprite images
act() invoked periodically in every simulation cycle
addActorCollisionListener(listener) registers a collision listener
addCollisionActor(actor) registers a collision partner
addMouseTouchListener (event mask) registers a MouseTouchListener
collide(actor1, actor2) callback when a collision happens, returns the number of cycles in which the events are inhibited
getCollisionsActors() returns the list of collision actors
getDirection() returns the actor's direction
getIdVisible() returns the id of the currently visible sprite image
getNeighbours(distance) returns a list of all actors in given distance. The distance defines a circle around the current cell center (unit: cell width). All actors in cells that intersects with this circle are returned
getNextMoveLocation() returns the location of the next move() operation
getX() returns the x cell coordinate of the current location
getY() returns the y cell coordinate of the current location
hide() hides the actor, but does not remove it from the game grid
isInGrid() returns True, if the actor's location is inside the game grid
isHorzMirror() returns True, if the sprite image is mirror horizontally
isVertMirror() returns True, if the sprite image is mirror vertically
isMoveValid() returns True, if the actor remains inside the game grid by the next move()
isNearBorder() returns True, if the actor is in a cell near the border of the game grid
isVisible() returns True, if the actor is visible
move() moves the actor in the current direction to a neighbor location
move(distance) moves the actor in current direction for the given distance
setDirection(dir) sets the direction of movement of the actor
setHorzMirror(True) mirrors the sprite image horizontally
setVertMirror(True) mirrors the sprite image vertically
setSlowDown(factor) slows down the call of act() by the the given factor
setLocation(location) sets actor in cell with given location
setLocationOffset(point) moves actor's center to the point relative to the current cell (location unchanged)
setX(x) moves actor in cell with given x-coordinate (y-coordinate unchanged)
setY(y) moves actor in cell with given y-coordinate (x-coordinate unchanged)
show() shows sprite image with id 0
show(spriteId) shows sprite with given id
showNextSprite() shows sprite with id increased by 1 (modulo number of sprites)
showPreviousSprite() shows sprites with id decreased by 1
removeSelf() removes actor from game grid (the actor reference is still valid)
turn(angle) modifies the actor's direction (in degrees clockwise)

Class Location
Location(x, y) creates location with given coordinates
Location(location) creates location from given location (clone)
equals(location) returns True if the current location is the same as the given location
getDirectionTo(location) returns direction to the given location (in degrees, clockwise, zero to NORTH)
getCompassDirectionTo(location) returns the direction from the current position to the given position
get4CompassDirectionTo(location) returns the direction from the current position to the given position (only the 4 main directions)
getNeighbourLocation(direction) returns the neighbor location that fits best the given direction
getNeighbourLocations(distance) returns all locations of cells with center within given distance
getX() or loc.x returns the current horizontal coordinate
getY() or loc.y returns the current vertical coordinate


Callback registration

makeGameGrid(10,10,60, Color.red,False, mousePressed = pressCallback) registers the callback function pressCallback, which responds when a mouse button is pressed
makeGameGrid(10,10,60, Color.red,False, mouseDragged = dragCallback) registers the callback function dragCallback, which responds to movement with the mouse button pressed
makeGameGrid(10,10,60, Color.red,False, mouseReleased = releaseCallback) registers the callback function releaseCallback, which responds to the mouse button being released
addMouseTouchListener
(onMouseEvent, mask)
registriers a MouseListener, Maske: GGMouse.lDrag, GGMouse.lPress, GGMouse.lRelease)
makeGameGrid(10,10,60, Color.red,False, keyPressed = keyCallback registers the callback function keyCallback, which responds when a key is pressed

Sound

Import: from gmusic import playTone
playTone(frequency, duration) plays sound at the given frequency for a specified number of milliseconds

Import: from soudsystem import * : provides the sound library
openSoundPlayer("wav/ping.wav") opens a WAV formatted sound file for playing

play()

plays the opened sound file

Some sound files are ditributed with WebTigerPython:
bird.wav, boing.wav, cat.wav, click.wav, explode.wav, fade.wav, flute.wav, frog.wav, mmm.wav, notify.wav, oboe.wav, ping.wav