/
MainConstructor.py
83 lines (68 loc) · 3.08 KB
/
MainConstructor.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
from SpaceShip import SpaceShip
from Enemy import Enemy
from objects import Objects
from DropedObjects import DropedObjects
from stars import Stars
from buttonToStartGame import StartGame
class MainConstructor():
def __init__ (self, mainMenuSound, soundMouse, soundSpace, soundGun, soundClick, takeSomething, soundCoin, soundSpaceShip):
self.spaceShip = SpaceShip(width/2, height/2+150, 150, 150, 5, soundGun, takeSomething, soundCoin)
self.enemy = Enemy(random(0+75/2, width-75/2), -300, 75, 75, 3)
self.spaceShip.setEnemy(self.enemy)
self.objects = Objects(soundGun)
self.spaceShip.setSecondWeapon(self.objects.secondWeapon)
self.spaceShip.setSecondWeaponTimer(self.objects.secondWeaponTimer)
self.dropedObjects = DropedObjects(random(0+25, width-25), -2400, 50, 50, 2, random(0+25, width-25))
self.spaceShip.setDropedSecondWeapon(self.dropedObjects.dropedSecondWeapon)
self.stars = Stars()
self.gameState = False
self.buttonToStartGame = StartGame(width/2, height/2, 100, 50)
self.mainMenuSound = mainMenuSound
self.mainMenuSound.loop()
self.soundMouse = soundMouse
self.soundSpace = soundSpace
self.soundClick = soundClick
self.soundSpaceShip = soundSpaceShip
def game(self, mouseState):
if self.gameState == False:
self.soundClick.rewind()
self.soundSpace.rewind()
self.buttonToStartGame.run()
newGameState = self.buttonToStartGame.pressed(mouseState)
self.soundSpaceShip.pause()
if newGameState:
self.mainMenuSound.pause()
self.soundSpaceShip.loop()
self.gameState = newGameState
self.spaceShip.score.timer.workTimer(self.spaceShip.score.bestScore, self.buttonToStartGame.x, self.buttonToStartGame.y)
self.enemy.spawn()
aiming = self.buttonToStartGame.aiming()
if aiming:
self.soundMouse.play()
else:
self.soundMouse.rewind()
self.soundMouse.pause()
else:
self.soundClick.play()
self.soundSpace.play()
self.spaceShip.score.timer.restartOptions()
self.run()
def run(self):
self.stars.run()
self.spaceShip.run()
self.enemy.run(self.spaceShip.firstWeapon.listOfBullets, self.objects.secondWeapon.listOfBullets)
self.objects.run()
self.dropedObjects.run()
newGameState = self.spaceShip.setGameState(self.gameState)
if newGameState == False:
self.mainMenuSound.rewind()
self.mainMenuSound.loop()
self.gameState = newGameState
def shootWithFirstWeapon(self):
if self.gameState:
if self.spaceShip.state == 'ShootWithFirstGun':
self.spaceShip.firstWeapon.runToShoot(self.spaceShip.x)
def shootWithSecondWeapon(self):
if self.gameState:
if self.spaceShip.state == 'ShootWithSecondGun':
self.objects.secondWeapon.shoot(self.spaceShip.x)