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:
|
if p==1:
|
||||||
players[0].colliding=True
|
players[0].colliding=True
|
||||||
direction=players[1].facing
|
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
|
players[0].facing=(direction+2)%4
|
||||||
return True
|
return True
|
||||||
elif p==0:
|
elif p==0:
|
||||||
players[1].colliding=True
|
players[1].colliding=True
|
||||||
direction=players[0].facing
|
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
|
players[1].facing=(direction+2)%4
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
16
mygame.py
16
mygame.py
@ -26,6 +26,21 @@ all_sprites.add(events.players)
|
|||||||
|
|
||||||
events.running=True
|
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
|
# game loop
|
||||||
|
|
||||||
while events.running:
|
while events.running:
|
||||||
@ -37,6 +52,7 @@ while events.running:
|
|||||||
all_sprites.update()
|
all_sprites.update()
|
||||||
screen.fill(BLACK)
|
screen.fill(BLACK)
|
||||||
# draw
|
# draw
|
||||||
|
draw_debug_text()
|
||||||
all_sprites.draw(screen)
|
all_sprites.draw(screen)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
12
sprites.py
12
sprites.py
@ -16,7 +16,7 @@ def load_img(name):
|
|||||||
return image, image.get_rect()
|
return image, image.get_rect()
|
||||||
|
|
||||||
def load_sound(name):
|
def load_sound(name):
|
||||||
sound_path=os.path.join('data\\sounds')
|
sound_path=os.path.join('data/sounds')
|
||||||
sound=pygame.mixer.Sound(sound_path)
|
sound=pygame.mixer.Sound(sound_path)
|
||||||
return sound
|
return sound
|
||||||
|
|
||||||
@ -39,7 +39,6 @@ class Player(pygame.sprite.Sprite):
|
|||||||
self.friction=-0.25
|
self.friction=-0.25
|
||||||
self.facing=0 # where the player is looking (0-north, 1-east, 2-south, 3-west)
|
self.facing=0 # where the player is looking (0-north, 1-east, 2-south, 3-west)
|
||||||
self.colliding=False
|
self.colliding=False
|
||||||
|
|
||||||
def moveup(self):
|
def moveup(self):
|
||||||
if self.facing!=0:
|
if self.facing!=0:
|
||||||
self.image=pygame.transform.rotate(self.image, (self.facing*90))
|
self.image=pygame.transform.rotate(self.image, (self.facing*90))
|
||||||
@ -49,25 +48,28 @@ class Player(pygame.sprite.Sprite):
|
|||||||
|
|
||||||
def movedown(self):
|
def movedown(self):
|
||||||
if self.facing!=2:
|
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.facing=2
|
||||||
self.acc.y=1.5
|
self.acc.y=1.5
|
||||||
self.acc.x=0
|
self.acc.x=0
|
||||||
|
|
||||||
def moveright(self):
|
def moveright(self):
|
||||||
if self.facing!=1:
|
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.facing=1
|
||||||
self.acc.x=1.5
|
self.acc.x=1.5
|
||||||
self.acc.y=0
|
self.acc.y=0
|
||||||
|
|
||||||
def moveleft(self):
|
def moveleft(self):
|
||||||
if self.facing!=3:
|
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.facing=3
|
||||||
self.acc.x=-1.5
|
self.acc.x=-1.5
|
||||||
self.acc.y=0
|
self.acc.y=0
|
||||||
|
|
||||||
|
def shoot(self):
|
||||||
|
nothing
|
||||||
|
|
||||||
def stopmoving(self):
|
def stopmoving(self):
|
||||||
self.acc=vec(0, 0)
|
self.acc=vec(0, 0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user