added beta shooting
This commit is contained in:
parent
9e5b73b27c
commit
80aee6c546
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -24,3 +24,6 @@ P2_RIGHT=pygame.K_RIGHT
|
||||
P2_LEFT=pygame.K_LEFT
|
||||
P2_SHOOT=pygame.K_RCTRL
|
||||
|
||||
# bullets
|
||||
BULLET_SPEED=20
|
||||
SHOOT_SPEED=10
|
||||
|
20
events.py
20
events.py
@ -3,10 +3,16 @@ import pygame
|
||||
from pygame.locals import *
|
||||
|
||||
from sprites import *
|
||||
|
||||
from config import *
|
||||
running=True
|
||||
players=[]
|
||||
|
||||
p1_bullet=[]
|
||||
p2_bullet=[]
|
||||
|
||||
p1_bullet_group=pygame.sprite.Group()
|
||||
p2_bullet_group=pygame.sprite.Group()
|
||||
|
||||
def events():
|
||||
global running
|
||||
for event in pygame.event.get():
|
||||
@ -36,6 +42,12 @@ def collision_check(p):
|
||||
return False
|
||||
|
||||
def player1_input(keys):
|
||||
if keys[P1_SHOOT]:
|
||||
p1_bullet.append(Bullet('bullet', players[0].pos.x, players[0].pos.y, players[0].facing))
|
||||
p1_bullet_group.add(p1_bullet[-1])
|
||||
all_sprites.add(p1_bullet[-1])
|
||||
p1_bullet[-1].direction=players[0].facing
|
||||
p1_bullet[-1].shoot()
|
||||
if not (keys[P1_UP] or keys[P1_DOWN] or keys[P1_RIGHT] or keys[P1_LEFT]):
|
||||
players[0].stopmoving()
|
||||
elif not collision_check(0):
|
||||
@ -49,6 +61,12 @@ def player1_input(keys):
|
||||
players[0].movedown()
|
||||
|
||||
def player2_input(keys):
|
||||
if keys[P2_SHOOT]:
|
||||
p2_bullet.append(Bullet('bullet', players[1].pos.x, players[1].pos.y, players[1].facing))
|
||||
p2_bullet_group.add(p1_bullet[-1])
|
||||
all_sprites.add(p2_bullet[-1])
|
||||
p2_bullet[-1].direction=players[1].facing
|
||||
p2_bullet[-1].shoot()
|
||||
if not (keys[P2_UP] or keys[P2_DOWN] or keys[P2_RIGHT] or keys[P2_LEFT]):
|
||||
players[1].stopmoving()
|
||||
elif not collision_check(1):
|
||||
|
@ -20,8 +20,8 @@ clock=pygame.time.Clock()
|
||||
|
||||
# initialize two players
|
||||
|
||||
events.players.append(Player('asd', 400, 100, 5))
|
||||
events.players.append(Player('qwe', 400, 500, 5))
|
||||
events.players.append(Player('asd', 400, 100, 10))
|
||||
events.players.append(Player('qwe', 400, 500, 10))
|
||||
all_sprites.add(events.players)
|
||||
|
||||
events.running=True
|
||||
@ -34,13 +34,16 @@ def draw_debug_text():
|
||||
text_sprites=pygame.sprite.Group()
|
||||
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("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))
|
||||
]
|
||||
count=0
|
||||
for text in texts:
|
||||
screen.blit(text, (0,count*12))
|
||||
count+=1
|
||||
|
||||
# set hitbox objects as screen boundaries ### DEBUG ###
|
||||
# game loop
|
||||
|
||||
while events.running:
|
||||
|
29
sprites.py
29
sprites.py
@ -1,6 +1,6 @@
|
||||
# import all files
|
||||
from config import *
|
||||
import events
|
||||
#import events
|
||||
# import modules
|
||||
import os, sys
|
||||
import pygame
|
||||
@ -67,9 +67,6 @@ class Player(pygame.sprite.Sprite):
|
||||
self.acc.x=-1.5
|
||||
self.acc.y=0
|
||||
|
||||
def shoot(self):
|
||||
nothing
|
||||
|
||||
def stopmoving(self):
|
||||
self.acc=vec(0, 0)
|
||||
|
||||
@ -97,7 +94,29 @@ class Player(pygame.sprite.Sprite):
|
||||
self.move()
|
||||
|
||||
class Bullet(pygame.sprite.Sprite):
|
||||
def __init__(self, fname):
|
||||
def __init__(self, fname, x, y, direction):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.image, self.rect=load_img(fname + '.png')
|
||||
self.rect.center=(x, y)
|
||||
self.speed=vec(0, 0)
|
||||
self.direction=direction
|
||||
|
||||
def shoot(self):
|
||||
if self.direction==0:
|
||||
self.speed.y=-BULLET_SPEED
|
||||
elif self.direction==1:
|
||||
self.speed.x=BULLET_SPEED
|
||||
elif self.direction==2:
|
||||
self.speed.y=BULLET_SPEED
|
||||
elif self.direction==3:
|
||||
self.speed.x=-BULLET_SPEED
|
||||
self.rect.center+=self.speed
|
||||
|
||||
def update(self):
|
||||
self.shoot()
|
||||
|
||||
class Hitbox(pygame.sprite.Sprite):
|
||||
def __init__(self, x, y, w, h):
|
||||
self.size=vec(w, h)
|
||||
self.rect=self.size.get_rect()
|
||||
self.rect.center=vec(x,y)
|
Loading…
Reference in New Issue
Block a user