2020-03-28 20:56:52 +01:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
|
|
|
### Tangled Mind
|
|
|
|
### Author: Arthur 'Grizzly' Grisel-Davy
|
|
|
|
|
|
|
|
import pygame
|
|
|
|
|
|
|
|
class perso():
|
|
|
|
|
2020-03-29 04:38:20 +02:00
|
|
|
def __init__(self,name,posx,posy,key_up,key_down,key_left,key_right,texture):
|
2020-03-28 20:56:52 +01:00
|
|
|
self.name = name
|
|
|
|
self.posx = posx
|
|
|
|
self.posy = posy
|
|
|
|
self.key_up = key_up
|
|
|
|
self.key_down = key_down
|
|
|
|
self.key_left = key_left
|
|
|
|
self.key_right = key_right
|
2020-03-29 21:45:37 +02:00
|
|
|
self.img_up = pygame.image.load(texture+'_up.png')
|
|
|
|
self.img_down = pygame.image.load(texture+'_down.png')
|
|
|
|
self.img_right = pygame.image.load(texture+'_right.png')
|
|
|
|
self.img_left = pygame.image.load(texture+'_left.png')
|
|
|
|
self.img = self.img_up
|
2020-03-29 04:38:20 +02:00
|
|
|
self.size = self.img.get_size()
|
2020-03-28 20:56:52 +01:00
|
|
|
|
|
|
|
def check_move(self,keystate,screen_width,screen_height,speed):
|
|
|
|
if keystate[self.key_left]:
|
|
|
|
self.posx -= speed
|
|
|
|
if self.posx <0:
|
|
|
|
self.posx=0
|
2020-03-29 21:45:37 +02:00
|
|
|
self.img = self.img_left
|
2020-03-28 20:56:52 +01:00
|
|
|
if keystate[self.key_right]:
|
|
|
|
self.posx += speed
|
2020-03-29 04:38:20 +02:00
|
|
|
if self.posx+self.size[0] > screen_width:
|
|
|
|
self.posx = screen_width-self.size[0]
|
2020-03-29 21:45:37 +02:00
|
|
|
self.img = self.img_right
|
2020-03-28 20:56:52 +01:00
|
|
|
if keystate[self.key_up]:
|
|
|
|
self.posy -= speed
|
|
|
|
if self.posy < 0:
|
|
|
|
self.posy = 0
|
2020-03-29 21:45:37 +02:00
|
|
|
self.img = self.img_up
|
2020-03-28 20:56:52 +01:00
|
|
|
if keystate[self.key_down]:
|
|
|
|
self.posy += speed
|
2020-03-29 04:38:20 +02:00
|
|
|
if self.posy+self.size[1] > screen_height:
|
|
|
|
self.posy = screen_height-self.size[1]
|
2020-03-29 21:45:37 +02:00
|
|
|
self.img = self.img_down
|
2020-03-28 20:56:52 +01:00
|
|
|
|
|
|
|
def draw(self,surface):
|
2020-03-29 04:38:20 +02:00
|
|
|
surface.blit(self.img,(self.posx,self.posy))
|