Wednesday, January 6, 2010

Intro to Allegro. [Part 1]

After the previous post of setting up allegro in your pc what you want to do now is start writing codes in allegro.

Before I even teach you what to code I must tell you that you should at least have some idea about programming and C language. If you don’t then you might want to refer to this.

Ok after all that let us get to Allegro 101 [Part 1].

Just like in C you start the allegro programming with the header file. But before even including <stdio.h> or <iostream> header files, allegro does not need the two basic header that we are so accustomed to. In fact allegro can do with just <allegro.h> header file. So the start of your program is going to be with this line:-

#include <allegro.h>

After that line depending on the complexity of your program either custom function can appear or the main function can be written. But since we are in 101 class let us start with the main function.

Your line normally should be:-

int main()

{

After that line you would need to start the allegro master function(no it’s not called that, I made that up). You would need to initialize allegro library. To do that you would do:-

allegro_init();

With that done what I always do just to make sure allegro library is up and running is test the simple program from allegro. Normally it goes something like this:-

allegro_message(“Hello world”);

return 0;

}

END_OF_MAIN();

Woah!! what is all that thing over there?? Don’t panic, the first line is the message box that allegro creates and displays “hello world” without the quote of course. The last line(macro) is something you need to declare because of the cross-platform compatibility. If forgetting to write that line could result in crashing of the program.

 

Now that you know that END_OF_MAIN(); is essential part of the allegro just as allegro_init() make yourself a note that you would never forget this part.

Let us go through something more in this 101 class shall we? Because “hello world” is just too dull to do anything. Let us import image into our allegro window.

I will provide you with code first, go through it and try to understand as much as possible then go through the explanation below.

#include <allegro.h>
int main()
{
         allegro_init(); 
         install_keyboard();
         set_color_depth(32);
         set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
         BITMAP *image;
         image = load_bitmap(“mypic.bmp”,NULL);
         blit(image,screen,0,0,0,0,image->w,image->h);
         read_key();
         destroy_bitmap(image);
         return 0;
}
END_OF_MAIN();

 

Ok by now you should know till allegro_init(). Now let’s move further down shall we?

The install_keyboard() function does what it says. It installs keyboard to your program so that you can make use of the keyboard. That was easy but let us move further down.

set_color_depth(32);

If you have any slight idea about how computers generate color in the screen then you would have no problem with this else you would scratch your head on what this even means. The number 32 isn’t given just randomly. In fact you can just write either 8,15,16,24,32. What it does is it sets the pixel format to your screen. Higher the number greater the detail can be shown in the image inside your allegro program. 8 bit is something you would play back in NES. Anyway it depends on how vast you want the users to be. 8 bit is almost supported by all while 32 might not.

set_gfx_mode(GFX_AUTODETECT,640,480,0,0);

After setting the color depth, you should tell the allegro what kind of driver you are using as a graphic device to allegro. Luckily you don’t have to manually put the graphic driver, allegro does that for you with GFX_AUTODETECT and 640 and 480 are the setting of the screen width and height (640 and 480 are chose because it is the standard monitor resolution of many and even if it isn’t I can guarantee that majority of computer supports this resolution even if they have 1920X1200 resolution). The later 0,0 was required for virtual screens but is not required anymore hence it can be left with 0,0.

BITMAP *image;

image = load_bitmap(“my_pic.bmp”,NULL);

The next thing after that is BITMAP pointer for holding your image. BITMAP sets the address for your “image” variable to load the image which it does in the next line. Think of it like int but only much more powerful.

load_bitmap() function loads the given image to your image pointer variable which in our case is image. load_bitmap only takes BMP,TGA,LBM and PCX file format till now. So before you start loading up those 10 MP Jpeg file you better watch out.

blit(image,screen,0,0,0,0,image->w,image->h);

The blit line is the crucial and yet most complicated part of this program so far. What some beginner might think this as is it is responsible for displaying the image into the screen, but is not so.

What blit does is copy from source to the given destiny, in the code above lit is copying from image to screen (your monitor) and the rest of the parameters that follow are the clipping of the source width and height 0,0 means no clipping. If you entered something like this 10,3 then your image will be clipped 10 pixels wide and 3 pixels height. The other 0,0 is the position where you would want to place your image. 0,0  here means to the top left side of your screen. If given other variable then the image is placed according to the x and y coordinate of the screen. Left generally means negative x coordinate and Up generally means negative y coordinate and vice versa for Right and Down. The last two parameters are the width and height of the screen that you would actually want to display on your screen. You could also write SCREEN_W,SCREEN_H to display your whole screen.

read_key();

This line just waits for you to press some keys before exiting.

destroy_bitmap();

Because you take up memory after every compilation of the program it is not just a good idea but a must to destroy the memory that you took on your last compilation so that you clear up the memory and there is no memory leak.

The rest are usual standard procedure for ending your program.

Now go play with it and try to add that are not supposed to be added and ask questions to yourself about the possibilities.

Technorati Tags: ,,

Thursday, December 10, 2009

Setting up Allegro in Visual C++ 2010

Before I even tell you how to set-up allegro, let me tell you something about Allegro.

Basically Allegro is a game programming library that gives the game programmer much more power to create games with ease. More on Wiki.

Now, setting up Allegro on Dev-Cpp is a bit easier than setting up in Visual C++ which is why this tutorial is made in the first place. If you want me to show you how to setup allegro in Dev-Cpp then please do not hesitate to ask for tutorial. I will be more than happy to walk you through the process. After that said, let us go to tutorial.

Step 1 [GETTING THE ALLEGRO]:-

->Go to http://www.allegro.cc and in the files section download the latest allegro library for your appropriate compiler.

Step 2 [COPYING THE FILES]:

->After you downloaded the files open the zipped file and copy the files from “bin” ,”include”, “lib”  to their respective order to your Microsoft Visual C++ folder. Your “VC” folder inside Microsoft Visual Studio should have the same folder as you downloaded one. Put all the files.

->Copy the “bin” files from your zipped file to “Windows/system32/” folder too. After that you have completely configured your compiler to atleast look for the library if it needs it.

Step 3 [SETTING UP IN VISUAL C++]

->Before you start typing the code, first you will need to make a new project (making just a new file will not do).

->After that go to Project->Option->Configuration Properties->Linker->Input and in the Additional dependencies click the drop-down box and click edit. Type “alld.lib”. And you’re done.

 

You have configured Allegro in your Visual C++ 2010 for that project. Congratulation!!!, If you are still confused and lost then the video below might be useful.

 

Technorati Tags: ,,

Sunday, April 26, 2009

Fill or Bust V3 Complete Game

After two weeks we finally completed our project. Hope our professor will like what we have done with our code. I love deadlines, it’s when you get to see people starting to work in a group trying to solve the same problem. And I am glad that we completed this project in a group rather than a solo effort. HURRAY FOR US

Nicole - (Mainly worked on Logic of the game)

Aric - (Mainly worked on the Graphics)

Trent - (Bug fixer/ Part Graphics)

Yojan - (Bug fixer / Part Logic)

Download the Game

Technorati Tags: ,,

Monday, April 6, 2009

Fill or Bust Game : Working on it

Ok, so this is our final project for this semester. It is supposed to cover all the things that we are taught. Even though I have no clue how to play this game here are the rules:-

RULES:-

2 or more players
Ages 9 to Adult

The game consists of:
6 DICE & 54 DRAW CARDS
12 - 300 pt. "BONUS" cards
10 - 400 pt. "BONUS" cards
8 - 500 pt. "BONUS" cards
8 - "NO DICE" cards
6 - "FILL 1000" cards
4 - "MUST BUST!" cards
4 - "VENGEANCE 2500" cards
2 - "DOUBLE TROUBLE" cards

The object of the game is to be the highest scorer. You can play to any number, for example, 5,000 or 10,000 points. The winner would be the first player to reach goal. Or, you can play within any time limit. The winner would then be the highest scorer at the end of the time period.

You need to supply paper and pencil for scoring

BEGINNING PLAY

Shuffle the DRAW CARDS before each game and place them face down in the middle of the table.

You start by selecting a player to begin. Each player tosses one die. The player with the highest toss begins the game. Play continues clockwise.

RULE 1 You MUST turn over a DRAW CARD before each turn and after each "FILL". The card you turn over will determine your course of play. How you play each card is explained later under "PLAYING THE DRAW CARDS".

RULE 2—You MUST score EVERY time you toss the dice. After turning over a card, you begin your turn by tossing all six dice.

You score by tossing 1s, 5s, any triples or a straight (1,2,3,4,5 and 6 thrown in a single toss of all six dice). The chart under "SCORING WITH THE DICE" shows the points you will receive for the combinations thrown.

RULE 3 After each toss you MUST remove some or all of the scoring dice. Set aside all the scoring dice you have chosen and add up their points.

You can decide to take these points and add them to the scoresheet ending your turn. Or, you can take a chance and try to score more points with the remaining dice.

HOW TO SCORE A FILL

If you can continue to score on every toss of the dice, and you eventually set aside all six dice., YOU HAVE SCORED A "FILL"~

After scoring a "FILL" you can decide to take the points scored during that turn and add them to the scoresheet, ending your turn. Or, you can take a chance and try to score more points by turning over another "DRAW CARD" and start by tossing all six dice again.

There is no limit to the number of "FILLS" that may be scored in a turn.

WHAT IS A BUST?

If on any toss you DO NOT score, that toss is a "BUST".

When you "BUST' during a turn, you lose ALL the points you scored in that tum. You do not lose any points that were already added to the scoresheet.

After a "BUST", your turn ends and you pass the dice to the next player.

SCORING WITH THE DICE

The object of scoring with the dice is to roll as many points in a turn as possible without tossing a "BUST".

It is up to you to decide when to stop, take your points and add them to the scoresheet where they are safe. Or whether to risk your points and continue tossing the dice in order to try and score more points.

The chart below shows the points you receive according to the combinations you toss.

HOW TO SCORE A TRIPLE

A triple can only be scored in a single toss of the dice. You CANNOT add dice from different tosses together to form a triple. For example, you cannot add a single die from one toss to a pair of the same number from another toss to create a triple.

HOW TO SCORE A STRAIGHT

In a single toss of all six dice you must throw a 1,2,3,4,5 and 6. A straight can only be scored on the first toss of your turn or the first toss after scoring a "FILL" when you are tossing all six dice.

PLAYING THE DRAW CARDS

The DRAW CARDS are used to add variety and excitement to the game.

Depending on which card is drawn, DRAW CARDS make scoring easier or more difficult. Some cards give you bonus points for scoring a "FILL", and some cards take away your turn. One card can be used to subtract points from the leaders' score.

The DRAW CARDS are shuffled and placed face down at the center of the table. As the cards are drawn, they are turned face up and placed in a discard pile.

WHEN TO USE THE DRAW CARDS

You draw a card before each turn begins.

A card is also drawn after each "FILL" is scored if you decide to continue your turn.

The card drawn will determine how you will proceed with your turn.

HOW EACH CARD IS PLAYED

BONUS 300, 400 and 500

When you draw a "BONUS" card you will receive bonus points ONLY IF you score a "FILL".

The amount of the bonus is determined by the number on each card. This number is added to the points scored in that turn.

You have the option to stop tossing before you score a "FILL" with this card. However, if you stop before a "FILL", you DO NOT collect the bonus points.

NO DICE

When you draw a "NO DICE" card you lose your turn.

If "NO DICE" is drawn after a "FILL", you lose ALL points scored in that turn. You do not lose any points that have already been added to the scoresheet.

FILL 1000

When you draw this card, you MUST score a "FILL". You lose your option to stop tossing the dice before scoring a "FILL".

If you score a "FILL", ADD an extra 1000 points to those points scored in that turn.

If you "BUST" before scoring a "FILL", you lose your turn and all oints scored in that turn. You do not lose any points already on the scoresheet.

MUST BUST

The "MUST BUST' card makes scoring the easiest. When you draw this card you are certain to score points unless you "BUST" on your first toss.

You begin by tossing all six dice. After each toss you MUST set aside ALL scoring dice. You continue to toss the dice, setting aside all scoring dice and adding up your points until you toss a "BUST". There is no limit to the number of tosses or "FILLS" that you may make.

You do not draw another card after each "FILL" when playing the MUST BUST card.

After you "BUST", you ADD the total number of points that you scored in that turn to the scoresheet. You then pass the dice to the next player.

DOUBLE TROUBLE DOUBLE

When you draw "DOUBLE TROUBLE", you MUST score two consecutive "FILLS". You lose your option to stop tossing before you "FILL" two times consecutively. If you score two consecutive "FILLS", double all the points you scored in that turn an add the total to the scoresheet.

After adding your total to the scoresheet, you can continue your turn without the risk of losing those points.

If you "BUST" before scoring two "FILLS", you lose your turn and all the points you scored in that turn. You do not lose any points already on the scoresheet.

VENGEANCE 2500

This card can only be used against the player with the highest core. If two or more players are tied for the lead, the "VENGEANCE" Gard is used against all of them.

When you draw a "VENGEANCE" card, you have the option of playing the card or not. If you choose not to play the card, discard and draw again.

If you choose to play the card, you MUST score a "FILL". If you "FILL", total all the points scored in that turn and add them to the scoresheet.

SUBTRACT 2500 points from the leaders score. If two or more players are tied for the lead, each player loses 2500 points. If the leader(s) has less than 2500 points, his score becomes zero.

After scoring a 'VENGEANCE FILL", you can continue your turn without risking the points that were add to the scoresheet durig that turn.

If you "BUST", before scoring a "VENGEANCE FILL", you lose your turn and all points scored in that tum. You do not lose any points already on the scoresheet.

NOTE:

The leader can only play the "VENGEANCE" card if one or more players are tied with him for the lead If the leader draws the "VENGEANCE" card and no one is tied with him, he must discard and draw again.

BEWARE: With every extra toss of the dlce or draw of a card, you take the risk of losing any points you have scored which have NOT been added to the scoresheet.

TEAM PLAY

Select teams with an equal number of players. Players are situated so that each team alternates in turn. One player from each team tosses one die. The team with the highest toss begins. Play continues clockwise. Team play is suggested for groups of 8 or more players. All rules remain the same. However, you can choose to double the value of "VENGEANCE 2500" for more excitement.

TOURNAMENT PLAY

All toumament play is within a timed period. Split all players up into groups or 2 to 6 players. These groups play 20 to 30 minute rounds. When all groups do not have an equal number of players, allow 5 to 10 minutes per player in each group. Any tum in progress at the end of the time period is played out.

SINGLE ELIMINATION

After Round 1 all players are listed in order from the highest scorer to the lowest. The top half of the higher scorers proceed to Round 2. The bottom half are eliminated. Continue play by listing the players after Round 2. The top half of the higher scorers proceed to the next round while the bottom half are eliminated. Continue playing rounds until all but the top 2 players are eliminated. These 2 players then participate in a 15 minute "FACE-OFF" Round.

The highest scorer wins.

DOUBLE ELIMINATlON
In double elimination , a player who scores in the lower half of all scorers twice is eliminated.

OPTIONAL RULES
All players must agree to an option before the game starts for the optional rules to be valid. One or more of these optional rules may be used in a game.

SHOW DOWN option
When a player has won the game, the remaining players each have one last chance to out score or "VENGEANCE" the leader. The highest scorer after this final SHOW DOWN round wins. If a successful "VENGEANCE" card has been played and the leader's score has been brought under the goal, the game continues until some player reaches goal again.

MUST BUST! option
"MUST BUST" can be played as a penalty card. When you draw "MUST BUST" under this option, you begin by tossing all six dice. You continue tossing until you "BUST". SUBTRACT the total number of points scored in that turn from your board score and pass the dice to the next player.

COMBO 5 option
Any combination of 5 (2+3 or 4+1) can be set aside to score 50 points. This option can only be used to score a "FILL"

Will post the game once it’s done!!

 

Technorati Tags: ,,

Sunday, April 5, 2009

Hangman with Graphics

Well, this was my assignment when I was studying CS1 (Python). One of my first game in python with graphics, I have to say. It’s not pretty but it’s something.

Download Hangman

If you need the description about the functions and the process of how the game works then feel free to comment about in the comment box.