Skip to content

Commit

Permalink
added animated hourglass, still independant of actual load progess
Browse files Browse the repository at this point in the history
  • Loading branch information
BinkyToo committed Dec 7, 2014
1 parent 08aeed8 commit 1d872bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions WorldView.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,40 @@
from TextBox import TextBox
from colors import *
import pygame
import time
import random

class WorldView:
def __init__(self, player, window):
self.player = player
self.window = window
self.geplayer = None
self.scrollpos = None
self.progress = 0.0

def draw(self, region):
with self.player.statelock:
state = self.player.state
mapdef = self.player.mapdef
geplayer = self.player.geplayer
if state != 'normal':
def splash(message, fontsize=40, icon=None):
def splash(message, fontsize=40, icon=None, progress=1.0):
"""Display a splash message across the viewing area"""
pygame.draw.rect(self.window, BLACK, region)
textbox = TextBox(fontsize, WHITE, False)
if icon == HourGlass:
progress = (0.5*progress)+0.25
iconleft = (region.size[0]-icon.get_size()[0])/2
icontop = (region.size[1]-icon.get_size()[1])/2
iconwidth = icon.get_rect().width
iconhalfheight = icon.get_rect().height/2
upperrect = (iconleft, icontop+(iconhalfheight*progress)), (iconwidth, iconhalfheight*(1-progress))
lowerrect = (iconleft, icontop+(iconhalfheight*(2-progress))), (iconwidth, iconhalfheight*progress)
pygame.draw.rect(self.window, DARKYELLOW, upperrect)
pygame.draw.rect(self.window, DARKYELLOW, lowerrect)
pygame.draw.line(self.window, DARKYELLOW, (iconleft+(iconwidth/2), icontop+iconhalfheight), (iconleft+(iconwidth/2)+random.randint(-2, 2), icontop+(2*iconhalfheight)-1))
if icon is not None:
pass
self.window.blit(icon, [(region.size[axis]-icon.get_size()[axis])/2 for axis in [0,1]])
region.move_ip(0, icon.get_height()/2 + fontsize)
textbox.draw(message, region, surface=self.window)
Expand All @@ -30,7 +45,11 @@ def splash(message, fontsize=40, icon=None):
elif state == 'won':
splash("You won!")
elif state == 'loading':
splash("Loading "+mapdef['name'], 25, HourGlass)
splash("Loading "+mapdef['name'], 25, HourGlass, self.progress)
if self.progress < 1:
self.progress += 0.02
else:
self.progress = 0
elif state == 'crashed':
splash("Game crashed!")
return self.scrollpos
Expand Down
Binary file modified hud/HourGlass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hud/HourGlass.xcf
Binary file not shown.

0 comments on commit 1d872bd

Please sign in to comment.