-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.py
52 lines (44 loc) · 1.74 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
File for player functions (move, attack, etc.)
"""
import game
import pygame
from pygame.locals import *
from pytmx.util_pygame import load_pygame
class Player:
def __init__(self, x, y):
self.image = pygame.image.load("tile PNGs\\blueWizard.png")
self.x = x
self.y = y
self.speed = 10
def draw(self, XYpos, screen):
screen.blit(self.image, XYpos)
def getMapProperties(self, x, y):
xTile = x // 16
yTile = y // 16
wallProp = game.Game().tmxdata.get_tile_properties(xTile, yTile, 0)
stairProp = game.Game().tmxdata.get_tile_properties(xTile, yTile, 1)
#print("got wall props")
if wallProp is None and stairProp is None:
wallProp = {"solid":0, "stairs":0}
stairProp = {"solid":0, "stairs":0}
return (wallProp, stairProp)
def move(self, x, y, keyPressed, tmxdata):
if keyPressed[ord("a")]: # check what key was pressed
westTile = self.getMapProperties(x-5, y+11) #find the tile next to the player and get its properties
if westTile[0]['solid'] == 0: # if not solid keep moving, stop otherwise
x += -self.speed
if keyPressed[ord("d")]:
eastTile = self.getMapProperties(x+24, y+22)
if eastTile[0]['solid'] == 0:
x += self.speed
if keyPressed[ord("w")]:
northTile = self.getMapProperties(x, y)
if northTile[0]['solid'] == 0:
y += -self.speed
if keyPressed[ord("s")]:
southTile = self.getMapProperties(x-2, y+32)
if southTile[0]['solid'] == 0:
y += self.speed
return(x, y)
#def attack(self, dt):