I can't seem to blit colored spaces to my screen.

I can't seem to blit colored spaces to my screen.

Postby toywhiz » Sat Sep 17, 2016 8:11 am

Code: Select all
#!/usr/bin/env python

import pygame
from pygame.locals import *

import pygcurse

#GAME MODES
game_modes = ['tiro',
                'rookie',
                'amateur',
                'professional',
                'maestro',
                'Grand Master']
game_modes = enumerate(game_modes)

#Title of Game.
TITLE = "Knights Templar: Resurgence"

#Game Screen Size
SIZE = 1920, 1080
#Speed of Characters
SPEED = 2
RUN = SPEED * 3


#Origin of cartesian
ORIGIN = 0, 0
#Tile Size
TILE = 64
TEAL = pygame.Color(0, 255, 255)
BLACK = pygame.Color(255, 255, 255)

def init():
    #Make a screen object

    pygame.init()
    screen = pygame.display.set_mode((1920, 1080))
    templar = TemplarSystem(screen)




class Screen(object):
    def __init__(self, size=(1920, 1080), ):
        try:pygame.display.init()
        except pygame.error as e:
            print "This message came back as an error: ", (e.message)

        self.screen = pygame.display.set_mode(SIZE)

class TileSystem(object):
    """
    This is the tile system. Tiles will be 64, 64 and will,
    if toggled, display over the screen.



    """
    tile_representation = pygame.Surface((TILE, TILE))
    tile_representation.fill(TEAL)
    tile_representation_color = TEAL

    def __init__(self, screen):
        self.tile = []
        self.screen = screen
        column = self.column = SIZE[0] / TILE
        row = self.row = SIZE[1] / TILE
        self.amount_of_tiles = column * row
        self.make_tiles()
        self.raw_tile = TileSystem.tile_representation
        self.tile_representation_color = TileSystem.tile_representation_color

    def make_tiles(self, ):
        self.tile_rect = pygame.Rect(ORIGIN, [TILE for x in xrange(2)])
        for i in range(self.amount_of_tiles):
            self.tile.append(self.tile_rect)

    def draw_to_screen(self, ):
        self.screen.blit(self.raw_tile, (0, 0))
        self.column_list = [x*TILE for x in range(SIZE[0]/TILE)]
        self.row_list = [x*TILE for x in range(SIZE[1]/TILE)]
        #column means the length of the row
        #row means the length of the column
        i = 0
        for column in range(self.column_list.__len__()):
            for row in range(self.row_list.__len__()):
                #if tuple((column, row)) == self.tile[i].topleft:
                #    new_surface = pygame.Surface((TILE, TILE), 0, TileSystem.tile_representation)
                #    new_surface.fill(TEAL)
                #    self.screen.blit(new_surface, (self.column_list[column], self.row_list[row]))
                #    i += 1
                #    continue
                self.screen.blit(self.raw_tile,(self.row_list[row], self.column_list[column]))
                i += 1
        self.raw_tile.fill(TEAL)
        self.screen.blit(self.raw_tile, (0, 0))

    def arrange_tile(self, ):
        for row in range(self.column.__len__()):
            for column in range(self.row.__len__()):
                self.tile.topleft = TILE*row, TILE*column

    def mos_hover_tile(self, mos_pos):
        for i in range(self.amount_of_tiles):
            if self.tile[i].collidepoint(mos_pos):
                self.marked_tile = pygame.Rect(self.tile[i])
                self.marked_tile_again = i


class Unit(pygame.sprite.Sprite):
    def __init__(self, color, size, ai=None ):
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.Surface(size)
        self.image.fill(color)

        self.rect = self.image.get_rect()

class Enemy(Unit):
    def __init__(self, ):
        pass


class NPC(Unit):
    pass


class Friendly(Unit):
    pass

class UnitSystem(object):
    pass

class AssetSystem(object):
    pass

class TemplarSystem(object):
    Units = UnitSystem()
    Assets = AssetSystem()
    def __init__(self,screen, enemies=None, npcs=None, friendlies=None):
        self.screen = screen
        self.tile_system = TileSystem(self.screen)
        self.gameloop()

    def cleanup(self, ):
        del self
        pygame.quit()
    def gameloop(self,):
        ActiveLoop = True
        while ActiveLoop:
            self.screen.fill(BLACK)
            for event in pygame.event.get():
                if event.type == QUIT or (event.type == KEYUP and event.key \
                        == K_q):
                    ActiveLoop = False
                    self.tile_system.draw_to_screen()
        self.cleanup()

class ArtificialIntelligence(object):
    def __init__(self, ):
        pass
    pass

if __name__ == '__main__':
    init()

Just so you know the blitting statements in the TileSystem type draw_to_screen method.
Last edited by Yoriz on Sat Sep 17, 2016 9:42 am, edited 2 times in total.
Reason: First post lock.
toywhiz
 
Posts: 4
Joined: Sat Sep 17, 2016 8:09 am

Re: I can't seem to blit colored spaces to my screen.

Postby nilamo » Sat Sep 17, 2016 5:18 pm

If you draw/fill/blit things to the "screen", you're really just drawing things to the internal representation of the screen that's stored in memory. When you're actually ready for those changes to be pushed to the screen, call pygame.display.flip(). I stuck that in your code (and moved your draw_to_screen outside the "if event.type===QUIT" so it'd actually get called), and it seems to work fine.
This forum is shutting down. Future discussion should take place at http://python-forum.io
User avatar
nilamo
 
Posts: 87
Joined: Thu Jul 21, 2016 8:00 pm
Location: Michigan

Re: I can't seem to blit colored spaces to my screen.

Postby toywhiz » Sun Sep 18, 2016 1:52 am

Thanks. Haha... I forgot about pygame.display.update() or pygame.display.flip(). Thanks for looking at that for me. I was confused and frustrated.
toywhiz
 
Posts: 4
Joined: Sat Sep 17, 2016 8:09 am

Re: I can't seem to blit colored spaces to my screen.

Postby nilamo » Mon Sep 19, 2016 7:45 pm

No problem. Sometimes when we're looking at something for so long, something very, very basic just flies right over our heads and we assume the problem must be more complicated.
This forum is shutting down. Future discussion should take place at http://python-forum.io
User avatar
nilamo
 
Posts: 87
Joined: Thu Jul 21, 2016 8:00 pm
Location: Michigan


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests