forked from utmgdsc/dino-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.py
37 lines (31 loc) · 1.22 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
import pygame as pg
from constants import *
from sound import Sound
class Player:
def __init__(self, surface: pg.Surface):
self.width = PLAYER_WIDTH
self.height = PLAYER_HEIGHT
self.initial_pos = X_OFFSET, surface.get_height() - self.height
self.rect = pg.rect.Rect(X_OFFSET, surface.get_height() - self.height,
self.width,
self.height)
self.jumping = False
self.velocity = 0
self.sound = Sound()
def show(self, surface: pg.Surface):
pg.draw.rect(surface, PLAYER_COLOR, self.rect)
def jump(self):
if self.jumping:
return
self.jumping = True
if not self.sound.no_music:
self.sound.play('jump')
self.velocity = PLAYER_JUMP_FORCE
def update_coords(self, dt):
if self.jumping:
self.rect.move_ip(0, -dt * self.velocity * PLAYER_JUMP_COEFFICIENT)
self.velocity = self.velocity + dt * GRAVITY
if self.rect.y > self.initial_pos[1]:
self.rect.update(self.initial_pos[0], self.initial_pos[1],
PLAYER_WIDTH, PLAYER_HEIGHT)
self.jumping = False