This commit is contained in:
Marcin Kostrzewski 2019-01-30 23:35:43 +01:00
parent 65073bc55c
commit c45ead5bb8
11 changed files with 42 additions and 39 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,4 +3,5 @@
WHITE=(245, 245, 245)
BLACK=(10, 10, 10)
RED=(245, 0, 0)
BLUE=(0, 0, 245)
BLUE=(0, 0, 245)
BGCOLOR=(87,156,135)

View File

@ -9,6 +9,7 @@ FPS = 30
WIN_NAME = "Kostschevsky's shooter"
PLAYER_HP=100
# Controls
# player 1
@ -16,7 +17,7 @@ P1_UP=pygame.K_w
P1_DOWN=pygame.K_s
P1_RIGHT=pygame.K_d
P1_LEFT=pygame.K_a
P1_SHOOT=pygame.K_z
P1_SHOOT=pygame.K_LCTRL
# player 2
P2_UP=pygame.K_UP

View File

@ -4,6 +4,8 @@ from pygame.locals import *
from sprites import *
from config import *
mainloop=True
running=True
players=[]
@ -21,6 +23,7 @@ timer1=1000
clock2=pygame.time.Clock()
clock2.tick()
timer2=1000
def events():
global running
for event in pygame.event.get():
@ -51,7 +54,7 @@ def collision_check(p):
def bullethits():
hits1=pygame.sprite.groupcollide(p2_group, p1_bullet_group, False, True)
hits2=pygame.sprite.groupcollide(p1_group, p2_bullet_group, True, True)
hits2=pygame.sprite.groupcollide(p1_group, p2_bullet_group, False, True)
if hits1:
players[1].gothit()
if hits2:
@ -104,6 +107,11 @@ def player2_input(keys):
players[1].moveup()
if keys[P2_DOWN]:
players[1].movedown()
def dead():
if players[0].alive and players[1].alive:
return False
else:
return True
def event_handler():
global timer1

View File

@ -1,6 +1,6 @@
# import all files
from config import *
from sprites import *
from sprites import Player, all_sprites, load_img, screen
from colours import *
import maps
import events
@ -14,7 +14,6 @@ from pygame.locals import *
pygame.init()
#pygame.mixer.init()
screen=pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption(WIN_NAME)
clock=pygame.time.Clock()
@ -25,7 +24,6 @@ events.players.append(Player('p2', 430, 300, 10))
events.p1_group.add(events.players[0])
events.p2_group.add(events.players[1])
all_sprites.add(events.players)
events.running=True
# debug text
@ -34,10 +32,8 @@ font=pygame.font.SysFont("Arial", 12)
def draw_debug_text():
texts=[
font.render("P1 facing: " + str(events.players[0].facing), True, (100,100,100)),
font.render("P2 facing: " + str(events.players[1].facing), True, (100,100,100)),
font.render("P1 bullets: " + str(len(events.p1_bullet)), True, (100,100,100)),
font.render("P2 bullets: " + str(len(events.p2_bullet)), True, (100,100,100))
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))
]
count=0
for text in texts:
@ -46,20 +42,27 @@ def draw_debug_text():
bg, bg_rect=load_img("bg.png")
# game loop
def startscreen():
screen.fill(BGCOLOR)
while events.running:
clock.tick(FPS)
# events
pygame.event.pump()
events.event_handler()
# update
all_sprites.update()
screen.fill(BLACK)
# draw
screen.blit(bg,(0,0))
draw_debug_text()
all_sprites.draw(screen)
pygame.display.flip()
# game loop
while events.mainloop:
print('asd')
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))
draw_debug_text()
all_sprites.draw(screen)
pygame.display.flip()
print('asd')
pygame.quit()
sys.exit()

View File

@ -6,9 +6,10 @@ import maps
import os, sys
import pygame
from pygame.locals import *
# resource handler
screen=pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
def load_img(name):
img_path=os.path.join('data/graphics', name)
image=pygame.image.load(img_path).convert()
@ -82,20 +83,12 @@ class Player(pygame.sprite.Sprite):
return True
return False
def draw_healthbar(self):
width=int(self.rect.width*self.hp/100)
self.hp_bar=pygame.Rect(0, 0, width, 7)
if self.hp_visible:
pygame.draw.rect(pygame.display.get_surface(), (255,0,0), self.hp_bar)
def gothit(self):
self.hp_visible=True
if self.hp>0:
self.hp-=BULLET_DMG
else:
if self.hp<=0:
self.alive=False
print(self.hp)
def move(self):
if self.colliding or self.wallcollide():
@ -112,16 +105,13 @@ class Player(pygame.sprite.Sprite):
self.rect.center=self.pos
def update(self):
#if self.alive==False:
#print("rip")
self.move()
#self.draw_healthbar()
class Bullet(pygame.sprite.Sprite):
def __init__(self, fname, x, y, direction):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect=load_img(fname + '.png')
self.rect.center=vec(x, y)
self.rect.center=(x, y)
self.speed=vec(0, 0)
self.direction=direction