Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your draw method is wrong.</p> <pre><code>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)) </code></pre> <hr> <p>The first error is <code>for x in range(mapWi,1)</code>.</p> <p>Have a look at the <a href="http://docs.python.org/library/functions.html#range" rel="nofollow"><code>range</code></a> function. You're using two parameters, so you loop from <code>mapWi</code> to <code>1</code>, which is not what you want.</p> <p>You want to loop from <code>0</code> to <code>mapWi</code>, so you have to use</p> <pre><code>for x in range(mapWi): for y in range(mapHi): </code></pre> <p>(using <code>xrange</code> would be even better, but that would be just a very minor improvement)</p> <p>Otherwise, nothing will be drawn on the screen.</p> <hr> <p>The second error is this line:</p> <pre><code>if maparray[y,x] == 1: </code></pre> <p>You'll get an <code>IndexError</code> because you mixed up the initialization of the array. It's actually <code>mapWi</code> <em>high</em> and <code>mapHi</code> <em>wide</em>. So, you should initalize it using </p> <pre><code>groundArray = numpy.ones((mapHi,mapWi)) </code></pre> <p>instead of </p> <pre><code>groundArray = numpy.ones((mapWi,mapHi)) </code></pre> <p>To illustrate it, just a little test:</p> <pre><code>&gt;&gt;&gt; numpy.ones((10,5)) array([[ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.]]) &gt;&gt;&gt; </code></pre> <p>You'll see that using <code>(10, 5)</code> gives us an array of <code>height = 10</code> and <code>width = 5</code>.</p> <hr> <p>Sidenotes:</p> <pre><code>for event in pygame.event.get(): if event.type == "QUIT": </code></pre> <p>will do nothing. <code>event.type</code> is never a string <code>"QUIT"</code>. The type of the quit event is <code>12</code>, or better: <code>pygame.QUIT</code>; so it should read:</p> <pre><code>for event in pygame.event.get(): if event.type == pygame.QUIT: </code></pre> <p>Rewrite your mainloop like this:</p> <pre><code>while gameRunning: drawMapArray(groundArray) for event in pygame.event.get(): if event.type == pygame.QUIT: gameRunning = False break #Updates display and then sets FPS to 30 FPS. pygame.display.update() fpsClock.tick(30) pygame.quit() </code></pre> <p>to avoid calling <code>sys.exit</code>.</p> <p>Better: split your main loop into the three steps you usually do in a mainloop.</p> <pre><code>while gameRunning: draw() # do all the drawing stuff in this function handle_input() # handle all input stuff in this function update() # update the game state in this function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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