Sunday, March 17, 2013
Le Grande Hexagon
Yesterday I laid out the hexes for the Cyvasse game board. One problem I ignored was that, although my hexes were in the right pattern, I was basically printing a square of them.
There are probably a few ways to deal with this. One would be to define each hexagon to display manually, something like
board = { {x=7, y= 1}, {x=6, y=2}, {x=8, y=2}, ...}
This way seemed tedious. And if I ever need to change the coordinates of each hex, tedious again.
I know the coordinates of each corner of the board, so I thought I might be able to use something simple like checking whether the coordinates of a particular hex are greater than the coordinates of the corners... but it's not so simple.
I can instead check to see which side of a line a point falls on, and determine if any particular point is within my larger hexagon. The solution relies on using the cross product, a mathematical concept I don't understand in the least :)
It looks something like this:
left_of_line = ((point_b.x - point_a.x) *
(point_c.y - point_a.y) -
(point_b.y - point_a.y) *
(point_c.x - point_a.x)) >= 0
Wiring all of my edges up, I get something like:
One key point is that the order of these points seem to matter. I'm not sure of the intuition behind this, or what I would do if I had any points with negative coordinates, but point_b always needs to be larger than point_a in order for the sign of the answer to come out right.
(The answer seems to be that you are actually taking the cross product of vectors, so direction does matter. More here.)
I've gone and messed up my color scheme. I think this happened because previously I was incrementing colors each time through a nested loop of 13x13; now I'm only displaying hexes that fall within the coordinates, and so no longer bumping the colors correctly. I should definitely assign each hexagon a color when I initially create it, so that it keeps track of itself.
I'll also take the opportunity to set the window size and caption. This is easy:
love.graphics.setCaption( "Cyvasse" )
love.graphics.setMode( 525, 700 )
While I'll probably want to do make the sizes of things dependent on the window size, I'll worry about that later. Here are the results:
I still need to make each hexagon symmetrical from all sides, so that they are not all oblong. I'd love to start to get into the gameplay as well, but before I do that I need to learn how to separate functions into different files, and if possible classes, in Lua.
Saturday, March 16, 2013
A Hex on Hexes
First thing's first in my little Cyvasse experiment: make the game board.
Here is my life experience with game programming:
- When I was 10 or so, I learned QuickBasic by making a text based game show. Which door do you want to go through? Sweet, you got mauled by a lion!
- In high school, I again used Basic to animate a 2d stick figure guy running off a cliff and getting eaten by a shark.
- In college, I worked as part of a group creating a top down shooter in Java. This game was never playable for even a moment. It didn't even compile when we turned it in. I'm not sure how I passed that class.
- 3 years ago, I used Ruby and Gosu to make a 2d arcade style 'shoot the enemy coming from the right side of the screen' game. Not really finished, not published, but sort of playable with 3 levels.
So, when I say "first thing's first", what I mean is "I have no idea what to do first."
I'm going to start with the game board, which is a hexagon of hexagons, each side being 7 hexagons wide. The colors alternate between white, red, and black, with each player sitting on a corner with a white hex. Each hexagon is oriented such that faces are on the top and bottom, rather than corners.
Drawing a hex should be easy, right? Go ahead, try it. Here's my attempt, using Google Draw:
My hexes don't line up! Here's the problem: each side must be the same length, and must be parallel to the opposite side. I'm not sure how to solve this using a simple drawing app, so I've decided instead to draw each hex in code, rather than trying to use assets.
Because the hex is 13x13 between faces, I'll use a nested loop, and draw a polygon through calculated points.
If you've been paying attention, you may have noticed a few problems here. First, because my math skills are weak, not all of the faces are the same length - the top is shorter than the diagonal faces. That's fine for now, because they will at least fit together. Second, I've made a square of hexagons, rather than a hex. I'll figure that out later. But most importantly, these hexagons are all sitting on top of each other.
In a hexagonal grid, each hex shares faces diagonally as well as vertically. So I need to offset each hex vertically, depending on which column it is in. If a hex sits on an even column, it should move down a bit.
In a hexagonal grid, each hex shares faces diagonally as well as vertically. So I need to offset each hex vertically, depending on which column it is in. If a hex sits on an even column, it should move down a bit.
I've added edges to illustrate things more clearly.
Now I'm going to tackle the colors. Colors alternate vertically between white, black, and red, and no hex shares a face with another hex of the same color. I tried a number of schemes, but in the end I implemented a counter based on the y axis, resetting to either white or black for the top of each column.
Finally, a grid of hexes!
I'll leave it here for now.
Now I'm going to tackle the colors. Colors alternate vertically between white, black, and red, and no hex shares a face with another hex of the same color. I tried a number of schemes, but in the end I implemented a counter based on the y axis, resetting to either white or black for the top of each column.
Finally, a grid of hexes!
I'll leave it here for now.
Do Something!
Now that I have a shiny new computer, I've decided to try and write a game.
I'll be working on Cyvasse, a fictional game from George R.R. Martin's A Song of Ice and Fire books. It's only loosely defined there, but has some similarities to chess.
Believe it or not, some uber-fans have put together actual rules for the game. There seem to be some variations (http://gameofcyvasse.com/, http://boardgamegeek.com/boardgame/136975/cyvasse, and more I'm sure), but I'll go with the one that inspired me first: http://www.reddit.com/r/boardgames/comments/19es1l/my_interpretation_of_the_game_of_thrones_cyvasse/
First decision first: which language/framework/engine should I use?
Casting about on the interwebs, there seem to be a few. Gamemaker is recommended, but the Mac version seems out of date. Unity is also big, but it costs money and seems like overkill for a little 2d board game. I'm a Ruby developer, so Gosu would work, but I would like to try a different language.
So I'll start out with Love, an open source Lua framework with what seems like a great community.
Habits Die and You Forget Them
Blog. Say that word out loud. Roll it around with your tongue.
Bbbblllloooogggg.
Mmm, feels weird. 5 years is a long time to go between updates. Time to fire it up again?
Funny how something I did regularly for so long (between this blog and my more personal one over at livejournal) can so easily slip into dormancy. I had forgotten it even existed!
Onward.
Bbbblllloooogggg.
Mmm, feels weird. 5 years is a long time to go between updates. Time to fire it up again?
Funny how something I did regularly for so long (between this blog and my more personal one over at livejournal) can so easily slip into dormancy. I had forgotten it even existed!
Onward.
Subscribe to:
Posts (Atom)






