Commits

benbeltran  committed 3345771

Introduces grass actor, and adds debugging toggles

  • Participants
  • Parent commits 5d706ea

Comments (0)

Files changed (11)

File actors/actor.lua

 
 function Actor:draw()
   love.graphics.draw(self.image, self.x - self.image:getWidth() / 2, self.y - self.image:getHeight() / 2)
-  self:draw_bounding_box()
+  if game.show_hitbox then
+    self:draw_bounding_box()
+  end
   self:draw_shadow()
 end
 
         if tile.properties.passable == 0 then
           return false
         end
-        print(self.box.bottom.." <-> "..tile_y2*mapsys.map.tileHeight)
         if tile.properties.passable == 2 and
           self.y_vel >= 0 and
           self.y + self.box.bottom <= tile_y2 * mapsys.map.tileHeight + 12 + self.y_vel then

File actors/grass.lua

+local GrassActor = class('GrassActor', Actor)
+
+function GrassActor:initialize(x, y, color)
+  self.color = color
+  local image = "assets/images/sprites/static/grass_grn_16x16.png"
+
+  if color == "red" then
+    image = "assets/images/sprites/static/grass_red_16x16.png"
+  elseif color == "blue" then
+    image = "assets/images/sprites/static/grass_blu_16x16.png"
+  end
+
+  Actor.initialize(self, x, y, image)
+end
+
+return GrassActor

File assets/images/sprites/static/grass_blu_16x16.png

Added
New image

File assets/images/sprites/static/grass_grn_16x16.png

Added
New image

File assets/images/sprites/static/grass_red_16x16.png

Added
New image

File assets/maps/cowtest.tmx

  </layer>
  <layer name="Collision" width="100" height="50">
   <data encoding="base64" compression="zlib">
-   eJzt10sOgzAQBFEuC9z/BlF2rHD87YpVT+otHqZlCY6D5XpkF1dFaMiztajpgvjO5Nla2AeLfbDYB88ufdTOeT5CN7OPGc9qmfN+hO5f7seXfcw/dwX7yDkLoRvdR7rPuxAy4vdVz/mlu7HqnrTscpfv3dmhzDhDz7NTfZTmJcyQkOyDEJr0PtIZtb9R0vtIhya9j3RoSv8VPXmT7oHamX381seqfuwjc1/S77BTeqRn3zEt0jMbY4wxxqyK1nH3kiRJkiRJkiRJksT1ARgdXss=
+   eJzt10EOhDAMQ1EuC9z/BrPtakLTprai/yRvIY1VCa7LyzOki2cibpxny5jpwvHMzrNl0IcX+vBCH3669DE75z3EXWUfFc/KzPkOcZc9p+I+0Uf9e0+gD507iLvdfaj7fIM4c/y+Wnl/dDdO3ZPMLrt871bHZcYKK89W9RHN6zCDgrIPh7hR70OdXfvbRb0Pddyo96GOm+i/YiX/qHtw7Yw+vvVxqh/60NwX9Rk6ZYV69o7JUM9MCCGEEHIqOIfdAwAAAAAAAAAAAICvH3ilYGM=
   </data>
  </layer>
  <objectgroup name="Objects" width="100" height="50">
     <property name="spawn" value="walker"/>
    </properties>
   </object>
-  <object name="Blue Grass" type="SPAWN" x="1040" y="336" width="16" height="16">
+  <object name="Player" type="SPAWN" x="64" y="256" width="16" height="16">
    <properties>
-    <property name="spawn" value="blue_grass"/>
+    <property name="spawn" value="player"/>
    </properties>
   </object>
-  <object name="Player" type="SPAWN" x="64" y="256" width="16" height="16">
+  <object name="Blue Grass" type="SPAWN" x="1008" y="336" width="16" height="16">
    <properties>
-    <property name="spawn" value="player"/>
+    <property name="color" value="blue"/>
+    <property name="spawn" value="grass"/>
    </properties>
   </object>
-  <object name="Green Grass" type="SPAWN" x="784" y="144" width="16" height="16">
+  <object name="Green Grass" type="SPAWN" x="768" y="144" width="16" height="16">
    <properties>
-    <property name="spawn" value="green-grass"/>
+    <property name="color" value="green"/>
+    <property name="spawn" value="grass"/>
    </properties>
   </object>
-  <object name="Blue Grass" type="SPAWN" x="1024" y="336" width="16" height="16">
+  <object name="Red Grass" type="SPAWN" x="0" y="304" width="16" height="16">
    <properties>
-    <property name="spawn" value="blue_grass"/>
+    <property name="color" value="red"/>
+    <property name="spawn" value="grass"/>
    </properties>
   </object>
-  <object name="Blue Grass" type="SPAWN" x="1008" y="336" width="16" height="16">
+  <object name="Red Grass" type="SPAWN" x="16" y="304" width="16" height="16">
    <properties>
-    <property name="spawn" value="blue_grass"/>
+    <property name="color" value="red"/>
+    <property name="spawn" value="grass"/>
    </properties>
   </object>
-  <object name="Green Grass" type="SPAWN" x="768" y="144" width="16" height="16">
+  <object name="Red Grass" type="SPAWN" x="32" y="304" width="16" height="16">
+   <properties>
+    <property name="color" value="red"/>
+    <property name="spawn" value="grass"/>
+   </properties>
+  </object>
+  <object name="Green Grass" type="SPAWN" x="784" y="144" width="16" height="16">
    <properties>
-    <property name="spawn" value="green-grass"/>
+    <property name="color" value="green"/>
+    <property name="spawn" value="grass"/>
    </properties>
   </object>
   <object name="Green Grass" type="SPAWN" x="800" y="144" width="16" height="16">
    <properties>
-    <property name="spawn" value="green-grass"/>
+    <property name="color" value="green"/>
+    <property name="spawn" value="grass"/>
    </properties>
   </object>
-  <object name="Red Grass" type="SPAWN" x="0" y="304" width="16" height="16">
+  <object name="Blue Grass" type="SPAWN" x="1024" y="336" width="16" height="16">
+   <properties>
+    <property name="color" value="blue"/>
+    <property name="spawn" value="grass"/>
+   </properties>
+  </object>
+  <object name="Blue Grass" type="SPAWN" x="1040" y="336" width="16" height="16">
    <properties>
-    <property name="spawn" value="red-grass"/>
+    <property name="color" value="blue"/>
+    <property name="spawn" value="grass"/>
    </properties>
   </object>
  </objectgroup>

File lib/vendor/AdvancedTiledLoader/ObjectLayer.lua

 ---------------------------------------------------------------------------------------------------
 -- Creates and returns a new ObjectLayer
 function ObjectLayer:new(map, name, color, opacity, prop)
-    
+
     -- Create a new table for our object layer and do some error checking.
     local layer = setmetatable({}, ObjectLayer)
-    
+
     layer.map = map                             -- The map this layer belongs to
     layer.name = name or "Unnamed ObjectLayer"  -- The name of this layer
     layer.color = color or grey                 -- The color theme
     layer.opacity = opacity or 1                -- The opacity
     layer.objects = {}                          -- The layer's objects indexed numerically
     layer.properties = prop or {}               -- Properties set by Tiled.
-    layer.visible = true                        -- If false then the layer will not be drawn
-    
+    layer.visible = true                        -- If false then the layer will not be dratrue
     -- Return the new object layer
     return layer
 end
 
 ---------------------------------------------------------------------------------------------------
 -- Sorting function for objects. We'll use this below in ObjectLayer:draw()
-local function drawSort(o1, o2) 
-    return o1.drawInfo.order < o2.drawInfo.order 
+local function drawSort(o1, o2)
+    return o1.drawInfo.order < o2.drawInfo.order
 end
 
 ---------------------------------------------------------------------------------------------------
     r,g,b,a = 255, 255, 255, 255 ---love.graphics.getColor()    -- Save the color so we can set it back at the end
     line = love.graphics.getLineWidth() -- Save the line width too
     self.color[4] = 255 * self.opacity  -- Set the opacity
-    
+
     -- Put only objects that are on the screen in the draw list. If the screen range isn't defined
     -- add all objects
     for i = 1, #self.objects do
         obj:updateDrawInfo()
         di = obj.drawInfo
         if dr[1] and dr[2] and dr[3] and dr[4] then
-            if  di.right > dr[1]-20 and 
-                di.bottom > dr[2]-20 and 
-                di.left < dr[1]+dr[3]+20 and 
-                di.top < dr[2]+dr[4]+20 then 
+            if  di.right > dr[1]-20 and
+                di.bottom > dr[2]-20 and
+                di.left < dr[1]+dr[3]+20 and
+                di.top < dr[2]+dr[4]+20 then
                     drawList[#drawList+1] = obj
             end
         else
             drawList[#drawList+1] = obj
         end
     end
-    
+
     -- Sort the draw list by the object's draw order
     table.sort(drawList, drawSort)
 
     -- Draw all the objects in the draw list.
     offsetX, offsetY = self.map.offsetX, self.map.offsetY
-    for i = 1, #drawList do 
+    for i = 1, #drawList do
         obj = drawList[i]
         love.graphics.setColor(r,b,g,a)
         drawList[i]:draw(di.x, di.y, unpack(self.color or neutralColor))
     end
-    
+
     -- Reset the color and line width
     love.graphics.setColor(r,b,g,a)
     love.graphics.setLineWidth(line)
 
 Actor = require('actors/actor')
 Player = require('actors/player')
+GrassActor = require('actors/grass')
 
 entities = {}
 
       love.audio.setVolume(0.0)
     end
   end
+  if key == "1" then
+    if game.show_hitbox then
+      game.show_hitbox = false
+    else
+      game.show_hitbox = true
+    end
+  end
+  if key == "2" then
+    if game.show_map_markers then
+      game.show_map_markers = false
+    else
+      game.show_map_markers = true
+    end
+  end
+  if key == "3" then
+    if game.show_map_collisions then
+      game.show_map_collisions = false
+    else
+      game.show_map_collisions = true
+    end
+  end
+  if key == "0" then
+    game.show_map_markers = false
+    game.show_hitbox = false
+  end
 end
 
 function debug_message(message, x, y)

File map.lua

Empty file removed.

File map_manager.lua

         local player = Player:new(v.x, v.y)
         camera:setPosition(v.x, v.y)
       end
+      if v.properties.spawn == "grass" then
+        local grass = GrassActor:new(v.x, v.y, v.properties.color)
+      end
     end
   end
 end
 end
 
 function MapManager:update(dt)
-  self.map:autoDrawRange(camera.wl, camera.wt, camera.scale, self.padding)
+  if game.show_map_markers then
+    self.map("Objects").visible = true
+  else
+    self.map("Objects").visible = false
+  end
+
+  if game.show_map_collisions then
+    self.map("Collision").visible = true
+  else
+    self.map("Collision").visible = false
+  end
+
+  local tx, ty = camera:toWorld(0,0)
+  self.map:autoDrawRange(-tx, -ty, camera.scale, self.padding)
 end
 
 function MapManager:displace(tx, ty)

File screens/game.lua

 
 function GameScreen:update(dt)
   beetle.update("Actors", table.getn(self.actor_manager.actors))
+  self.map_manager:update(dt)
   self.actor_manager:update(dt)
 end