Hello all!

I am a beginner programmer, and I have been told that a great first project would be to make an ASCII game, I have done all of the coding (I think) and I'm still having some problems (i.e. it won't work, at all), I believe it's the render. Any help would be appreciated.

import pygame

class RenderWindow:
    def __init__(self, x , y):
        self.width = x
        self.height = y

        self.font = pygame.font.Font("fonts/font.ttf, 10")
        self.twidth, self.thight =self.font.size(" ")

        self.screen = pygame.surface((x*self.twidth, y*self.thight))

        self.memory = []
        self.set_up_screen(x, y)

    def set_up_screen(self, x, y):
        for y in xrange(y):
            for x in xrange(x):
                self.memory[y][x] = [(0, 0, 0), (0, 0, 0), " "]

    def draw_tile(self, x, y):
        obj = self.memory[y][x]

        forground = obj[0]
        background = obj[1]
        letter = obj[2]

        surface = self.font.render(letter, False, foreground, background)
        self.screen.blit(surface, (x*self.twidth, y*thight))

    def draw(self):
        for y in xrange(self.hight):
            for x in xrange(self.width):
                self.draw_tile(x, y)

    def set_tile(self, x, y, desc):
        self.memory[y][x] = desc()

I know it isn't very good.

Again, Thanks for any help.
lucksoar

What is error message? What is it supposed to do?

I see one class definition but not any creation of objects or the pygame main loop (which is explicit, not hidden).

At least at line 8 you seem to have second parameter misplaced inside quotes: http://www.pygame.org/ctypes/pygame-api/pygame.font.Font-class.html#__init__

I added in beginning of init pygame.init(), and fixed the size of font issue, but line 19 is strange you are accessing sublist of empty list.

Edited 6 Years Ago by pyTony: n/a

nn I have three separate .py files, game.py, which calls on the render.py for text size, font, and what-not, he error I get is:

>>> 
Traceback (most recent call last):
  File "C:\Documents and Settings\lucksoar\Desktop\my ASCII\main.py", line 6, in ?
    app = RenderWindow(10, 10)
  File "C:\Documents and Settings\lucksoar\Desktop\my ASCII\render.py", line 8, in __init__
    self.font = pygame.font.Font("fonts/font.ttf, 10")
TypeError: function takes exactly 2 arguments (1 given)
>>>

The last file is a map.py, which sets the characters and the colors, and I'm almost certain there isn't anything wrong with it.

Move the closing quote after .ttf like I said. Also line 29 is missing self.

Edited 6 Years Ago by pyTony: n/a

This article has been dead for over six months. Start a new discussion instead.