This commit is contained in:
Waylon Walker 2023-07-01 13:51:57 -05:00
parent 32c78767df
commit c3b1f40a58
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
3 changed files with 46 additions and 25 deletions

View file

@ -36,7 +36,7 @@ class Client:
self.menu = Menu(self) self.menu = Menu(self)
self.map = Map(self) self.map = Map(self)
self.light = Light(self) self.light = Light(self)
self.font = pygame.font.SysFont("", 50) self.font = pygame.font.SysFont("", 25)
self.joysticks = {} self.joysticks = {}
self.darkness = pygame.Surface( self.darkness = pygame.Surface(
(self.screen.get_width(), self.screen.get_height()) (self.screen.get_width(), self.screen.get_height())
@ -62,10 +62,10 @@ class Client:
return self._ws return self._ws
def run(self): def run(self):
# from pyinstrument import Profiler from pyinstrument import Profiler
# profiler = Profiler() profiler = Profiler()
# profiler.start() profiler.start()
while self.running: while self.running:
console.print("running") console.print("running")
console.print("handle_events") console.print("handle_events")
@ -80,8 +80,8 @@ class Client:
Console().print(self.clock.get_fps()) Console().print(self.clock.get_fps())
console.print(f"time: {time}") console.print(f"time: {time}")
console.print(f"ticks: {self.ticks}") console.print(f"ticks: {self.ticks}")
# profiler.stop() profiler.stop()
# print(profiler.output_text()) print(profiler.output_text())
self.quit() self.quit()
def quit(self): def quit(self):

View file

@ -36,6 +36,10 @@ class Map:
self.persistence = 0.05 # Amplitude of each octave self.persistence = 0.05 # Amplitude of each octave
self.lacunarity = 1.0 # Frequency of each octave self.lacunarity = 1.0 # Frequency of each octave
self.thresh = 125 self.thresh = 125
# try to load the map from map.png
try:
self.surf = pygame.image.load("map.png").convert_alpha()
except FileNotFoundError:
self.pre_draw() self.pre_draw()
def refresh_surf(self): def refresh_surf(self):
@ -66,6 +70,7 @@ class Map:
def pre_draw(self): def pre_draw(self):
self.refresh_surf() self.refresh_surf()
for x in range(int(self.screen_width)): for x in range(int(self.screen_width)):
for y in range(int(self.screen_height)): for y in range(int(self.screen_height)):
if not self.point_check_collision(x, y): if not self.point_check_collision(x, y):
@ -80,6 +85,7 @@ class Map:
), ),
) )
pygame.image.save(self.surf, "map.png") pygame.image.save(self.surf, "map.png")
# av1 = ( # av1 = (
# Image.open("rock.jpg") # Image.open("rock.jpg")
# .convert("RGB") # .convert("RGB")

View file

@ -21,6 +21,7 @@ class Player:
flashlight_angle=0, flashlight_angle=0,
) )
self.hero = HeroCreate(**hero.dict()).post() self.hero = HeroCreate(**hero.dict()).post()
self.hero.size = 64
self.game = game self.game = game
self.others = [] # Heros(heros=[]) self.others = [] # Heros(heros=[])
@ -31,7 +32,10 @@ class Player:
self.y = self.game.screen.get_height() / 2 self.y = self.game.screen.get_height() / 2
self.speed = 10 self.speed = 10
self.max_speed = 10 self.max_speed = 10
self.image = pygame.image.load("player.png").convert_alpha() self.image = pygame.image.load("creeper.png").convert_alpha()
self.image = pygame.transform.scale(
self.image, (self.hero.size, self.hero.size)
)
self.x_last = self.x self.x_last = self.x
self.y_last = self.y self.y_last = self.y
self.hitbox_surface = pygame.Surface((self.width, self.height)) self.hitbox_surface = pygame.Surface((self.width, self.height))
@ -201,7 +205,7 @@ class Player:
self.x_last = self.hero.x self.x_last = self.hero.x
self.y_last = self.hero.y self.y_last = self.hero.y
if self.game.ticks % 30 == 0 or self.game.ticks == 0: # if self.game.ticks % 1 == 0 or self.game.ticks == 0:
console.print("updating") console.print("updating")
update = HeroUpdate(**self.hero.dict(exclude_unset=True)) update = HeroUpdate(**self.hero.dict(exclude_unset=True))
console.print(update) console.print(update)
@ -222,18 +226,29 @@ class Player:
def render(self): def render(self):
for other in self.others.__root__: for other in self.others.__root__:
if other.id != self.hero.id: if other.id != self.hero.id:
pygame.draw.circle( # put self.image on the game.screen
self.game.screen, (255, 0, 0), (other.x, other.y), other.size
)
self.game.screen.blit( self.game.screen.blit(
self.game.font.render(other.name, False, (255, 255, 255), 1), self.image,
(other.x, other.y), (other.x - other.size / 2, other.y - other.size / 2),
) )
pygame.draw.circle( # pygame.draw.circle(
self.game.screen, (0, 0, 255), (self.hero.x, self.hero.y), self.hero.size # self.game.screen, (255, 0, 0), (other.x, other.y), other.size
# )
self.game.screen.blit(
self.game.font.render(other.name, False, (255, 255, 255), 1),
(other.x - other.size / 2, other.y + other.size / 2),
) )
self.game.screen.blit( self.game.screen.blit(
self.game.font.render(self.hero.name, False, (255, 255, 255), 1), self.image,
(self.hero.x, self.hero.y), (self.hero.x - self.hero.size / 2, self.hero.y - self.hero.size / 2),
)
# pygame.draw.circle(
# self.game.screen, (0, 0, 255), (self.hero.x, self.hero.y), self.hero.size
# )
self.game.screen.blit(
self.game.font.render(self.hero.name, False, (255, 255, 255), 1),
(self.hero.x - self.hero.size / 2, self.hero.y + self.hero.size / 2),
) )