AI-Project/survival/image.py
2021-06-06 19:55:55 +02:00

31 lines
1.1 KiB
Python

import os
import pygame
class Image:
def __init__(self, filename='', pos=(0, 0), scale=1, surface=None):
if surface is None:
self.texture = pygame.image.load(os.path.join('..', 'assets', filename)).convert_alpha()
else:
self.texture = surface
self.image = self.texture
self.origin = (0, 0)
self.pos = pos
self.set_scale(scale)
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
def draw(self, window, camera):
window.blit(self.image, camera.apply(self.pos),
pygame.Rect(self.origin[0] * self.scale, self.origin[1] * self.scale, 32 * self.scale,
32 * self.scale))
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))