-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.py
109 lines (89 loc) · 4.12 KB
/
view.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
94
95
96
97
98
99
100
101
102
103
104
105
106
import pygame
from pygame.locals import *
from evManager import *
from constants import *
class CharactorSprite(pygame.sprite.Sprite):
def __init__(self, group=None):
pygame.sprite.Sprite.__init__(self, group)
self.image = pygame.image.load("xiao.png")
self.rect = self.image.get_rect()
self.moveTo = None
self.image_sleep = 40
self.flag_switch = 0
#----------------------------------------------------------------------
def update(self):
if self.moveTo:
self.rect.center = self.moveTo
self.moveTo = None
#------------------------------------------------------------------------------
class PygameView:
"""..."""
def __init__(self, evManager):
self.evManager = evManager
self.evManager.RegisterListener(self)
pygame.init()
self.window = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Xiao fighter')
self.background = pygame.Surface(self.window.get_size())
self.background.fill((255, 255, 255))
self.backSprites = pygame.sprite.RenderUpdates()
self.frontSprites = pygame.sprite.RenderUpdates()
self.window.blit(self.background, (0,0))
pygame.display.flip()
#----------------------------------------------------------------------
#Wrote by Rodrigo
def ShowCharactor(self, charactor):
charactorSprite = CharactorSprite(self.frontSprites)
# sector = charactor.sector
# sectorSprite = self.GetSectorSprite(sector)
charactor.sprite = charactorSprite
charactorSprite.rect.center = charactor.rect.center
#----------------------------------------------------------------------
#Wrote by Rodrigo
def MoveCharactor(self, charactor):
charactor.sprite.moveTo = charactor.rect.center
charactorSprite = charactor.sprite
if charactorSprite.flag_switch == 0:
charactorSprite.image_sleep -= 1
else:
charactorSprite.image_sleep += 1
if charactor.eyeDirection == 3:
if charactorSprite.image_sleep== 0:
charactorSprite.image = pygame.image.load("xiao2.png")
charactorSprite.flag_switch = 1
if charactorSprite.image_sleep== 40:
charactorSprite.image = pygame.image.load("xiao.png")
charactorSprite.flag_switch = 0
if charactorSprite.image_sleep == 20:
charactorSprite.image = pygame.image.load("xiao3.png")
else:
if charactorSprite.image_sleep== 0:
charactorSprite.image = pygame.image.load("xiao2.png")
charactorSprite.image = pygame.transform.flip(charactorSprite.image,1,0)
charactorSprite.flag_switch = 1
if charactorSprite.image_sleep== 40:
charactorSprite.image = pygame.image.load("xiao.png")
charactorSprite.image = pygame.transform.flip(charactorSprite.image,1,0)
charactorSprite.flag_switch = 0
if charactorSprite.image_sleep == 20:
charactorSprite.image = pygame.image.load("xiao3.png")
charactorSprite.image = pygame.transform.flip(charactorSprite.image,1,0)
#----------------------------------------------------------------------
def Notify(self, event):
if isinstance(event, TickEvent):
#Draw Everything
self.backSprites.clear( self.window, self.background)
self.frontSprites.clear( self.window, self.background)
self.backSprites.update()
self.frontSprites.update()
dirtyRects1 = self.backSprites.draw(self.window)
dirtyRects2 = self.frontSprites.draw(self.window)
dirtyRects = dirtyRects1 + dirtyRects2
pygame.display.update(dirtyRects)
elif isinstance(event, MapBuiltEvent):
map = event.map
self.ShowMap(map)
elif isinstance(event, CharactorPlaceEvent):
self.ShowCharactor(event.charactor)
elif isinstance(event, CharactorMoveEvent):
self.MoveCharactor(event.charactor)