예제 #1
0
 def post(self):
   tile = Tile()
   tile.x = int(self.request.get("x"))
   tile.y = int(self.request.get("y"))
   tile.height = int(self.request.get("height"))
   tile.type = int(self.request.get("type"))
   tile.put()
예제 #2
0
  def get(self):

    map = memcache.get("map")
    HeightMapData = FetchImage("http://humanitymmo.appspot.com/static/earthmini.png")
    w,h = HeightMapData[:2]

    # should get the tiles, within proximity of units.
    # foreach unit, get tiles within range of the unit
    # in this instance limit it to 1 unit only
    unit = Unit.get_by_id( int(self.request.get("id")) )

    json = {"tiles":[],"enemyunits":[]}        

    fov =  2 # fov is how many tiles a unit can see around it
    xleft = max(unit.x - fov, 0)
    xright = min(unit.x + fov + 1, w)
    ytop = max(unit.y - fov, 0)
    ybottom = min(unit.y + fov + 1, h)

    # get heightmap based tiles
    for x in range(xleft, xright):
        for y in range(ytop, ybottom):
          # is the tile in the datastore
          curTile = Tile.gql("where x = :1 and y = :2", x,y)
          if curTile.count() > 0:
              if curTile.type.canTravel:
                 curAlt = 80
              else:
                 curAlt = 81

              json["tiles"].append( {"x":curTile.x,"y":curTile.y,"alt":curAlt} )
          else
              alt = GetHeightAt(x,y,HeightMapData)
              json["tiles"].append( {"x":x, "y":y, "alt":alt } )
              # write to datastore
              t = Tile()
              t.x = x
              t.y = y
              t.height = alt
              
              if alt < 81:
                # get tile type where name = water, then reference it

              else:
                # get tile type for land

              t.put()
          
    self.response.out.write(demjson.encode(json))