cursor on blocks
This commit is contained in:
parent
3ce8002e0e
commit
3846ae096e
1 changed files with 15 additions and 6 deletions
19
creeper.py
19
creeper.py
|
|
@ -10,9 +10,9 @@ from game import Game
|
||||||
|
|
||||||
|
|
||||||
class MouseSprite:
|
class MouseSprite:
|
||||||
def __init__(self, surf):
|
def __init__(self, surf, hotbar):
|
||||||
self.surf = surf
|
self.surf = surf
|
||||||
self.image = pygame.image.load("assets/spotlight.png")
|
self.hotbar = hotbar
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mouse_pos(self):
|
def mouse_pos(self):
|
||||||
|
|
@ -23,7 +23,14 @@ class MouseSprite:
|
||||||
return pygame.Rect(self.mouse_pos, (4, 4))
|
return pygame.Rect(self.mouse_pos, (4, 4))
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
if self.hotbar.selected.type is None:
|
||||||
pygame.draw.rect(self.surf, (255, 0, 0), self.rect)
|
pygame.draw.rect(self.surf, (255, 0, 0), self.rect)
|
||||||
|
else:
|
||||||
|
self.img = pygame.image.load(f"assets/{self.hotbar.selected.type}.png")
|
||||||
|
self.surf.blit(
|
||||||
|
pygame.transform.scale(self.img, (32, 32)),
|
||||||
|
[i - (i % 32) for i in pygame.mouse.get_pos()],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TreeSprite:
|
class TreeSprite:
|
||||||
|
|
@ -208,10 +215,11 @@ class Bee:
|
||||||
class Creeper(Game):
|
class Creeper(Game):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.inventory = {}
|
self.inventory = {"log": 10}
|
||||||
self.day_len = 1000 * 60
|
self.day_len = 1000 * 60
|
||||||
self.background = pygame.Surface(self.screen.get_size())
|
self.background = pygame.Surface(self.screen.get_size())
|
||||||
self.foreground = pygame.Surface(self.screen.get_size())
|
self.foreground = pygame.Surface(self.screen.get_size())
|
||||||
|
self.build = pygame.Surface(self.screen.get_size())
|
||||||
self.ui = pygame.Surface((24 * 8, 24), pygame.SRCALPHA, 32).convert_alpha()
|
self.ui = pygame.Surface((24 * 8, 24), pygame.SRCALPHA, 32).convert_alpha()
|
||||||
self.ui.fill((50, 50, 50))
|
self.ui.fill((50, 50, 50))
|
||||||
self.darkness = pygame.Surface(self.screen.get_size()).convert_alpha()
|
self.darkness = pygame.Surface(self.screen.get_size()).convert_alpha()
|
||||||
|
|
@ -238,6 +246,7 @@ class Creeper(Game):
|
||||||
self.bee = Bee()
|
self.bee = Bee()
|
||||||
x = 0
|
x = 0
|
||||||
self.hotbar = HotBar(game=self, surf=self.ui)
|
self.hotbar = HotBar(game=self, surf=self.ui)
|
||||||
|
self.hotbar.items[0].type = "log"
|
||||||
self.leafs = []
|
self.leafs = []
|
||||||
self.trees = []
|
self.trees = []
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
|
|
@ -273,14 +282,12 @@ class Creeper(Game):
|
||||||
def process_deaths(self):
|
def process_deaths(self):
|
||||||
for i, tree in enumerate(copy(self.trees)):
|
for i, tree in enumerate(copy(self.trees)):
|
||||||
if tree.health <= 0:
|
if tree.health <= 0:
|
||||||
self.hotbar.items[0].type = "log"
|
|
||||||
self.inventory["log"] = self.inventory.get("log", 0) + 10
|
self.inventory["log"] = self.inventory.get("log", 0) + 10
|
||||||
del self.trees[i]
|
del self.trees[i]
|
||||||
print(f"you have {self.inventory['log']} log")
|
print(f"you have {self.inventory['log']} log")
|
||||||
|
|
||||||
def game(self):
|
def game(self):
|
||||||
creeper = next(self.creepers)
|
creeper = next(self.creepers)
|
||||||
self.mouse_box = MouseSprite(self.screen)
|
|
||||||
self.screen.blit(self.background, (0, 0))
|
self.screen.blit(self.background, (0, 0))
|
||||||
self.background.fill((0, 255, 247))
|
self.background.fill((0, 255, 247))
|
||||||
self.process_deaths()
|
self.process_deaths()
|
||||||
|
|
@ -315,6 +322,8 @@ class Creeper(Game):
|
||||||
for hot_bar_item in self.hotbar.items:
|
for hot_bar_item in self.hotbar.items:
|
||||||
hot_bar_item.draw()
|
hot_bar_item.draw()
|
||||||
|
|
||||||
|
self.mouse_box = MouseSprite(self.screen, hotbar=self.hotbar)
|
||||||
|
|
||||||
y = self.screen.get_size()[1] - 24 - 4
|
y = self.screen.get_size()[1] - 24 - 4
|
||||||
x = self.screen.get_size()[0] / 2 - (24 * 8 - 8) / 2
|
x = self.screen.get_size()[0] / 2 - (24 * 8 - 8) / 2
|
||||||
self.screen.blit(
|
self.screen.blit(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue