-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathentities.py
More file actions
45 lines (38 loc) · 1.61 KB
/
entities.py
File metadata and controls
45 lines (38 loc) · 1.61 KB
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
import pygame
from math import sin
class Entity(pygame.sprite.Sprite):
def __init__(self, groups):
super().__init__(groups)
self.frame_index = 0
self.animation_speed = 0.15
self.direction = pygame.math.Vector2()
def move(self, speed):
#CORRIGIR A MOVIMENTAÇÃO QUANDO O PERSONAGEM ANDA NA DIAGONAL
if self.direction.magnitude() != 0:
self.direction = self.direction.normalize()
self.hitbox.x += self.direction.x * speed
self.colisao('horizontal')
self.hitbox.y += self.direction.y * speed
self.colisao('vertical')
self.rect.center = self.hitbox.center
def colisao(self, direcao):
if direcao == 'horizontal':
for sprite in self.obstaculo_sprites:
if sprite.hitbox.colliderect(self.hitbox):
if self.direction.x > 0: #INDO PARA A DIREITA
self.hitbox.right = sprite.hitbox.left
if self.direction.x < 0: #INDO PARA A ESQUERDA
self.hitbox.left = sprite.hitbox.right
if direcao == 'vertical':
for sprite in self.obstaculo_sprites:
if sprite.hitbox.colliderect(self.hitbox):
if self.direction.y > 0: #INDO PARA BAIXO
self.hitbox.bottom = sprite.hitbox.top
if self.direction.y < 0: #INDO PARA CIMA
self.hitbox.top = sprite.hitbox.bottom
def flicker(self):
value = sin(pygame.time.get_ticks())
if value >= 0:
return 255
else:
return 0