Cory Li avatar Cory Li committed 6022803

adding basic tileset, spriteize scaffolding added

Comments (0)

Files changed (3)

 
 # DECLARE ENUMS
 class Terrain:
-    GROUND = 0
-    WATER = 1
+    WATER = 0
+    GROUND = 1
     WALL = 2
 
-
 class TileSet:
 
     def __init__(self,filename,size):
     def initialize_grid(self,(sizeX,sizeY), val=0):
         return [[val for y in range(sizeY)] for x in range(sizeX)]
 
-    def add_spawn(team, position):
+    def add_spawn(self,team, position, radius):
         (x,y) = position
         self.spawn_data.append({
                 'team' : team,
+                'r': radius,
                 'x': x,
                 'y': y,
             })
         ds_algo = DiamondSquare(lod,roughness)
         size = ds_algo.size
 
-        self.map_collision = ds_algo.generate().threshold([0.33,0.66,1.0]).world
+        self.map_collision = ds_algo.generate().threshold([0.33,0.66,1.0]).scale_by(2).spriteize()
         self.map_ground = self.initialize_grid((size,size))
         self.map_sky = self.initialize_grid((size,size))
 
 class MapViewer:
     tile_size = 8 #pixels
 
-    camWidth = 129
-    camHeight = 129
+    camWidth = 130
+    camHeight = 130
     camX = 0
     camY = 0
 
         sizeX,sizeY = self.model.size
         for x in range(sizeX):
             for y in range(sizeY):
-                self.draw_value((x,y),mapdata[x][y])
+                self.draw_tile((x,y),int(mapdata[x][y]))
                 # if mapdata[x][y] == 0:
                 #     self.draw_color((x,y),(255,0,0))
                 # if mapdata[x][y] == 1:
 
 
 if __name__=='__main__':
-    model = TiledMap((129,129))
-    model.randomize_ds(7,0.67)
+    # model = TiledMap((4,4))
+    # model.add_spawn(1,(1,1),2)
+    # print model.export()
+    model = TiledMap((130,130))
+    model.randomize_ds(6,0.68)
 
-    tiles = TileSet('tileset_one.png',16)
+    tiles = TileSet('tileset_two.png',16)
     view = MapViewer(model,tiles)
 
     mainloop = True
             elif event.type == pygame.KEYDOWN:
                 if event.key == pygame.K_ESCAPE:
                     mainloop = False
+
         view.update()
 from random import random, uniform
 
 
+WALL = 10
+WALL_N = 1
+WALL_E = 11
+WALL_S = 19
+WALL_W = 9
+WALL_NE = 2
+WALL_NW = 0
+WALL_SE = 20
+WALL_SW = 18
 
+WATER = 13
+WATER_N = 4
+WATER_E = 14
+WATER_S = 22
+WATER_W = 12
+WATER_NE = 5
+WATER_NW = 3
+WATER_SE = 23
+WATER_SW = 21
+
+GRASS_1 = 6
+GRASS_2 = 7
+GRASS_3 = 8
+GRASS_4 = 15
+
+GRASS = (GRASS_1, GRASS_2, GRASS_3, GRASS_4)
 
 
 
         self.world = bigworld
         return self
 
-
     def __repr__(self):
         return str(self.world)
 
+    def spriteize(self):
+        size = self.size
+        out = numpy.empty((size,size))
+        for x in range(size):
+            for y in range(size):
+                t = self.world[x][y]
+
+                if t==0:
+                    out[x][y] = WATER
+                elif t==1:
+                    out[x][y] = GRASS_1
+                elif t==2:
+                    out[x][y] = WALL
+        return out
 
 class DiamondSquare:
     def __init__(self, lod, roughness):
 
     print terrain
     terrain.scale_by(2)
-    print terrain
+    print terrain.spriteize()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.