summaryrefslogtreecommitdiff
path: root/gui.py
diff options
context:
space:
mode:
authorSpitfireX <timm.weber@me.com>2015-08-16 04:48:55 +0200
committerFlorian Jung <flo@windfisch.org>2015-08-18 00:49:36 +0200
commit57609975e0ea98c7152859ffd4c965c0879608ad (patch)
treeec6a61039355c4cdea116d13ec44b68dcc417e51 /gui.py
parentecdfcf48607ab9a382695dd0cdbdaada5d731762 (diff)
draw_text is now callable externally (cherrypick from strategy-rework)
Diffstat (limited to 'gui.py')
-rw-r--r--gui.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/gui.py b/gui.py
index 0293152..92b1982 100644
--- a/gui.py
+++ b/gui.py
@@ -81,6 +81,25 @@ def draw_arc(pos, r, bounds, color, global_coords=True):
gfxdraw.arc(screen, pos[0], pos[1], r, int(bounds[0]*180/math.pi), int(bounds[1]*180/math.pi), color)
+def draw_text(pos, text, color, font_size=16, global_coords=True, draw_centered=False):
+ if global_coords:
+ pos = world_to_win_pt(pos, c.player.center)
+
+ output = None
+
+ if font_fallback:
+ font = pygame.font.SysFont(pygame.font.get_default_font(), font_size)
+ output = font.render(text, 1, color)
+ else:
+ font = pygame.freetype.SysFont(pygame.freetype.get_default_font(), font_size)
+ output = font.render(text, color)[0]
+
+ if draw_centered:
+ screen.blit(output, (pos[0] - (output.get_width()/2), pos[1] - (output.get_height()/2)))
+ else:
+ screen.blit(output, pos)
+ return output
+
def update():
pygame.display.update()
@@ -121,16 +140,6 @@ def generate_virus(spikes, spike_length, radius, global_coords):
points.append(t);
return points
-def draw_text(text, color, font_size):
- if font_fallback:
- font = pygame.font.SysFont(pygame.font.get_default_font(), font_size)
- output = font.render(text, 1, color)
- return output
- else:
- font = pygame.freetype.SysFont(pygame.freetype.get_default_font(), font_size)
- output = font.render(text, color)
- return output[0]
-
def draw_cell(cell):
cx,cy = world_to_win_pt(cell.pos,c.player.center)
radius = world_to_win_length(cell.size)
@@ -159,11 +168,13 @@ def draw_cell(cell):
font_size = 16
- surface = draw_text(cell.name, (0, 0, 0), font_size)
- screen.blit(surface, (cx - (surface.get_width()/2), cy + radius + 5))
+ draw_text((cx, cy + radius + 10), cell.name, (0, 0, 0), font_size, False, True)
+ # surface = draw_text(cell.name, (0, 0, 0), font_size)
+ # screen.blit(surface, (cx - (surface.get_width()/2), cy + radius + 5))
- surface = draw_text(str(int(cell.mass)), (255, 255, 255), font_size)
- screen.blit(surface, (cx - (surface.get_width()/2), cy - (surface.get_height()/2)))
+ draw_text((cx, cy), str(int(cell.mass)), (255, 255, 255), font_size, False, True)
+ # surface = draw_text(str(int(cell.mass)), (255, 255, 255), font_size)
+ # screen.blit(surface, (cx - (surface.get_width()/2), cy - (surface.get_height()/2)))
else:
gfxdraw.aacircle(screen, cx, cy, radius, color)
gfxdraw.filled_circle(screen, cx, cy, radius, color)
@@ -175,8 +186,9 @@ def draw_leaderboard():
font_size = 16
for i, s in zip(range(1, len(leaderboard)+1), leaderboard):
- surface = draw_text((str(i) + ": " +s), (0, 0, 0), font_size)
- screen.blit(surface, (5, next_y))
+ surface = draw_text((5, next_y), (str(i) + ": " +s), (0, 0, 0), font_size, False)
+ # surface = draw_text((str(i) + ": " +s), (0, 0, 0), font_size)
+ # screen.blit(surface, (5, next_y))
next_y += surface.get_height()+5
def draw_world_borders():