textures = {file[:file.index(".")]:pg.transform.scale(
pg.image.load(path.join("Assets/world/blocks", file)), (50, 50)) for
file in listdir("Assets/world/blocks")}
+ textures = {name: surf.convert() for name, surf in textures.items()}
+
width, height = textures["PLACEHOLDER"].get_size()
colour = (71, 77, 97)
from pygame import font
+from functools import lru_cache
-def createText(X, Y, size, textColour, weight, textInfo, alignment = "l"):
- fontx = font.Font(f"./Font/Exo2-{weight}.ttf", size)
- text = fontx.render(textInfo, True, textColour)
- textRect = text.get_rect()
- if(alignment == "left" or alignment == "l"):
- textRect = (X // 2, Y // 2) # Left aligned text
- elif(alignment == "center" or alignment == "c"):
- textRect.center = (X//2, Y//2) # Centered text
- elif(alignment == "right" or alignment == "r"):
- textRect.right = (X//2, Y//2) # Right aligned text
-
- return text, textRect;
\ No newline at end of file
+@lru_cache
+def get_font(weight, size):
+ return font.Font(f"./Font/Exo2-{weight}.ttf", size)
+
+
+def createText(X, Y, size, textColour, weight, textInfo, alignment="l"):
+ fontx = get_font(weight,size)
+
+ text = fontx.render(textInfo, True, textColour)
+ textRect = text.get_rect()
+ if (alignment == "left" or alignment == "l"):
+ textRect = (X // 2, Y // 2) # Left aligned text
+ elif (alignment == "center" or alignment == "c"):
+ textRect.center = (X // 2, Y // 2) # Centered text
+ elif (alignment == "right" or alignment == "r"):
+ textRect.right = (X // 2, Y // 2) # Right aligned text
+
+ return text, textRect;
def update(self, delta):
Setup.camera_offset = self.player.update(delta)
+ Setup.camera_offset.x = max(0, min(Setup.camera_offset.x, MAP_WIDTH - SCREEN_WIDTH))
+ Setup.camera_offset.y = max(0, min(Setup.camera_offset.y, MAP_HEIGHT - SCREEN_HEIGHT))
if self.player.dead:
self.level = self.scene.level
def get_display_rect(collision_rect):
- camera_offset.x = max(0, min(camera_offset.x, MAP_WIDTH - SCREEN_WIDTH))
- camera_offset.y = max(0, min(camera_offset.y, MAP_HEIGHT - SCREEN_HEIGHT))
-
pos = collision_rect.topleft
width, height = collision_rect.w, collision_rect.h
return pg.Rect(pos - camera_offset, (width, height))
def get_display_point(vec):
- camera_offset.x = max(0, min(camera_offset.x, MAP_WIDTH - SCREEN_WIDTH))
- camera_offset.y = max(0, min(camera_offset.y, MAP_HEIGHT - SCREEN_HEIGHT))
return vec - camera_offset
from Area import Area