-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.py
73 lines (61 loc) · 2.24 KB
/
Player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
"""Player Class"""
import pygame
from Constants import *
from BulletManager import *
from LevelLoader import *
from Sword import Sword
from Gun import Gun
__author__ = "Joshua Sonnenberg and Ethan Richardson"
pygame.mixer.init(44100, -16, 2, 2048)
player_death_sound = pygame.mixer.Sound('Player_Death.wav')
class Player(pygame.Rect):
"""Handles player input, logic, and display"""
def __init__(self, surface):
"""Constructor"""
super(Player, self).__init__(PLAYER_X, PLAYER_Y, PLAYER_WID, PLAYER_HT)
self.surface = surface
self.bullet_manager = BulletManager()
self.gun = Gun(self, surface)
self.sword = Sword(self)
self.speed = 10
self.ammo = 6
self.status = 'GROUND'
self.facing = 'RSTOP'
self.current_weapon = 'GUN'
self.lives = 3
self.hit = [0, 0]
self.jump_offset = 200
def move(self, levelloader):
"""Handles x movement and collisions"""
self.hit = levelloader.check_collisions(self, False)
if self.facing == 'LEFT':
if self.x > PLAYER_WID:
self.x -= PLAYER_SPEED
if self.facing == 'RIGHT':
if self.x < SCREEN_WIDTH/2:
self.x += PLAYER_SPEED
elif self.x >= SCREEN_WIDTH/2 and not levelloader.end_of_level:
levelloader.shift(self.speed)
else:
self.x += PLAYER_SPEED
def update_jump(self):
"""Updates game based on player input"""
if self.status == 'RISE' and self.y > PLAYER_JUMP_HT-self.jump_offset:
self.y -= PLAYER_GRAVITY
elif self.status == 'FALL' and self.y < SCREEN_HEIGHT-PLAYER_HT-GROUND_HEIGHT and self.status != 'GROUND':
self.y += PLAYER_GRAVITY
else:
self.status = 'GROUND'
def die(self):
"""Handles player death"""
player_death_sound.play()
self.lives -= 1
self.x = PLAYER_X
self.y = PLAYER_Y
def update(self):
if self.current_weapon == 'GUN':
self.gun.draw()
elif self.current_weapon == 'SWORD':
self.sword.update()
pygame.draw.rect(self.surface, LIGHT_GREY, self.sword, 0)