2021-03-14 22:43:26 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
import pygame
|
|
|
|
|
|
|
|
|
|
|
|
class Image:
|
2021-05-24 13:10:10 +02:00
|
|
|
def __init__(self, filename, pos=(0, 0), scale=1):
|
2021-03-14 22:43:26 +01:00
|
|
|
self.texture = pygame.image.load(os.path.join('..', 'assets', filename)).convert_alpha()
|
|
|
|
self.image = self.texture
|
|
|
|
self.origin = (0, 0)
|
2021-05-24 13:10:10 +02:00
|
|
|
self.pos = pos
|
|
|
|
self.set_scale(scale)
|
2021-03-14 22:43:26 +01:00
|
|
|
|
|
|
|
def set_scale(self, scale):
|
|
|
|
self.image = pygame.transform.scale(self.texture,
|
|
|
|
(self.texture.get_width() * scale, self.texture.get_height() * scale))
|
|
|
|
self.scale = scale
|
|
|
|
|
2021-03-15 13:31:25 +01:00
|
|
|
def draw(self, window, camera):
|
|
|
|
window.blit(self.image, camera.apply(self.pos),
|
2021-03-14 22:43:26 +01:00
|
|
|
pygame.Rect(self.origin[0] * self.scale, self.origin[1] * self.scale, 32 * self.scale,
|
|
|
|
32 * self.scale))
|
2021-05-24 13:10:10 +02:00
|
|
|
|
|
|
|
def draw_static(self, window):
|
|
|
|
window.blit(self.image, self.pos,
|
|
|
|
pygame.Rect(self.origin[0] * self.scale, self.origin[1] * self.scale, 32 * self.scale,
|
|
|
|
32 * self.scale))
|