-
Notifications
You must be signed in to change notification settings - Fork 0
/
characters.py
60 lines (52 loc) · 1.96 KB
/
characters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pygame
from settings import ARENAWIDTH, ARENAHEIGHT, ARENAWIDTH_Q, ARENAHEIGHT_Q
from enums import Direction
from otherfunctions import rot_center
class Character(pygame.sprite.Sprite):
"""Główna klasa dla postaci"""
def __init__(self):
super().__init__()
self.org_image = None
self.image = None
self.selectedgun = None
self.direction = Direction.GORA
self.rect = pygame.Rect((0, 0), [40, 40])
self.rect.x = ARENAWIDTH//2
self.rect.y = ARENAHEIGHT//2
self.maxhp = 1000
self.hp = self.maxhp
self.enemy = False
def set_position(self, x: int, y: int, d: Direction):
self.rect.x = x
self.rect.y = y
self.direction = d
def update(self, x: int, y: int, d: Direction):
self.rect.x += x
self.rect.y += y
self.direction = d
if self.rect.x > ARENAWIDTH_Q:
self.rect.x = ARENAWIDTH_Q
elif self.rect.x < 0:
self.rect.x = 0
if self.rect.y > ARENAHEIGHT_Q:
self.rect.y = ARENAHEIGHT_Q
elif self.rect.y < 0:
self.rect.y = 0
if d is Direction.LEWO:
self.image = rot_center(self.org_image, 90)
elif d is Direction.PRAWO:
self.image = rot_center(self.org_image, -90)
elif d is Direction.GORA:
self.image = rot_center(self.org_image, 0)
elif d is Direction.DOL:
self.image = rot_center(self.org_image, 180)
elif d is Direction.GORAPRAWO:
self.image = rot_center(self.org_image, -45)
elif d is Direction.GORALEWO:
self.image = rot_center(self.org_image, 45)
elif d is Direction.DOLLEWO:
self.image = rot_center(self.org_image, 135)
elif d is Direction.DOLPRAWO:
self.image = rot_center(self.org_image, -135)
def damage(self, n):
self.hp -= n