Skip to content
Browse files

Remove shebang or make file executable

Almost all python files in the project have shebang, but they are not
intended to be executed directly so remove the shebang if the file is
not intended to be executed directly. Set executable bit to files which
are meant to be executed directly.

Accidentally this also fixes bunch of trailing white-spaces as my editor
does that for me - bonus :). No actual code change included!
  • Loading branch information...
1 parent 192fa92 commit ea0197850ac8127e66833069a7130c0ebca4dc8a @lczerner lczerner committed Dec 8, 2012
Showing with 754 additions and 811 deletions.
  1. +0 −3 monorail/ai.pyx
  2. +15 −17 monorail/control.py
  3. +6 −8 monorail/controlview.py
  4. +13 −14 monorail/event.py
  5. +1 −2 monorail/eventview.py
  6. +11 −12 monorail/frame.py
  7. +66 −67 monorail/hud.py
  8. +12 −13 monorail/koon/app.py
  9. +9 −10 monorail/koon/build.py
  10. +9 −10 monorail/koon/cfg.py
  11. +9 −9 monorail/koon/geo.py
  12. +13 −15 monorail/koon/gfx.py
  13. +39 −40 monorail/koon/gui.py
  14. +3 −4 monorail/koon/input.py
  15. +7 −8 monorail/koon/res.py
  16. +6 −7 monorail/koon/snd.py
  17. +8 −9 monorail/koon/tests/test_cfg.py
  18. +0 −1 monorail/koon/tests/test_geo.py
  19. +5 −6 monorail/koon/tests/test_gfx.py
  20. +33 −34 monorail/koon/tests/test_gui.py
  21. +6 −7 monorail/koon/tests/test_input.py
  22. +1 −2 monorail/koon/tests/test_res.py
  23. +1 −2 monorail/koon/tests/test_snd.py
  24. +51 −52 monorail/menu.py
  25. +18 −18 monorail/monkey.py
  26. +39 −40 monorail/monorail.py
  27. +10 −11 monorail/pickups.py
  28. +21 −22 monorail/pickupsview.py
  29. +20 −21 monorail/player.py
  30. +12 −13 monorail/playerview.py
  31. +54 −55 monorail/scenarios.py
  32. +23 −24 monorail/settings.py
  33. +2 −5 monorail/setup.py
  34. +2 −0 monorail/setup_py2app.py
  35. +6 −7 monorail/sndman.py
  36. +27 −28 monorail/tests/test_ai.py
  37. +18 −19 monorail/tests/test_control.py
  38. +4 −5 monorail/tests/test_frame.py
  39. +2 −3 monorail/tests/test_geo.py
  40. +0 −1 monorail/tests/test_menu.py
  41. +2 −3 monorail/tests/test_pickups.py
  42. +2 −3 monorail/tests/test_pickupsview.py
  43. +7 −8 monorail/tests/test_player.py
  44. +2 −3 monorail/tests/test_playerview.py
  45. +4 −5 monorail/tests/test_scenarios.py
  46. +2 −3 monorail/tests/test_settings.py
  47. +22 −23 monorail/tests/test_tiles.py
  48. +46 −47 monorail/tests/test_world.py
  49. +47 −50 monorail/tiles.py
  50. +9 −10 monorail/tilesview.py
  51. +26 −27 monorail/world.py
  52. +3 −4 monorail/worldview.py
  53. +0 −1 setup.py
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,14 +215,14 @@ 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 )
self.sprite.draw( frame.surface, self.pos + Vec2D(frame.X_OFFSET, frame.Y_OFFSET) )
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,20 +159,20 @@ 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 )
gui.Dialog.tick( self, indev, self.guistate )
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,17 +437,17 @@ 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):
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,27 +844,27 @@ 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 )
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,20 +1044,20 @@ 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 ):
SingleDlg.__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,19 +59,19 @@ 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()
# main loop
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,15 +105,15 @@ 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 ):
return Rectangle(pos.x, pos.y, size.x, size.y)
@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,17 +234,17 @@ 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
for i in range( self.block_size.x ):
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,15 +255,15 @@ 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
self._went_down = False
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,15 +568,15 @@ 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 )
if userinput.key.is_down( K_RIGHT ):
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
View
11 monorail/koon/tests/test_gfx.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
from monorail.koon.gfx import *;
import pygame
@@ -43,10 +42,10 @@ def test_times_run_equals_hertz( self ):
Then it is run 2 times"""
# Given
timer = Timer( 2 )
-
+
# When
timer.start( 20 )
-
+
# Then
assert timer.do_tick( 21 )
assert timer.do_tick( 21 )
@@ -58,7 +57,7 @@ def test_times_run_equals_hertz( self ):
assert not timer.do_tick( 22 )
assert not timer.do_tick( 22 )
assert not timer.do_tick( 22 )
-
+
assert timer.do_tick( 24 )
assert timer.do_tick( 24 )
assert timer.do_tick( 24 )
@@ -92,10 +91,10 @@ def test_fps_later_when_time_ellapses( self ):
Then it is 2 frames later"""
# Given
anim = LoopAnimationTimer( 2, 0, 100 )
-
+
# When
anim.set_frame( 10, 4 )
-
+
# Then
assert anim.get_frame( 10 ) == 4
assert anim.get_frame( 11 ) == 6
View
67 monorail/koon/tests/test_gui.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
import pygame
import monorail.koon.gui as gui
@@ -29,7 +28,7 @@ def test_get_interactive_components_should_return_all_and_no_more( self ):
child21 = gui.InteractiveComponent( Rectangle(0,0,0,0) )
child22 = gui.Component()
child222 = gui.InteractiveComponent( Rectangle(0,0,0,0) )
-
+
root.add_subcomponent( child1 )