-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
31 lines (26 loc) · 1008 Bytes
/
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
import pygame
from settings import *
class Player(pygame.sprite.Sprite):
def __init__(self, camera):
super().__init__()
self.image = pygame.Surface(PLAYER_SIZE)
self.image.fill((160, 219, 115))
self.rect = self.image.get_rect(center=(SCREEN_WIDTH // 2, int(SCREEN_HEIGHT * 0.9)))
self.mask = pygame.mask.from_surface(self.image)
self.max_speed = 30
self.camera = camera
self.counter = 0
self.x = SCREEN_WIDTH // 2
def update(self):
if self.counter == 0:
self.counter = 2
temp_x = self.camera.get_x()
self.x = (temp_x / 1080 * 1920) if temp_x != -1 else self.x
else:
self.counter -= 1
dx = self.x - self.rect.centerx
dx = min(self.max_speed, max(-self.max_speed, dx))
self.rect.x += dx
# dx = pygame.mouse.get_pos()[0] - self.rect.centerx
# dx = min(self.max_speed, max(-self.max_speed, dx))
# self.rect.x += dx