Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8354627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:36:18+00:00 2026-06-09T09:36:18+00:00

Thanks for taking the time to read this. I am trying to create a

  • 0

Thanks for taking the time to read this. I am trying to create a very basic tile game system with pygame. I am not the best at pygame, so I may be missing something fairly obvious. So far I have everything in one file. What I have right now seems really sloppy and there is probably a more efficient way of doing it, but right now I am just using 2d Arrays with a number that equates to a specific type of tile, (grass, water, etc). For that I am using numpy because that is what someone recommended to me. Though I don’t know if I like this method, because what if in the future I had some tile that was not simply graphical, and had more specific attributes to it? Like a treasure chest for example or a trap? How would you structure this?

But none the less, my problem is right now the screen is simply black, and isn’t drawing the grass tiles.

Here is the code:

import numpy
import pygame
import sys
from pygame.locals import *

pygame.init()

fpsClock = pygame.time.Clock()

windowWi = 800
windowHi = 608

mapWi = 50 # *16 = 800, etc
mapHi = 38

# ----- all of the images ------------------------------

grass1 = pygame.image.load('pictures\(Grass\grass1.png')


#-------------------------------------------------------
screen = pygame.display.set_mode((windowWi, windowHi))
pygame.display.set_caption("Tile Testing!")

gameRunning = True

groundArray = numpy.ones((mapWi,mapHi))

def drawMapArray(maparray):
    for x in range(mapWi,1):
        for y in range(mapHi,1):
            #Determines tile type.
            if maparray[y,x] == 1:
                screen.blit(grass1, (x*16, y*16))
            else:
                print "Nothing is here!"

while gameRunning:
    drawMapArray(groundArray)

    for event in pygame.event.get():
        if event.type == "QUIT":
            pygame.quit()
            sys.exit()



    #Updates display and then sets FPS to 30 FPS. 
    pygame.display.update()
    fpsClock.tick(30)

Please feel free to steer me in a better structural direction as I am very new to game design and want any feedback!

Thanks,
Ryan

EDIT:
I have tried this, which makes sense logically but I am getting an index out of range error.

def drawMapArray(maparray):
    for x in range(0,mapWi,1):
        for y in range(0,mapHi,1):
            #Determines tile type.
            if maparray[y,x] == 1:
                screen.blit(grass1, (x*16, y*16))
            else:
                print "Nothing is here!"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:36:20+00:00Added an answer on June 9, 2026 at 9:36 am

    One solution that might scale better as you add more tile types is using a dictionary to get from the numbers in your array to the images, e.g.:

    tile_dict = {1 : pygame.image.load('pictures\(Grass\grass1.png'),
                 2 : pygame.image.load('pictures\rock.png')
                }
    

    And then just draw the relevant entry from the dictionary in your draw function

    def drawMapArray(maparray):
        for x in range(0, mapWi):
            for y in range(0, mapHi):
                #Determines tile type.
                current_tile = tile_dict[maparray[x, y]]
                screen.blit(current_tile, (x*16, y*16))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

thanks for taking the time out to read this post. I'm having trouble trying
Thanks for taking the time to read this. I have an unknown number of
Thanks everyone for taking the time to read this. I have styled my navigation
First, thanks in advance for taking the time to read through this. I have
Thanks for taking time to read this question. I am designing a 3-tier solution
thanks for taking the time to read this. I have a JavaScript (jQuery) navigation
Thanks in advance for taking the time to read this. Apologies that it is
First, thanks for taking the time to read this. I'm having some difficulties with
Thanks for taking the time to read my post... I'm trying to extract some
Problem: Thanks for taking the time to read this. I'm having a problem which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.