Monthly Archives: June 2016

How To Calculate If Line Segments Intersect The Easy Way

I am currently working away at Drone Tournament, Game #2 for 2016, and started implementing combat into the game. In order to make combat happen, each little drone unit in the game will be able to fire their weapon every so often, and if they hit an opponent it loses armor and can be destroyed.

The trick is how to figure out if we get a hit.

Previous Collision Detection

At the beginning of 2015 I made my first game Prism Ship with Monkey-X and it implements a little ship that shoots blocks. The collision detection there is not pretty but fairly simple because everything is kept square and straight.

Projectiles go straight up and the things they hit are coming straight down so no real fancy math is needed. I simply checked each of the corners of the projectile to see if they were inside the squares you are trying to hit.

A New Challenge

In Drone Tournament however, things can turn when they shoot which means that bullets go off at weird angles and their potential targets are not always moving directly towards them. Additionally I did not make the projectiles in this game as large as in Prism Ship. They are basically line segments.

It Has Been Solved

This problem is common enough that it has been solved before, and in a most elegant and simple manner. Here is some Monkey-X code that I derived from an implementation of the solution in Python. I will explain what is going on below. I even borrowed a picture that shows what is going on really well.


	Function LinesIntersect:Bool(pointA:Vec2D, pointB:Vec2D, pointC:Vec2D, pointD:Vec2D)

		Local abc:Bool = CounterClockwise(pointA, pointB, pointC)
		Local abd:Bool = CounterClockwise(pointA, pointB, pointD)
		Local cda:Bool = CounterClockwise(pointC, pointD, pointA)
		Local cdb:Bool = CounterClockwise(pointC, pointD, pointB)

		Return(( abc <> abd) And (cda <> cdb))
	End

        Function CounterClockwise:Bool(pointOne:Vec2D, pointTwo:Vec2D, pointThree:Vec2D)
	        Return ((pointThree.y - pointOne.y) * (pointTwo.x - pointOne.x) > 
                        (pointTwo.y - pointOne.y) * (pointThree.x - pointOne.x)) 
        End

For those of you not familiar with Visual Basic, "<>" is its way of writing "!=" (Not Equal)

Explanation

If you remember from your geometry class back in high school, line segments have a slope which just measures the change from the beginning point to the end. If you have three points A, B, and C, and the slope of the line from A to B is larger than the slope from A to C (meaning it changes more) then the points are in Clockwise (CW) order. If the slope from A to B is less than that of A to C then they are considered Counter Clockwise (CCW).

borrowed_diagram_ccw
Image borrowed from here (article 1 in reference below).

So we test the two points of our particle to see whether they are CW or CCW to each edge of the Drone hit box. If 1 point is CW and the other is CCW to an edge, then we know that the lines intersect because you have a point on either side of the edge of the hit box.

Special Case I am Ignoring

There is a special case where the 2 lines lay across one another called Collinear. I am ignoring this special case because for the purposes of the game it would not really be a solid hit and is not that important. If you would like to know how to handle it you can read more about this solution at the following articles.

References

  1. Line Section Intersection Algorithm
  2. How To Check If Two Line Segments Intersect?
  3. Stack Overflow: How Can I Check If Two Segments Intersect?

Handling Edge Cases – Literally

Game #2 is coming along quite well and as it is getting farther along I am running into certain design decisions. One of these is what to do when a player’s little drone gets to the edge of the map.

Why have a limited map size at all?

If you take a look at 10 things every game needs, you will notice that #3 on that list is the need for Interaction. Limiting the map size keeps a player from just flying away from their opponent for forever and no interaction happening.

What are the options?

After taking another look at Steambirds, they used 2 different approaches between their web version and their iPad version.

In the web version, if you get close to the edge, there are stationary turrets that destroy your little airplane as it flies off the edge. So option 1 is to destroy anybody who flies off the edge.

In the iPad version, the game prevents you from flying off the edge and makes your airplane sort of slow down and turn sharper so that you cannot fly off the edge. So option 2 is bend the movement rules near the edge of the map so that players can’t fly off.

Option 3 that I came up with, and the one I went with, is to allow the player to move outside of the map, but sort of do a 180 degree flip and bring them back at the edge of the map. I borrowed this idea from Star Fox which I spent many hours playing on my old N64.

Why choose that option?

First of all, it is a really easy option to implement. Just check if the next control waypoint is outside of the map and set it to just inside the edge that you crossed.

Second, I don’t like the idea of destroying the player if they go past the edge on a small map like I am using.

Third, I think it will allow for a little extra Strategy (number 7 in our list of 10 things games need) for players to flip around on the edge of the map.

Remember

When you are thinking about how to handle edge cases in a game, consider all of your options then ask yourself which one will make the game better and why.

Keep being awesome and making games.

Book 1 of 2016 Review – The Art of Game Design

I wrote an initial review over the first few chapters of the book earlier this year, then quickly realized with the types of notes I was taking it would take forever to finish the book. Well it took 5 months anyway with everything I had going on. I suspect if I had focused on it bit more I could have finished it in 1 month no problem. This is a very brief set of notes with a thought about every chapter.

Rating 10/10

This book is fantastic. It is essentially 500 pages of great ideas and questions to ask yourself when making a game. This may sound overwhelming and it is a little, but just get 1 or 2 of the ideas at a time. In fact, there is a separate little deck of cards that can be bought (or you can make your own) from the “lenses” in the book. Highly recommend anyone who is interested in games creation, game design, or the game industry read through this book.

Notes and Thoughts

The only way to be a game designer is to design games (and make them). So if you want to be a game designer say “I am a game designer” and go make games.

There are several important skills every game designer can have but the most important is the ability to listen. Not just listening to what people say, but also to their body language and other non verbal communication.

As a designer, you are really designing an experience that the player(s) of the game will have. Then you design a game that will deliver that experience.

Games are made for players. Who is your player? Ofter written as, who is your target demographic?

Even though people usually interact with the game through some sort of interface, the experience you design actually takes place in the player’s mind.

Games are made up of different elements. Only one of those elements is the game’s mechanics. This includes rules of the game and the playing pieces and interactions.

Balancing the game’s mechanics is very important to the experience.

The mechanics of the game support puzzles in a game. By this we mean that there is some sort of problem solving in the game caused by the mechanics.

All games have an interface so you can play them. It is a loop. Player puts inputs into interface, game interprets and gives an output, player interprets the output and gives a new input. The ideal design is to have the interface add to the experience that is being designed.

Interest curves are very important for judging experiences. One of the most effective interest curves is well known and is basically a short period of rising action at the beginning, a small drop in action, then a longer period of rising action to the climax of the story. However the best interest curves are fractals of this curve so that a small arc of the story along this larger interest curve will also follow the same pattern.

Stories are one type of experience. The dream is to have a completely interactive story with open endings. This is both difficult and impractical for now (see this post I wrote about branching explosion of story writing). There is good ways to design story into the game and the book has several good tips.

The game and the story can be merged together with “indirect control.”

Stories and games take place in worlds. Some of the best worlds are those that people actually want to visit and even pretend to visit and translate into other forms of media well.

There are characters in our worlds. We want to create compelling characters.

Worlds contain spaces, we usually call them levels. You can use the design of the spaces to create a better experience through giving visual clues the players may not even notices but react to and follow.

The aesthetics of the world define its look and feel. Sound, art and the technology used to create the world all work together to help get the experience where you want it.

Some games are played with other people. This can sometimes get a little tricky.

Sometimes communities form around games. It is important if you are designing a game where you hope a community will form to build in support for a strong community. The author gives several good suggestions and examples of ways to build a strong community.

Game designers usually work with a team (even if it is only a team of 1 other person). Getting buy in from everyone on the team is super important. Keep communication levels good.

Sometimes the team communicates with documents. Make sure to not let them get stale.

Playtesting is the key to a good game. You can never playtest enough. You need to ask the playtesters: Why, Who, Where, What and How?

The team builds the game with Technology. Technology can be tricky, especially on games that are being developed over a multi year cycle. Choose carefully.

Games usually have a client. By this we mean someone who is financially backing the game.

The designer usually gives a “pitch” to the client to get them to buy-in to the idea of the game. There is a list of tips for how to give a successful pitch.

Most of the time, the client (and you as the designer) want to make a profit from the game. You should spend some time learning the lingo of game sales and figuring out the business model of the game.

Games actually change the people who play them, the book uses the word “transform.” Games can be both good and bad for you.

Because of the affects games can have, game designers have certain responsibilities.

Every game designer has motivation, what’s yours?

The End

Seriously, go get this book and read it. Even if you don’t want to design games, it still has valuable ideas for anyone wanting to get into design or creation of software.

If You Are Having Trouble Finding a Topic to Write About, Do Something Intersting

The title basically says it all.

One of the reasons people give about why they don’t write a blog or don’t keep it going consistently is they can’t think of things to write about. Many times, I am having trouble thinking of something to write about. But if I am being honest, it is usually because I have not been spending my time doing interesting things. I have actually usually been wasting time.

But as soon as I start taking action on making games or learning something new, all of a sudden I have ideas shooting through my mind on topics to write about. There has never been a week that I did spent at least an hour working on a game or reading a good book that I did not also have an idea for a topic to write about.

Now go find something interesting to do and write about it.

May 2016 End of Month Goal Review

Last month I said it wasn’t pretty, well it got a little uglier there for a minute.

Goals

  1. Write 3 Blog Posts Per Week and Publish 2 – Two things happened in May that I let derail me pretty hard from my writing. I went to Texas for a week for OSCON and immediately upon coming back I moved to a completely new state. Instead of writing 12 posts and publishing 8, I wrote and published 3 posts. Not gonna lie, could be better. Looking on the positive side, I did get a few ideas for things to write about.
  2. 1 Game Designed, Created, and Released Per Quarter – Even though I did not get much writing done, I did get some work done on Game #2. The mechanics of movement have been kind of tricky and still had some bugs in them which are now thankfully removed. It still needs polish but I feel like a minimum working version of the game will be ready by the end of the June.
  3. 1 Book Read Every 2 Months on Game Design – Finally completely finished reading the Art of Game Design. What an elephant it turned out to be. But like all elephants, just eat it one bit at a time. It is a fantastic book and I will be writing a final review post this month as well as choosing a new book.
  4. 1 Article Read Or 1 Video Watched About Game Design/Creation Per Week – I was actually hoping there would be a talk or 2 at OSCON about games and game design like last year, but there was not. I did get to meet the guys who gave the talk and they said that they submitted a follow up and it was rejected. There was however a few games in the Expo hall at the convention that I may write about.
  5. Get 100 People Reading Evolving Developer Per Month – Last month I said I planned on telling 20 people about Evolving Developer at OSCON. The actual number was 1 person. There was a 5k run on the first night and afterwards while talking with one of the other runners, I found out he worked for a university and that he knew a professor who might be looking into setting up a game design course. This was a fantastic opportunity to provide value and I almost let it slip away. On the last day of the conference I caught him just before he left and got his contact info so I could send him some things I had learned. No other conversations I had really opened an opportunity to bring it up, and I failed to create any opportunities.

What Went Right

  1. I was able to provide value to someone and sort of tie it in to Evolving Developer.
  2. Once again I am having fun making a game and learning new things about games, game design and funky math.
  3. Book 1 for the year has been read completely.
  4. I have a list of at least 15 topics I want to write about.

What Is Not Perfect Yet

  1. If analytics is to be believed, I have exactly 0 readers of this blog.
  2. Writing volume is still well below what I would like it to be.
  3. I don’t yet have what is described in The Art of Game Design as “lack the fear of ridicule” for telling people about Evolving Developer.

Corrective Measures

I did some studying in March about how to get more readers and the March Madness Marketing notes need to be reviewed and applied. In addition, I need to embrace the fear of talking to people and possible ridicule and rejection and just tell them about what I am doing. Now that my daily routine is being less disrupted, I need to get back into consistent writing so that when I do have readers, they will have something interesting to read every week.

Possiblity mixed with difficulty.

What I Learned About Game Design From a Brazilian Steakhouse

What an Experience

I attended the Open Source Conference in Austin TX. It is a pretty good conference and there are a lot of people out there doing amazing things. But as interesting as the conference was, I learned the most from going to a restaurant.

While I was there, my coworkers and I tried out a few of the local eateries. Several were good, but 1 of them stands out far above the others. One of my coworkers who was not at this conference and is from Brazil had recommended we try a Brazilian steakhouse called Fogo de Chao. It was a restaurant experience unlike any I have had before.

There was no written menu, other than a drink menu. There was no visible price listed anywhere. They had a salad bar with a few various vegetables and other side items, but the main course was why we were there.

Several waiters walk around with 3 foot long kebabs with different cuts of meat on them. They had steak in all sorts of varieties, chicken, pork, and lamb.

It was amazing.

It was by far the best restaurant experience I have ever had. It was so good I wanted to tell people about it. It was a little expensive for my current salary range (thankfully I got to expense it) but it was so good I would go again having to pay for it myself and I would recommend others that they have to try it at least once.

Designers Create an Experience

One of the major themes in the Art of Game Design is that the game creates an experience for the user and the game designer is responsible for designing that experience. The goal of the designer should be to create an experience like the Brazilian Steakhouse.

You want to design an experience that people want to have again. You want to design an experience that people want to tell other people about and that they want other people to experience.

So take a look at your current game and ask yourself these questions.

  1. Does my game create an experience that the person who plays it will want to have again?
  2. Does my game create an experience that people will want to tell others about and want their friends to have?

If the answer to either of these questions is NO, my questions is, why not?

Secrets To Success: Get Moving

Its story time.

I was working on my current game and had just fixed a bug with the controls and realized I didnt know what to work on next. It was late in the afternoon and I had already worked my day job for 8 hours and spent some time and brainpower fixing this issue. I wanted to keep working but was feeling mentally exhausted.

I figured I was just done for the day and decided to go for a run. Normally I like to go on runs outside, get some fresh air and sun, but this day it was raining so I hopped on the treadmill.

Three miles and 27 minutes later my brain was filled with ideas for what to work on next in the game and how to do implement them. I couldn’t wait to get back in front of my computer and start putting them in place.

Why This Works

Short answer, we don’t know why for sure. I looked at several articles and there are a few commonly held theories such as increased blood flow to the brain improves performance and the areas of the brain that are active during exercise are the ones used for learning and critical thinking. If you are interested in the studies you can search for ones like this one from Harvard. Regular Exercise Changes Brain, Improve Memory Thinking Skills

But just because we are not sure why or how something works, doesn’t mean it doesn’t work. We know it works. So when you are feeling a little burnt out in the brain, get up out of you chair and go for a quick walk (or run if you are so inclined). You might get some of your best ideas yet.