1. Sami Loone
  2. Fat x Fast

Commits

dryatu  committed 7b47e19

Now shadowing the minimap. Weaving disabled because of an unknown bug.

  • Participants
  • Parent commits 06a42e2
  • Branches default

Comments (0)

Files changed (11)

File FatxFast/config.py

View file
  • Ignore whitespace
 #        self.hotkeys["player2-turbo"] = pygame.K_RSHIFT
 #        self.hotkeys["map-zoom-in"] = pygame.K_PLUS
 #        self.hotkeys["map-zoom-out"] = pygame.K_MINUS
-#        self.hotkeys["player1-map"] = pygame.K_z
-#        self.hotkeys["player2-map"] = pygame.K_m
+        self.hotkeys["map"] = pygame.K_m
         #self.hotkeys["solve"] = pygame.K_o
         self.mapstyle = "auto"
         self.fullscreen = False

File FatxFast/gui/container.py

View file
  • Ignore whitespace
 
     def _call_child_widgets(self, function): 
         for widget in self.widgets.values():
-            return_value = function(widget)
+            return_value = function(widget)  
             if not return_value and isinstance(widget, Container):
                 return_value = widget._call_child_widgets(function)
             if return_value:

File FatxFast/gui/hud/minimapframe.py

View file
  • Ignore whitespace
 from FatxFast.gui.hud.frame import Frame
 from FatxFast.camera import Camera
 from FatxFast.tilemap.editor.tile import TILEWIDTH, TILEHEIGHT
+from FatxFast.graphics import SCREENSIZE
 import pygame
 
 class MiniMapFrame(Frame):
     def __init__(self, game, flipped=False, loaded=False,**kwargs):
         super(MiniMapFrame, self).__init__(game, **kwargs)
         self._loaded = loaded
-        self._temp_surf = pygame.Surface((0,0)) 
+        self._temp_surf = pygame.Surface((0,0))
+        self.loaded = loaded
+        self.camera = Camera((0,0))
         if loaded:
             self.load_minimap()
         # Flipped: True = Center up right, False Right Corner
         self.flipped = flipped
+        self.fullscreen = kwargs.get("fullscreen")
+
+    def _calculate_size(self):
+        new_rect = pygame.rect.Rect((0,0),(0,0))
+        new_rect.width = self.rect.width #self._border.width
+        new_rect.height = self.rect.height #self._border.width
+        new_rect.x = self.rect.x + self._border.width
+        new_rect.y = self.rect.y + self._border.width
+        return new_rect
+
+    def draw(self, surface):
+        if not self._loaded:
+            return
+
+        surface.blit(self._temp_surf, self.rect.topleft)
+        surface.blit(self.overlay_surf, self.rect.topleft)
+        player_rect = pygame.rect.Rect((0,0), 
+            (10, 10))
+
+        for index, player in zip(xrange(
+                0,len(self.game.players)), self.game.players):
+            if index >= len(self._player_colors):
+                index = len(self._player_colors)-1
+            player_rect.width = 2+ (player.rect.width/\
+                self._map_to_minimap_width_ratio())
+            player_rect.height = 2+ (player.rect.height/\
+                self._map_to_minimap_height_ratio())
+            player_rect.x = self.rect.x+(player.rect.x/\
+                self._map_to_minimap_width_ratio())
+            player_rect.y = self.rect.y+(player.rect.y/\
+                self._map_to_minimap_height_ratio())
+
+            # Do some revealing of the map
+            # TODO: Add a more dynamic shadow revealing
+            shadow_overlay_rect = player_rect.copy()
+            shadow_overlay_rect.size = (player_rect.width*2, 
+                player_rect.height*2)
+            shadow_overlay_rect.center = player_rect.center
+            shadow_overlay_rect.move_ip(-self.rect.x, -self.rect.y)
+            self.overlay_surf.fill((0,0,0,0), shadow_overlay_rect)
+            surface.fill(self._player_colors[index], player_rect)
+
+        super(MiniMapFrame, self).draw(surface)
+
+    def _map_to_minimap_width_ratio(self):
+        return (self.camera.rect.width/float(self.rect.width))
+
+    def _map_to_minimap_height_ratio(self):
+        return (self.camera.rect.height/float(self.rect.height))
+
+    def load_minimap(self):
+        self.tilemap = self.game.tilemap
+        self.camera.rect.size = (self.tilemap.width*TILEWIDTH, 
+                self.tilemap.height*TILEHEIGHT)
+        self._set_camera_zoom()
+        self.tilemap.draw_map(self._temp_surf, self.camera)
+
+        self._temp_surf = pygame.transform.scale(self._temp_surf, 
+            self._calculate_size().size)
+
+        if not self.loaded:
+            self.overlay_surf = pygame.Surface(self._temp_surf.get_size(), 
+                pygame.SRCALPHA)
+            self.overlay_surf.fill((0,0,0,255))
+        else:
+            self.overlay_surf =  pygame.transform.scale(self.overlay_surf,
+                self._calculate_size().size)
+        self._loaded = True
+
+    def reset_minimap(self):
+        template = "flippedminimap" if self.flipped else "minimap"
+        self.__init__(self.game, flipped=self.flipped, 
+                loaded=False, fullscreen=False,
+                **self.fetch_template(template))
+        self.load_minimap()
+
+    def _set_camera_zoom(self):
+        # Optimize to cache a resized surface
+        if self._temp_surf.get_size() != self.camera.rect.size:
+            self._temp_surf = pygame.Surface(self.camera.rect.size)
+
+
+    def toggle_fullscreen(self):
+        if self.fullscreen:
+            template = "flippedminimap" if self.flipped else "minimap"
+            self.__init__(self.game, flipped=self.flipped, 
+                loaded=True, fullscreen=False,
+                **self.fetch_template(template))
+        else:
+            self.__init__(self.game, flipped=self.flipped, 
+                loaded=True, fullscreen=True,
+                **self.fetch_template("fullmap"))
 
     def toggle_position(self):
         if self.flipped:
         else:
             self.__init__(self.game, flipped=True, loaded=True, 
                 **self.fetch_template("flippedminimap"))
-
-    def _calculate_size_without_borders(self):
-        new_rect = pygame.rect.Rect((0,0),(0,0))
-        new_rect.width = self.rect.width - self._border.width
-        new_rect.height = self.rect.height - self._border.width
-        new_rect.x = self.rect.x + self._border.width
-        new_rect.y = self.rect.y + self._border.width
-        return new_rect
-
-    def load_minimap(self):
-        self.tilemap = self.game.tilemap
-        self.camera = Camera(
-            (self.tilemap.width*TILEWIDTH, 
-                self.tilemap.height*TILEHEIGHT))
-        self._set_camera_zoom()
-        self.tilemap.draw_map(self._temp_surf, self.camera)
-
-        self._temp_surf = pygame.transform.scale(self._temp_surf, 
-            self._calculate_size_without_borders().size)
-        self._loaded = True
-
-    def _set_camera_zoom(self):
-        # Optimize to cache a resized surface
-        if self._temp_surf.get_size() != self.camera.rect.size:
-            self._temp_surf = pygame.Surface(self.camera.rect.size)
-
-    def draw(self, surface):
-        if not self._loaded:
-            return
-
-        surface.blit(self._temp_surf, self.rect.topleft)
-        
-        player_rect = pygame.rect.Rect((0,0), 
-            (10, 10))
-
-        for index, player in zip(xrange(
-                0,len(self.game.players)), self.game.players):
-            if index >= len(self._player_colors):
-                index = len(self._player_colors)-1
-            player_rect.width = 2+ (player.rect.width/\
-                (self.camera.rect.width/self.rect.width))
-            player_rect.height = 2+ (player.rect.height/\
-                (self.camera.rect.height/self.rect.height))
-            player_rect.x = self.rect.x+(player.rect.x/\
-                (self.camera.rect.width/float(self.rect.width)))
-            player_rect.y = self.rect.y+(player.rect.y/\
-                (self.camera.rect.height/float(self.rect.height)))
-            surface.fill(self._player_colors[index], player_rect) 
-
-        super(MiniMapFrame, self).draw(surface)
-

File FatxFast/levelsystem.py

View file
  • Ignore whitespace
 from fileio import LOGGER
 from FatxFast.utils import xmlparser
 from FatxFast.objects import triggers
+import pygame
 
 class LevelSchemeParser(xmlparser.XmlParser):
 
                 save=self.gamescene.save)
         elif self.level_complexity["type"] == "generated":
             kwargs = copy.deepcopy(self.gamescene.save.mapdata)
+            if kwargs.get("minimap_overlay"):
+                del kwargs["minimap_overlay"]
             if self.gamescene.save.game["level_complexity"]:
                 kwargs.update(copy.deepcopy(
                     self.gamescene.save.game["level_complexity"]))
             kwargs.update(copy.deepcopy(self.level_complexity["data"]))
             self.gamescene.tilemap.load_generated(**kwargs)
+        minimap = self.gamescene.get_widget("minimap")
+        minimap.load_minimap()
+        if self.gamescene.save.mapdata.get("minimap_overlay"):
+            minimap.overlay_surf = pygame.image.frombuffer(
+                self.gamescene.save.mapdata["minimap_overlay"], 
+                minimap.overlay_surf.get_size(), 'RGBA')
+
         self.gamescene.save.mapdata = {}
-        self.level_reload = False
-        self.gamescene.hud.widgets["minimap"].load_minimap()
 
     def load_level_scheme_from_file(self, filename="maps.xml"):
         pass

File FatxFast/modes/mapmode.py

View file
  • Ignore whitespace
 
     def __init__(self, scene, **kwargs):
         self.scene = scene 
-        self.camera = camera.Camera()
+        self.minimap = self.scene.get_widget("minimap")
+        self.camera = self.minimap.camera
         self.create_players()    
         self.hotkeys = scene.manager.game.config.hotkeys
         self.scene.playing = True
-        self._camera_sizes = [SCREENSIZE, 
-            (SCREENSIZE[0]*1.5, SCREENSIZE[1]*1.5)]
-        self._cam_size_index = 0
+#        self._camera_sizes = [SCREENSIZE, 
+#            (SCREENSIZE[0]*1.5, SCREENSIZE[1]*1.5)]
+#        self._cam_size_index = 0
 
-    # Returns (W,H)
-    @property
-    def _camera_size(self):
-        return self._camera_sizes[self._cam_size_index]
-
-    def _set_cam_zoom_level(self, value):
-        if (value >= 0 and value < len(self._camera_sizes)):
-            self._cam_size_index = value
-            self.camera.rect.size = self._camera_size
-
+#    # Returns (W,H)
+#    @property
+#    def _camera_size(self):
+#        return self._camera_sizes[self._cam_size_index]
+#
+#    def _set_cam_zoom_level(self, value):
+#        if (value >= 0 and value < len(self._camera_sizes)):
+#            self._cam_size_index = value
+#            self.camera.rect.size = self._camera_size
+#
     def create_players(self):
         x = self.scene.tilemap.properties.get("start_x", 64)
         y = self.scene.tilemap.properties.get("start_y", 64)
         self.player1 = self.scene.create_character(
             Player, pos=(x,y), add_to_world=False)
-        self.camera.follow_target(self.player1)
+#        self.camera.follow_target(self.player1)
         self.player1.physics.collides = False
+        pass
 
     def key_pressed(self, key, utf, mod):
-        if (key == self.hotkeys["player1-map"] or 
-            key == self.hotkeys["player2-map"]):
+        if key == self.hotkeys["map"]: 
             self.scene.close_map()
-        elif key == self.hotkeys["map-zoom-in"]:
-                self._set_cam_zoom_level(self._cam_size_index-1)
-        elif key == self.hotkeys["map-zoom-out"]:
-            self._set_cam_zoom_level(self._cam_size_index+1)
+#        elif key == self.hotkeys["map-zoom-in"]:
+#                self._set_cam_zoom_level(self._cam_size_index-1)
+#        elif key == self.hotkeys["map-zoom-out"]:
+#            self._set_cam_zoom_level(self._cam_size_index+1)
 
     def mouse_moved(self, pos, rel):
         player1 = self.player1
         pos = player1.get_position()
         player1.set_position((rel[0]+pos[0], rel[1]+pos[1]))
 
+    def pause(self):
+        super(MapMode, self).pause()
+
     def resume(self):
         super(MapMode, self).resume()
-        self.player1.maps_left = self.scene.gamemode.player1.maps_left
-        self.player1.rect.topleft = self.scene.gamemode.player1.rect.topleft
+#        self.player1.rect.topleft = self.scene.gamemode.player1.rect.topleft
     
     def start(self):
         super(MapMode, self).start()
-        self.player1.maps_left = self.scene.gamemode.player1.maps_left
-        self.player1.rect.topleft = self.scene.gamemode.player1.rect.topleft
+#        self.player1.rect.topleft = self.scene.gamemode.player1.rect.topleft
 
     def update(self, dt):
         self.keys_held()
-        self.player1.update(dt)
-        self.camera.update()
+#        self.player1.update(dt)
+#        self.camera.update()

File FatxFast/modes/mode.py

View file
  • Ignore whitespace
             played_mode=self.__class__.__name__.lower())
 
     def key_pressed(self, key, utf, mod):
-#        if key == self.hotkeys["player1-map"]:
-#            self.open_map(self.player1)
-        pass
+        if key == self.hotkeys["map"]:
+            self.open_map(self.player1)
 
     def keys_held(self):
         keys = super(GameMode, self).keys_held()
             self.scene.save.playerdata[player.name] = {}
             return True
 
-#    def open_map(self, player):
-#        if player.maps_left:
-#            player.maps_left -= 1
-#            self.scene.open_map()
+    def open_map(self, player):
+        self.scene.open_map()
 
     def pause(self):
         self.scene.game.input.remove_key_listener(self)
   
     def reload_level(self):
         self.scene.levelsystem.load_level()
+        self.scene.get_widget("minimap").reset_minimap()
         x = self.scene.tilemap.properties.get("start_x", 64)
         y = self.scene.tilemap.properties.get("start_y", 64)
         for player in self.scene.players: 

File FatxFast/physics/physics.py

View file
  • Ignore whitespace
     minspeed = 0.3
     accelspeed = 0.8
     bb_rect_component_relations = {"x":"width", "y":"height"}
+    _speed_down_factor = 0.4
     def __init__(self, entity, worldmap, collides=True):
         self.collides = collides
         self.speedvector = Vector2(0,0)
         self.worldmap = worldmap
         self._xmove = axismoving.MoveOnXAxis(self)
         self._ymove = axismoving.MoveOnYAxis(self)
-        self._speed_down_factor = 0.4
 
     def get_collision_tile(self, x, y):
         return self.worldmap.sprite_layers[COLLIDE_LAYER].content2D[y][x]

File FatxFast/pointsystem.py

View file
  • Ignore whitespace
         self.error_points = 1337
         self.max_points = 50000
 
+    def get_columns_and_rows(self):
+        return self.scene.tilemap.width, self.scene.tilemap.height
+    
     def increase_points(self, character):
         # Maze guy meets math
-        columns, rows = self.scene.tilemap.width, self.scene.tilemap.height
+        columns, rows = self.get_columns_and_rows()
         try: 
             points = int(round(columns*rows*
                 (1+(rows/(self.scene.levelsystem.leveltime/1000.0)))))

File FatxFast/rsc/levels.xml

View file
  • Ignore whitespace
         <floor_width>2</floor_width>
         <floor_height>2</floor_height>
         <item_count>3</item_count>
-        <algorithm>weave</algorithm>
+        <algorithm>binary</algorithm>
         <map_time>15000</map_time>
         <tileset>tileset4.png</tileset>
     </map>
         <rows>32</rows>
         <floor_width>3</floor_width>
         <floor_height>3</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>backtrack</algorithm>
         <maps_left>3</maps_left>
         <map_time>20000</map_time>
         <tileset>tileset2.png</tileset>
         <rows>12</rows>
         <floor_width>2</floor_width>
         <floor_height>2</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>backtrack</algorithm>
         <tileset>tileset4.png</tileset>
     </map>
     <map type="generated">
         <rows>44</rows>
         <floor_width>3</floor_width>
         <floor_height>3</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>prim</algorithm>
         <maps_left>3</maps_left>
         <tileset>tileset3.png</tileset>
     </map>
         <rows>50</rows>
         <floor_width>3</floor_width>
         <floor_height>3</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>backtrack</algorithm>
         <maps_left>3</maps_left>
         <tileset>tileset2.png</tileset>
     </map>
         <rows>20</rows>
         <floor_width>3</floor_width>
         <floor_height>3</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>prim</algorithm>
     </map>
     <map type="generated">
         <columns>32</columns>
         <rows>44</rows>
         <floor_width>3</floor_width>
         <floor_height>3</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>prim</algorithm>
     </map>
     <map type="generated">
         <columns>70</columns>
         <rows>60</rows>
         <floor_width>3</floor_width>
         <floor_height>3</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>backtrack</algorithm>
     </map>
 </practicemode>
 <multimode>
         <rows>12</rows>
         <floor_width>2</floor_width>
         <floor_height>2</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>prim</algorithm>
     </map>
     <map type="generated">
         <columns>16</columns>
         <rows>20</rows>
         <floor_width>3</floor_width>
         <floor_height>3</floor_height>
-        <algorithm>weave</algorithm>
+        <algorithm>backtrack</algorithm>
         <maps_left>2</maps_left>
         <tileset>tileset2.png</tileset>
     </map>

File FatxFast/rsc/widgets.xml

View file
  • Ignore whitespace
     <separator type="boxwidget" y="0" x="0" bgcolor="black" border-color="grey40" border-width="1" />
 
     <rageframe type="containerwidget" y="600" width="200" x="50" height="20" bgcolor="transblack-gui" border-width="1" border-color="grey7" />
-    <flippedminimap type="boxwidget" y="5" width="160" x="400" height="160" border-width="2" border-color="grey20" />
-    <minimap type="boxwidget" y="430" width="200" x="750" height="200" border-width="0" border-color="grey7" />
+    <flippedminimap type="boxwidget" name="minimap" y="5" width="160" x="400" height="160" border-width="2" border-color="grey20" />
+    <minimap type="boxwidget" name="minimap" y="430" width="200" x="750" height="200" border-width="2" border-color="grey7" />
+    <fullmap type="boxwidget" name="minimap" y="0" width="960" x="0" height="650" border-width="5" border-color="grey7" />
 	<buffwidget type="boxwidget" y="auto" width="100" height="64"></buffwidget>
 	<bufftext name="bufftext" type="textwidget" y="17" x="17" size="22" color="gold3" font="lavoir.ttf"></bufftext>
     <buffstacksizetext name="buffstacksizetext" type="textwidget" y="0" x="0" size="22" color="red3" font="lavoir.ttf"/>

File FatxFast/scenes/gamescene.py

View file
  • Ignore whitespace
         self._mode = None
         self.mode = self.gamemodes[self.save.game["mode"]](self, **kwargs)
         self.gamemode = self._mode
-#        self.mapmode = mapmode.MapMode(self)
+        self.mapmode = mapmode.MapMode(self)
     
     def add_player(self, player, camera):
         self.hud.add_player(player, camera)
             
     def close_map(self):
         self.mode = self.gamemode
+        self.get_widget("minimap").toggle_fullscreen()
 
     def create_character(self, charatype, pos, add_to_world=False):
         character = charatype(self.tilemap, x=pos[0], y=pos[1])
         self._mode = value
 
     def open_map(self):
-        self.mode = self.mapmode 
+        self.mode = self.mapmode
+        self.get_widget("minimap").toggle_fullscreen()
     
     def pause(self):
         super(GameScene, self).pause()
                     "x": item.rect.x,
                     "y": item.rect.y}
 
+
+        save.mapdata["minimap_overlay"] = pygame.image.tostring(
+            self.get_widget("minimap").overlay_surf, 'RGBA')
+
         self.game.savemanager.edit_save(index, save)
         LOGGER.log_message("Game saved at index {0}".format(index))