AffichPygame Module

Generical classe and functions from Pygame to make the graphical user interface (GUI). This script provides shortcuts and utilities to other modules, but it can also be used to check the compatibility with pygame.

In a terminal, launching the scrit, with $ ./AffichPygame.py, will launch a demo.

Warning

The Python binding to SDL, Pygame, is required for the project as well as for this demo.

Example:

This show how the graphical window looks like during the game (for the client) :
_images/exemplegraphical.png

About:

This module use the datas store in ./datas/ folder.
  • The sprites are made with ‘.png’ pictures, usually this is supported on every platform;
  • The soundtrack is made with ‘.mp3’ tracks.

Warning

On some Linux distribution mp3 are not supported !
Maybe we have to install some extra libs.

Or maybe you don’t have a sound server.

Hint

You can disable music for the client and the bot with the –nomusic and –nosoundeffect options.

Soundtrack:

In the folder datas/sound/:

Here are stored all the sound used for the game. Those mp3 music tracks are used by the client.

The music can be disable with the –nomusic option, or you can force to try to launch it with the –music option.

A description:

  1. battle.mp3, menu.mp3, oeuf.mp3 : One of those 3 is chosed for the soundtrack of the game (and play in loop).
  2. explosion.mp3 : When a bomb blow.
  3. item.mp3 : When a new bonus is catched (not yet fully implemented).
  4. world_clear.mp3 : When the game is done (and only if you wan !).

About the soundtrack:

The soundtrack is from many different sources. This is an exhaustive list :

  1. The Legend of Zelda - Ocarina of Time, Link’s awakening (Nintendo (c) 1991 & 1997);
  2. Super Mario World 1 (Nintendo (c) 1985);
  3. Super Smash Bros Melee (Nintendo (c) 2001 - HAL Laboratory),

Copyrigths:

The game is released under the GPLv3 Licence, but the soundtrack is not distributed freely with the game (at least, not under a free licence). Although, you can download it from the same source that the game (just not in the same archive).

Pictures:

In the folder datas/48_48/:

Here are stored all the pictures used for the game. Those png pictures are used by the client, to build a GUI with PyGame.

The GUI can be disable with the –nowindow option, or you can force to try to launch it with the –window option. The game should run without any additionnal window. But maybe it require an X server anyway.

A description:

  1. block_destr.png, block_undestr.png: For the wall (destructible or not).
  2. player{0|1|2|3|4|5|6|7|8|9}.png : For the players (many different models).
  3. bomb_{1|2|3|4} : For the bombs (many different models).

About the pictures:

The soundtrack is from many different sources. This is a non exhaustive list.

  1. Pacman (Nintendo (c) 1991);
  2. Super Mario World 1 (Nintendo (c) 1985);
  3. Pokémon Red/Blue (Nintendo (c) 1995 - GameFreak).

Moreover, some images were made with an online generator [http://www.softicons.com/icon-tools/icon-converter], so you can also use this to make your own !

Copyrigths:

The game is released under the GPLv3 Licence, but the soundtrack is not distributed freely with the game (at least, not under a free licence). Although, you can download it from the same source that the game (just not in the same archive).

Warning

When the main window is initialized, this module try to set her icon.
Sometime it works : so you can see a nice bomberman player as an icon for your window. Sometime it doesn’t. I wasn’t able to understand why this seems to act randomly, sorry.

TODOs:

  • Try to update the sprite only when it changed.
  • Find a cool sound for game over.
AffichPygame.PICTURE_block_destr = 'block_destr.png'

For a destructible spot.

AffichPygame.PICTURE_block_solid = 'block_solid.png'

For an undestructible spot.

AffichPygame.PICTURE_player = 'player%i.png'

For players.

AffichPygame.PICTURE_player_direction = 'player_%s.png'

For players.

AffichPygame.PICTURE_bomb = 'bomb%i.png'

For bombs.

AffichPygame.PICTURE_bonus = 'bonus_%s.png'

For bonuses.

AffichPygame.PICTURE_block_bonus = 'block_bonus.png'

For a spot with a bonus.

AffichPygame.MUSIC_world_clear = 'world_clear.mp3'

When a player (not the active one) win the game.

AffichPygame.MUSIC_bonus_main = 'item.mp3'

When the active player get a bonus.

AffichPygame.MUSIC_explosion = 'explosion.mp3'

When a bomb is exploding.

AffichPygame.MUSIC_loop_list = ['battle.mp3', 'oeuf.mp3', 'menu.mp3']

Random : choose from this list !

AffichPygame.MUSIC_loop() → music file name[source]
AffichPygame.color_to_number(color)[source]

Convert one of the following color [‘black’, ‘red’, ‘green’, ‘yellow’, ‘blue’, ‘magenta’, ‘cyan’, ‘white’], to an integer between 1 and 8 (to choose the right picture).

AffichPygame.load_tile_table(filename, width, height)[source]

A test to use a picture as an array of sub pictures.

AffichPygame.namePicture_of_SpriteSpot(state, verb=False)[source]

Give the name of the picture used to print the state.

If more than one player is in the same spot, return the first one.

See how return more than one pictures,
and make a blur effect to show all of the returned pictures.
AffichPygame.load_png(name, verb=False)[source]

Load a picture, and return a image object.

The picture have to be in the folder ./datas/48_48/, or ./datas/32_32/,
otherwise, error might occur quickly :s !
About:
A lot of pre set pictures are from softicons.com, and a few of them where made by their tools [http://www.softicons.com/icon-tools/icon-converter].
AffichPygame.play_music(name, number=-1, volume=1.0, time=0.0, verb=True)[source]

Load a music. Set the volume to volume, and play it number time. To play in loop, set number=-1.

The music have to be in the folder ./sound/,
otherwise, error might occur quickly :s !
About the soundtrack:

The default soundtrack is from many different sources. This is an exhaustive list :

  • Pokemon Red (Nintendo (c) 1995 - GameFreak);
  • The Legend of Zelda - Ocarina of Time, Link’s awakening (Nintendo (c) 1991 & 1997);
  • Super Mario World 1 (Nintendo (c) 1985);
  • Super Smash Bros Melee (Nintendo (c) 2001 - HAL Laboratory).
Copyrigths:
The game is released under the GPLv3 Licence,
but the soundtrack is not distributed freely with the game (at least, not under a free licence).

Although, you can download it from the same source that the game (just not in the same archive).

class AffichPygame.SpriteSpot(state, pos=(0, 0))[source]

Bases: pygame.sprite.Sprite

A simple class for a spot (instance of Board.State) in the board. This one is more oriented around moves by direct order.

FIXME: use update ?

__init__(state, pos=(0, 0))[source]

Spot is a wrapper around Board.State, and state is attend to be one of this.

state = None

The Spot contain a state.

reinit(pos)[source]

Initialize the sprite, make it stable.

update()[source]

Update the position of the sprite.

For now, it is done stupidly : the sprites are all recomputed each turn. FIXME: make sure this is done more cleverly.

AffichPygame.TRY_UPDATE_CLEVERLY = False

If true, try to update ony the changed sprites.

AffichPygame.listsprite_of_board(board, verb = False) → pygame.Sprites[source]
AffichPygame.toggle_explosion(board, pl, clock, MAKE_DESTROY=False, num_thread=0) → infinite loop[source]

A small function to toggle explosions tag when they have to be erased.

On the server, MAKE_DESTROY is True, and is False on the client.

Have to be threaded too.

AffichPygame.main(nbmax, lx, ly, pl, board, Mi, Mj, verb=False)[source]

The main loop for testing.

Notice that every thing here will have to be put in the correct spot in BombermanClient.