wip
This commit is contained in:
parent
32c78767df
commit
c3b1f40a58
3 changed files with 46 additions and 25 deletions
|
|
@ -36,7 +36,7 @@ class Client:
|
|||
self.menu = Menu(self)
|
||||
self.map = Map(self)
|
||||
self.light = Light(self)
|
||||
self.font = pygame.font.SysFont("", 50)
|
||||
self.font = pygame.font.SysFont("", 25)
|
||||
self.joysticks = {}
|
||||
self.darkness = pygame.Surface(
|
||||
(self.screen.get_width(), self.screen.get_height())
|
||||
|
|
@ -62,10 +62,10 @@ class Client:
|
|||
return self._ws
|
||||
|
||||
def run(self):
|
||||
# from pyinstrument import Profiler
|
||||
from pyinstrument import Profiler
|
||||
|
||||
# profiler = Profiler()
|
||||
# profiler.start()
|
||||
profiler = Profiler()
|
||||
profiler.start()
|
||||
while self.running:
|
||||
console.print("running")
|
||||
console.print("handle_events")
|
||||
|
|
@ -80,8 +80,8 @@ class Client:
|
|||
Console().print(self.clock.get_fps())
|
||||
console.print(f"time: {time}")
|
||||
console.print(f"ticks: {self.ticks}")
|
||||
# profiler.stop()
|
||||
# print(profiler.output_text())
|
||||
profiler.stop()
|
||||
print(profiler.output_text())
|
||||
self.quit()
|
||||
|
||||
def quit(self):
|
||||
|
|
|
|||
|
|
@ -36,7 +36,11 @@ class Map:
|
|||
self.persistence = 0.05 # Amplitude of each octave
|
||||
self.lacunarity = 1.0 # Frequency of each octave
|
||||
self.thresh = 125
|
||||
self.pre_draw()
|
||||
# try to load the map from map.png
|
||||
try:
|
||||
self.surf = pygame.image.load("map.png").convert_alpha()
|
||||
except FileNotFoundError:
|
||||
self.pre_draw()
|
||||
|
||||
def refresh_surf(self):
|
||||
|
||||
|
|
@ -66,6 +70,7 @@ class Map:
|
|||
|
||||
def pre_draw(self):
|
||||
self.refresh_surf()
|
||||
|
||||
for x in range(int(self.screen_width)):
|
||||
for y in range(int(self.screen_height)):
|
||||
if not self.point_check_collision(x, y):
|
||||
|
|
@ -80,6 +85,7 @@ class Map:
|
|||
),
|
||||
)
|
||||
pygame.image.save(self.surf, "map.png")
|
||||
|
||||
# av1 = (
|
||||
# Image.open("rock.jpg")
|
||||
# .convert("RGB")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class Player:
|
|||
flashlight_angle=0,
|
||||
)
|
||||
self.hero = HeroCreate(**hero.dict()).post()
|
||||
self.hero.size = 64
|
||||
|
||||
self.game = game
|
||||
self.others = [] # Heros(heros=[])
|
||||
|
|
@ -31,7 +32,10 @@ class Player:
|
|||
self.y = self.game.screen.get_height() / 2
|
||||
self.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.y_last = self.y
|
||||
self.hitbox_surface = pygame.Surface((self.width, self.height))
|
||||
|
|
@ -201,16 +205,16 @@ class Player:
|
|||
self.x_last = self.hero.x
|
||||
self.y_last = self.hero.y
|
||||
|
||||
if self.game.ticks % 30 == 0 or self.game.ticks == 0:
|
||||
console.print("updating")
|
||||
update = HeroUpdate(**self.hero.dict(exclude_unset=True))
|
||||
console.print(update)
|
||||
self.game.ws.send(update.json())
|
||||
console.print("sent")
|
||||
# if self.game.ticks % 1 == 0 or self.game.ticks == 0:
|
||||
console.print("updating")
|
||||
update = HeroUpdate(**self.hero.dict(exclude_unset=True))
|
||||
console.print(update)
|
||||
self.game.ws.send(update.json())
|
||||
console.print("sent")
|
||||
|
||||
raw_heros = self.game.ws.recv()
|
||||
console.print(raw_heros)
|
||||
self.others = Heros.parse_raw(raw_heros)
|
||||
raw_heros = self.game.ws.recv()
|
||||
console.print(raw_heros)
|
||||
self.others = Heros.parse_raw(raw_heros)
|
||||
|
||||
def draw(self):
|
||||
self.move()
|
||||
|
|
@ -222,18 +226,29 @@ class Player:
|
|||
def render(self):
|
||||
for other in self.others.__root__:
|
||||
if other.id != self.hero.id:
|
||||
pygame.draw.circle(
|
||||
self.game.screen, (255, 0, 0), (other.x, other.y), other.size
|
||||
)
|
||||
# put self.image on the game.screen
|
||||
self.game.screen.blit(
|
||||
self.game.font.render(other.name, False, (255, 255, 255), 1),
|
||||
(other.x, other.y),
|
||||
self.image,
|
||||
(other.x - other.size / 2, other.y - other.size / 2),
|
||||
)
|
||||
|
||||
pygame.draw.circle(
|
||||
self.game.screen, (0, 0, 255), (self.hero.x, self.hero.y), self.hero.size
|
||||
# pygame.draw.circle(
|
||||
# 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.image,
|
||||
(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.y),
|
||||
(self.hero.x - self.hero.size / 2, self.hero.y + self.hero.size / 2),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue