-
Notifications
You must be signed in to change notification settings - Fork 2
/
sprites.py
93 lines (75 loc) · 2.09 KB
/
sprites.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pygame as pg
from settings import *
import random
import time
class Player(pg.sprite.Sprite):
def __init__(self, game, x, y, hp, prot, atk):
#PYGAME
self.groups = game.all_sprites
pg.sprite.Sprite.__init__(self, self.groups)
self.game = game
self.image = pg.Surface((TILESIZE, TILESIZE))
self.image.fill(GREEN)
self.rect = self.image.get_rect()
self.x = x
self.y = y
#Player attr
self.hp = hp
self.prot = prot
self.hp_max = hp
self.atk = atk
self.armor = {'head': None, 'chest': None, 'legs': None, 'feet': None}
self.weapon = None
self.p_coins = 0
def move(self, dx=0, dy=0):
if self.game.inventory.display_inventory != True:
self.x += dx
self.y += dy
self.check_collision()
def addHp(self, hp_gain):
self.hp += hp_gain
if self.hp > self.hp_max:
self.hp = self.hp_max
def addProt(self, prot_gain):
self.prot += prot_gain
def equip_armor(self, item):
if self.armor[item.slot] != None:
self.unequip_armor(item.slot)
self.armor[item.slot] = item
self.prot += item.prot
def unequip_armor(self, slot):
if self.armor[slot] != None:
self.prot -= self.armor[slot].prot
self.armor[slot] = None
def equip_weapon(self, weapon):
if self.weapon != None:
self.unequip_weapon()
self.weapon = weapon
self.atk += weapon.atk
def unequip_weapon(self):
if self.weapon != None:
self.atk -= self.weapon.atk
self.weapon = None
def check_collision(self):
self.check_coin()
def check_coin(self):
if self.x == self.game.coin.x and self.y == self.game.coin.y:
self.add_coin()
self.game.new_coin()
def add_coin(self):
self.p_coins += 10
def update(self):
self.rect.x = self.x * TILESIZE
self.rect.y = self.y * TILESIZE
class Coin(pg.sprite.Sprite):
def __init__(self, game, x, y):
self.groups = game.all_sprites, game.all_coins
pg.sprite.Sprite.__init__(self, self.groups)
self.game = game
self.image = pg.image.load('img/coin.png').convert_alpha()
self.rect = self.image.get_rect()
self.x = x
self.y = y
def update(self):
self.rect.x = self.x * TILESIZE+COINOFFSET
self.rect.y = self.y * TILESIZE+COINOFFSET