Python Forum
[PyGame] Problem assigning positions on CC plane.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Problem assigning positions on CC plane.
#1
        def arrange_tile(self, ):
            i = 0
            for row in range(self.column):
                for column in range(self.row):
                    self.tile[i].topleft = (64*row, 64*column)
                    i += 1
I have that as my code. This iterates through tiles that are 64, 64.

self.column is 30
self.row is 18
the i iterator increments through the loops.

When I insert this in my code... for some reason it only gives the value <rect(1856, 960, 64, 64)>

    #!/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)
    WHITE = 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_color = TEAL

        mos_hover_boolean = False
        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.arrange_tile()
            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.column_list = [x*TILE for x in range((SIZE[0])/TILE)]
            self.row_list = [x*TILE for x in range((SIZE[1]+64)/TILE)]
            hover_counter = 1
            #column means the amount of 64 by 1080 columns
            #row means the amount of 1920 by 64 rows
            #The next two lines mean it blits by vertically down first...
            for row in range(self.row_list.__len__()):
                for column in range(self.column_list.__len__()):
                    if TileSystem.mos_hover_boolean:
                        if hover_counter == self.marked_tile_again:
                            new_surface = pygame.Surface((TILE, TILE), 0)
                            new_surface.fill(TEAL)
                            self.screen.blit(new_surface, (self.column_list[column], self.row_list[row]))
                            hover_counter += 1
                            del self.marked_tile
                            TileSystem.mos_hover_boolean = False
                            continue
                    self.raw_tile.fill(WHITE)
                    self.screen.blit(self.raw_tile,(self.column_list[column], self.row_list[row]))
                    hover_counter += 1

        def arrange_tiles(self, ):
            max_row = self.row
            max_column = self.column
            i_again = 0
            for i in range(self.amount_of_tiles):
                if i < max_column:
                    if i < max_row:
                        if i == max_row - 1:
                            max_y = i * TILE
                        self.tile[i].topleft = (TILE*i, TILE*i)
                        continue
                    self.tile[i].topleft = (TILE*i, max_y)

        def arrange_tile(self, ):
            i = 0
            for row in range(self.column):
                for column in range(self.row):
                    self.tile[i].topleft = (64*row, 64*column)
                    i += 1
            for i in range(self.amount_of_tiles):
                print self.tile[i],


        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
                    TileSystem.mos_hover_boolean = True


    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(WHITE)
                self.tile_system.mos_hover_tile(pygame.mouse.get_pos())
                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()
                pygame.display.update()
            self.cleanup()

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

    if __name__ == '__main__':
        init()
ignore the arrange_tiles method but not the arrange_tile method.
Reply


Messages In This Thread
Problem assigning positions on CC plane. - by Gengar - Sep-19-2016, 01:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] assigning rect to sprite pfaber11 1 2,147 May-18-2019, 05:39 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020