Permalink
Browse files

migrate to twisted #1

  • Loading branch information...
1 parent 375e485 commit c7977743fa6b1497b02b163f9390f0e7cce8a2f8 @bitcraft committed Apr 11, 2012
Showing with 93 additions and 5,663 deletions.
  1. +13 −10 docs/TODO
  2. +77 −54 lib/worldstate.py
  3. +1 −1 lib2d/ani.py
  4. +0 −663 lib2d/area.py
  5. +0 −249 lib2d/bbox.py
  6. +0 −57 lib2d/buttons.py
  7. +0 −289 lib2d/cmenu.py
  8. +0 −17 lib2d/config.py
  9. +0 −355 lib2d/fsa.py
  10. +0 −31 lib2d/game.py
  11. +0 −100 lib2d/gamestate.py
  12. +0 −91 lib2d/gfx.py
  13. +0 −384 lib2d/gui.py
  14. +0 −90 lib2d/maputils.py
  15. +0 −312 lib2d/objects.py
  16. +0 −171 lib2d/playerinput.py
  17. +0 −301 lib2d/quadtree.py
  18. +1 −2 lib2d/res.py
  19. +0 −287 lib2d/statedriver.py
  20. +0 −120 lib2d/subpixelsurface.py
  21. +0 −455 lib2d/tilemap.py
  22. +0 −44 lib2d/timer.py
  23. +0 −964 lib2d/tmxloader.py
  24. +0 −607 lib2d/tmxloader3.py
  25. +1 −9 run.py
View
@@ -39,24 +39,18 @@ features from movies/tv that should be in game:
rumors
party forming
-
mega maps:
divide large maps into regions
regions can be loaded from disk, complete with geometry
entities in the game world can request regions be loaded into memory
-renderer should be able to render many regions simutaneously
+renderer should be able to render many regions simultaneously
the tilesets 'images' can be loaded on the fly without affecting metadata
-
-
-
-
-
questing:
a quest:
has a goal
- has prerequsits to finish (quests too?)
+ has prerequisites to finish (quests too?)
has a defined consequence when completed
has a defined consequence while being completed
@@ -118,7 +112,7 @@ strategy sets and commands to companions could fail depending on relationship to
real-time nature and strategy will have to be a mix of options
-should be enough npcs and variety that poor decisions will not be a huge consequence to the player.
+should be enough npcs and variety so that poor decisions will not have huge consequences for the player.
may require another rewrite with the following kept in mind:
all objects must be able to be loaded and unladed at any moment
@@ -135,4 +129,13 @@ view:
controller:
any object that communicates between a model and view
- does not have state
+ does not have state
+
+
+it is apparent now that my scope has expanded rapidly and the current base needs another rewrite. the rewrite i did last week was good and set the game forward so much, but in order to support more advanced features in a reliable way, i will need another rewrite, this time with a cleaner separation between pygame and the game core.
+
+on the topic of the game core, in order to have a reliable game world with multiple players and advanced ai agents (possibly run in a separate process), a stable framework will have to be devised.
+
+twisted offers a real possibility to create a clean client/server base that will be able to be extended by other people.
+
+the use of signals may be lost now, i will see where that will go once i get the server separated from the client.
View
@@ -11,7 +11,6 @@
import math, pygame
debug = 1
-
movt_fix = 1/math.sqrt(2)
@@ -31,8 +30,73 @@ def play(self, name, volume=1.0):
SoundMan = SoundManager()
+
+
+class WorldStateController(object):
+ """
+ Controller to manipulate the world
+ """
+
+ def __init__(self, view, model):
+ self.view = view
+ self.model = model
+
+
+ def process(self, cmdlist):
+ """
+ supply a list of game events
+ """
+
+ x = 0
+ y = 0
+
+ for cls, cmd, arg in cmdlist:
+ if arg == BUTTONUP:
+ if cmd == P1_UP:
+ self.player_vector.x = 0
+ elif cmd == P1_DOWN:
+ self.player_vector.x = 0
+ elif cmd == P1_LEFT:
+ self.player_vector.y = 0
+ elif cmd == P1_RIGHT:
+ self.player_vector.y = 0
+ elif cmd == P1_ACTION2:
+ self.hero.ungrab()
+ elif cmd == P1_ACTION3:
+ self.hero.unlift()
+
+ # these actions will repeat as button is held down
+ elif arg == BUTTONDOWN or arg == BUTTONHELD:
+ if cmd == P1_UP: x = -1
+ elif cmd == P1_DOWN: x = 1
+ elif cmd == P1_LEFT: y = -1
+ elif cmd == P1_RIGHT: y = 1
+
+ # these actions will not repeat if button is held
+ if arg == BUTTONDOWN:
+ if cmd == P1_ACTION1:
+ self.hero.attack()
+
+ elif cmd == P1_ACTION2:
+ self.hero.grab()
+
+ elif cmd == P1_ACTION3:
+ self.hero.lift()
+
+
+ if (not x == 0) and (not y == 0):
+ x *= movt_fix
+ y *= movt_fix
+ if (not x == 0) or (not y == 0):
+ self.player_vector.y = y * self.hero.move_speed
+ self.player_vector.x = x * self.hero.move_speed
+
+ # don't rotate the player if he's grabbing something
+ if not self.hero.arms == GRAB:
+ self.area.setOrientation(self.hero, math.atan2(x, y))
+
class WorldState(GameState):
"""
@@ -47,18 +111,22 @@ class WorldState(GameState):
equipted items always have a dedicated button
should have hot-swap button and drop button
+ This is a VIEW in mvc.
+
"""
def __init__(self, area, startPosition=None):
GameState.__init__(self)
self.area = area
+
+
+ def activate(self):
+ self.blank = True
self.background = (203, 204, 177)
self.foreground = (0, 0, 0)
- self.blank = True
-
+ self.controller = WorldStateController(self, self.area)
- def activate(self):
self.msgFont = pygame.font.Font((res.fontPath("volter.ttf")), 9)
self.border = gui.GraphicBox("dialog2-h.png", hollow=True)
self.borderFilled = gui.GraphicBox("dialog2.png")
@@ -109,7 +177,7 @@ def deactivate(self):
pass
- def drawSidebar(self, surface, rect):
+ def _drawSidebar(self, surface, rect):
# draw the static portions of the sidebar
sx, sy, sw, sh = rect
@@ -132,7 +200,7 @@ def draw(self, surface):
if self.blank:
self.blank = False
surface.fill(self.background)
- self.drawSidebar(surface, self.hudBorder)
+ self._drawSidebar(surface, self.hudBorder)
self.camera.center(self.area.getPosition(self.hero))
# the main map
@@ -171,7 +239,8 @@ def draw(self, surface):
(255,0,128, 20),
(self.camera.toScreen((x+ox, y+oy)), (sy, sx)))
- surface.set_clip(originalClip)
+ surface.set_clip(originalClip)
+
def _update(self, time):
self.area.update(time)
@@ -194,54 +263,8 @@ def update(self, sender, **kwargs):
def handle_commandlist(self, cmdlist):
- x = 0
- y = 0
-
- for cls, cmd, arg in cmdlist:
- if arg == BUTTONUP:
- if cmd == P1_UP:
- self.player_vector.x = 0
- elif cmd == P1_DOWN:
- self.player_vector.x = 0
- elif cmd == P1_LEFT:
- self.player_vector.y = 0
- elif cmd == P1_RIGHT:
- self.player_vector.y = 0
- elif cmd == P1_ACTION2:
- self.hero.ungrab()
- elif cmd == P1_ACTION3:
- self.hero.unlift()
-
- # these actions will repeat as button is held down
- elif arg == BUTTONDOWN or arg == BUTTONHELD:
- if cmd == P1_UP: x = -1
- elif cmd == P1_DOWN: x = 1
- elif cmd == P1_LEFT: y = -1
- elif cmd == P1_RIGHT: y = 1
-
- # these actions will not repeat if button is held
- if arg == BUTTONDOWN:
- if cmd == P1_ACTION1:
- self.hero.attack()
-
- elif cmd == P1_ACTION2:
- self.hero.grab()
-
- elif cmd == P1_ACTION3:
- self.hero.lift()
-
-
- if (not x == 0) and (not y == 0):
- x *= movt_fix
- y *= movt_fix
+ self.controller.process(cmdlist)
- if (not x == 0) or (not y == 0):
- self.player_vector.y = y * self.hero.move_speed
- self.player_vector.x = x * self.hero.move_speed
-
- # don't rotate the player if he's grabbing something
- if not self.hero.arms == GRAB:
- self.area.setOrientation(self.hero, math.atan2(x, y))
"""
View
@@ -7,7 +7,7 @@
"""
TODO: make some sort of manager class for animations
would make resource sharing less expensive
- in many cases, a cache doesn't make sence, but here...it does
+ in many cases, a cache doesn't make sense, but here...it does
"""
def padimage(image):
Oops, something went wrong.

0 comments on commit c797774

Please sign in to comment.