Browse Source

Draw a player

master
Elis Axelsson 4 years ago
parent
commit
d7572498d3
  1. 62
      classes/player.py
  2. 9
      watersteal.py

62
classes/player.py

@ -0,0 +1,62 @@
class Player:
def __init__(self, pygame, color, size):
self.__size = size
self.__color = color
self.__pygame = pygame
self.__player = None
def getPlayer(self):
if not self.__player:
self.__player = self.__pygame.Surface(
self.__size,
self.__pygame.SRCALPHA
)
self.__pygame.draw.lines(
self.__player,
self.__color,
False,
[
# Left Arm
(0, 0),
# Top body
((self.__size[0] / 2), (self.__size[1] / 3)),
# Right Arm
(self.__size[0], 0),
# Top body
((self.__size[0] / 2), (self.__size[1] / 3)),
# Bottom body
((self.__size[0] / 2), (self.__size[1] / 5 * 4)),
# Left leg
(0, self.__size[1]),
# Bottom body
((self.__size[0] / 2), (self.__size[1] / 5 * 4)),
# Right leg
(self.__size[0], self.__size[1]),
# Bottom body
((self.__size[0] / 2), (self.__size[1] / 5 * 4)),
# Neck
((self.__size[0] / 2), (self.__size[1] / 5)),
# Neck
((self.__size[0] / 4), 0),
# Neck
((self.__size[0] / 4 * 3), 0),
# Neck
((self.__size[0] / 2), (self.__size[1] / 5)),
],
3
)
return self.__player

9
watersteal.py

@ -3,6 +3,7 @@
import sys, pygame
from classes.bucket import Bucket
from classes.player import Player
pygame.init()
@ -33,6 +34,11 @@ bucket = Bucket(pygame, (204, 204, 204), (50, 50)).getBucket()
bucketrect = bucket.get_rect()
bucketrect.bottomleft = (width * 0.9, (height / 4 * 3))
# Define a player.
player = Player(pygame, (0, 0, 0), (60, 100)).getPlayer()
playerrect = player.get_rect()
playerrect.bottomleft = (10, (height / 4 * 3))
while True:
# Handle events
for event in pygame.event.get():
@ -70,5 +76,8 @@ while True:
# Draw bucket
screen.blit(bucket, bucketrect)
# Draw player
screen.blit(player, playerrect)
# Upload buffer to real screen
pygame.display.flip()

Loading…
Cancel
Save