-
Notifications
You must be signed in to change notification settings - Fork 0
/
jugador.py
58 lines (56 loc) · 1.77 KB
/
jugador.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
import pygame
from settings import *
class Jugador(pygame.sprite.Sprite):
def __init__(self,pos,m):
pygame.sprite.Sprite.__init__(self)
self.m=m
self.accion=3
self.con=0
self.image=self.m[self.con]
self.rect=self.image.get_rect()
self.rect.x=pos[0]
self.rect.y=pos[1]
self.velx=0
self.vely=0
self.score=0
self.plataformas=None
def gravedad (self, g=0.7):
if self.vely == 0:
self.vely = g
else:
self.vely += g
def update(self):
if self.velx!=self.vely:
if self.con < self.accion:
self.con+=1
else:
self.con=0
self.image=self.m[self.con]
self.rect.x+=self.velx
ls_col=pygame.sprite.spritecollide(self,self.plataformas,False)
#Colision en X
for b in ls_col:
if self.velx > 0:
if self.rect.right > b.rect.left:
self.rect.right= b.rect.left
self.velx=0
else:
if self.rect.left < b.rect.right:
self.rect.left= b.rect.right
self.velx=0
#Colision en Y
self.rect.y+=self.vely
ls_col=pygame.sprite.spritecollide(self,self.plataformas,False)
for b in ls_col:
if self.vely > 0:
if self.rect.bottom > b.rect.top:
self.rect.bottom= b.rect.top
self.vely=0
else:
if self.rect.top < b.rect.bottom:
self.rect.top= b.rect.bottom
self.vely=0
self.gravedad()
""" if self.rect.bottom > ALTO:
self.rect.bottom=ALTO
self.vely=0 """