-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainGame.py~
76 lines (69 loc) · 2.25 KB
/
MainGame.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
import pygame, sys, time, random
from pygame.locals import *
from Tank import *
from ETank import*
from pandaAttack import*
#from alienattack import*
from SpriteManager import *
def DrawGame():
playerTank.drawTank(screen)
Enemy.drawTank(screen)
screen.blit(infoSurf,infoRect)
screen.blit(scoreSurf,scoreRect)
pygame.display.update()
def checkForKeyPress():
if len(pygame.event.get(QUIT)) > 0:
pygame.quit()
sys.exit()
keyUpEvents = pygame.event.get(KEYUP)
if len(keyUpEvents) == 0:
return None
if keyUpEvents[0].key == K_ESCAPE:
pygame.quit()
sys.exit()
return keyUpEvents[0].key
#(^_^) (=3=) (~ =3=)~ L(T^T L)
#Game Starts
pygame.init()
pygame.display.set_caption('TANK FIGHT: GO!')
background = pygame.image.load('background.png')
#Set Game Variables
white = (255,64,64)
gameWidth = 1200
gameHeight = 600
FPSCLOCK = pygame.time.Clock()
DARKGRAY = ( 40, 40, 40)
WHITE = ( 255, 255, 255)
#Displaying Variables on screen
BASICFONT = pygame.font.Font('freesansbold.ttf', 16)
infoSurf = BASICFONT.render('Move the Tank using Q, W, A, S keys.', 1, DARKGRAY)
infoRect = infoSurf.get_rect()
infoRect.topleft = (10, gameWidth - 25)
#Scoring Variables
score = 0
scoreSurf = BASICFONT.render('Score: ' + str(score), 1, WHITE)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (gameWidth - 100, 10)
screen = pygame.display.set_mode((gameWidth,gameHeight))
screen.fill((white))
groundHeight = 400
playerTank = Tank(0,groundHeight)
Enemy = ETank(gameWidth*3/4,groundHeight)
Panda = pandaList(gameWidth*3/4, groundHeight-50)
spManager = SpriteManager(playerTank,Enemy,Panda)
#Here is the Main Loop for running the game
while True:
screen.blit(background,(0,0))
checkForKeyPress()
playerTank.moveByKeyBoard(gameWidth,gameHeight)
Enemy.moveTank(gameWidth,gameHeight)
Panda.movePanda(gameWidth,gameHeight)
Alien.moveAlien(gameWidth, gameHeight)
spManager.do_collide()
Panda.drawPanda(screen)
# Alien.drawAlien(screen)
pygame.display.set_caption(str(Enemy.getCount()))
#screen.blit(playerTank.getImage(),(playerTank.getX(),playerTank.getY()))
#########################Handles Draws for the Game ######################################
DrawGame()
pygame.display.update()