-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.py
More file actions
70 lines (58 loc) · 2.38 KB
/
Copy pathBlock.py
File metadata and controls
70 lines (58 loc) · 2.38 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# coding=utf-8
import random
import pygame
from pygame import *
class Block(pygame.sprite.Sprite):
__width = 32
__height = 32
def __init__(self, x, y, block_type):
pygame.sprite.Sprite.__init__(self)
self.__type = block_type # Тип блока
self.__exist = True # Существование блока в мире
self.__bone_texture = "textures/items/bone.png" # Текстура кости
self.__dirt_texture = "textures/blocks/dirt.png" # Текстура грязи
self.__grass_side_texture = "textures/blocks/grass_side.png" # Текстура грязи с травой
self.__grass_textures = [ # Текстуры травы
"textures/blocks/crops_3.png",
"textures/blocks/crops_4.png",
"textures/blocks/deadbush.png",
"textures/blocks/flower.png",
"textures/blocks/netherStalk_0.png",
"textures/blocks/netherStalk_1.png",
"textures/blocks/rose.png",
"textures/blocks/sapling.png",
"textures/blocks/sapling_birch.png",
"textures/blocks/sapling_jungle.png",
"textures/blocks/sapling_spruce.png",
"textures/blocks/stem_bent.png",
"textures/blocks/stem_straight.png"
]
self.__draw_block(x, y)
def __draw_block(self, x, y):
if self.__type == "dirt":
self.image = image.load_extended(self.__dirt_texture)
elif self.__type == "grass_side":
self.image = image.load_extended(self.__grass_side_texture)
elif self.__type == "bone":
self.image = image.load_extended(self.__bone_texture)
elif self.__type == "grass":
self.image = image.load_extended(self.__grass_textures[random.randint(0, 12)])
self.rect = Rect(x, y, self.__width, self.__height)
def update(self, update_speed):
self.rect.x -= update_speed # Перенос позицию игрока по x
def destroy(self):
self.__exist = False
self.kill()
def get_type(self):
return self.__type
def get_exist(self):
return self.__exist
def set_exist(self, flag):
self.__exist = flag
@staticmethod
def get_blocks_width():
return Block.__width
@staticmethod
def get_blocks_height():
return Block.__height