Not sure this is the best way to do this, but it works. Working on a project and I’m writing a lot of code to do RegEx searches. Each match is 3 or 4 lines to do the match, check if there was a match, and then do something with the match. Since I was… Read more »
Posts Categorized: Coding
For another site of mine I needed a way to determine whether black or white was a better choice for text on a randomly colored background. The function takes a color as an array with elements r, g, and b and returns an array with the same 3 elements. Although in the returned array all… Read more »
Getting enemies to move tends to be one of the more difficult things for me to get right. It just doesn’t always seem natural. And I’m not talking about moving with any type of AI. Just moving around the screen in a pattern. Sure, straight lines are pretty easy. But games get really boring if… Read more »
It’s a pretty common task to get the distance between 2 points. Maybe you’re wanting to see if two points are close enough to have collided. Maybe you’re making a golf game and the closer the ball is to the hole the higher the score. Either way, you need to know the distance. The Math… Read more »
There are two ways to measure angles. You probably learned to measure angles in degrees early in school. A circle has 360 degrees, a perfect corner is a 90 degree angle, and 180 degrees forms a straight line. But then you took trigonometry or pre-calculus and were introduced to a radian. A radian does the… Read more »
At first glance the Pythagorean Theorem doesn’t appear to relate to game development. But we’ll see in a bit that it does. First though, let’s cover a bit of math. The Pythagorean Theorem states that for any right triangle, the sum of the squares of the two legs is equal to the square of the… Read more »
Creating the next great side scroller? Well, you’ll need a scrolling background. And if you’re programming in Java, here’s an easy way to do it. Quick Demo Here’s a little demo of what we’re going to create. What’s happening is that there are two copies of the same image scrolling from the right to left…. Read more »
This is a follow up to an earlier post where we created a scrolling background in Flash using ActionScript. This time we’re going to do the same thing, but using Python and Pygame.
Take a look at your favorite game. Odds are good that there is a scrolling background of some type. Think Super Mario Brothers. Mario is a bit different than what we’re after though. The background in Mario is a single graphic that scrolls as Mario moves through the world. What we want is a scrolling… Read more »
Thanks to Pygame, there’s a quick and easy method to get the dimensions of an image. You just have to load it into a Surface and use the Surface methods get_height() and get_width().