-
Notifications
You must be signed in to change notification settings - Fork 0
/
abg.py
executable file
·95 lines (76 loc) · 2.59 KB
/
abg.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
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
#
# File: abg.py
# Author: Casey Jones
#
# Created on July 20, 2009, 4:48 PM
#
# This file is part of Alpha Beta Gamma (abg).
#
# ABG 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.
#
# ABG 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 ABG. If not, see <http://www.gnu.org/licenses/>.
import sys, pygame, frametime, properties, time
pygame.init()
screen = pygame.display.set_mode(properties.size)
pygame.display.set_caption("Alpha Beta Gamma")
pygame.key.set_repeat()
def play():
from menu import Menu
menu = Menu(screen)
#show menu before starting game.
menu.showMenu()
from player import Player
from bullet import Bullet
from enemies import Enemies
player = Player()
player.set_screen(screen)
to_update = player.create()
#draw player to screen immediately
pygame.display.update(to_update)
bullet = Bullet()
bullet.set_screen(screen)
enemies = Enemies()
enemies.set_screen(screen)
while player.is_alive():
to_update = []
pygame.event.pump()
key = pygame.key.get_pressed()
#key events that only need to be pressed once
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
menu.showMenu()
if event.key == pygame.K_SPACE:
player.fire(bullet, True)
if key[pygame.K_ESCAPE]:
sys.exit()
if key[pygame.K_RIGHT]:
to_update += player.move_right()
if key[pygame.K_LEFT]:
to_update += player.move_left()
if key[pygame.K_SPACE]:
player.fire(bullet, False)
frametime.start()
to_update += bullet.move(enemies, player)
to_update += enemies.move(bullet)
pygame.display.update(to_update)
#find how long it took to render this frame so we can adjust speeds
frametime.end()
#player died
player.game_over()
enemies.game_over()
bullet.game_over()
pygame.display.flip()
while 1:
play()