Note that there are some explanatory texts on larger screens.

plurals
  1. POTile based game using pygame questions / problems
    text
    copied!<p>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?</p> <p>But none the less, my problem is right now the screen is simply black, and isn't drawing the grass tiles. </p> <p>Here is the code: </p> <pre><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) </code></pre> <p>Please feel free to steer me in a better structural direction as I am very new to game design and want any feedback!</p> <p>Thanks, Ryan </p> <p>EDIT: I have tried this, which makes sense logically but I am getting an index out of range error.</p> <pre><code>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!" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload