From 80aee6c54607de725d6cb4b9c28681f822d59508 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Mon, 21 Jan 2019 22:55:58 +0100 Subject: [PATCH] added beta shooting --- __pycache__/config.cpython-37.pyc | Bin 524 -> 573 bytes __pycache__/events.cpython-37.pyc | Bin 1817 -> 2358 bytes __pycache__/sprites.cpython-37.pyc | Bin 3468 -> 3815 bytes config.py | 3 +++ events.py | 20 +++++++++++++++++++- mygame.py | 9 ++++++--- sprites.py | 29 ++++++++++++++++++++++++----- 7 files changed, 52 insertions(+), 9 deletions(-) diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc index 936abe0da2e02cd0dbeb259cd25eaa395f7ad8f4..edb7a485462a61cf5ec12942115a0d8a36d96e57 100644 GIT binary patch delta 111 zcmeBS*~`M~#LLUY00cZXZZY>J@=7vhOjJ+cWsj0d;fRt>VGL%_9*Ix{Lwe$A-J!p6+P F2mreQ8nXZZ delta 61 zcmdnX(!;{*#LLUY00cQqt}&Y?@=7u$OjJ)`WejG}WS=<2h)Gjw;-!0>D;bJFii)@< OUtx4+l$$KUqzC}2(GFe! diff --git a/__pycache__/events.cpython-37.pyc b/__pycache__/events.cpython-37.pyc index 8a7ba710007412e6db857b20a56766bd6cfb038c..f7649adf2b7c3e952242087ef772e25b12d578c4 100644 GIT binary patch delta 1205 zcmb`H-D(p-6vt=wW4hVRZqg*iZY^rs+7hWBt$I@|LIoB4sMuae5JT+5+7Oa3y9EUy zVts+KD0;WO@&Od@y%T+d(HHQpLhtpQ-OVU+HuC{vz^(wRl=3FzDBs(U>l@10^NX~X(}xicL~Kxj!V4PeHi3$05+f4QM7TH zuz9V8xEk$JW0mncxJ&d0K^ZmSX&6*2VL&l>$!4xgw%+YL+}sfOB;pT@ zj(r}clEn{B>R0h0ifIhFfMTIUACMLlOTkw*Gl|K0tfF8gjcN*ZlbVXbjIvQQioXEY C*ag-A delta 708 zcmcgqJxc>Y5Z$@l$KG8oM9~nnFedRNK_i$>5JW*lL=YPZAtAUyg>b~pDF{jmC54T| ztL(J#4+z%Q`VagEHr94J6OUMkmhN%y4R1bnW_KS3uVb+#$FUf$D|e+l%)7B9l)F>Y zvyqy%%SyUXg?7$LhR}t9%mo)FvMDTKBU>UW9AvwD_XO7c0Xzf5gN4X^Tfvgc__r<) zPMFU|SgU{xAuAzAh<#O{exuzoVBWT`3pj&T2ct1cu7zHMyr^M@tb`g5HLNaWsF|dt zzqXQ{P_#%CY>VZT4GGv%&JNzyj3(n~2V+{ra;ez_0t+s+M0*mA9SWpH{J#Sge@yh( zKvC=u2bwXmn>3FcCm1D25lj%I2{H&dkXf?LKG6NYIL$`wxGv|a`(E?VFQW8)8juej zjdkty16MG>v#WGEGLP_EvHDTn^Q(I`Pc-Usk&5*m8R%dE$4?e0IU1aDHzhgRy^D}G eS-r;lJIF%t#@*x)dg7F-a76`G;W|%nhdZD7ZG@u$ diff --git a/__pycache__/sprites.cpython-37.pyc b/__pycache__/sprites.cpython-37.pyc index a55588e7634c45656741a399058ba8f155663d01..8307f7b5f3dbbc57ec3220c31938d81888075bae 100644 GIT binary patch delta 750 zcmYk4&ubGw6vyZ7uWV*_leEN`w3K4owB2G8uxcb!!Pr!UHi~I3K}ky{wpqibOtv0E zz(acxy@WY=P!v2XlK;TF|3Ll$Pa^&YzS)N04)fXB?|W}}-o>)th)V>un03R2s35ObI#Rz z47DhusL`nw|NiA8Kwdmh-oT#tsqAZ2;?9m%)fruUFsraT`fI)icqHD^CfpEz=rwpQ zW~_Oz#HO_`Ms_lD1$$h?*-IcyFsT{29OA3B2rIa0*2YcEu~9nfbXtMPsVUeIhMg6j z8e3rsQ_htEX+#Gak}`tHYNfB`PW@vJxTkB0qP;9?G+rA=S(~?-LA&d_I$y#dUzS*x zSd+LT5uZZ##M6i)oW1ZoAqGjXarEPphK5=S%|>6JV9tPeguzRNrvk9#m(o!E?NC)v z-3TDmG=DwRRMhTGG}TXrnuglbX*HVibd7k1tSbp)qUJ1?dP1)gwL_UvnBcX+{ zU8?Qvl@A)#C*|@EUy$+8U+6R=Kj-i^=JI;)q}vT-=e=130gBG(f1__-y3B=%;s?DB zMXb!+ikrySl#5X&=RKVpS&Ypq5n~#_l pmztXx8_ll&qJ1oW+lNrVUuzRV5Z~Es?l!x3mo`mnq!g*4srM2r+CQN9kU}dJgJMBA3a4hzG~v9HyKA8l zq+nkJUz&X?is(m>KKSg{$QKZN@*_B#y371#cILM;zxloNY0>Mrt{`|iYdZ&BdG0mf z{rPI^IgMGs6j2bD_lYVgc18kAm6e6wj@XcYt9&Pcz(@|Az}+RvR{V@8ZfZmCLn)|Y zuA&6y4C^X4^W)1`fCGJxeuRDfRIcbh^p>M)*i@>yXT+~xE|g}=O+Z20XgNnH2oOcE z2wfinJ4uVfLDJW|?$Y%g!=VTSM$VJ?Qo`^j#&F`()VrsS2im?&2AzqYwBO_+(rY#9$L;22zW56UbSt9;UF0lVc7Lq zwvM%I!@#D2##lC5TNu4Uo36?sGjD%(V)fGG^`JkoqT?tja=quhfUU8-wmRYW-=yj& Xjvg4Hc^v`wqcecW%#MO_THpQ$FO6sx diff --git a/config.py b/config.py index 8725d97..a392767 100644 --- a/config.py +++ b/config.py @@ -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 diff --git a/events.py b/events.py index 1056e14..433a224 100644 --- a/events.py +++ b/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): diff --git a/mygame.py b/mygame.py index a35a8ff..6e58113 100644 --- a/mygame.py +++ b/mygame.py @@ -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: diff --git a/sprites.py b/sprites.py index 5d97af0..3480b0f 100644 --- a/sprites.py +++ b/sprites.py @@ -1,6 +1,6 @@ # import all files from config import * -import events +#import events # import modules import os, sys import pygame @@ -66,9 +66,6 @@ class Player(pygame.sprite.Sprite): self.facing=3 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) \ No newline at end of file