|
@@ -9,19 +9,18 @@ from anarchmap import AnarchMap
|
|
|
assets_folder = '../anarch/assets/'
|
|
|
|
|
|
class LevelModel:
|
|
|
- def get_tex(self,file):
|
|
|
- tex = pyglet.image.load(file).get_texture()
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
|
|
|
+ def get_tex(self, file):
|
|
|
+ try:
|
|
|
+ tex = pyglet.image.load(file).get_texture()
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
|
|
|
+ except:
|
|
|
+ return None
|
|
|
+
|
|
|
return pyglet.graphics.TextureGroup(tex)
|
|
|
|
|
|
- def get_texture(self, textureIndex):
|
|
|
- tex = pyglet.image.load()
|
|
|
-
|
|
|
def add_block(self, x, y, z, wall_tex, ceil_color=0, floor_color=0):
|
|
|
-
|
|
|
X, Y, Z = x+1, y+1, z+1
|
|
|
-
|
|
|
tex_coords = ('t2f', (0, 0, 1, 0, 1, 1, 0, 1))
|
|
|
white = [255]*4
|
|
|
|
|
@@ -34,18 +33,52 @@ class LevelModel:
|
|
|
self.batch.add(4, GL_QUADS, None, ('v3f', (x, y, z, X, y, z, X, y, Z, x, y, Z)), ('c4b', white * 4)) # bottom
|
|
|
self.batch.add(4, GL_QUADS, None, ('v3f', (x, Y, Z, X, Y, Z, X, Y, z, x, Y, z)), ('c4b', white * 4)) # top
|
|
|
|
|
|
+ def add_entity(self, x, z, texture, is_item=True):
|
|
|
+ y=3
|
|
|
+ X, Y, Z = x+1, y+1, z+1
|
|
|
+ tex_coords = ('t2f', (0, 0, 1, 0, 1, 1, 0, 1))
|
|
|
+
|
|
|
+ self.batch.add(4, GL_QUADS, texture, ('v3f', (X, y, Z, X, y, z, X, Y, z, X, Y, Z)), tex_coords)
|
|
|
+
|
|
|
def __init__(self, basepath):
|
|
|
self.base_path = basepath
|
|
|
|
|
|
self.batch = pyglet.graphics.Batch()
|
|
|
+ self.entity_group = pyglet.graphics.NullGroup()
|
|
|
|
|
|
- # build list of wall textures
|
|
|
+ # build lists of textures
|
|
|
idxs = range(16)
|
|
|
filename_template = os.path.join(self.base_path, 'wall_texture{}.png')
|
|
|
self.wall_textures = list(map(lambda x: self.get_tex(filename_template.format(x)), idxs))
|
|
|
|
|
|
- # self.add_block(0, 0, -1, 0)
|
|
|
- # self.add_block(0, 2, -1, 0)
|
|
|
+ item_images = [
|
|
|
+ '',
|
|
|
+ 'item_barrel.png',
|
|
|
+ 'item_health.png',
|
|
|
+ 'item_bullets.png',
|
|
|
+ 'item_rockets.png',
|
|
|
+ 'item_plasma.png',
|
|
|
+ 'item_tree.png',
|
|
|
+ 'item_finish.png',
|
|
|
+ 'item_teleport.png',
|
|
|
+ 'item_terminal.png',
|
|
|
+ 'item_column.png',
|
|
|
+ 'item_ruin.png',
|
|
|
+ 'item_lamp.png',
|
|
|
+ 'item_card.png',
|
|
|
+ ]
|
|
|
+ monster_images = [
|
|
|
+ 'monster_spider.png',
|
|
|
+ 'monster_destroyer.png',
|
|
|
+ 'monster_warrior.png',
|
|
|
+ 'monster_plasmabot.png',
|
|
|
+ 'monster_ender.png',
|
|
|
+ 'monster_turret.png',
|
|
|
+ 'monster_exploder.png',
|
|
|
+ ]
|
|
|
+
|
|
|
+ self.item_textures = list(map(lambda x: self.get_tex(os.path.join(self.base_path, x)), item_images))
|
|
|
+ self.monster_textures = list(map(lambda x: self.get_tex(os.path.join(self.base_path, x)), monster_images))
|
|
|
|
|
|
def load_level_image(self, file):
|
|
|
self.ceiling_color = 0xff0000
|
|
@@ -65,7 +98,40 @@ class LevelModel:
|
|
|
floor_tex = self.map.floorDict[item[0]][0]
|
|
|
floor_ht = self.map.floorDict[item[0]][1]
|
|
|
# print("tile: %s, %s, %s" % (tile_index, item[0], floor_ht))
|
|
|
- self.add_block(0-x, floor_ht / 32, 0-y, floor_tex)
|
|
|
+ self.add_block(0-x, floor_ht / 4, 0-y, floor_tex)
|
|
|
+
|
|
|
+ for e in self.map.elements:
|
|
|
+ # if below a certain value, it's from itemSprites
|
|
|
+ tex_index = e[0]
|
|
|
+ is_item = True
|
|
|
+
|
|
|
+ # idk
|
|
|
+ if e[0] == 0:
|
|
|
+ return
|
|
|
+
|
|
|
+ # skip non-visible door locks TODO: draw lock indicator
|
|
|
+ if e[0] == 15 or e[0] == 16 or e[0] == 17:
|
|
|
+ continue
|
|
|
+
|
|
|
+ # use single texture for card TODO: draw card color indicator
|
|
|
+ if e[0] == 12 or e[0] == 13 or e[0] == 14:
|
|
|
+ tex_index = 12
|
|
|
+
|
|
|
+ # "blocker"
|
|
|
+ if e[0] == 19:
|
|
|
+ tex_index = 11
|
|
|
+
|
|
|
+ if e[0] > 19:
|
|
|
+ tex_index = e[0] - 32
|
|
|
+ is_item = False
|
|
|
+
|
|
|
+ if is_item:
|
|
|
+ texture = self.item_textures[tex_index]
|
|
|
+ else:
|
|
|
+ texture = self.monster_textures[tex_index]
|
|
|
+
|
|
|
+ print("adding entity %s at (%s, %s), is_item=%s" % (tex_index, e[1], e[2], is_item))
|
|
|
+ self.add_entity(0-e[1], 0-e[2], texture)
|
|
|
|
|
|
def draw(self):
|
|
|
self.batch.draw()
|