-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.py
More file actions
71 lines (56 loc) · 2.01 KB
/
Copy pathrenderer.py
File metadata and controls
71 lines (56 loc) · 2.01 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
import pygame, operator, random
from pygame import *
#from player import Player
import board, game
def init (isize) :
global size, boardercolor, screen
global black, green, blue, pink, maroon
pink = [ 255, 0, 255]
blue = [ 0, 0, 255]
maroon = [128, 0, 0]
size = isize
screen = pygame.display.set_mode(isize)
black = [0,0,0]
green = [0,200,0]
boardercolor = [160,140,20]
scorehieght = 16
size[1] -= scorehieght
def getRect(pixel):
return Rect(map(operator.mul, pixel, pixelsize), pixelsize)
def updateboard () :
global boardimage, pixelsize, rfont
boardimage = pygame.Surface(size)
pixelsize = map (operator.div, size, board.dim)
rfont = pygame.font.Font(None, int (pixelsize[1]*1.6))
for pixel in board.obstacles :
boardimage.fill (boardercolor, getRect(pixel))
def render ():
screen.fill(black)
screen.blit(boardimage, [0]*2)
for player in game.players :
if not player.playing:
continue
pixels = player.body
if player.dead > 0:
pixels = random.sample (pixels, player.dead * len(pixels) / player.deadtimer)
for pixel in pixels :
screen.fill (player.color, getRect(pixel))
for place,item in game.items.iteritems():
# TODO: Replace them with images
text = rfont.render (item["type"], True, boardercolor)
screen.blit(text, getRect(place))
share = size[0] / len(game.players)
for pixel in list(game.blocked):
screen.fill([100,100,100], Rect((pixel[0] * pixelsize[0] + pixelsize[0] /3 , pixel[1] * pixelsize[1] + pixelsize[1] / 3), (pixelsize[0] / 3, pixelsize[1] / 3)))
for num,player in enumerate(game.players) :
text = rfont.render ("{}, Score: {}, Lives: {} "\
.format(player.name, player.score, player.lives), True, player.color)
loc = share * num + (share - text.get_size()[0]) / 2, size[1] + 1
screen.blit (text, loc)
if game.gameover:
gfont = pygame.font.Font(None,size[1]/3)
text = gfont.render ("Game Over", True, maroon)
loc = map(operator.div, map(operator.sub, size, text.get_size()), [2]*2)
screen.blit (text, loc)
pygame.display.flip()
# vim: ts=2 sw=2