brightened second frame for all stars
shortened duration of second frame changed drawing code to do proper rect-updates instead of always doing fullscreen updates --HG-- branch : vssg
Before Width: | Height: | Size: 353 B After Width: | Height: | Size: 362 B |
Before Width: | Height: | Size: 538 B After Width: | Height: | Size: 543 B |
Before Width: | Height: | Size: 421 B After Width: | Height: | Size: 429 B |
Before Width: | Height: | Size: 354 B After Width: | Height: | Size: 363 B |
Before Width: | Height: | Size: 569 B After Width: | Height: | Size: 568 B |
Before Width: | Height: | Size: 424 B After Width: | Height: | Size: 471 B |
Before Width: | Height: | Size: 354 B After Width: | Height: | Size: 363 B |
Before Width: | Height: | Size: 572 B After Width: | Height: | Size: 563 B |
Before Width: | Height: | Size: 431 B After Width: | Height: | Size: 469 B |
Before Width: | Height: | Size: 308 B After Width: | Height: | Size: 324 B |
Before Width: | Height: | Size: 499 B After Width: | Height: | Size: 502 B |
Before Width: | Height: | Size: 403 B After Width: | Height: | Size: 405 B |
Before Width: | Height: | Size: 346 B After Width: | Height: | Size: 345 B |
Before Width: | Height: | Size: 350 B After Width: | Height: | Size: 354 B |
Before Width: | Height: | Size: 533 B After Width: | Height: | Size: 503 B |
Before Width: | Height: | Size: 418 B After Width: | Height: | Size: 419 B |
25
starmap.py
|
@ -2,21 +2,30 @@ import math
|
|||
import pygame
|
||||
import random
|
||||
import gametimer
|
||||
import video
|
||||
|
||||
class Galaxy(object):
|
||||
def __init__(self, width, height):
|
||||
self.starmap = [[[] for x in range(width)] for x in range(height)]
|
||||
self.starlist = []
|
||||
self.selection = None
|
||||
self.selectionpng = None
|
||||
|
||||
def update(self):
|
||||
for star in self.get_all_stars():
|
||||
star.update()
|
||||
def draw(self, scr):
|
||||
if self.selectionpng == None:
|
||||
self.selectionpng = pygame.image.load("img/selection.png")
|
||||
self.selectionpng.convert_alpha(scr)
|
||||
for star in self.get_all_stars():
|
||||
if video.get_forced_redraw():
|
||||
star.draw_dirty = True
|
||||
star.draw(scr)
|
||||
|
||||
def add_star(self, star):
|
||||
self.starlist.append(star)
|
||||
star.map = self
|
||||
self.starmap[int(star.y / 100)][int(star.x / 100)].append(star)
|
||||
|
||||
def get_distance(self, x, y, x2, y2):
|
||||
|
@ -58,8 +67,12 @@ class StarSys(object):
|
|||
self.startype = startype
|
||||
self.habitat = habitat
|
||||
self.minerals = minerals
|
||||
self.map = None
|
||||
self.draw_dirty = True
|
||||
def draw(self, surf):
|
||||
self.startype.draw(surf, int(self.x / 10), int(self.y / 10), self.frame)
|
||||
if self.draw_dirty:
|
||||
self.startype.draw(self, surf, int(self.x / 10), int(self.y / 10), self.frame)
|
||||
self.draw_dirty = False
|
||||
def update(self):
|
||||
#if self.startype.size == "Dwarf" and self.startype.color == "White":
|
||||
#print gametimer.elapsed()
|
||||
|
@ -68,11 +81,14 @@ class StarSys(object):
|
|||
#print self.delays
|
||||
#sys.exit(0)
|
||||
self.frame_timer -= gametimer.elapsed()
|
||||
oldframe = self.frame
|
||||
while self.frame_timer <= 0:
|
||||
self.frame_timer += self.delays[self.frame]
|
||||
self.frame += 1
|
||||
if self.frame >= len(self.delays):
|
||||
self.frame = 0
|
||||
self.frame_timer += self.delays[self.frame]
|
||||
if self.frame != oldframe:
|
||||
self.draw_dirty = True
|
||||
|
||||
def set_frame_timers(self, delays):
|
||||
self.delays = [int(x * 1000) for x in delays]
|
||||
|
@ -88,7 +104,7 @@ class StarClass(object):
|
|||
self.minerals_mod = minerals_mod
|
||||
self.frames = None
|
||||
|
||||
def draw(self, surf, x, y, frame):
|
||||
def draw(self, star, surf, x, y, frame):
|
||||
if self.frames == None:
|
||||
self.frames = [pygame.image.load('img/%s_%s%d.png' % (self.color.lower(), self.size.lower(), i+1)) for i in range(2)]
|
||||
for png in self.frames:
|
||||
|
@ -97,4 +113,7 @@ class StarClass(object):
|
|||
dest.x = x - (dest.w / 2) + 1
|
||||
dest.y = y - (dest.h / 2) + 1
|
||||
surf.blit(self.frames[frame], dest)
|
||||
if id(star.map.selection) == id(star):
|
||||
surf.blit(star.map.selectionpng, dest)
|
||||
video.update(dest)
|
||||
|
||||
|
|
|
@ -167,8 +167,8 @@ def starmap_generate():
|
|||
print "Generated star %s %s %s at (%s, %s)" % (startype.name, hab, min, int(x), int(y))
|
||||
|
||||
star = StarSys(int(x), int(y), startype, hab, min)
|
||||
star.set_frame_timers([0.6 + (random.random() * 1.5), 0.6 + (random.random() * 1.5)])
|
||||
star.set_frame_timers([0.6 + (random.random() * 1.5), 0.2 + (random.random() * 0.5)])
|
||||
map.add_star(star)
|
||||
|
||||
map.selection = star
|
||||
i += 1
|
||||
return map
|
||||
|
|
69
video.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
import pygame
|
||||
|
||||
updatelist = []
|
||||
force_full = False
|
||||
g_scr = None
|
||||
|
||||
|
||||
def get_forced_redraw():
|
||||
global force_full
|
||||
return force_full
|
||||
|
||||
def force_redraw():
|
||||
"""
|
||||
>>> force_redraw() -> None
|
||||
forces a fullscreen update (slow! use with care)
|
||||
"""
|
||||
global updatelist, force_full
|
||||
updatelist = []
|
||||
force_full = True
|
||||
|
||||
def update(r):
|
||||
"""
|
||||
>>> update(rect) -> None
|
||||
queues the given rectangle(s) for an update
|
||||
"""
|
||||
global updatelist, force_full
|
||||
|
||||
if force_full:
|
||||
return
|
||||
if type(r) == tuple:
|
||||
r = list(r)
|
||||
elif type(r) != list:
|
||||
r = [r]
|
||||
updatelist += r
|
||||
if len(updatelist) > 100:
|
||||
force_full = True
|
||||
updatelist = []
|
||||
|
||||
|
||||
def next_frame():
|
||||
"""
|
||||
>>> next_frame() -> None
|
||||
finalizes and draws the next frame
|
||||
"""
|
||||
global updatelist, force_full
|
||||
|
||||
if force_full:
|
||||
print "Doing FULL redraw!"
|
||||
pygame.display.flip()
|
||||
else:
|
||||
pygame.display.update(updatelist)
|
||||
updatelist = []
|
||||
force_full = False
|
||||
|
||||
def set_scr(scr):
|
||||
"""
|
||||
>>> set_scr(scr) -> None
|
||||
sets the main screen (turn on?)
|
||||
"""
|
||||
global g_scr
|
||||
g_scr = scr
|
||||
|
||||
def get_scr():
|
||||
"""
|
||||
>>> get_scr() -> pygame.Surface
|
||||
gets the screen
|
||||
"""
|
||||
global g_scr
|
||||
return g_scr
|
14
vssg.py
|
@ -11,6 +11,7 @@ import starmap_gen
|
|||
import gametimer
|
||||
from ocempgui.widgets import *
|
||||
from ocempgui.widgets.Constants import *
|
||||
import video
|
||||
|
||||
|
||||
pygame.init()
|
||||
|
@ -194,6 +195,7 @@ while True:
|
|||
gametimer.next_frame()
|
||||
|
||||
if guiscreen != None:
|
||||
video.force_redraw() # irrelevant right now, but when we exit, we'll need a full redraw!
|
||||
for ev in events:
|
||||
if ev.type == QUIT:
|
||||
do_quit = True
|
||||
|
@ -202,7 +204,6 @@ while True:
|
|||
break
|
||||
guiscreen.distribute_events(*events)
|
||||
continue
|
||||
scr.fill((0,0,0))
|
||||
|
||||
|
||||
for ev in events:
|
||||
|
@ -216,13 +217,20 @@ while True:
|
|||
pass
|
||||
elif ev.type == KEYDOWN:
|
||||
keys += [ev.key]
|
||||
elif ev.type == VIDEOEXPOSE:
|
||||
video.force_redraw()
|
||||
elif ev.type in (MOUSEBUTTONDOWN, MOUSEBUTTONUP):
|
||||
pass
|
||||
|
||||
if do_quit:
|
||||
break
|
||||
|
||||
handle_keys(keys)
|
||||
map.update()
|
||||
|
||||
if video.get_forced_redraw():
|
||||
scr.fill((0,0,0))
|
||||
|
||||
map.draw(scr)
|
||||
|
||||
|
||||
pygame.display.flip()
|
||||
video.next_frame()
|
||||
|
|