-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsciiInvaders.py
95 lines (80 loc) · 3.24 KB
/
AsciiInvaders.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
"""
Ascii Invaders
* A minimalist version of an arcade classic, Space Invaders, using ascii characters and a terminal window for graphics
* Copyright (C) 2019 Meaj
* This program 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.
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import pdb
from GameVariables import GameVariables
def main():
#pdb.set_trace()
# Set console to fit game grid
os.system('mode con: cols=52 lines=20')
# Display variables
bool_loaded = True
bool_started = False
bool_quit = False
# Initial game variables
game_vars = GameVariables()
while not bool_quit:
# Resets game for replay
if not bool_loaded:
game_vars = GameVariables()
bool_loaded = True
# Start menu loop
if not bool_started:
game_vars.enter_menu()
game_vars.update_board()
while game_vars.is_in_menu():
game_vars.print_game_start()
game_vars.get_keypress()
if game_vars.is_selection_confirmed():
if game_vars.is_replay_selected():
bool_started = True
break
else:
bool_quit = True
game_vars.exit_menu()
game_vars.advance_frame()
# Game Loop
if not bool_quit:
while game_vars.is_playing():
# Input Checking every frame
game_vars.get_keypress()
# Projectile movement every three frames
game_vars.move_projectiles()
# Check for collisions
game_vars.check_collisions()
# Enemy Movement once every 15 frames
game_vars.move_enemies()
# Updates the Game Grid after position checking once per frame
game_vars.update_board()
# Prints Game Grid after updating once per frame
game_vars.print_board()
# Timing Calculations, should cause loop to run roughly once every 30th of a second
game_vars.advance_frame()
game_vars.enter_menu()
while game_vars.is_in_menu():
# Exits or resets the game
game_vars.print_game_over()
game_vars.get_keypress()
if game_vars.is_selection_confirmed():
if game_vars.is_replay_selected():
bool_loaded = False
del game_vars
break
else:
bool_quit = True
game_vars.exit_menu()
game_vars.advance_frame()
main()