/
Block_Module.py
52 lines (38 loc) · 1.42 KB
/
Block_Module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
This module creates the object type Block, and several subfunctions which
generate specific varieties of the Block class.
"""
import pygame
class Block(object):
'''Hold all the data about '''
graphics_names = ['tree.png', 'water.png', 'grass.png', 'dirt.png', 'wood.png', 'water.png']
Graphics = {item: pygame.image.load('graphics/' + item) for item in graphics_names}
def __init__(self, name, graphic, walkable=True, destructible=False, drop=None):
"""
Defines the Block objecct type.
"""
self.name = name
self.graphic = graphic #Filename for the block's image
self.walkable = walkable #Whether the player can move on top of the block
self.destructible = destructible #Whether or not a block can be mined
self.drop = drop #What is added to the player inventory if the block is mines
def __str__(self):
return self.name
def loadgraphic(self):
'''loads the pygame image that is supposed to represent a block'''
return Block.Graphics[self.graphic]
"""
These functions return a distinct block with specific parameters.
"""
def Tree():
return Block('tree', 'tree.png', False, True, Wood)
def Water():
return Block('water', 'water.png', False, True, Water)
def Grass():
return Block('grass', 'grass.png', True, True, Grass)
def Dirt():
return Block('dirt', 'dirt.png', True, False)
def Wood():
return Block('wood', 'wood.png', False, True, Wood)
def Blank():
return Block('blank', 'water.png', False, False)