2019-01-21 20:37:58 +01:00
|
|
|
# import all files
|
|
|
|
from config import *
|
2019-01-31 09:17:12 +01:00
|
|
|
from sprites import Player, all_sprites, load_img, screen, HPBar, load_img_noalpha
|
2019-01-21 20:37:58 +01:00
|
|
|
from colours import *
|
2019-01-29 21:17:55 +01:00
|
|
|
import maps
|
2019-01-21 20:37:58 +01:00
|
|
|
import events
|
|
|
|
# import modules
|
2019-01-29 21:17:55 +01:00
|
|
|
from os import path
|
2019-01-21 20:37:58 +01:00
|
|
|
import os, sys
|
|
|
|
import pygame
|
|
|
|
from pygame.locals import *
|
|
|
|
|
|
|
|
# initialization
|
|
|
|
|
|
|
|
pygame.init()
|
2019-01-30 20:21:08 +01:00
|
|
|
#pygame.mixer.init()
|
2019-01-21 20:37:58 +01:00
|
|
|
pygame.display.set_caption(WIN_NAME)
|
|
|
|
clock=pygame.time.Clock()
|
|
|
|
|
|
|
|
# initialize two players
|
|
|
|
|
2019-01-29 21:17:55 +01:00
|
|
|
events.players.append(Player('p1', 400, 100, 10))
|
|
|
|
events.players.append(Player('p2', 430, 300, 10))
|
2019-01-21 23:43:13 +01:00
|
|
|
events.p1_group.add(events.players[0])
|
|
|
|
events.p2_group.add(events.players[1])
|
2019-01-21 20:37:58 +01:00
|
|
|
all_sprites.add(events.players)
|
|
|
|
events.running=True
|
2019-01-31 09:17:12 +01:00
|
|
|
all_sprites.add(events.bars)
|
2019-01-21 21:56:43 +01:00
|
|
|
# debug text
|
|
|
|
|
|
|
|
font=pygame.font.SysFont("Arial", 12)
|
|
|
|
|
|
|
|
def draw_debug_text():
|
|
|
|
texts=[
|
2019-01-30 23:35:43 +01:00
|
|
|
font.render("P1 HP: " + str(events.players[0].hp), True, (100,100,100)),
|
|
|
|
font.render("P2 HP: " + str(events.players[1].hp), True, (100,100,100))
|
2019-01-21 21:56:43 +01:00
|
|
|
]
|
|
|
|
count=0
|
|
|
|
for text in texts:
|
|
|
|
screen.blit(text, (0,count*12))
|
|
|
|
count+=1
|
|
|
|
|
2019-01-31 09:17:12 +01:00
|
|
|
bg, bg_rect=load_img_noalpha("bg.png")
|
|
|
|
splash, splash_rect=load_img_noalpha("splash.png")
|
2019-01-30 20:21:08 +01:00
|
|
|
|
2019-01-31 09:17:12 +01:00
|
|
|
def waitforkey():
|
|
|
|
waiting=True
|
|
|
|
while waiting:
|
|
|
|
clock.tick(FPS)
|
|
|
|
keys=pygame.key.get_pressed()
|
|
|
|
if keys[pygame.K_SPACE]:
|
|
|
|
waiting=False
|
2019-01-21 20:37:58 +01:00
|
|
|
|
2019-01-31 09:17:12 +01:00
|
|
|
def startscreen():
|
|
|
|
screen.blit(splash,(0,0))
|
|
|
|
pygame.display.flip()
|
|
|
|
waitforkey()
|
|
|
|
|
2019-01-30 23:35:43 +01:00
|
|
|
# game loop
|
|
|
|
while events.mainloop:
|
2019-01-31 09:17:12 +01:00
|
|
|
#startscreen()
|
2019-01-30 23:35:43 +01:00
|
|
|
while events.running:
|
|
|
|
clock.tick(FPS)
|
|
|
|
# events
|
|
|
|
pygame.event.pump()
|
|
|
|
events.event_handler()
|
|
|
|
# update
|
|
|
|
all_sprites.update()
|
|
|
|
screen.fill(BLACK)
|
|
|
|
if events.dead():
|
|
|
|
break
|
|
|
|
# draw
|
|
|
|
screen.blit(bg,(0,0))
|
2019-01-31 09:17:12 +01:00
|
|
|
#draw_debug_text()
|
2019-01-30 23:35:43 +01:00
|
|
|
all_sprites.draw(screen)
|
|
|
|
pygame.display.flip()
|
|
|
|
print('asd')
|
2019-01-21 23:45:35 +01:00
|
|
|
pygame.quit()
|
2019-01-21 20:37:58 +01:00
|
|
|
sys.exit()
|