From e936541e63bf84a70c5261eacf4cd886b01b4181 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Sun, 1 Jan 2023 19:40:19 -0600 Subject: [PATCH] log png --- assets/log.png | Bin 0 -> 813 bytes creeper.py | 46 +++++++++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 assets/log.png diff --git a/assets/log.png b/assets/log.png new file mode 100644 index 0000000000000000000000000000000000000000..3c8e15145f3a397aa114b356d363fb1e73c54faa GIT binary patch literal 813 zcmV+|1JeA7P)7x64t5Z6$WTSWf~bh2RIvyaN?V~-2a}inL6e3g#l=x@EjakI zSaoo5*44pP5CnffTwRBNdN{+1#oa zc!iI?5XLYnF;h>Z7c=mzuY2mHx{LBG@4i2)Psy7M@QK88OgAjz4dR(iOXs{#9A+g+ zAwDM_H|T)Gk6f2se&bwpSm2pqBa@mZ4ik&T4wgHZl?;`5nmD4U8s!UFmle)ioYhK= zwa&?J7|d%cX|B^6LL5s-APEsNYAB-u3sL%Oq?kz2e$2x^==hW5lF3yDBgX=&P$4;f z@HhB9TeC1V=_UnZK=+Gne+&bGU7%UF?eAmTZk_=CXW&X}`>PFL_LKB_TZ5#e zx~<83z~v4w@T5zIpV2erfc{&ccg>w!Yagc%K!#?ud;=UD0wYDrUiY|n zPv_kJ?P<;L2ZlRxuj8?JcmMzZ19L)2R0s$N+u={(00048Nkl|fX@PDNmfdXCTsyo;NzEH5X6A$X%q`6j{rObkSX&&Myn4xW8Vq=}G}iedrP0X##HW&!b@Kn7Iv z0j_wWdvT2)eE#$SQxLg^q0|D19aycw1+e4;c=E?@4KJSnITjFOI@}Hh1_oX}0sN^8 rC5VVO9nBhIEx->*EfCSNG_3#tz>$!qJpkeB00000NkvXXu0mjf&+lBB literal 0 HcmV?d00001 diff --git a/creeper.py b/creeper.py index b833793..623083a 100755 --- a/creeper.py +++ b/creeper.py @@ -1,4 +1,5 @@ import random +from copy import copy from itertools import cycle, repeat from pathlib import Path @@ -121,13 +122,19 @@ class HotBarItem: self.pos = pos self.selected = False self.surf.fill((0, 0, 0)) + self.type = None def draw(self): + self.surf.fill((0, 0, 0, 20)) if self.selected: - self.surf.fill((100, 100, 100)) - else: - self.surf.fill((0, 0, 0)) - self.ui.blit(self.surf, (self.pos * 24 + 4, 4)) + self.surf.fill((185, 185, 205, 60)) + + if self.type: + self.img = pygame.image.load(f"assets/{self.type}.png") + self.ui.blit( + pygame.transform.scale(self.img, (16, 16)), (self.pos * 24 + 4, 4) + ) + self.ui.blit(self.surf.convert_alpha(), (self.pos * 24 + 4, 4)) class LightSource: @@ -201,6 +208,7 @@ class Bee: class Creeper(Game): def __init__(self): super().__init__() + self.inventory = {} self.day_len = 1000 * 60 self.background = pygame.Surface(self.screen.get_size()) self.foreground = pygame.Surface(self.screen.get_size()) @@ -248,6 +256,8 @@ class Creeper(Game): ) ) self.joysticks = {} + self.hotbar_back_debounce = 0 + self.hotbar_forward_debounce = 0 def attack(self): @@ -260,11 +270,20 @@ class Creeper(Game): tree.hit = True tree.shake() + def process_deaths(self): + for i, tree in enumerate(copy(self.trees)): + if tree.health <= 0: + self.hotbar.items[0].type = "log" + self.inventory["log"] = self.inventory.get("log", 0) + 10 + del self.trees[i] + print(f"you have {self.inventory['log']} log") + def game(self): creeper = next(self.creepers) self.mouse_box = MouseSprite(self.screen) self.screen.blit(self.background, (0, 0)) self.background.fill((0, 255, 247)) + self.process_deaths() for tree in self.trees: tree.draw() @@ -324,27 +343,24 @@ class Creeper(Game): # joystick, filling up the list without needing to create them manually. joy = pygame.joystick.Joystick(event.device_index) self.joysticks[joy.get_instance_id()] = joy - print(f"Joystick {joy.get_instance_id()} connencted") if event.type == pygame.JOYDEVICEREMOVED: del self.joysticks[event.instance_id] - print(f"Joystick {event.instance_id} disconnected") - print(self.joysticks) for joystick in self.joysticks.values(): - if joystick.get_button(4) and self.hotbar_debounce: + if joystick.get_button(4) and self.hotbar_back_debounce: self.hotbar.next(-1) - self.hotbar_debounce = 0 + self.hotbar_back_debounce = 0 + elif not joystick.get_button(4): + self.hotbar_back_debounce = 1 - if joystick.get_button(5) and self.hotbar_debounce: + if joystick.get_button(5) and self.hotbar_forward_debounce: self.hotbar.next(1) - self.hotbar_debounce = 0 - - if not joystick.get_button(4) and not joystick.get_button(5): - self.hotbar_debounce = 1 + self.hotbar_forward_debounce = 0 + elif not joystick.get_button(5): + self.hotbar_forward_debounce = 1 hats = joystick.get_numhats() - print("numhats", hats) for i in range(hats): hat = joystick.get_hat(i) if hat[0] == 1: