This repository has been archived by the owner on Jul 4, 2021. It is now read-only.
forked from orlp/PyGG2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gg2.py
76 lines (54 loc) · 1.78 KB
/
gg2.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
from __future__ import division
import pygame
from pygame.locals import *
import map
import character
import math
import console
class GG2:
"""
Central class
"""
# This is to replace the gmk "all" and also to update everything.
GameObjectList = []
Xview = 0
Yview = 0
def __init__(self):
# All drawing should be done on the Surface object
self.Window = pygame.display.set_mode((800, 600), HWSURFACE | DOUBLEBUF)
self.Surface = self.Window
self.sysFont = pygame.font.SysFont("None", 30)
self.Wview = self.Window.get_width()
self.Hview = self.Window.get_height()
self.gameMap = map.Map(self)
self.Myself = character.Scout(self)
self.console = console.Console(self)
self.clock = pygame.time.Clock()
# text drawing is quite expensive, save it
self.fps = 0
self.fpstext = self.sysFont.render("0 FPS", 0, (130, 130, 130))
def update(self, frametime):
for obj in self.GameObjectList: obj.beginStep(frametime)
for obj in self.GameObjectList: obj.step(frametime)
for obj in self.GameObjectList: obj.endStep(frametime)
for obj in self.GameObjectList:
if obj.destroyInstance:
obj.destroy()
self.console.update()
def render(self):
# get info
self.Xview = self.Myself.x - self.Wview/2
self.Yview = self.Myself.y - self.Hview/2
# draw background
self.Surface.fill((245, 245, 235))
self.gameMap.draw()
for obj in self.GameObjectList: obj.draw()
# text drawing is quite expensive, save it
newfps = int(self.clock.get_fps())
if newfps != self.fps:
self.fps = newfps
self.fpstext = pygame.font.SysFont("None", 30).render("%d FPS" % self.fps, 0, (130, 130, 130))
self.Surface.blit(self.fpstext, (10, 10))
if self.console.show:
self.Surface.blit(self.console.imgText, (120, 10))
pygame.display.update()