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 7505593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:58:07+00:00 2026-05-29T21:58:07+00:00

I have made the following code to render the map using tiles, it loops

  • 0

I have made the following code to render the map using tiles, it loops through the file and translates letters into tiles (rectangles);

currtile_x = 0
currtile_y = 0
singlerun = 1

if singlerun == 1:
    singlerun = 0
    with open('townhall.map', 'r') as f:
        for line in f:
                for character in line:
                    if character == "\n":
                        currtile_y += 10
                    else:
                        if character == "x":
                            pygame.draw.rect(screen, (1,2,3), (currtile_x, currtile_y, 10, 10), 0)
                            currtile_x += 10
                        else: 
                            if character == "a":
                                pygame.draw.rect(screen, (0,255,255), (currtile_x, currtile_y, 10, 10), 0)
                                currtile_x += 10

Here is the townhall.map file:

xxxxx
xaaax
xaaax
xaaax
xxxxx
  • 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-05-29T21:58:11+00:00Added an answer on May 29, 2026 at 9:58 pm

    Your code works well when event loop code is added to it. Since you haven’t posted the whole program, everything I can do is to post a working program that contains your code.

    import pygame
    from pygame.locals import *
    
    pygame.init()
    screen = pygame.display.set_mode((300, 300))
    
    currtile_x = 0
    currtile_y = 0
    with open('townhall.map') as f:
        for line in f:
            for character in line:
                if character == '\n':
                    currtile_y += 10
                    currtile_x = 0
                elif character == 'x':
                    pygame.draw.rect(screen, (0,0,0), (currtile_x, currtile_y, 10, 10), 0)
                    currtile_x += 10
                elif character == 'a':
                    pygame.draw.rect(screen, (0,255,255), (currtile_x, currtile_y, 10, 10), 0)
                    currtile_x += 10
    
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == QUIT:
                running = False
        pygame.display.update()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have roughly the following code. Could this be made nicer or more efficient?
I have made a new windows service which works fine using barebone code (just
I have made the following code: procedure TForm15.Button1Click(Sender: TObject); var Bitmap1: TBitmap; im: TImageControl;
I have made the following code to retrive data from SQLite database. public Cursor
I am trying to understand pthreads by example. I have made the following code
I have made the following class to avoid the repetition if else code ,
I have made the following code:- class A{ bool bFlag[2]; public: A(){ for(int i
I have run the following code in this page RsyntaxTextArea using Java and i
The following code should be pretty self-evident. What I have made up so far
I have made following code, but whatever I type it will always print some

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.