Added game.py etc.
This commit is contained in:
@@ -1 +1,3 @@
|
||||
# init file
|
||||
|
||||
import game
|
||||
|
||||
74
robotgame/game.py
Normal file
74
robotgame/game.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# This file is part of ROBOTGAME
|
||||
#
|
||||
# ROBOTGAME is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# ROBOTGAME is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# ROBOTGAME. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
||||
#
|
||||
# game.py
|
||||
# --------------------
|
||||
# date created : Tue Aug 7 2012
|
||||
# copyright : (C) 2012 Sakse Dalum
|
||||
# maintained by : Sakse Dalum <don_s@hongabar.org>
|
||||
|
||||
"""
|
||||
The game. Handles everything.
|
||||
"""
|
||||
|
||||
import pygame
|
||||
|
||||
class Game(object):
|
||||
"""Create an object to handle the game."""
|
||||
def __init__(self, window, running=False, speed=30):
|
||||
self.__dict__.update(locals())
|
||||
|
||||
self.active_objs = []
|
||||
self.passive_objs = []
|
||||
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
def start(self):
|
||||
self.running = True
|
||||
self.run()
|
||||
|
||||
def stop(self):
|
||||
self.running = False
|
||||
|
||||
def activate_object(self, obj):
|
||||
self.active_objs.remove(obj)
|
||||
self.passive_objs.append(obj)
|
||||
|
||||
def deactivate_object(self, obj):
|
||||
self.passive_objs.remove(obj)
|
||||
self.active_objs.append(obj)
|
||||
|
||||
def run(self):
|
||||
while self.running:
|
||||
self.update()
|
||||
self.draw()
|
||||
self.clock.tick(self.speed)
|
||||
|
||||
def update(self):
|
||||
# Get all events since last update call (this prevents event
|
||||
# "bottlenecking"/lock-ups)
|
||||
events = pygame.event.get()
|
||||
for event in events:
|
||||
# Stop the game when closing the window
|
||||
if event.type == pygame.QUIT:
|
||||
self.stop()
|
||||
|
||||
t = pygame.time.get_ticks()
|
||||
for obj in self.active_objs:
|
||||
obj.update(t)
|
||||
|
||||
def draw(self):
|
||||
pass
|
||||
Reference in New Issue
Block a user