-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.py
More file actions
97 lines (78 loc) · 3.1 KB
/
renderer.py
File metadata and controls
97 lines (78 loc) · 3.1 KB
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
import pygame
import os
from pygame.locals import *
from item import Item
from river import RiverScene
from pile import Pile
from menu import Menu
from bin import Bins
from gameLogic import GameLogic
class Renderer:
def __init__(self):
self.running = True
self.surface = None
self.background_surface = None
self.size = self.width, self.height = 1400, 900
self.count = 0
self.count1 = 0
self.color = (255,255,255)
def on_init(self):
pygame.init()
self.surface = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
self.background_surface = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
self.running = True
self.menu = Menu(self)
self.pile = Pile(self.width, self.height, self.surface)
self.river = RiverScene(self.width, self.height, self.surface)
self.bins = Bins()
self.logic = GameLogic()
self.item = Item(0, (2,2))
self.menupic = pygame.image.load(os.path.join("images", "menu.png")).convert()
self.pilepic = pygame.image.load(os.path.join("images", "pileBackground.png")).convert()
self.riverpic = pygame.image.load(os.path.join("images", "riverBackground.png")).convert()
#Event listener
def on_event(self, event):
if event.type == pygame.QUIT:
self.running = False
if self.logic.getState() == 0:
self.menu.update(self.logic, event)
if self.count == 0:
pygame.mixer.Channel(0).play(pygame.mixer.Sound("sounds/Menu.mp3"), -1)
self.count = 1
elif self.logic.getState() == 2:
self.river.update(self.logic, event)
elif self.logic.getState() == 1:
self.pile.update(self.logic, event)
# Render updater
def on_render(self):
if self.logic.getState() == 0:
self.background_surface.blit(self.menupic, (0, 0))
elif self.logic.getState() == 1:
self.background_surface.blit(self.pilepic, (0, 0))
elif self.logic.getState() == 2:
self.background_surface.blit(self.riverpic, (0, 0))
else:
new_surface = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
self.background_surface.blit(new_surface, (0, 0))
if self.logic.getState() == 0:
self.menu.render(self.surface)
elif self.logic.getState() == 2:
self.river.render(self.surface, self.logic)
elif self.logic.getState() == 1:
self.pile.render(self.surface, self.logic)
pygame.display.flip()
def on_cleanup(self):
pygame.quit()
def on_execute(self):
if self.on_init() == False:
self.running = False
# Main game loop
while( self.running ):
for event in pygame.event.get():
self.on_event(event)
self.on_render()
# Exiting
self.on_cleanup()
if __name__ == "__main__" :
window = Renderer()
window.on_execute()