-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcd.py
executable file
·64 lines (61 loc) · 2.11 KB
/
mcd.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
#!/usr/bin/env python3
"""
Spin-off of the Missile Commander Arcade game.
"""
import sys
import pygame
from pygame.locals import QUIT, KEYDOWN, K_ESCAPE, MOUSEBUTTONDOWN
from mcdlib import Game, set_display_size, set_game_sprites, get_enemy_freq
def main():
"""Start here! Initialize and start the game."""
#Initialize pygame
pygame.init()
#Adjust the screen size
#Not needed as it feeds the defaults. Used to showcase when and how to use it.
set_display_size((960, 720))
#Adjust the sprites the game is going to use.
#Not needed as it feeds the defaults. Used to showcase when and how to use it.
set_game_sprites({
'BG_IMG' : 'img/background.png',
'CROSS_IMG' : 'img/crosshair.png',
'CITY_IMG' : 'img/city.png',
'CITI_DEST' : 'img/city_dmg.png',
'MISSILE_IMG' : 'img/missile.png'
})
#Create an instance of Game object
main_game = Game()
#Game's "Brain" aka the main loop
game_running = True
mills = 0
#While no exit condition is met
while game_running:
for cur_event in pygame.event.get():
if cur_event.type == QUIT:
#On Quit, exit.
game_running = False
elif cur_event.type == KEYDOWN:
if cur_event.key == K_ESCAPE:
#On Esc, exit.
game_running = False
elif cur_event.type == MOUSEBUTTONDOWN:
#On mouse press, shoot missile.
shooting_pos = pygame.mouse.get_pos()
main_game.shoot_missile(shooting_pos)
#Control enemy missile frequency.
if mills > get_enemy_freq():
mills = 0
main_game.generate_missile()
#Render game garaphics.
main_game.render()
#Increase time since last enemy missile.
mills += main_game.clock_tick()
#Adjust game dificulty (if needed).
main_game.adjust_dificulty()
#Check for Game Over.
if main_game.is_over():
main_game.game_over()
game_running = False
pygame.quit()
sys.exit()
if __name__ == '__main__':
main()