2022-07-27 22:19:04 -05:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
|
|
|
|
class ImageSprite(pygame.sprite.Sprite):
|
|
|
|
def __init__(self, image_path, screen_width, screen_height):
|
|
|
|
"""
|
|
|
|
Initializes Card object.
|
|
|
|
:param image_path: Path of
|
|
|
|
:param screen_width:
|
|
|
|
:param screen_height:
|
|
|
|
"""
|
|
|
|
super().__init__()
|
|
|
|
|
2022-07-28 12:38:41 -05:00
|
|
|
self.image = pygame.image.load(image_path)
|
2022-07-27 22:19:04 -05:00
|
|
|
self.rect = self.image.get_rect()
|
|
|
|
self.rect.move(screen_width / 2, screen_height / 2)
|
2022-07-28 12:38:41 -05:00
|
|
|
self.width = screen_width
|
|
|
|
self.height = screen_height
|
2022-07-27 22:19:04 -05:00
|
|
|
|
|
|
|
def is_clicked(self):
|
|
|
|
"""
|
|
|
|
Tests if the sprite is clicked
|
|
|
|
:return: Returns True if clicked, False otherwise
|
|
|
|
"""
|
|
|
|
mouse_pos = pygame.mouse.get_pos()
|
|
|
|
if self.rect.collidepoint(mouse_pos) and pygame.mouse.get_pressed()[0]:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def move(self, x, y):
|
|
|
|
"""
|
|
|
|
Moves to the given x and y coordinates
|
|
|
|
:param x: x coordinate
|
|
|
|
:param y: y coordinate
|
|
|
|
:return: None
|
|
|
|
"""
|
2022-07-28 12:38:41 -05:00
|
|
|
self.rect.move(x / self.width, y / self.height)
|