HomeTurtlegraficsGPanelRoboticsGameGrid WebTigerPython
 Python - Online
spielfenster
Deutsch   English   

1. THE GAME WINDOW

 

 

YOU LEARN HERE...

 

how to create a game window using the GameGrid class. All characters and objects appear in the game window.

 

 

EXAMPLES

 

The game window is structured as a grid and consists of a certain number of square cells. The cell size and the number of cells in the horizontal and vertical directions can be freely selected. Larger cells are suitable for certain applications (grid games), while other applications benefit from using cells that are only 1 pixel in size (pixel games). The cell coordinates are used for positioning within the graphics window.

The size and appearance of the game window is determined by selecting the parameters when creating the game window. In the first example, the parameters (number of horizontal cells, number of vertical cells, cell size and colour of the grid lines) are used.

from gamegrid import * imports the GameGrid module.

makeGameGrid(10, 10, 60, Color.red) creates a game window with 10 horizontal and 10 vertical cells, cell sizes of 60 pixels and red grid lines. The 600x600 pixel graphics window appears after calling the show() method. The navigation bar with the Step, Run, Reset buttons and a slider has no effect in this example.

 

Program:

# Gg1.py
from gamegrid import *

makeGameGrid(10, 10, 60, Color.red)
# makeGameGrid(20, 20, 20, Color.green)
# makeGameGrid(10, 10, 60, Color.red, "sprites/reef.gif")
# makeGameGrid(10, 10, 60, Color.red, "sprites/reef.gif", False)
# makeGameGrid(600, 600, 1, None, "sprites/town.jpg", False)
show() 
► Copy to clipboard

Click on the ‘WebTigerPython’ button to insert the programme into the WTP editor. Start the programme with the green start arrow. You can stop the programme execution with the red stop button.


 

makeGameGrid() can have additional parameters. By activating the commented-out lines in the programme code, you can create additional game windows:

makeGameGrid(20, 20, 30, Color.green)

20x20 cells, 30 pixels in size, green grid lines:.
  makeGameGrid(10,10,60,Color.red,
"sprites/reef.git")

Window with background image reef.gif:
 
     

makeGameGrid(10, 10, 60, Color.red, 
"sprites/reef.gif", False)

The parameter False causes the navigation bar not to be displayed:.

 

makeGameGrid(600, 600, 1, None, 
"sprites/town.jpg", False)

Window with 1-pixel resolution, without grid lines (parameter None) and without navigation bar

 

All background images used in our learning environment are included in the WebTigerPython distribution. The size of the background image must match the size of the game window. The background images in our examples are mostly 601x601 pixels in size. You can find an overview of the images available in the distribution in the documentation under the link Image Library.

 

 

REMEMBER YOU...

 

The size and appearance of the window is determined by the choice of parameters in the makeGameGrid() command.

makeGameGrid(nbHorzCells, nbVertCells, cellSize, color) creates a game window without grid lines, with a background image and without a navigation bar.

makeGameGrid(nbHorzCells, nbVertCells, cellSize, None, bgImage, False) creates a game window without grid lines, with a background image and without a navigation bar.

 

 

TO SOLVE BY YOURSELF

 
1. Create a game window with 5 horizontal and 5 vertical cells, 120 pixels in size and yellow grid lines.

2.

Create a 600x600 pixel game window with 1-pixel resolution, without grid lines, using the background image ‘sprites/mazegrid.gif’, which depicts a maze.