info

C++ Event System using Delegates

0

Posted by Thomas | Posted in News, Snippets, Tutorials | Posted on April 21, 2012

Recently I’ve been working on an Event System in C++. You might be reading that right now and wonder why that small sentence makes it sound like a true endeavor. Well, it was. As many of you may know I’m a student at Champlain College, and in one of my classes, each of the students are tasked to use an event system or a messaging system in their game. The teacher provided us with one, and it’s really great and all, but I couldn’t help but feeling restricted, especially after having used C# for so long where the code is so forgiving, and easy.

I did some research and it turns out that a lot of event systems in C++ are organized in such a way that when you want to do events you must:

  • Create an EventManager class (nothing wrong with this)
  • Create an EventListener class (for setting up events)
  • Create and Event base class
  • Be restricted to use only one function to handle your events
  • Create a huge enum holding a key for each of your events (Can hash it for speed)

I saw those and my heart dropped. I immediately thought that is way to restrictive, there must be an easier way to get events to work. And so the researching began.

Read the rest of this entry »

Understanding C# 2D XNA HLSL – Part 2

0

Posted by Thomas | Posted in Tutorials, XNA | Posted on February 22, 2012

Read the first part here

I know a lot of you loved the first part of this breakdown, and now I’m back to continue the explaining!

Breakdown of Effect Parameter

Continuing from the end of the first part: What the effect parameter does here is that it takes our effect and then applies it to all of the textures that you draw then on. This is effective for coloration effects such as black and white, or inverting colors, but if you have an effect that works based on certain coordinates or is constricted similarly, then you need to beĀ  very careful! To avoid issues like that, there is a rather simple solution when you want to apply an aforementioned size/position constricted effect to the screen.

Further Implementation

Adjusting the Effect parameter of the SpriteBatch.Begin() function is not the only way to use HLSL effects in your projects. Another method that you can do is draw all of your textures to one RenderTarget2D (Think of this as an empty texture, or a blank canvas). After you’ve drawn all your textures to that, it’s really easy to apply your effect to “the screen”.

RenderTarget2D MainTexture;

//In the Initialize function set up the rendertarget:
PresentationParameters pp = GraphicsDevice.PresentationParameters;
MainTexture = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);

        //Then create a function to draw your game textures to, and draw it all up       

        private void DrawGame(GameTime gameTime)
        {
            GraphicsDevice.SetRenderTarget(MainTexture);
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            spriteBatch.Draw(bg, GraphicsDevice.Viewport.Bounds, Color.White);
            spriteBatch.Draw(player, new Vector2(200, 300), new Rectangle(0, 0, 128, 128), Color.White);

            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            DrawGame(gameTime);

            GraphicsDevice.Clear(Color.Black);

            // Use Immediate mode and our effect to draw the scene again, using our pixel shader.
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            mainEffect.CurrentTechnique.Passes[0].Apply(); // for every pass that you have you can apply
                                                           // all them to the texture if you want.
            spriteBatch.Draw(MainTexture, Vector2.Zero, Color.White);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }

Alternatively, you can use the effect parameter in the spriteBatch.Begin() function when drawing MainTexture, because remember: The effect is applied to the texture in every Draw() function call. If you only have to draw one texture and want all the passes applied when drawn, then you can use the Effect parameter.

Why do this?

In a project I was working on I really wanted to have an INFINITE amount of 2D lights in my game, and after countless attempts at getting a high number lights (higher than 5) from all HLSL effects, I found that by drawing a my lights to a texture, and then my game to another, I could then use an HLSL effect to blend my lights together.

 

I hope this helped.

-Tom

Using Git with a Subversion Repository

0

Posted by Thomas | Posted in Tutorials | Posted on January 30, 2012

Using git bash with a subversion repository is very easy when you know how to use it!

First, you’ll want to head over to the Git Website and get the latest release of the git application (we’ll be using git bash)

NOTE: when you install, consider checking “Git Bash Here” as a context menu option:

After it’s installed, go ahead and open git bash and cd to a directory where you want to download the repo to, or if you chose to install that context menu option, navigate to your folder in explorer (or finder) and right click on it then “Git Bash here”.

After that go ahead and run the “git svn clone” command on your repo, example:

git svn clone https://svn.webhost.com/svn/sp12egp31001

Alternatively, you can clone a subdirectory of the svn repository by simply writing the directory name at the end of the repo address. This is particularly useful when you’re working on a large project and don’t want to download all the files on the server.

git svn clone https://svn.webhost.com/svn/sp12egp31001/subdirectory

After you run the command you’ll be prompted for authentication, go ahead and fill that out and your repository will be downloaded onto your machine.

From there you’ll be able to modify the code, or whatever it is as you would regularly, then when you are ready to push changes back to the server, all you have to do is add these changes, and get them ready for commiting.

To start, go ahead and run this command:

git status

That should list out all the files you’ve modified, added, or deleted.

To track these changes run the add command:

git add .

The “.” at the signifies that you would like to track all the changes that were made. Another thing to note is that if you deleted a lot of files you would want to run the add command with another optional parameter:

git add -u .

This should track all the changes made, regardless of deleted, added, or changed.

Once you are satisfied you will need to make a commit to your local git repository by running the git command:

git commit -m "Your message goes here!"

Something to note about the commit command: You don’t have to use the -m parameter, it’s just that it’s much easier to do this, rather than being taken to a command line text editor to write a message.

Once you’ve commited your changes to your local git repository, you’re ready to push them to online subversion repository!

When pushing your git changes back to the online repository, you’ll want to run the subversion rebase command. What this command does is download all the changed files from the repository. You won’t be able to add your changes to the online repository if you don’t do this:

git svn rebase

After you’ve run that command, the only thing left is to commit those changes to your online svn repository:

git svn dcommit

And, that’s it! You’ve successfully learned to use the git bash with a subversion repository!

One more thing to note if you work on multiple machines. If you’ve cloned your repository on multiple machines you’ll need to run the rebase command:

git svn rebase

to download any changes from the server that you’ve commited from your other machine BEFORE you start working on your code on your current machine.

 

Now you’re ready to get working with git on your subversion repositories!

Minecraft-Style Engine in XNA 4.0

0

Posted by Thomas | Posted in XNA | Posted on January 15, 2012

Hey gang,

So lately I’ve been messing around with creating a minecraft-styled engine in XNA 4.0. Currently I think it’s going really well. Check it out and let me know what you think:

One of the most important things about this project for me is optimization. What’s great about minecraft is that there are so many things on the screen and there is virtually no lag at all. This isn’t just about me making a minecraft clone, I really want to become better at working in large environments, and allowing them to run as fast as they can!

Understanding C# 2D XNA HLSL

1

Posted by Thomas | Posted in XNA | Posted on November 26, 2011

Introduction

Firstly, what is HLSL? What can we use it for? HLSL is an acronym for High-Level Shader Language, and because it is a shader language, it runs on the GPU of the computer. With HLSL you can perform many post-processing effects, such as: blur, point lights, black and white, bloom, and pretty much any filter you can think of that can be done in Adobe Photoshop.

When working with HLSL on the Xbox 360, you are limited to using Pixel Shader 2.0 (This way you can support all Xbox’s) rather than 3.0, which isn’t terribly bad, but it could be so much better. You can do a lot with pixel shader 2.0 with up to 64 mathematical operations per-pixel. Because it is a pixel shader, the code that you write will be executed on every single pixel that is on the texture you’re working with. If your game resolution is 720×360, totalling to 259200 pixels, and if you have 3 mathematical operations per pixel (for example you are using sin, cos, and +), totalling to 777600 mathematical operations done for every time this shader code is ran (typically the total amount of times you draw the effect to the screen).

 

Examples

Nearly any filter that can be done in photoshop can be done with a shader. So, check out an example (more to come):

Radial Blur Example

fig. 1.0: Radial Blur

Read the rest of this entry »

Crate Crash 2 and More

0

Posted by Thomas | Posted in Flash | Posted on May 26, 2011

Hey,

It’s been a pretty long time since I last updated. I’ve been up to a few things lately. One of the biggest things I want to address is the development of Crate Crash 2. A few of you know of the first Crate Crash game, but for those of you who don’t, you can play it here: Crate Crash at TopPhysicsGames.com. The first Crate Crash game is all about clicking the game screen to apply impulses or little explosions that launch the crates. The goal of the game was to get the crates off of the screen, and this goal is still pertinent in the second game, BUT there are more crazy levels, obstacles, and challenges to get through.

The biggest issue that I noticed that people were having was that the game was way too damn hard. Now that I go back and play it again, I think it’s too hard. What I’m going to do with CC2 is create different difficulties. By default users will be playing on casual mode which will allow you to just play the game with no limits of restrictions (that means no medals on the levels, and no click limit). I’ve found having a sandbox-type mode allows the user to have a more enjoyable experience, I know that for a fact because sometimes in developing the game I get distracted just messing with the physics.

Another change from the original is that there will be less levels. It isn’t completely final how many levels there will be, but right now I have a 45 level cap. It could increase, but I don’t think it will.

The biggest feature of Crate Crash 2 will be the level editor. Users these days like to create their own content, and with the level editor that I’ve made, creating your own content should be VERY easy. I’ve had a few ideas of how I wanted to share these levels and I have few ideas going on in my head.

In other news, I am developing my own arcade script, Custom Arcade Script (Pretty cool name, right?). After being in the arcade scene for nearly 2 years now, and having mild success, and looking at how the arcade business is being handled, I’m not 100% satisfied with the way that arcade scripts work today. I’ve tried a few arcade scripts, and none of them are particularly great. They all their ups and downs, but none of them are a one-stop solution. Custom Arcade Script looks to provide just that. CAS will encompass some of the newest and most reliable arcade-related code available. With its streamlined interface, and easy to use admin panel, I have no doubt that Custom Arcade Script will be a huge contender in the arcade script market when it’s released!

-Tom

A Review of 1upmedia.biz

0

Posted by Thomas | Posted in Reviews | Posted on October 29, 2010

Hey everybody, it’s been a long time since I last updated, nearly a year!

One of the things I’ve been doing a lot lately is focusing on website promotion. As many of you may or may not know, I’ve been getting into flash arcades and the monetization behind them quite a bit lately, and I’d like to touch upon a new online games advertising company that I started using in early June of this year (2010). 1upMedia.biz is an arcade and flash game advertising platform looking to deliver quality and targeted ads on your arcade sites. I’ve used both the Publisher and Advertising features on the site, and I’d have to say for what I’ve used them for, I’m pretty pleased. On the Publisher side of 1upMedia you get an easy to use and comprehensive overlook of the months earnings, clicks, and impressions, as well as other miscellaneous details. The best part about this is that the data is presented on an interactive flash graph, and allows you seamlessly and easily check your earnings for the previous day or whichever. Another thing I liked about 1upMedia.biz is that minimum payouts are at $25. Just this month I’ve actually reached the $25 minimum payout, and I think Eddie (the owner and CEO of 1upMedia) pays on a NET30 basis, meaning I’ll receive my payment by the end of November. You may be thinking that earning $25 in 4 months is not that great at all, however, this is not really that bad at all, I mainly use 1upMedia as a filler ad, and a footer ad. Really, 1upMedia is just an extra ad to try to fetch me some more money, and really, it does work. Currently, I only have a 728×90 banner on the top of every pre-game page, and two 728×90 ads at the top of my play pages. The ads that are delivered are not intrusive, don’t spawn popups, and give my users (or me) viruses. I can attest to the fact that anyone who uses 1upMedia’s advertising platform doesn’t have the chance to create an intrusive ad, or anything that will truly annoy a user. I started advertising at the same time I signed up for the publisher program, and from the time I started using it, and the time I stopped advertising with them (for financial reasons, not because of anything to do with 1upMedia) I was very pleased. I had a great conversion rate, and earnings on quite a few days were greater than what I had spent for the users from 1upMedia.

For anyone who is looking for a great filler ad with great earning potential look no further than the Flash ads company, 1upMedia.

Tom

How to make a platform engine in QuickBox2D – Part 2

0

Posted by Thomas | Posted in Flash, Tutorials | Posted on October 03, 2009

Read Part One of the article, it covers some of the basics, and explains a few things.

With the release of QuickBox2D 1.0 I figure I should update my game engine articles. I won’t actually update the first one, but instead I will provide updated versions here, with links to download the files (source).

One of the best things about the new QuickBox2D is the addition of QuickContacts.

var contacts:QuickContacts = sim.addContactListener();
contacts.addEventListener(QuickContacts.ADD, onAdd);
contacts.addEventListener(QuickContacts.PERSIST, onPersist);
contacts.addEventListener(QuickContacts.REMOVE, onRemove);

function onAdd(evt:Event):void{
	if(contacts.currentPoint.shape1 == main.shape || contacts.currentPoint.shape2 == main.shape){
		if(contacts.currentPoint.normal.y >= -1 && contacts.currentPoint.normal.y < 0){
			grounded = true;
		}
	}
}
function onPersist(evt:Event):void{
	if(contacts.currentPoint.shape1 == main.shape || contacts.currentPoint.shape2 == main.shape){
		if(contacts.currentPoint.normal.y >= -1 && contacts.currentPoint.normal.y < 0){
			grounded = true;
		}
	}
}
function onRemove(evt:Event):void{
	grounded = false;
}

QuickContacts is a class that uses the b2ContactListener class that comes stock with Box2D. If you remember, we actually modified that class so we could detect if we were touching things (this way our character could jump). With this addition, we won’t actually need to modify that, AND we won’t have to make that global class. We can just do all the code on the timeline.

On the first part of the series, someone commented saying that if you add an object that does NOT have a zero density, that game would get pretty messed up. Well, he was right. That was because in the b2ContactListener, when we checked to see if we were grounded, the class was actually checking every single object against each other. Meaning that any object with zero density was being checked, and since it was sitting on the boxes right, it would set our grounded variable to true.

One more addition to the platform engine is the ability to make platforms that you can jump through the bottom, this isn’t really new feature, but it’s pretty nice. To be honest, the code that actually makes it so you can jump through the bottom of platforms was originally taken from a snippet on Actionsnippet.com, the creator of QB2D. So, thanks Zevan.

I also made numerous fixes to the code from the last version. One of these fixes include changing direct modification of gravity, to setting the main character object to sleep. I would change the gravity to 0 when the main character was standing on a platform, specifically on a slope, so that the character wouldn’t slide down. However, it turns out to be a better plan to set the object to sleep. Why? Well, if you push one of those non-zero density spheres off a platform, it won’t actually fall with the old system, whereas the new system fixes that.

Test the QB2D Engine

Download the source

What should I add to the new version? Suggestions?

Tom

5 Ways to Improve Your Flash Game

0

Posted by Thomas | Posted in Flash | Posted on July 24, 2009

You just made the best flash game ever, huh? Is that so? Before releasing your game into the wild, make sure you try some of the following:

Add a Highscore Table

Highscores are a great way to get people to play your game more, and enjoy it. A highscore table in this day and age is becoming more of a standard for flash games than ever before. The player practically lives to be ‘the best’, so why not help them the best by letting them show it.

Add Achievements

This practically goes hand in hand with having a highscore a table. Users lately have been expecting a rewards for actions they perform in games. Major consoles have them, and if they have them, there’s no doubt that Flash game players will be expecting them as well.

Have Good Audio

Some people totally skip this part. This is a vital part of creating a great game. Games that totally skimp out on taking the time to get audio that fits the game are only hurting themselves. I’m not saying throw a sound effect on every little thing in the game, I’m just saying don’t be too intrusive on how it’s played out. Menu’s should have their own music, different locations in the game should have different music. Every viral and popular game has great audio that adds to feeling of the game. Imagine you’re doing the final level of Halo to vivaldi, not very epic is it? Vivaldi would definetly ruin the mood.

Use less text!

One mistake that most developers make is that they use too much text. People going online looking to play some free flash games after a hard day aren’t looking to read, they want to relax and have some fun. So, try to avoid lengthy instruction screens. Players are looking for simple intuitive controls. If you absolutely need to have directions in the game, so be it. But, add a skip button so they don’t have to sit through it. Then, show a graphics, or something real quick to tell the controls. Just so they know.

Spend a day or two tweaking

You don’t know how many developers skip this step and are just so eager to get they’re game out there that they forget to bug check, and as a result lose fans. Let’s say a developer gave the boss on level 12 too much health, resulting in half the people playing getting frustrated. Five minutes of adjustment could have made the game that much more enjoyable. Other things could be added to keep the players hooked are save games, cutscenes, special effects, and etc.

Making a great viral flash game can be a daunting task, but I hope this guide/outline will help make that task a little easier.

Please, don’t hesitate to comment. Your opinions are always welcome.

-Tom

Convert Unsigned Integers to Hexadecimal Strings

0

Posted by Thomas | Posted in Flash, Snippets | Posted on July 21, 2009

So, you wanna convert a uint to hex in AS3, huh? Well, this is how you do it:

function uintToHex(val:uint):String {
	var pref:String = "000000";
	var str:String = String(pref + val.toString(16));
	return "#" + str.substr(-6).toUpperCase();
}

What I think this is really useful for is converting randomly generated colors to hexadecimals so that you can access them later. I mean, it’s not that the uint equivalents are bad or anything, but the hex codes are generally easier to work with.

Also, awhile back I was browsing the web seeing how other people managed to do this, and I found this post: Tylerbeck.com
Feel free to check it out. It’s really great for understanding hexadecimals a bit more. It’s a longer function, but does the exact same thing as this one.

Good Luck,
Thomas