f3a5647e5b
Im now working next on shoorting for turret Added new sand map and new cannon tower images aswell as function to play animations, showing range, placing turrets on allowed tiles for towers Buy and cancel button to buy towers
80 lines
2.0 KiB
Python
80 lines
2.0 KiB
Python
import pygame
|
|
import pygame_gui
|
|
|
|
from game.util import *
|
|
from game.tilemap import Tilemap
|
|
from game.screens.main_menu import MainMenu
|
|
from game.screens.game_play import GamePlay
|
|
|
|
FPS=60
|
|
WINDOW_SIZE=(960,540)
|
|
TILE=16
|
|
|
|
class Game:
|
|
|
|
def __init__(self):
|
|
|
|
pygame.init()
|
|
|
|
self.window = pygame.display.set_mode(WINDOW_SIZE)
|
|
self.clock = pygame.time.Clock()
|
|
self.ui_manager = pygame_gui.UIManager(
|
|
WINDOW_SIZE,
|
|
"assets/theme/theme.json"
|
|
)
|
|
self.tilemap = Tilemap(self)
|
|
|
|
self.assets={
|
|
"base": load_images('/tiles/test'),
|
|
"jungle": load_images('/tiles/jungle'),
|
|
"desert": load_images('/tiles/desert'),
|
|
"enemy": load_image('/entities/enemies/enemy.png'),
|
|
"cannon": load_image('/entities/towers/cannon/shoot/0.png'),
|
|
"red_cannon": load_image('/entities/towers/cannon/red_cannon.png'),
|
|
"cannon/shoot": Animation(load_images('/entities/towers/cannon/shoot'), 10, False)
|
|
}
|
|
|
|
self.screens = {
|
|
"menu": MainMenu(self),
|
|
"game": GamePlay(self)
|
|
}
|
|
self.current_screen = self.screens["menu"]
|
|
|
|
def change_screen(self, name):
|
|
|
|
self.current_screen.hide()
|
|
|
|
self.current_screen = self.screens[name]
|
|
|
|
self.current_screen.show()
|
|
|
|
def run(self):
|
|
|
|
running = True
|
|
|
|
while running:
|
|
|
|
dt = self.clock.tick(FPS) / 1000.0
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
running = False
|
|
|
|
self.ui_manager.process_events(event)
|
|
|
|
self.current_screen.process_event(event)
|
|
|
|
self.current_screen.update(dt)
|
|
|
|
self.ui_manager.update(dt)
|
|
|
|
self.window.fill((20, 20, 20))
|
|
|
|
self.current_screen.draw(self.window)
|
|
|
|
self.ui_manager.draw_ui(self.window)
|
|
|
|
pygame.display.update()
|
|
|
|
pygame.quit() |