You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.1 KiB
Python

# -*- coding: UTF-8 -*-
### Tangled Mind
### Author: Arthur 'Grizzly' Grisel-Davy
import pygame
import yaml
from models import Game, Player, Carte, Camera, Enemy, Hud, Weapon
from utils import enemy_placement
pygame.init()
screen_width = 1200
screen_height = 800
center_screen = (int(screen_width/2),int(screen_height/2))
screen = pygame.display.set_mode((screen_width, screen_height))
BACKGROUND=(200,200,200)
WHITE=(255,255,255)
BLUE=(0,0,255)
RED=(255,0,0)
with open(r'./config.yaml') as file:
data = yaml.load(file,Loader=yaml.FullLoader)
path_player = data['path_player']
path_canon = data['path_canon']
path_enemy = data['path_enemy']
path_projectile = data['path_projectile']
carte = Carte(n=5)
enemies = []
for positions in enemy_placement(carte.carte):
for position in positions:
enemies.append(Enemy('Plop',position,path_enemy))
# Generate instances:
start_pos = carte.player_start_pos
player = Player('Alice',start_pos,center_screen,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,323,path_player,path_canon)
base_weapon = Weapon('Base', 25, 0, 30, path_projectile)
player.add_weapon(base_weapon)
camera = Camera(start_pos,screen_width,screen_height,0.3)
hud = Hud(player)
game = Game(carte,player,camera,enemies,hud)
clock = pygame.time.Clock()
done = False
fps_counter_time = pygame.time.get_ticks()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
game.pause = not game.pause
keystate = pygame.key.get_pressed() + pygame.mouse.get_pressed()
if not game.pause:
player.check_keys(keystate,screen_width,screen_height,carte,camera)
screen.fill(BACKGROUND)
game.draw(screen)
if game.pause:
game.draw_pause(screen)
span = pygame.time.get_ticks()-fps_counter_time
hud.write_fps(screen,span/1000)
fps_counter_time = pygame.time.get_ticks()
pygame.display.flip()
clock.tick(60)