Skip to content
Browse files

Merge pull request #8 from lczerner/more_cleanup

More cleanup
  • Loading branch information...
2 parents 247a80f + b8ebb1c commit c7592a3af3095dd53b15f65b61b5ce81816fc34b @heinervdm heinervdm committed
Showing with 771 additions and 5,041 deletions.
  1. +13 −20 MANIFEST.in
  2. +0 −3 monorail/ai.pyx
  3. +15 −17 monorail/control.py
  4. +6 −8 monorail/controlview.py
  5. +13 −14 monorail/event.py
  6. +1 −2 monorail/eventview.py
  7. +11 −12 monorail/frame.py
  8. +66 −67 monorail/hud.py
  9. +12 −13 monorail/koon/app.py
  10. +9 −10 monorail/koon/build.py
  11. +9 −10 monorail/koon/cfg.py
  12. +9 −9 monorail/koon/geo.py
  13. +13 −15 monorail/koon/gfx.py
  14. +39 −40 monorail/koon/gui.py
  15. +3 −4 monorail/koon/input.py
  16. +7 −8 monorail/koon/res.py
  17. +6 −7 monorail/koon/snd.py
  18. +8 −9 monorail/koon/tests/test_cfg.py
  19. +0 −1 monorail/koon/tests/test_geo.py
  20. +5 −6 monorail/koon/tests/test_gfx.py
  21. +33 −34 monorail/koon/tests/test_gui.py
  22. +6 −7 monorail/koon/tests/test_input.py
  23. +1 −2 monorail/koon/tests/test_res.py
  24. +1 −2 monorail/koon/tests/test_snd.py
  25. +0 −4,207 monorail/mac_ai/ai.c
  26. BIN monorail/mac_ai/ai.so
  27. +51 −52 monorail/menu.py
  28. +18 −18 monorail/monkey.py
  29. +39 −40 monorail/monorail.py
  30. +10 −11 monorail/pickups.py
  31. +21 −22 monorail/pickupsview.py
  32. +20 −21 monorail/player.py
  33. +12 −13 monorail/playerview.py
  34. +54 −55 monorail/scenarios.py
  35. +23 −24 monorail/settings.py
  36. +2 −5 monorail/setup.py
  37. +2 −0 monorail/setup_py2app.py
  38. +6 −7 monorail/sndman.py
  39. +27 −28 monorail/tests/test_ai.py
  40. +18 −19 monorail/tests/test_control.py
  41. +4 −5 monorail/tests/test_frame.py
  42. +2 −3 monorail/tests/test_geo.py
  43. +0 −1 monorail/tests/test_menu.py
  44. +2 −3 monorail/tests/test_pickups.py
  45. +2 −3 monorail/tests/test_pickupsview.py
  46. +7 −8 monorail/tests/test_player.py
  47. +2 −3 monorail/tests/test_playerview.py
  48. +4 −5 monorail/tests/test_scenarios.py
  49. +2 −3 monorail/tests/test_settings.py
  50. +22 −23 monorail/tests/test_tiles.py
  51. +46 −47 monorail/tests/test_world.py
  52. +47 −50 monorail/tiles.py
  53. +9 −10 monorail/tilesview.py
  54. +26 −27 monorail/world.py
  55. +3 −4 monorail/worldview.py
  56. +4 −4 setup.py
View
33 MANIFEST.in
@@ -1,25 +1,17 @@
-include README README.md setup.py build.py LICENSE.txt MysticMine
+include README
+include README.md
+include setup.py
+include build.py
+include LICENSE.txt
+include MysticMine
+include Makefile
-include locales/gettext.sh locales/messages.pot locales/de_DE.po locales/en_US.po locales/ru_RU.po
+include data/800x600/edmunds.ttf
+data/800x600/font_default.fnt
+data/800x600/font_default.png
+data/800x600/resources.cfg
-include data/800x600/edmunds.ttf data/800x600/font_default.fnt data/800x600/font_default.png data/800x600/resources.cfg
-
-include monorail/fonts/freesansbold.ttf
-
-include monorail/__init__.py monorail/ai.pyx monorail/control.py monorail/controlview.py monorail/event.py
-include monorail/eventview.py monorail/frame.py monorail/hud.py monorail/menu.py monorail/monkey.py
-include monorail/monorail.py monorail/pickups.py monorail/pickupsview.py monorail/player.py
-include monorail/playerview.py monorail/profile.py monorail/scenarios.py monorail/settings.py
-include monorail/setup.py monorail/setup_py2app.py monorail/setup_py2exe.py monorail/sndman.py
-include monorail/tiles.py monorail/tilesview.py monorail/world.py monorail/worldview.py
-
-include monorail/koon/__init__.py monorail/koon/app.py monorail/koon/build.py monorail/koon/cfg.py monorail/koon/geo.py
-include monorail/koon/gfx.py monorail/koon/gui.py monorail/koon/input.py monorail/koon/res.py monorail/koon/snd.py
-
-include monorail/tests/__init__.py monorail/tests/test_ai.py monorail/tests/test_control.py monorail/tests/test_frame.py
-include monorail/tests/test_geo.py monorail/tests/test_menu.py monorail/tests/test_pickups.py monorail/tests/test_pickupsview.py
-include monorail/tests/test_player.py monorail/tests/test_playerview.py monorail/tests/test_scenarios.py
-include monorail/tests/test_settings.py monorail/tests/test_tiles.py monorail/tests/test_world.py
+recursive-include monorail *.py *.pyx *.lvl *.ttf
recursive-include data/800x600/gfx *
recursive-include data/800x600/levels *
@@ -28,3 +20,4 @@ recursive-include data/800x600/music *
recursive-include data/800x600/snd *
recursive-include assets *
+recursive-include locales *
View
3 monorail/ai.pyx
@@ -1,7 +1,4 @@
-#!/usr/bin/env python
-
import copy
-
import tiles
import pickups
View
32 monorail/control.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
import random
from koon.input import Mouse
@@ -25,7 +23,7 @@ def game_tick( self, indev ):
# for debugging
if hasattr(self, "views"):
self.views[0].game_tick( indev )
-
+
# check each goldcar's keys
for controller in self.controllers:
controller.do_tick( indev )
@@ -38,7 +36,7 @@ def game_tick( self, indev ):
tile_x = (-mouse_y + (mouse_x+32)/2 - X_OFFSET/2 + Y_OFFSET) / 32
tile_y = (mouse_y + (mouse_x-32)/2 - X_OFFSET/2 - Y_OFFSET) / 32
-
+
tile = self.playfield.level.get_tile( tile_x, tile_y )
if tile is not None and tile.is_switch():
@@ -58,7 +56,7 @@ def game_tick( self, indev ):
if not had_it:
tile.switch_it()
- if self.contains_ai:
+ if self.contains_ai:
self._update_prediction_trees()
def add_controllers( self, controllers ):
@@ -79,7 +77,7 @@ def add_controllers( self, controllers ):
if not isinstance( controller, HumanController ):
self.contains_ai = True
-
+
i += 1
def _update_prediction_trees( self ):
@@ -103,7 +101,7 @@ def _update_prediction_trees( self ):
## if prediction_tree.root_node is not None:
## print prediction_tree.root_node._best_score,
i += 1
-
+
def _get_other_prediction_trees( self, car ):
"""Return all prediction trees that are not from car.
"""
@@ -115,7 +113,7 @@ def _get_other_prediction_trees( self, car ):
if car_it is not car:
trees.append( prediction_tree )
- i += 1
+ i += 1
return trees
@@ -128,15 +126,15 @@ def get_tree( self, car ):
return prediction_tree
i += 1
- return None
-
-class Controller:
+ return None
+
+class Controller:
"""Controller of a goldcar
public members:
- prediction_tree: the prediction tree of the goldcar
"""
-
+
def __init__( self, goldcar ):
"""goldcar can be None"""
self.goldcar = goldcar
@@ -176,11 +174,11 @@ def __init__( self, goldcar, iq = 1.0 ):
self.prev_switch = None
self.best_dir = None
self.iq = iq
-
+
def do_tick( self, indev ):
if self.goldcar.switch is not None:
switch_node = self.find_switch_node()
-
+
# find best direction for switch
if switch_node is not None:
best_childs = switch_node.get_best_childs()
@@ -190,7 +188,7 @@ def do_tick( self, indev ):
self.best_dir = None
else:
self.best_dir = None
-
+
self.handle_switching()
# TODO: improve algorithm here!
@@ -204,7 +202,7 @@ def find_switch_node( self ):
if len(best_childs) > 0:
node_it = best_childs[0]
## if node_it._best_score < 0:
-## print node_it._best_score
+## print node_it._best_score
else:
node_it = None
else:
@@ -224,4 +222,4 @@ def handle_switching( self ):
else: # Stupid move
if random.randint(0,32) == 0:
self.goldcar.keydown()
-
+
View
14 monorail/controlview.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
import pygame
from pygame.locals import *
@@ -25,17 +23,17 @@ def game_tick( self, indev ):
self.generation += 1
if indev.key.went_down( K_g ):
self.show_best_score = not self.show_best_score
-
+
def draw( self, frame ):
return
-
+
i = 0
for tree in self.model.prediction_trees:
car = self.model.playfield.goldcars[i]
if tree.root_node is not None:
- if i == 0:
+ if i == 0:
font = gfx.Font( None, 20, (255,0,0) )
else:
font = gfx.Font( None, 20, (0,255,0) )
@@ -48,15 +46,15 @@ def draw( self, frame ):
x = tile.pos.x * 32 + tile.pos.y * 32 + frame.X_OFFSET + 32
y = -tile.pos.x * 16 + tile.pos.y * 16 + frame.Y_OFFSET + 16 + (i * 10 - 10)
- if self.show_best_score:
+ if self.show_best_score:
score = ai_node.get_best_score()
else:
score = ai_node.get_score()
-
+
## font.draw( "%02.2f" % score, frame.surface, (x,y),
## gfx.Font.CENTER, gfx.Font.MIDDLE )
font.draw( str(score), frame.surface, (x,y),
gfx.Font.CENTER, gfx.Font.MIDDLE )
-
+
i += 1
View
27 monorail/event.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import pygame
import random
@@ -29,10 +28,10 @@ def update( self ):
def draw( self, frame ):
pos = (self.pos[0] + frame.X_OFFSET,
self.pos[1] + frame.Y_OFFSET + self.life - 50)
-
+
self.font.draw( self.text, frame.surface, pos,
align=gfx.Font.CENTER, valign=gfx.Font.MIDDLE )
-
+
def is_alive( self ):
return self.life >= 0
@@ -58,27 +57,27 @@ def update():
resman.get("game.fuse_sound").is_playing():
resman.get("game.fuse_sound").stop()
Event.instance.play_fuse = False
-
+
@staticmethod
def dynamite_fuse():
Event.instance.play_fuse = True
@staticmethod
def dynamite_tick():
- resman.get("game.dynamite_tick_sound").play()
+ resman.get("game.dynamite_tick_sound").play()
@staticmethod
def coin_pickup( score, carpos ):
- resman.get("game.coin_sound").play()
+ resman.get("game.coin_sound").play()
Event.instance.points.append( Point( score, carpos.get_screen_position() ) )
-
+
@staticmethod
def flag_pickup( score, carpos ):
resman.get("game.collect_sound").play()
Event.instance.points.append( Point( score, carpos.get_screen_position() ) )
-
+
@staticmethod
def carhit():
resman.get("game.carhit_sound").play()
@@ -181,14 +180,14 @@ def game_tick( self ):
def is_dead( self ):
return self.progress > 1.0
-
+
def render( self, surface, x_offset, y_offset ):
if self.progress <= 1.0:
pos = self.pos
gold_sprite = resman.get("game.copper_sprite")
gold_sprite.draw( surface, pos + Vec2D(x_offset, y_offset) )
-
-
+
+
def __init__( self, pos, end_tiles ):
self.particles = []
for tile in end_tiles:
@@ -201,7 +200,7 @@ def __init__( self, pos, end_tiles ):
Event.explosion()
-
+
def game_tick( self ):
for particle in self.particles:
particle.game_tick()
@@ -216,7 +215,7 @@ def draw( self, frame ):
if self.animTimer is None:
self.animTimer = gfx.LoopAnimationTimer( 20, 0, 16 ) # real maxframe is in draw
self.animTimer.set_frame( frame.time_sec, 0 )
-
+
if self.sprite is not None:
self.sprite.nr = self.animTimer.get_frame( frame.time_sec )
@@ -224,6 +223,6 @@ def draw( self, frame ):
if self.sprite.nr >= 15:
self.sprite = None
-
+
def is_alive( self ):
return self.sprite is not None or len(self.particles > 0)
View
3 monorail/eventview.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import pygame
from pygame.locals import *
@@ -14,7 +13,7 @@ class EventView:
def __init__( self, model ):
self.model = model
-
+
def draw( self, frame ):
for point in self.model.points:
point.draw( frame )
View
23 monorail/frame.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
from world import *
from player import *
@@ -31,14 +30,14 @@ def __init__( self, surface, time_sec, interpol ):
def get_views( self, model ):
if hasattr( model, 'views' ) and model.views is not None:
return model.views
- else:
+ else:
if isinstance( model, Level):
views = [LevelView( model )]
elif isinstance( model, Playfield ):
views = [PlayfieldView( model )]
- elif isinstance( model, GoldCar ):
+ elif isinstance( model, GoldCar ):
views = [GoldCarView( model )]
-
+
elif isinstance( model, Torch ):
views = [TorchView( model )]
elif isinstance( model, Diamond ):
@@ -71,13 +70,13 @@ def get_views( self, model ):
views = [FlagView( model )]
elif isinstance( model, Leprechaun):
views = [LeprechaunView( model )]
-
+
elif isinstance( model, Enterance ):
- views = [EnteranceView( model ), EnteranceTopView( model )]
+ views = [EnteranceView( model ), EnteranceTopView( model )]
elif isinstance( model, RailGate ):
views = [RailGateView( model )]
elif isinstance( model, Tile ):
- views = [TileView( model )]
+ views = [TileView( model )]
elif isinstance( model, GroundControl ):
views = [GroundControlView( model )]
elif isinstance( model, Event ):
@@ -92,23 +91,23 @@ def get_views( self, model ):
def draw( self, model ):
if model is None: return
-
+
for view in self.get_views( model ):
view.draw( self )
- def draw_z( self, models ):
+ def draw_z( self, models ):
views = []
for model in models:
for view in self.get_views( model ):
views.append( view )
-
+
if hasattr(view, "submodels"):
for submodel in view.submodels:
for subview in self.get_views( submodel ):
views.append( subview )
views.sort( key = lambda v: v.z )
-
+
for view in views:
view.draw( self )
-
+
View
133 monorail/hud.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import pygame.font
import copy
@@ -29,7 +28,7 @@ def __init__( self, scenario, ground_control, game_data ):
self.guistate = gui.GuiState()
- btnFont = gfx.Font( "data/edmunds.ttf", color=(0,0,0), size=19, use_antialias = True )
+ btnFont = gfx.Font( "data/edmunds.ttf", color=(0,0,0), size=19, use_antialias = True )
self.menu_btn = gui.ImageButton( copy.copy(resman.get("game.hud_menu_button_sprite")), Vec2D(5, 257) )
self.menu_btn.set_label( _("Menu"), btnFont )
@@ -54,11 +53,11 @@ def game_tick( self, indev ):
event.Event.clock_ring()
self.last_clock_ring = timeout
-
+
def draw( self, frame ):
resman.get("game.hud_score_surf").draw( frame.surface, Vec2D(0,0) )
resman.get("game.hud_watch_surf").draw( frame.surface, Vec2D(5,290) )
-
+
y = 7
for goldcars in self.scenario.playfield.get_goldcar_ranking():
@@ -70,9 +69,9 @@ def draw( self, frame ):
self.font_score.draw( "%d" % (goldcar.score), frame.surface,
(110, y + 4), align = gfx.Font.RIGHT )
-
+
y += 35
-
+
timeout = self.scenario.get_timeout()
if timeout is not None:
time_string = "%01d:%02d" % (timeout/60, timeout%60)
@@ -116,7 +115,7 @@ def is_ready( self ):
return self.dialog.all_is_ready()
else:
return True
-
+
def _get_tip_dialog( self ):
if self.game_data.is_single_player():
if self.game_data.quest.progress == 0:
@@ -149,9 +148,9 @@ def _get_tip_dialog( self ):
class BaseDlg (gui.Dialog):
def __init__( self, scenario, ground_control ):
- gui.Dialog.__init__( self, Rectangle(140, 80, 800-200, 600-200 ) )
+ gui.Dialog.__init__( self, Rectangle(140, 80, 800-200, 600-200 ) )
self.background_image = resman.get("gui.paperdialog_surf")
-
+
self.scenario = scenario
self.ground_control = ground_control
@@ -160,7 +159,7 @@ def __init__( self, scenario, ground_control ):
self.small_font = gfx.Font( "data/edmunds.ttf", 16, use_antialias = True )
self.guistate = gui.GuiState()
-
+
def do_tick( self, indev ):
self.guistate.update( indev, self )
@@ -168,12 +167,12 @@ def do_tick( self, indev ):
def draw( self, frame ):
gui.Dialog.draw( self, frame.surface, frame.interpol, frame.time_sec )
-
-
+
+
class MultiDlg (BaseDlg):
def __init__( self, scenario, ground_control ):
BaseDlg.__init__( self, scenario, ground_control )
-
+
self.no_input_timeout = 25*1
self.all_ready = False
@@ -184,14 +183,14 @@ def __init__( self, scenario, ground_control ):
def do_tick( self, indev ):
BaseDlg.do_tick( self, indev )
-
+
if self.no_input_timeout <= 0:
if self.readys is None:
self.readys = [ isinstance( gc, ctrl.AiController ) for gc in self.ground_control.controllers ]
i = 0
for controller in self.ground_control.controllers:
- goldcar_rect = Rectangle( self.get_goldcar_x( i ) - 30,
+ goldcar_rect = Rectangle( self.get_goldcar_x( i ) - 30,
400, 60, 80)
if (isinstance(controller, ctrl.HumanController) and \
@@ -202,7 +201,7 @@ def do_tick( self, indev ):
self.readys[i] = True
i += 1
- if not False in self.readys:
+ if not False in self.readys:
self.all_ready = True
else:
self.no_input_timeout -= 1
@@ -217,16 +216,16 @@ def get_goldcar_x( self, place ):
def draw( self, frame ):
BaseDlg.draw( self, frame )
-
+
center = Vec2D( frame.surface.get_width()/2, frame.surface.get_height()/2 )
y = 365
-
+
if self.no_input_timeout <= 0:
self.font.draw( _("Press your button or click on the car"), frame.surface, (center.x, y+15), gfx.Font.CENTER )
y = 415
-
+
place = 0
for controller in self.ground_control.controllers:
goldcar = controller.goldcar
@@ -248,12 +247,12 @@ def draw( self, frame ):
sprite.nr = self.anim_timer.get_frame( frame.time_sec )
sprite.draw( frame.surface, Vec2D(x, y + 26) )
-
+
place += 1
def all_is_ready( self ):
return self.all_ready
-
+
class TipDlg (BaseDlg):
def __init__( self, scenario, ground_control ):
@@ -301,7 +300,7 @@ def __init__( self, scenario, ground_control ):
x = 2
y = 7
- self.playfield.level = Level()
+ self.playfield.level = Level()
self.playfield.level.set_tile( Tile( Vec3D(x+0,y,0), Tile.Type.FLAT, Trail.Type.EW ) )
self.playfield.level.set_tile( Tile( Vec3D(x+1,y,0), Tile.Type.FLAT ) )
self.playfield.level.set_tile( Tile( Vec3D(x+2,y,0), Tile.Type.FLAT ) )
@@ -336,7 +335,7 @@ def draw( self, frame ):
frame.optimize_speed = False
frame.draw( self.playfield )
frame.optimize_speed = True
-
+
class KeyTipDlg (TipDlg):
def __init__( self, scenario, ground_control ):
TipDlg.__init__( self, scenario, ground_control )
@@ -347,7 +346,7 @@ def __init__( self, scenario, ground_control ):
x = 2
y = 7
- self.playfield.level = Level()
+ self.playfield.level = Level()
self.playfield.level.set_tile( Tile( Vec3D(x+0,y,0), Tile.Type.FLAT, Trail.Type.EW ) )
self.playfield.level.set_tile( Tile( Vec3D(x+1,y,0), Tile.Type.FLAT ) )
self.playfield.level.set_tile( Tile( Vec3D(x+2,y,0), Tile.Type.FLAT ) )
@@ -395,7 +394,7 @@ def __init__( self, scenario, ground_control ):
self.playfield = Playfield()
- self.playfield.level = Level()
+ self.playfield.level = Level()
self._fill_level()
def _fill_level( self ):
@@ -438,7 +437,7 @@ def __init__( self, scenario, ground_control ):
def do_tick( self, indev ):
PassPickupTipDlg.do_tick( self, indev )
- self.dynamite.life = 0.9
+ self.dynamite.life = 0.9
class LampTipDlg (PassPickupTipDlg):
@@ -446,9 +445,9 @@ def __init__( self, scenario, ground_control ):
PassPickupTipDlg.__init__( self, scenario, ground_control )
self.description_field.text = _("Pass the lamp by bumping into other car.")
-
+
self.playfield.goldcars[0].add_pickup(pickups.Lamp())
-
+
class DiamondTipDlg (TipDlg):
def __init__( self, scenario, ground_control ):
@@ -460,7 +459,7 @@ def __init__( self, scenario, ground_control ):
x = 3
y = 5
- self.playfield.level = Level()
+ self.playfield.level = Level()
self.playfield.level.set_tile( Enterance( Vec3D(x+3,y+0,0) ))
self.playfield.level.set_tile( Tile( Vec3D(x+2,y+0,0), Tile.Type.FLAT ) )
self.playfield.level.set_tile( Tile( Vec3D(x+1,y+0,0), Tile.Type.FLAT ) )
@@ -482,7 +481,7 @@ def do_tick( self, indev ):
self.playfield.game_tick()
diamond_cnt = self.playfield.get_pickup_count( pickups.Diamond )
-
+
if diamond_cnt < 1:
self.playfield.spawn_pickup( pickups.Diamond() )
@@ -552,14 +551,14 @@ def do_tick( self, indev ):
self.timer += 1
if self.timer == 25*3:
- balloon_cnt = self.playfield.get_pickup_count( pickups.Balloon )
-
+ balloon_cnt = self.playfield.get_pickup_count( pickups.Balloon )
+
if balloon_cnt < 1:
self.playfield.spawn_pickup( pickups.Balloon() )
elif self.timer == 25*9:
self.playfield.goldcars[0].collectible = None
self.timer = 0
-
+
def draw( self, frame ):
TipDlg.draw( self, frame )
@@ -573,7 +572,7 @@ def __init__( self, scenario, ground_control ):
PassPickupTipDlg.__init__( self, scenario, ground_control )
self.description_field.text = _("Only the car with axe can cut gold.")
-
+
self.playfield.goldcars[0].add_pickup(pickups.Axe())
def _fill_level( self ):
@@ -597,12 +596,12 @@ def _fill_level( self ):
TrailPosition(self.playfield.level.get_tile(x+0,y), 500)]
self.playfield.goldcars = [GoldCar(pos[i], i) for i in range(0,2)]
self.playfield.goldcars[0].pos.reverse_progress()
-
+
def do_tick( self, indev ):
PassPickupTipDlg.do_tick( self, indev )
- gold_cnt = self.playfield.get_pickup_count( pickups.GoldBlock )
-
+ gold_cnt = self.playfield.get_pickup_count( pickups.GoldBlock )
+
if gold_cnt < 1:
self.playfield.spawn_pickup( pickups.GoldBlock() )
@@ -616,7 +615,7 @@ def __init__( self, scenario, ground_control ):
x = 3
y = 5
- self.playfield.level = Level()
+ self.playfield.level = Level()
self.playfield.level.set_tile( Tile( Vec3D(x+2,y+0,0), Tile.Type.FLAT ) )
self.playfield.level.set_tile( Tile( Vec3D(x+1,y+0,0), Tile.Type.FLAT ) )
self.playfield.level.set_tile( Tile( Vec3D(x+0,y+0,0), Tile.Type.FLAT ) )
@@ -650,7 +649,7 @@ def do_tick( self, indev ):
# Reset when flag is gone
if self.tiles[i].pickup is None:
self.tiles[i] = None
-
+
i += 1
@@ -699,18 +698,18 @@ def do_tick( self, indev ):
self.timer += 1
if self.timer == 25*3:
- oil_cnt = self.playfield.get_pickup_count( pickups.Oiler )
-
+ oil_cnt = self.playfield.get_pickup_count( pickups.Oiler )
+
if oil_cnt < 1:
x = 3
y = 4 + 3
tile = self.playfield.level.get_tile(x, y)
tile.pickup = pickups.Oiler()
tile.pickup.container = tile
-
+
elif self.timer == 25*11:
self.playfield.goldcars[0].modifier = None
- self.timer = 0
+ self.timer = 0
def draw( self, frame ):
TipDlg.draw( self, frame )
@@ -729,7 +728,7 @@ def __init__( self, scenario, ground_control ):
x = 3
y = 5
- self.playfield.level = Level()
+ self.playfield.level = Level()
self.playfield.level.set_tile( Enterance( Vec3D(x+3,y+0,0) ))
self.playfield.level.set_tile( Tile( Vec3D(x+2,y+0,0), Tile.Type.FLAT ) )
self.playfield.level.set_tile( Tile( Vec3D(x+1,y+0,0), Tile.Type.FLAT ) )
@@ -752,7 +751,7 @@ def do_tick( self, indev ):
rock_cnt = self.playfield.get_pickup_count( pickups.RockBlock )
coin_cnt = self.playfield.get_pickup_count( pickups.CopperCoin )
-
+
if rock_cnt < 1:
self.playfield.spawn_pickup( pickups.RockBlock() )
if coin_cnt < 2:
@@ -784,7 +783,7 @@ def __init__( self, scenario, ground_control ):
self.description_field.text = _("A Torch moves every car to a different location")
self.playfield = Playfield()
- self.playfield.level = Level()
+ self.playfield.level = Level()
self._fill_level()
self.playfield.goldcars = []
@@ -845,19 +844,19 @@ def do_tick( self, indev ):
self.timer += 1
if self.timer == 25*3:
- ghost_cnt = self.playfield.get_pickup_count( pickups.Ghost )
-
+ ghost_cnt = self.playfield.get_pickup_count( pickups.Ghost )
+
if ghost_cnt < 1:
x = 3
y = 4 + 3
tile = self.playfield.level.get_tile(x, y)
tile.pickup = pickups.Ghost()
tile.pickup.container = tile
-
+
elif self.timer == 25*11:
self.playfield.goldcars[0].modifier = None
self.playfield.goldcars[1].modifier = None
- self.timer = 0
+ self.timer = 0
def draw( self, frame ):
TipDlg.draw( self, frame )
@@ -865,7 +864,7 @@ def draw( self, frame ):
frame.optimize_speed = False
frame.draw( self.playfield )
frame.optimize_speed = True
-
+
class IntroDlg( MultiDlg ):
def __init__( self, scenario, ground_control ):
@@ -885,14 +884,14 @@ def draw( self, frame ):
self.info.draw_title( frame.surface, frame.time_sec, (center.x, y) )
self.info.draw_pickup( frame.surface, frame.time_sec, (center.x + 50, 240 ) )
-
- y += 50
-
+
+ y += 50
+
self.font.draw( self.scenario.description, frame.surface,
(center.x, y), gfx.Font.CENTER )
-
+
class EndDlg( MultiDlg ):
def __init__( self, scenario, ground_control ):
MultiDlg.__init__( self, scenario, ground_control )
@@ -904,7 +903,7 @@ def draw( self, frame ):
#for goldcar in self.playfield.goldcars:
# if winner is None or winner.score < goldcar.score:
# winner = goldcar
-
+
center = Vec2D( frame.surface.get_width()/2, frame.surface.get_height()/2 )
y = center.y - 180
@@ -919,7 +918,7 @@ def draw( self, frame ):
place = 1
y -= 5
- for goldcars in ranking:
+ for goldcars in ranking:
y += 32
self.font.draw( "%d." % place, frame.surface,
@@ -960,7 +959,7 @@ def draw( self, frame ):
place = 1
y -= 5
amount = 3
- for goldcars in ranking:
+ for goldcars in ranking:
y += 32
self.font.draw( "%d." % place, frame.surface,
@@ -990,7 +989,7 @@ def __init__( self, scenario, ground_control, game_data ):
self.font_tiny_white = gfx.Font("data/edmunds.ttf", 15, (255,255,255), use_antialias = True)
self.skill_value = self.game_data.skill_level.old_value
-
+
def do_tick( self, indev ):
MultiDlg.do_tick( self, indev )
@@ -1001,7 +1000,7 @@ def do_tick( self, indev ):
def draw( self, frame ):
MultiDlg.draw( self, frame )
-
+
center = Vec2D( frame.surface.get_width()/2, frame.surface.get_height()/2 )
y = center.y - 180
@@ -1024,13 +1023,13 @@ def draw_skill_bar( self, frame, x, y ):
pointer_y = geo.lin_ipol( self.skill_value,
MAX_Y + 7, MIN_Y + 17, 0.3, 1.0 )
pointer_y = max( min( pointer_y, MAX_Y ), MIN_Y )
-
+
# pointer_y = MAX_Y
resman.get("game.skill_pointer_surf").draw( frame.surface, Vec2D(x+10, pointer_y) )
self.font_tiny_white.draw("%d" % int(self.skill_value * 100), frame.surface, (x+13, pointer_y+2),
align=gfx.Font.CENTER, valign=gfx.Font.MIDDLE )
-
+
for skill_name in settings.SkillLevel.NAMES:
if skill_name == self.game_data.skill_level.name:
self.font_tiny_red.draw( skill_name, frame.surface, (x+40, y) )
@@ -1045,12 +1044,12 @@ def __init__( self, scenario, ground_control, game_data ):
def draw( self, frame ):
SingleDlg.draw( self, frame )
-
+
center = Vec2D( frame.surface.get_width()/2, frame.surface.get_height()/2 )
y = center.y - 180
- self.large_font.draw( _("Nice job!"), frame.surface, (center.x, y), gfx.Font.CENTER )
+ self.large_font.draw( _("Nice job!"), frame.surface, (center.x, y), gfx.Font.CENTER )
class LoseDlg( SingleDlg ):
def __init__( self, scenario, ground_control, game_data ):
@@ -1058,7 +1057,7 @@ def __init__( self, scenario, ground_control, game_data ):
def draw( self, frame ):
SingleDlg.draw( self, frame )
-
+
center = Vec2D( frame.surface.get_width()/2, frame.surface.get_height()/2 )
y = center.y - 180
@@ -1098,7 +1097,7 @@ def __init__( self, is_single_player, game_data ):
self.add_subcomponent( self.quit_btn )
self.update_neighbors()
-
+
self.options_dialog = None
self.to_menu = False
@@ -1137,4 +1136,4 @@ def tick( self, userinput, guistate ):
def is_done( self ):
return self._is_done
-
+
View
25 monorail/koon/app.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import sys
import gc
@@ -38,7 +37,7 @@ def init_pygame( self ):
else:
pygame.display.set_mode( self.config.resolution, pygame.FULLSCREEN )
pygame.display.set_caption( self.name )
-
+
# Init the input
pygame.mouse.set_visible( False )
pygame.event.set_grab( False )
@@ -47,11 +46,11 @@ def init_pygame( self ):
def deinit_pygame( self ):
snd.deinit()
- pygame.quit()
+ pygame.quit()
def before_gameloop( self ):
pass
-
+
def after_gameloop( self ):
pass
@@ -60,10 +59,10 @@ def run( self ):
self.init_pygame()
self.before_gameloop()
-
+
self.fps = 0
frame_count = 0
-
+
next_game_tick = pygame.time.get_ticks()
next_half_second = pygame.time.get_ticks()
@@ -71,8 +70,8 @@ def run( self ):
self.game_is_done = False
while not self.game_is_done:
# events
- self.handle_events()
-
+ self.handle_events()
+
# game tick
loop_count = 0
while pygame.time.get_ticks() > next_game_tick and loop_count < 4:
@@ -85,10 +84,10 @@ def run( self ):
loop_count += 1
## gc.collect()
-
+
if loop_count >= 4: # don't overdo the ticks
next_game_tick = pygame.time.get_ticks()
-
+
# render
time_sec = pygame.time.get_ticks() * 0.001
interpol = 1 - ((next_game_tick - pygame.time.get_ticks()) / float(GAMETICKS))
@@ -102,9 +101,9 @@ def run( self ):
next_half_second += 500
self.after_gameloop()
-
+
self.deinit_pygame()
-
+
except:
self.deinit_pygame()
print "Unexpected error:", sys.exc_info()[0]
@@ -128,7 +127,7 @@ def handle_events( self ):
self.userinput.joys[event.joy].feed_down( event.button )
elif event.type == JOYBUTTONUP:
self.userinput.joys[event.joy].feed_up( event.button )
-
+
def draw_fps( self, surface ):
font = pygame.font.Font( None, 20 )
render_text = font.render( str(self.fps), 0, (255,255,255) )
View
19 monorail/koon/build.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import os
from os import path
@@ -18,7 +17,7 @@ def should_update( filename, filenames_list ):
if time < os.path.getmtime( f ):
return True
return False
-
+
def get_bounding_box( image ):
x, y = 0, 0
@@ -33,7 +32,7 @@ def get_bounding_box( image ):
else: box[2] = max((box[2], x))
if box[3] is None: box[3] = y
else: box[3] = max((box[3], y))
-
+
x += 1
if x == image.size[0]:
y += 1
@@ -44,7 +43,7 @@ def get_bounding_box( image ):
return None
def max_bounding_box( images ):
- box = [ 999999999, 99999999999, -1, -1 ]
+ box = [ 999999999, 99999999999, -1, -1 ]
for im in images:
b = get_bounding_box( im )
if b is not None:
@@ -53,7 +52,7 @@ def max_bounding_box( images ):
box[2] = max( b[2], box[2] )
box[3] = max( b[3], box[3] )
return box
-
+
def pack_images( images ):
"""Returns the packed images (all of same size)"""
width = images[0].size[0]
@@ -80,10 +79,10 @@ def generate_sprite( configname, spritefilename, blenderfilename, scale, count,
scene = None, center = None ):
node = cfg.ConfigNode( configname )
node.value = "SpriteFilm"
-
+
tmpfilename = "assets/tmp/" + path.basename(spritefilename)
tmpfilename = tmpfilename.replace(".", "_%04d.")
-
+
if should_update( tmpfilename % 1, [blenderfilename] ):
for i in range(1, count+1):
print "generating", tmpfilename % i
@@ -114,7 +113,7 @@ def generate_sprite( configname, spritefilename, blenderfilename, scale, count,
images = [im.crop( box ) for im in images]
for im in images:
im.load() # for lazy crop
-
+
out_image = pack_images( images )
out_image.save(spritefilename)
@@ -125,7 +124,7 @@ def generate_image( configname, imagefilename, blenderfilename, scale,
node = cfg.ConfigNode( configname )
node.value = "Surface"
# node.set( "file", imagefilename )
-
+
tmpfilename = "assets/tmp/" + path.basename(imagefilename)
tmpfilename = tmpfilename.replace(".", "_0001.")
@@ -154,5 +153,5 @@ def generate_image( configname, imagefilename, blenderfilename, scale,
im.load() # for lazy crop
im.save(imagefilename)
-
+
return node
View
19 monorail/koon/cfg.py
@@ -1,13 +1,12 @@
-#!/usr/bin/env python
class ConfigFile:
"""Handles koonsolo config files
Public Members:
- root_node: the root ConfigNode of this file
-
+
example of such a file:
-
+
en = Language {
new game = New Game!
quit = Quit Game
@@ -27,7 +26,7 @@ class ConfigFile:
}
}
"""
-
+
def __init__( self, filename = None ):
if filename is not None:
self.load( filename )
@@ -75,7 +74,7 @@ def from_file( configfile ):
for line in configfile.readlines():
line = ConfigNode._strip_comments( line )
-
+
assign = line.find("=")
if assign >= 0:
if line.strip()[-1] == '{':
@@ -93,7 +92,7 @@ def from_file( configfile ):
if len( nodes ) <> 1:
raise ParseException("too few {'s")
-
+
return root
@staticmethod
@@ -113,14 +112,14 @@ def to_file( self, configfile, indent = 0 ):
values.sort(key=lambda a:a.name)
for attrib in values:
attrib.to_file( configfile, indent+1 )
-
+
configfile.write( "\t" * indent)
configfile.write("}")
configfile.write("\n")
def append_attribute( self, node ):
if node is None: return
-
+
if self.attribs.has_key( node.name ):
if node.value is not None and node.value != "":
self.attribs[ node.name ].value = node.value
@@ -137,7 +136,7 @@ def get( self, name ):
node = self
for name in names:
node = node.attribs[ name ]
-
+
return node
def set( self, name, value ):
@@ -154,4 +153,4 @@ def set( self, name, value ):
node = node.attribs[ name ]
node.value = str( value )
-
+
View
18 monorail/koon/geo.py
@@ -17,10 +17,10 @@ def __ne__(self, other):
def __add__(self, other):
return Vec3D( self.x + other.x, self.y + other.y, self.z + other.z )
-
+
def __sub__(self, other):
return Vec3D( self.x - other.x, self.y - other.y, self.z - other.z )
-
+
def __mul__(self, factor):
return Vec3D( self.x * factor, self.y * factor, self.z * factor )
@@ -29,7 +29,7 @@ def __div__(self, factor):
def __neg__(self):
return Vec3D( -self.x, -self.y, -self.z )
-
+
def dot( self, other ):
"""returns dot product of 2 vectors"""
return (self.x * other.x) + (self.y * other.y) + (self.z * other.z)
@@ -68,10 +68,10 @@ def __ne__(self, other):
def __add__(self, other):
return Vec2D( self.x + other.x, self.y + other.y )
-
+
def __sub__(self, other):
return Vec2D( self.x - other.x, self.y - other.y )
-
+
def __mul__(self, factor):
return Vec2D( self.x * factor, self.y * factor )
@@ -80,7 +80,7 @@ def __div__(self, factor):
def __neg__(self):
return Vec2D( -self.x, -self.y )
-
+
def dot( self, other ):
"""returns dot product of 2 vectors"""
return (self.x * other.x) + (self.y * other.y)
@@ -105,7 +105,7 @@ def __str__( self ):
class Rectangle:
def __init__( self, x, y, width, height ):
self.pos = Vec2D( x, y )
- self.size = Vec2D( width, height )
+ self.size = Vec2D( width, height )
@staticmethod
def from_pos_size( pos, size ):
@@ -113,7 +113,7 @@ def from_pos_size( pos, size ):
@staticmethod
def from_tuple( tup ):
- return Rectangle(tup[0], tup[1], tup[2], tup[3])
+ return Rectangle(tup[0], tup[1], tup[2], tup[3])
def contains( self, pos ):
return pos.x >= self.pos.x and \
@@ -146,7 +146,7 @@ def __and__( self, other ):
bottom = min( self.bottom, other.bottom )
return Rectangle(x, y, right-x, bottom-y)
-
+
def __eq__( self, other ):
return self.pos == other.pos and self.size == other.size
View
28 monorail/koon/gfx.py
@@ -1,6 +1,4 @@
-## Automatically adapted for numpy.oldnumeric Nov 20, 2012 by
-
-#!/usr/bin/env python
+## Automatically adapted for numpy.oldnumeric Nov 20, 2012 by
import copy
from numpy.oldnumeric import array
@@ -15,7 +13,7 @@ def __init__( self, param ):
Parameter param can be a filename, a pygame.Surface or a
(width, height) tuple.
-
+
"""
assert param is not None
@@ -38,7 +36,7 @@ def draw( self, surface, pos, rect = None ):
"""
if isinstance( pos, tuple ):
pos = Vec2D( pos[0], pos[1] )
-
+
if isinstance( surface, pygame.Surface ):
if rect is not None:
surface.blit( self.pysurf, pos.get_tuple(), rect )
@@ -66,7 +64,7 @@ def get_blended( self, alpha ):
assert alpha >= 0.0 and alpha <= 1.0
result = Surface((self.get_width(), self.get_height()))
result.pysurf = self.pysurf.copy()
-
+
a = pygame.surfarray.pixels_alpha(result.pysurf)
b = a * array(alpha)
a[:] = b.astype('B')
@@ -119,7 +117,7 @@ class SpriteFilm (Sprite):
"""Contains surface frames of equal size
Members:
-
+
surface: the sprite image
nr: sprite nr to draw
center: center of the sprite (Vec2D)
@@ -168,7 +166,7 @@ def clone( self ):
class Font:
LEFT, RIGHT, CENTER = range(3)
TOP, BOTTOM, MIDDLE = range(3)
-
+
def __init__( self, filename = None, size = 16, color = (0,0,0), \
use_antialias = False ):
if filename is None:
@@ -224,7 +222,7 @@ def do_tick( self, time_sec ):
# initialize when not done already
if not hasattr(self, 'next_tick'):
self.start( time_sec - self.timeskip )
-
+
if self.next_tick < time_sec:
self.next_tick += self.timeskip
return True
@@ -248,10 +246,10 @@ def get_frame( self, time ):
frame = int( (time - self.starttime) * self.fps )
frame = (frame + self.startframe) % self.maxframes
-
+
return frame + self.firstframe
-
-
+
+
class PingPongTimer:
def __init__( self, fps, firstframe, maxframes ):
@@ -272,7 +270,7 @@ def get_frame( self, time ):
if frame >= self.maxframes:
frame = self.maxframes*2 - frame
-
+
return frame + self.firstframe
-
-
+
+
View
79 monorail/koon/gui.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import pygame
import pygame.draw as draw
@@ -39,7 +38,7 @@ def activate_next( self ):
def activate_prev( self ):
if self.active.prev_neighbor is not None:
- self.set_active( self.active.prev_neighbor )
+ self.set_active( self.active.prev_neighbor )
while not self.active.is_enabled: self.set_active( self.active.prev_neighbor )
def _update_active( self, userinput, component ):
@@ -56,7 +55,7 @@ def _update_active( self, userinput, component ):
for comp in interactives:
if comp.place.contains( userinput.mouse.pos ) and comp.is_enabled:
self.set_active( comp )
-
+
if userinput.mouse.went_down( Mouse.LEFT ):
if self.active is not None and self.active.has_input_lock():
self.active.lock_input( False )
@@ -67,7 +66,7 @@ def _update_active( self, userinput, component ):
if self.active is None or self.active not in interactives or not self.active.is_enabled:
if len(interactives) > 0:
self.set_active( interactives[0] )
-
+
@staticmethod
def _get_interactive_components( component ):
@@ -102,7 +101,7 @@ def draw( self, surface, interpol=0.0, time_sec=0.0 ):
if self.is_visible:
for sub in self.subs:
sub.draw( surface, interpol, time_sec )
-
+
def add_subcomponent( self, subcomponent ):
self.subs.append( subcomponent )
@@ -111,13 +110,13 @@ def remove_subcomponent( self, subcomponent ):
def update_neighbors( self ):
"""Update the neighbors for key navigation"""
-
+
comps = GuiState._get_interactive_components( self )
if len(comps) > 2:
for i in range(0, len(comps)-1):
comps[i].next_neighbor = comps[i+1]
-
+
for i in range(1, len(comps)):
comps[i].prev_neighbor = comps[i-1]
@@ -146,7 +145,7 @@ def has_input_lock( self ):
return self._has_input_lock;
def lock_input( self, has_input_lock ):
- self._has_input_lock = has_input_lock
+ self._has_input_lock = has_input_lock
class Screen (Component):
@@ -161,7 +160,7 @@ class Dialog (Component):
def __init__( self, place ):
super(Dialog, self).__init__()
-
+
self.place = place
self.background_image = None
@@ -178,9 +177,9 @@ def draw( self, surface, interpol=0.0, time_sec=0.0 ):
self.background_image.draw( surface, self.place.pos )
else:
surface.fill( (50, 50, 50), self.place.get_tuple() )
-
+
super(Dialog, self).draw( surface, interpol, time_sec )
-
+
class ImageDialog (Dialog):
def __init__( self ):
@@ -196,7 +195,7 @@ def set_surf( self, surface ):
yc = surface.get_height()
ya = yc / 3
yb = yc * 2 / 3
-
+
self.top_left = Rect( 0, 0, xa, ya )
self.top_cen = Rect( xa, 0, xb-xa, ya )
self.top_right = Rect( xb, 0, xc-xb, ya )
@@ -235,7 +234,7 @@ def draw( self, backbuffer, interpol=0.0, time_sec=0.0 ):
y += self.top_left.height
- for j in range( self.block_size.y ):
+ for j in range( self.block_size.y ):
x = self.pos.x
self.surf.draw( backbuffer, Vec2D(x, y), self.mid_left )
x += self.mid_left.width
@@ -243,9 +242,9 @@ def draw( self, backbuffer, interpol=0.0, time_sec=0.0 ):
self.surf.draw( backbuffer, Vec2D(x, y), self.mid_cen )
x += self.mid_cen.width
self.surf.draw( backbuffer, Vec2D(x, y), self.mid_right )
-
+
y += self.mid_left.height
-
+
x = self.pos.x
self.surf.draw( backbuffer, Vec2D(x, y), self.bot_left )
x += self.bot_left.width
@@ -256,7 +255,7 @@ def draw( self, backbuffer, interpol=0.0, time_sec=0.0 ):
class Button (InteractiveComponent):
SELECT_KEYS = [K_SPACE, K_RETURN, K_KP_ENTER]
-
+
def __init__( self, place = Rectangle(0,0,0,0) ):
InteractiveComponent.__init__( self, place )
self.label = None
@@ -264,7 +263,7 @@ def __init__( self, place = Rectangle(0,0,0,0) ):
self.is_down = False
self.active = False
- def tick( self, userinput, guistate ):
+ def tick( self, userinput, guistate ):
Component.tick( self, userinput, guistate )
@@ -292,7 +291,7 @@ def tick( self, userinput, guistate ):
userinput.key.any_is_down( Button.SELECT_KEYS ):
self.is_down = True
- self.active = (guistate is not None and guistate.get_active() == self)
+ self.active = (guistate is not None and guistate.get_active() == self)
def draw( self, surface, interpol, time_sec ):
@@ -320,7 +319,7 @@ class Checkbox (Button):
def __init__( self, place = Rectangle(0,0,0,0), selected = False ):
Button.__init__( self, place )
-
+
self.selected = selected
def is_selected( self ):
@@ -455,17 +454,17 @@ def __init__( self, sprite, pos = Vec2D(0,0) ):
Checkbox.__init__(self, Rectangle(pos.x, pos.y, sprite.width, sprite.height))
self.sprite = sprite
- self.sprite.nr = 1
+ self.sprite.nr = 1
self.animTimer = PingPongTimer( 20, 1, 3 )
def tick( self, userinput, guistate ):
Checkbox.tick( self, userinput, guistate )
-
+
if self.is_selected():
self.sprite.nr = 3
else:
self.sprite.nr = 1
-
+
if self == guistate.get_active():
self.sprite.nr = 4
@@ -505,7 +504,7 @@ def tick( self, userinput, guistate ):
def draw( self, surface, interpol, time_sec ):
Component.draw( self, surface, interpol, time_sec )
- draw.rect( surface, (255,255,255), self.place.get_tuple(), 2 )
+ draw.rect( surface, (255,255,255), self.place.get_tuple(), 2 )
val = (self.place.get_right() - self.place.pos.x) * self._value
@@ -527,7 +526,7 @@ def set_value( self, value ):
value = 1.0
if value < 0.0:
value = 0.0
-
+
self._value = value
def went_up( self ):
@@ -539,7 +538,7 @@ def __init__( self, pos, sprite, button = None):
Slider.__init__( self, Rectangle.from_pos_size(pos, Vec2D(size[0], size[1]) ) )
self.sprite = sprite
- self.button = button
+ self.button = button
if button is not None:
self.add_subcomponent( button )
@@ -569,7 +568,7 @@ def tick( self, userinput, guistate ):
# Handle keys
STEP = 0.01
LARGE_STEP = 0.2
-
+
if guistate.active == self.button:
if userinput.key.is_down( K_LEFT ):
self.set_value( self.get_value() - STEP )
@@ -577,7 +576,7 @@ def tick( self, userinput, guistate ):
self.set_value( self.get_value() + STEP )
if userinput.key.any_went_down( Button.SELECT_KEYS ):
new_value = self.get_value() + LARGE_STEP
- new_value = (int(new_value * 5) / 5.0)
+ new_value = (int(new_value * 5) / 5.0)
if new_value > 1.0: new_value = 0.0
self.set_value( new_value )
@@ -611,7 +610,7 @@ def draw( self, surface, interpol, time_sec ):
Component.draw( self, surface, interpol, time_sec )
-
+
class Label (Component):
def __init__( self, pos, text = None, font = None, image = None ):
@@ -642,7 +641,7 @@ def draw( self, surface, interpol, time_sec ):
if self.text is not None and self.font is not None:
self.font.draw( self.text, surface, self.pos.get_tuple() )
-
+
class TextField (InteractiveComponent):
def __init__( self, place, font ):
@@ -667,37 +666,37 @@ def _handle_last_word( self, lines, word, length_pixels ):
else:
lines.append( word.strip() )
word = " "
-
+
return word
- def _wrap_to_lines( self, text, length_pixels ):
+ def _wrap_to_lines( self, text, length_pixels ):
lines = [""]
word = ""
for ch in text:
if ch == "\n" or ch == " ":
word = self._handle_last_word( lines, word, length_pixels )
-
+
if ch == "\n":
lines.append("")
-
+
else:
word += ch
-
+
word = self._handle_last_word( lines, word, length_pixels)
-
+
return lines
-
-
+
+
def _set_text( self, text ):
self._text = text
self.lines = self._wrap_to_lines( text, self.place.size.x )
-
-
+
+
def _get_text( self ):
return self._text
-
+
text = property(_get_text, _set_text)
def draw( self, surface, interpol, time_sec ):
View
7 monorail/koon/input.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
""" Contains keyboard, mouse, joysticks, etc...
"""
@@ -49,7 +48,7 @@ def any_went_up( self, keys = None ):
return False
else:
return len( self.went_up_buttons ) > 0
-
+
def is_down( self, key ):
return key in self.down_buttons
@@ -88,7 +87,7 @@ class Mouse (ButtonLogger):
- pos: the current Vec2D position of the mouse
"""
UNKNOWN, LEFT, RIGHT, MIDDLE, SCROLLUP, SCROLLDOWN = range( 6 )
-
+
def __init__( self ):
ButtonLogger.__init__( self )
self.pos = None
@@ -101,7 +100,7 @@ def feed_pos( self, pos ):
def has_moved( self ):
return self._prev_pos is not None and \
self._prev_pos <> self.pos
-
+
class Joystick (ButtonLogger):
def get_name( self, key ):
return "joy " + str(key)
View
15 monorail/koon/res.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
"""use 'resman' as the main ResourceManager in this module
"""
import pygame
@@ -45,7 +44,7 @@ def get_from_node( self, node, typ = str ):
int( node.get("y").value ),
int( node.get("width").value ),
int( node.get("height").value ) )
-
+
elif node.value == "Vec2D":
return geo.Vec2D(
typ( node.get("x").value ),
@@ -68,7 +67,7 @@ def get_from_node( self, node, typ = str ):
subsurf.rect = self.get_from_node( node.get("rect") )
else:
subsurf = gfx.SubSurf( gfx.Surface( node.get("file").value ) )
-
+
if "offset_x" in node.attribs.keys():
subsurf.offset = geo.Vec2D(
int( node.get("offset_x").value),
@@ -77,20 +76,20 @@ def get_from_node( self, node, typ = str ):
elif node.value == "Music":
return snd.Music( node.get("file").value )
-
+
elif node.value == "Sound":
return snd.Sound( node.get("file").value )
-
+
else:
raise Exception("unknown type in resource file")
-
-
+
+
def load( self, filename ):
"""Load a file, or get it from memory."""
if filename not in self.loaded_files:
if filename.lower().endswith(".png") or filename.lower().endswith(".jpg"):
self.loaded_files[ filename ] = pygame.image.load( filename ).convert_alpha()
-
+
return self.loaded_files[ filename ]
View
13 monorail/koon/snd.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import pygame
import pygame.mixer as mixer
@@ -17,7 +16,7 @@ def deinit():
class Music (object):
our_music_volume = 0.8
our_current_music = None
-
+
def __init__( self, filename = None ):
self.sound = None
self.channel = None
@@ -31,7 +30,7 @@ def play( self, loop = -1 ):
self.sound.set_volume( Music.our_music_volume )
self.channel = self.sound.play( loop )
Music.our_current_music = self.sound
-
+
def stop( self ):
self.sound.stop()
@@ -54,11 +53,11 @@ def set_global_volume( volume ):
@staticmethod
def get_global_volume():
return Music.our_music_volume
-
+
class Sound (object):
our_sound_volume = 0.8
-
+
def __init__( self, filename = None ):
self.sound = None
self.channel = None
@@ -72,7 +71,7 @@ def play( self, loop = 0 ):
"""for infiniteloop, set loop to -1"""
self.sound.set_volume( Sound.our_sound_volume )
self.channel = self.sound.play( loop )
-
+
def stop( self ):
self.sound.stop()
@@ -92,4 +91,4 @@ def set_global_volume( volume ):
@staticmethod
def get_global_volume():
return Sound.our_sound_volume
-
+
View
17 monorail/koon/tests/test_cfg.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import monorail.koon.cfg as cfg
@@ -15,7 +14,7 @@ def test_get( self ):
sub1.attribs["sub2a"] = sub2a
sub1.attribs["sub2b"] = sub2b
sub2b.attribs["sub3"] = sub3
-
+
assert root.get("sub1").value == "val1"
assert root.get("sub1.sub2a").value == "val2a"
assert root.get("sub1.sub2b").value == "val2b"
@@ -27,7 +26,7 @@ def test_get( self ):
except:
assert True
- def test_set( self ):
+ def test_set( self ):
root = cfg.ConfigNode("root", "root")
sub1 = cfg.ConfigNode("sub1", "val1")
sub2a = cfg.ConfigNode("sub2a", "val2a")
@@ -41,16 +40,16 @@ def test_set( self ):
root.set("sub1.sub2a", "val2Set")
assert root.get("sub1.sub2a").value == "val2Set"
-
+
root.set("sub1.subNew", 18)
assert int( root.get("sub1.subNew").value ) == 18
-
+
def test_parse_single( self ):
cf = open( "cfg.tmp", "w" )
cf.write("""
timeout = 30
-
+
x = 25.5
y = 7""")
cf.close()
@@ -137,7 +136,7 @@ def test_comments( self ):
cf.write("""
# A line comment
timeout = 30 # a trailing comment
-
+
x = 25.5
y = 7""")
cf.close()
@@ -168,7 +167,7 @@ def test_load( self ):
conf = cfg.ConfigFile("cfg.tmp")
assert conf.root_node.get("hero.y").value == "60"
-
+
def test_save( self ):
root = cfg.ConfigNode("root", "root")
sub1 = cfg.ConfigNode("sub1", "val1")
@@ -186,7 +185,7 @@ def test_save( self ):
conf.save("cfg.tmp")
conf.load("cfg.tmp")
-
+
assert conf.root_node.get("sub1").value == "val1"
assert conf.root_node.get("sub1.sub2a").value == "val2a"
assert conf.root_node.get("sub1.sub2b").value == "val2b"
View
1 monorail/koon/tests/test_geo.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
from monorail.koon.geo import *
import pygame