Added sprite rotation
This commit is contained in:
parent
c2778d8b6d
commit
9e5b73b27c
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
data/graphics/bullet.png
Normal file
BIN
data/graphics/bullet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 227 B |
@ -19,11 +19,13 @@ def collision_check(p):
|
||||
if p==1:
|
||||
players[0].colliding=True
|
||||
direction=players[1].facing
|
||||
players[0].image=pygame.transform.rotate(players[0].image, players[0].facing*90-((direction+2)%4)*90)
|
||||
players[0].facing=(direction+2)%4
|
||||
return True
|
||||
elif p==0:
|
||||
players[1].colliding=True
|
||||
direction=players[0].facing
|
||||
players[1].image=pygame.transform.rotate(players[1].image, players[1].facing*90-((direction+2)%4)*90)
|
||||
players[1].facing=(direction+2)%4
|
||||
return True
|
||||
else:
|
||||
|
16
mygame.py
16
mygame.py
@ -26,6 +26,21 @@ all_sprites.add(events.players)
|
||||
|
||||
events.running=True
|
||||
|
||||
# debug text
|
||||
|
||||
font=pygame.font.SysFont("Arial", 12)
|
||||
|
||||
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))
|
||||
]
|
||||
count=0
|
||||
for text in texts:
|
||||
screen.blit(text, (0,count*12))
|
||||
count+=1
|
||||
|
||||
# game loop
|
||||
|
||||
while events.running:
|
||||
@ -37,6 +52,7 @@ while events.running:
|
||||
all_sprites.update()
|
||||
screen.fill(BLACK)
|
||||
# draw
|
||||
draw_debug_text()
|
||||
all_sprites.draw(screen)
|
||||
pygame.display.flip()
|
||||
pygame.quit()
|
||||
|
12
sprites.py
12
sprites.py
@ -16,7 +16,7 @@ def load_img(name):
|
||||
return image, image.get_rect()
|
||||
|
||||
def load_sound(name):
|
||||
sound_path=os.path.join('data\\sounds')
|
||||
sound_path=os.path.join('data/sounds')
|
||||
sound=pygame.mixer.Sound(sound_path)
|
||||
return sound
|
||||
|
||||
@ -39,7 +39,6 @@ class Player(pygame.sprite.Sprite):
|
||||
self.friction=-0.25
|
||||
self.facing=0 # where the player is looking (0-north, 1-east, 2-south, 3-west)
|
||||
self.colliding=False
|
||||
|
||||
def moveup(self):
|
||||
if self.facing!=0:
|
||||
self.image=pygame.transform.rotate(self.image, (self.facing*90))
|
||||
@ -49,25 +48,28 @@ class Player(pygame.sprite.Sprite):
|
||||
|
||||
def movedown(self):
|
||||
if self.facing!=2:
|
||||
self.image=pygame.transform.rotate(self.image, (self.facing*90))
|
||||
self.image=pygame.transform.rotate(self.image, (self.facing*90)-180)
|
||||
self.facing=2
|
||||
self.acc.y=1.5
|
||||
self.acc.x=0
|
||||
|
||||
def moveright(self):
|
||||
if self.facing!=1:
|
||||
self.image=pygame.transform.rotate(self.image, (self.facing*90))
|
||||
self.image=pygame.transform.rotate(self.image, (self.facing*90)-90)
|
||||
self.facing=1
|
||||
self.acc.x=1.5
|
||||
self.acc.y=0
|
||||
|
||||
def moveleft(self):
|
||||
if self.facing!=3:
|
||||
self.image=pygame.transform.rotate(self.image, (self.facing*90))
|
||||
self.image=pygame.transform.rotate(self.image, (self.facing*90)-270)
|
||||
self.facing=3
|
||||
self.acc.x=-1.5
|
||||
self.acc.y=0
|
||||
|
||||
def shoot(self):
|
||||
nothing
|
||||
|
||||
def stopmoving(self):
|
||||
self.acc=vec(0, 0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user