Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Pygame 2D game times from a map
    primarykey
    data
    text
    <p>Alright I've tried to ask this before but I'm not really getting anywhere yet. I'm hoping i can explain what i want to do well enough. i will past all the code I have so far below.</p> <ul> <li>Im trying to create a 2D game just as practice to get to know pygame and python better.</li> <li>The game will be basically like the NES Zelda game (first one)</li> <li>Right now I want to recreate a one of the topdown screens. Simple sprites of 16x16 pixels on a grid. </li> <li><p>Now with the great help of you guys I have already gotten a clue about how to create the grid in a nice compact def with two 'for' statements (above).</p> <pre><code>def drawMapArray(maparray): for x in range(0, xTile): for y in range(0, yTile): current_tile = tile_dict[maparray[x, y]] screen.blit(current_tile, (x*spritesize, y*spritesize)) </code></pre></li> <li><p>Now what i want to do is from another file, take a map to map out tiles on the grid from a png file. so if my screen was 8 by 4 tiles:</p> <pre><code> 1 0 2 2 2 3 2 3 3 0 0 0 0 1 0 0 4 4 4 4 4 1 1 1 1 1 1 3 3 3 4 4 1 = thing1.png 2 = thing2.png 3 = thing3.png 4 = thing4.png </code></pre></li> <li><p>So then somehow I could import that into the maparray so each tile had the right .png file showing up on the grid. How would i go about getting this to happen? Here is my code below. </p> <pre><code>import numpy import pygame import sys from pygame.locals import * pygame.init() fpsClock = pygame.time.Clock() #print help(numpy) resmulti=3 spritesize=16*resmulti resolution=(256*resmulti,224*resmulti) screen = pygame.display.set_mode((resolution[0], resolution[1])) pygame.display.set_caption("testing.") xTile = 2 yTile = 2 gameRunning = True groundArray = numpy.ones((xTile,yTile)) ################################### ######### Image Manipulation ###### ################################### def pngLoad(imgloc, size, flipx, flipy): img = pygame.image.load(imgloc).convert_alpha() if size &gt; 1: #pygame.transform.scale(Surface, (width, height), DestSurface = None): return Surface img = pygame.transform.scale(img, (img.get_width()*size, img.get_height()*size)) if flipx == 1: #pygame.transform.flip(Surface, xbool, ybool) img = pygame.transform.flip(img, True, False) if flipy == 1: img = pygame.transform.flip(img, False, True) return img ################################### ######### All Image Tiles ######### ################################### tile_dict = {3 : pngLoad("link1.png", resmulti,0,0), 2 : pngLoad("shrub_01.png", resmulti,0,0), 1 : pngLoad("tanback.png", resmulti,0,0) } def drawMapArray(maparray): for x in range(0, xTile): for y in range(0, yTile): #Determines tile type. current_tile = tile_dict[maparray[x, y]] screen.blit(current_tile, (x*spritesize, y*spritesize)) 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></li> </ul>
    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.
 

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