Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Grid-aligned 2D game with QGraphicsView

Grid-aligned 2D game with QGraphicsView

Scheduled Pinned Locked Moved Game Development
9 Posts 4 Posters 8.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MTK358
    wrote on 14 Nov 2010, 14:52 last edited by
    #1

    I want to write a game using QGraphics View in which the items move in a grid.

    The items must always be aligned to the 16x16 grid, and may never have an X or Y position that isn't a multiple of 16. Also, there is a fixed amount of cells. How do I:

    • Keep items aligned with the grid (maybe it would be nice to have some kind of abstraction)
    • Keep the grid, which has a fixed number of cells, in the middle of the scene (in case the user resizes the window) and have the items move relative to it, not the scene.
    • For each item to be able to check for the presence of another item in an adjacent cell.
    1 Reply Last reply
    0
    • C Offline
      C Offline
      cochise
      wrote on 17 Nov 2010, 20:42 last edited by
      #2

      add a abstraction layer.

      Make a class wo draw a tile and a manager for compose all tiles in the grid.

      the tile manager no need to know the size os the nature of a tile.

      http://cochise.tumblr.com

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MTK358
        wrote on 17 Nov 2010, 21:50 last edited by
        #3

        I'm starting to think, maybe it's best to ditch the QGraphicsView framework and write my own simple grid-based framework?

        It might also make "collision detection" easier, because my game only needs to know what object is in a certain cell, not true collision detection.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cochise
          wrote on 17 Nov 2010, 22:25 last edited by
          #4

          You can use QGraphicsFramework for render the tiles. And write a grid based framework for manage the tiles.

          You can create a class hwo manage the map and recive cordinates like 2,3; work with this coordinates for colision and "see" what is around the cell and pass coordinates like 16,32 for the QGraphicsSene

          http://cochise.tumblr.com

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MTK358
            wrote on 18 Nov 2010, 02:20 last edited by
            #5

            It seems easy enough to do your own rendering, just for each item get its image and paint it in its x and y coordinates.

            One thing I am confused about, though: would it be better for the items to store their coordinates, of for the grid widget to keep track of the coordinates (or maybe even store the items in a 2D array corresponding to the grid)?

            Items will often have to move themselves and check for adjacent items.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cochise
              wrote on 18 Nov 2010, 10:01 last edited by
              #6

              well.. i don't know
              You can use QML also.
              The Grid container is a good solution.

              http://cochise.tumblr.com

              1 Reply Last reply
              0
              • B Offline
                B Offline
                brandont
                wrote on 20 Nov 2010, 04:30 last edited by
                #7

                Just out of curiosity, how were you going to do your own rendering? QPainter?

                I'm still new to this framework, but I think I would do it this way:
                Each cell is 16x16 big, in a grid of 16x16 correct?
                Use QGraphicsItem based classes and keep track of their x and y coordinates. When you set their position, just multiply x and y by 16. Then you can just keep track of all of them in an array, and add a checkNeighbours() function.

                Not sure about how to center it, but I'm sure it's easy.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MTK358
                  wrote on 20 Nov 2010, 14:25 last edited by
                  #8

                  [quote author="brandont" date="1290227431"]Just out of curiosity, how were you going to do your own rendering? QPainter?[/quote]

                  Yes.

                  For every item, draw its image at its X and Y coordinates multiplied by 16.

                  1 Reply Last reply
                  0
                  • Y Offline
                    Y Offline
                    yoogi
                    wrote on 6 Feb 2011, 15:24 last edited by
                    #9

                    Dear MTK358,

                    How your game is coming along? can you share the structure of the game you've designed.

                    Does it use state machines? How do you shift between Intro screen, Game Screen , help screen / Score screens.. etc.

                    How do you capture mouse interactions? Game Screen as one Widget or use MouseGrab items on interactive parts of games?

                    I am also intrested in making simple 2d games.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved