Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Player(object):
- def __init__(self, x, y):
- self.x = x
- self.y = y
- self.vel = tiles.tilesize / 12
- self.xVel = 0
- self.yVel = 0
- self.left = False
- self.right = False
- self.up = False
- self.down = False
- self.walkCount = 0
- self.dlugoscKroku = 32
- #self.kordy = [round(self.x / 32), round(self.y / 32)]
- self.hitbox = (self.x, self.y, 40, 52)
- self.colision = pygame.draw.rect(surface, (0,0,0), (self.hitbox[0], self.hitbox[1], 40,52))
- self.rect = self.colision
- self.kolizjaTarm = False
- self.basicfont = pygame.font.SysFont(None, 25)
- self.text = self.basicfont.render(str(textMsg), True, (255, 0, 0), (255, 255, 255))
- self.textrect = self.text.get_rect()
- self.textrect.centerx = self.x + 20
- self.textrect.centery = self.y - 15
- self.map2 = None
- def show_coordinates(self):
- self.kordy = [round(self.x / 32), round(self.y / 32)]
- return self.kordy
- def draw(self, win):
- #self.map_handler()
- if self.walkCount + 1 >= 12:
- self.walkCount = 0
- if self.left:
- win.blit(tiles.walkLeft[self.walkCount//3],(self.x,self.y))
- self.walkCount += 1
- elif self.right:
- win.blit(tiles.walkRight[self.walkCount//3],(self.x,self.y))
- self.walkCount += 1
- elif self.up:
- win.blit(tiles.walkUp[self.walkCount//3], (self.x,self.y))
- self.walkCount += 1
- elif self.down:
- win.blit(tiles.walkDown[self.walkCount//3], (self.x, self.y))
- self.walkCount += 1
- else:
- win.blit(tiles.char, (self.x, self.y))
- self.hitbox = (self.x, self.y, 40, 52)
- self.colision = pygame.draw.rect(surface, (0,0,0), (self.hitbox[0], self.hitbox[1], 40,52))
- self.wall_collisions()
- def wall_collisions(self):
- """Handle collisions with walls."""
- self.rect.centerx = self.x
- if self.colision.colliderect(tarmus.colision):
- self.kolizjaTarm = True
- if self.xVel > 0:
- self.rect.right = tarmus.rect.left
- self.x = self.rect.x
- elif self.xVel < 0:
- self.rect.left = tarmus.rect.right
- self.x = self.rect.x
- self.rect.centery = self.y
- if self.colision.colliderect(tarmus.colision):# and self.yVel != 0:
- self.kolizjaTarm = True
- if self.yVel > 0:
- self.rect.bottom = tarmus.rect.top
- self.y = self.rect.y
- elif self.yVel < 0:
- self.rect.top = tarmus.rect.bottom
- self.y = self.rect.y
- blocksLength = len(blocks)
- for item in range(blocksLength):
- if self.colision.colliderect(blocks[item].colision):
- if self.xVel > 0:
- self.rect.right = blocks[item].rect.left
- self.x = self.rect.x
- elif self.xVel < 0:
- self.rect.left = blocks[item].rect.right
- self.x = self.rect.x
- for item in range(blocksLength):
- if self.colision.colliderect(blocks[item].colision) and self.yVel != 0:
- if self.yVel > 0:
- self.rect.bottom = blocks[item].rect.top
- self.y = self.rect.y
- elif self.yVel < 0:
- self.rect.top = blocks[item].rect.bottom
- self.y = self.rect.y
- def move_handler(self):
- self.keys = pygame.key.get_pressed()
- #self.map_handler()
- if self.keys[pygame.K_LEFT] and self.x >= self.vel - 10:
- self.x -= self.vel
- self.left = True
- self.right = False
- self.up = False
- self.down = False
- self.xVel = -3
- self.yVel = 0
- tiles.tilesize = 32
- self.kolizjaTarm = False
- elif self.keys[pygame.K_RIGHT] and self.x < 512 - self.vel - self.hitbox[2]:
- self.x += player.vel
- self.left = False
- self.right = True
- self.up = False
- self.down = False
- self.xVel = 3
- self.yVel = 0
- tiles.tilesize = 32
- self.kolizjaTarm = False
- elif self.keys[pygame.K_UP] and self.y >= self.vel - 10:
- self.y -= self.vel
- self.left = False
- self.right = False
- self.up = True
- self.down = False
- self.yVel = -3
- self.xVel = 0
- tiles.tilesize = 32
- self.kolizjaTarm = False
- elif self.keys[pygame.K_DOWN] and self.y < 512 - self.vel - self.hitbox[3]:
- self.y += self.vel
- self.left = False
- self.right = False
- self.up = False
- self.down = True
- self.yVel = 3
- self.xVel = 0
- tiles.tilesize = 32
- self.kolizjaTarm = False
- else:
- self.left = False
- self.right = False
- self.up = False
- self.down = False
- self.walkCount = 0
- tiles.tilesize = 32
- self.xVel = 0
- self.yVel = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement