街机模块图块地图上下颠倒绘制

时间:2018-12-19 22:39:25

标签: python-3.x

我很难找到我在哪里出错了。我正在尝试生成一些随机填充的图块来表示墙,但是我的tilemap是通过在2d数组上循环并随机填充图块而生成的。我想似乎是在颠倒地画瓷砖。

import random
import arcade
import sys

def draw_grid(width, height, tileSize):

    for h in range(0, height, tileSize):
        arcade.draw_line(0, h, width, h, arcade.color.BLACK)

    for w in range(0, width, tileSize):
        arcade.draw_line(w, 0, w, height, arcade.color.BLACK)

def draw_wall(x, y, tileSize):

    pos_x = x*tileSize
    pos_y = y*tileSize

    arcade.draw_rectangle_filled(pos_x-tileSize/2, pos_y-tileSize/2, tileSize, tileSize, arcade.color.BLUE)

def create_random_tileMap(width, height, tileSize):
    tileMap = [[0 for c in range(width//tileSize)] for r in range(height//tileSize)]

    for h in range(height//tileSize):
        for w in range(width//tileSize):
            chance = random.randint(0, 100)
            if chance < 45:
                tileMap[h][w] = 1
            else:
                tileMap[h][w] = 0
    print(tileMap)
    return tileMap

def draw_tileMap(width, height, tileSize, tileMap):

    for h in range(height//tileSize):
        for w in range(width//tileSize):
            if tileMap[h][w] == 1:
                draw_wall(w+1, h+1, tileSize)
            else:
                continue  


def main():

    HEIGHT = 400
    WIDTH = 600
    TILESIZE = 20
    TITLE = 'Random_Cave_map'

    TILEMAP = create_random_tileMap(WIDTH, HEIGHT, TILESIZE)

    arcade.open_window(WIDTH, HEIGHT, TITLE)

    arcade.set_background_color(arcade.color.GREEN)

    arcade.start_render()
    #drawing code goes here 
    draw_grid(WIDTH, HEIGHT, TILESIZE)
    draw_tileMap(WIDTH, HEIGHT, TILESIZE, TILEMAP)
    arcade.finish_render()
    arcade.run()



main()

它可能真的很简单,我在for循环之一中考虑它。它使我疯狂了几个小时。

0 个答案:

没有答案