Aug 262011
 

Are you having trouble implementing the Kongregate API? Well I finished a fast and basic wrapper class for the API that allows developers to connect to Kongregate in 1 line and submit stats in 1 line. That means in 2 lines the extra revenue bonus is yours. Since I want to have only one place for updating I currently have the official post located here. All the details are in the first post and the FAQ is just below it. You can also ask questions here and I will answer to the best of my ability.

Jun 112011
 


The current version of MirrorMaze relies on some unique depth sorting, due to the 2 layers of tiles, all of which are graphically similar. Each tile has a lighted top and a darkened front, making the tile appear in 3d in perspective. Deciding which tiles to place where and when was the trickiest part of the display. The layer on the bottom must be added first, in the correct opinion, then the top layer can be added on top of that. You must also render from top to bottom of the screen to make sure each tile is placed ‘in-front’ of the tile behind that. How was this issue of depth sorting solved? Well here is some code.
Continue reading »

May 302011
 

Remember Cave Generation + Dynamic Lighting v1.0? Well we had a lot of really small areas in between all of those caves that aren’t really good for anything. Too small to be of much use for exploration value/mining value or anything. Writing an algorithm to detect those small ‘caverns’, lets call them, was not fairly simple. With such a large bitmap, I was encountering stack overflow with my recursive flood fill and area finder. What I really needed was a non-recursive function for the area finder and to use the bitmapdata.floodFill() function that is in the BitmapData class. The evolution of the area finder algorithm was recursive to color bounds using mass floodfilling to a non-recursive queue implementation. The filling algorithm just went straight to the bitmap’s floodfill which wasn’t limited by stack overflow as the recursive one I had designed. In the picture below you can see the areas that were detected as too small colored red, and will be filled in with the Solid color.

Continue reading »

May 282011
 

Inspired by Emanuele Feronato’s procedural cave generation, I took his code, and made this experiment. Instead of running on graphics data, which makes it hard to use when using incredibly large areas and changing colors of each individual ‘block’, I used a bitmap and vectors of uints to create the same effect. A fully visible cave system would look like this, with the larger caves filled in with color to show their sizes.
Continue reading »

Mar 182011
 

Function overloading and using templates are extremely useful when trying to not write duplicate methods with the same parameters, but only different types.

//main.cpp
#include <iostream>

using namespace std;

void get2Values  (int &data1, int &data2);
void get2Values  (double &data1, double &data2);

void print2Values  (const int &data1,const int &data2);
void print2Values (const double &data1,const double &data2);

template <class dataType>
void  swapC (dataType &a,  dataType &b);

int main ()
{
   int first, second;
   double dFirst, dSecond;

    get2Values(first, second);
    get2Values(dFirst, dSecond);

    print2Values(first, second);
    print2Values(dFirst, dSecond);

    cout << endl << "--Swap--" ;

    swapC<int>(first, second);
    swapC<double>(dFirst, dSecond);

    print2Values(first, second);
    print2Values(dFirst, dSecond);

	cout << endl;
	cin.get();
	return 0;
}

void  get2Values (double &data1, double &data2)
{
	cout << "Enter Double 1 ---> ";
	cin >> data1;
	cout << "Enter Double 2 ---> ";
	cin >> data2;
}

void  get2Values (int &data1, int &data2)
{
	cout << "Enter int 1 ---> ";
	cin >> data1;
	cout << "Enter int 2 ---> ";
	cin >> data2;
}

void  print2Values (const double &data1,const double &data2)
{
	cout << endl << "Double 1 ---> " << data1;
	cout << endl << "Double 2 ---> " << data2;
}
void  print2Values (const int &data1,const int &data2)
{
	cout << endl << "Int 1 ---> " << data1;
	cout << endl << "Int 2 ---> " << data2;
}

template <class dataType>
void  swapC (dataType &a,  dataType &b)
{
	dataType temp = a;  a = b;  b = temp;
}

The output should be:

Enter int 1 ---> 1
Enter int 2 ---> 2
Enter Double 1 ---> 3.21
Enter Double 2 ---> 8.125647

Int 1 ---> 1
Int 2 ---> 2
Double 1 ---> 3.21
Double 2 ---> 8.12565
--Swap--
Int 1 ---> 2
Int 2 ---> 1
Double 1 ---> 8.12565
Double 2 ---> 3.21

The template function allows you to pass in any value, saving you from creating the two methods above unique to double and int.

Mar 162011
 

I admit this is a terrible example I wrote up a few months ago. You should obviously have a temp variable so you aren’t casting all the time. But the point of the lab was to test user input, in which it performs just fine and is clean.

//main.cpp
#include <iostream>

using namespace std;

int main ()
{
	double purchaseAmount, cashPaid, temp;
	int change;

	cout << "Enter the purchase price: ";
	cin >> purchaseAmount;
	cout << "Enter the cash tendered: ";
	cin >> cashPaid;

	temp = cashPaid - purchaseAmount;
	change = int (temp * 100);

	cout << "Your change: " << change << " cents" << endl;
	int numQuarters = int(change/25);
	cout << "Quarters: " << numQuarters << endl;
	int numDimes  = int((change-numQuarters*25)/10);
	cout << "Dimes: " << numDimes << endl;
	int numNickels = int((change-numQuarters*25-numDimes*10)/5);
	cout << "Nickels: " << numNickels << endl;
	int numPennies = int((change-numQuarters*25-numDimes*10-numNickels*5)/1);
	cout << "Pennies: " << numPennies << endl;

	cin.get();
	return 0;
}

The output should be:

Enter the purchase price: 10.25  //10.25 was inputted
Enter the cash tendered: 20.21  //20.21 was inputted
Your change: 996 cents
Quarters: 39
Dimes: 2
Nickels: 0
Pennies: 1

And yes, I have noticed the divide by one. Its left in there to keep the standard so its easier to see the pattern of calculating the individual change.