Python Forum
Hex coords and using the tile
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hex coords and using the tile
I am trying to learn python through making a game. In my game, I used a script that built the set up for Settlers of Catan. My board is slightly larger and I can move a game piece around the board to different hexes.

Now, in each hex I am looking to have different options based where the game piece is and the hex type (color for now but later art). At the moment, I just want to print the hex type (called environment, like lava and basalt) is when I press a key.

This is how I am drawing each hex and board.

class Board:

hexes = []

def __init__(self, size):

self.cX = screen.get_rect().centerx

self.cY = screen.get_rect().centery

self.hexHeight = 0.866 * size

~ ~ ~

# Second Ring

self.tiles = [LAVA, BASALT]*3


# Second Ring of hexes

self.hexes.append(Hex((self.cX, self.cY - (2*self.hexHeight)), size, self.tiles[0]))

self.hexes.append(Hex((self.cX - (1.5*size), self.cY - self.hexHeight), size, self.tiles[1]))

self.hexes.append(Hex((self.cX - (1.5*size), self.cY + self.hexHeight), size, self.tiles[2]))

self.hexes.append(Hex((self.cX, self.cY + (2*self.hexHeight)), size, self.tiles[3]))

self.hexes.append(Hex((self.cX + (1.5*size), self.cY + self.hexHeight), size, self.tiles[4]))

self.hexes.append(Hex((self.cX + (1.5*size), self.cY - self.hexHeight), size, self.tiles[5]))

~ ~ ~

Then, later when I press number key 5...and this is where I am stuck. I want to say something like...

elif event.key == K_KP5:
if HEX == LAVA:

I'd be happy to share the entire script in a pm for those interested.
Are you using something like pygame for your input/graphics?
(Mar-10-2021, 03:42 PM)michael1789 Wrote: Are you using something like pygame for your input/graphics?

Yes! I should have said that...
Instead of a list, I'd use a dictionary for the game board.
game_board = {}

#loop over how you like adding hexes.
game_board.update({x,y : Hex(x,y)})
Then you can refer to them my location game_board[x,y].

As far as keyboard stuff, where are you at it?

Forum Jump:

User Panel Messages

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