-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlays.py
84 lines (65 loc) · 2.13 KB
/
overlays.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
'''
overlay classes and mechanisms
includes items and animators
'''
import pygame
import os
import random
import logging
logger=logging.getLogger('overlays')
import lib
class overlay(object):
def __init__(self):
##must have a self.surf first, crated by the overlay elsewhere...
self.rect=self.surf.get_rect()
def update(self,screen,loc,center,ms,map):
self.rect.center=center
screen.blit(self.surf,self.rect)
def __getstate__(self):
state=self.__dict__.copy()
state.pop('surf')
if 'frames' in state:
state.pop('frames')
return state
def __setstate__(self,state):
self.__dict__.update(state)
self.frames = tuple((lib.common.load_img(*file) for file in self.files))
if len(self.frames) ==1:
self.surf = self.frames[0]
else:
self.surf = self.frames[self.cur]
class item(overlay):
pass
class energy(item):
def __init__(self):
self.files=(
('items','energy','capsule3.png'),
('items','energy','capsule1.png'),
('items','energy','capsule2.png')
)
self.frames=tuple((lib.common.load_img(*file) for file in self.files))
self.surf=self.frames[0]
self.value = random.randint(0,100)
item.__init__(self)
self.cur=0
self.time=0
def update(self,screen,loc,center,ms,map):
self.rect.center=center
screen.blit(self.surf,self.rect)
self.time+=ms
if self.time > 250:
self.cur+=1
self.time=0
if self.cur>len(self.frames)-1:
self.cur=0
self.surf = self.frames[self.cur]
class metal(item):
def __init__(self):
self.files=(('items','scrap-metal.png'),)
self.surf = lib.common.load_img(*self.files[0])
self.value = random.randint(0,100)
item.__init__(self)
class datalog(item):
def __init__(self):
self.surf = pygame.Surface((50,50))
self.value = 'test item!'