![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
I'm new at this! |
Steve Terry
Member #1,989
March 2002
![]() |
The idea is to write functions to break up the work for you. You should have an initialization function, a draw function, and a function to get which card was clicked. Breaking it up this way makes it simpler for your main game loop. If you've done C for a year then you should know that. As far as Allegro goes please read up on many of its functions and look at all of the examples. Once you understand them then you can work on a game. You have the stuff on the screen already but you need to understand come simple concepts, for example you need a main game loop, once you initialize your cards then you go into a continual loop until the user exits the game (usually hitting the ESC key). You also need to understand double buffering (creating a separate off screen drawing space for drawing) which will allow you to do animations. Don't jump in so fast, make some simple double buffering apps, tie one of your bitmaps to the mouse movement for example. Move up from there. @ Simon... dear god don't teach him to write a bunch of if statements like that, that's horrible coding techniques. ___________________________________ |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
For one thing you are going to want randomize where the cards are. The way you have it with drawing the cards, its going to be the exact same game every time. It will be a true memory game. The player plays the game once and memorizes where all the cards were at and can beat it every time with no mistakes. As for flipping to cards... if num_cards_clicked equals 2 For drawing purposes you would check to see if the flag "matched" was set to true, if it was then draw the actual card instead of the default face down card. Each time a card is clicked there will be another flag set, something around the lines of "selected" if selected is true then this card will also be drawn face up. The main draw loop will check to see if the flags "matched" or "selected" are set, if either one is set then it will draw the actual card, if neither are then it will draw a generic face-down card graphic. For the clicking on a card section you will need to check if the card is not "matched" or "selected" if it isn't either of those then it can be "selected" Once 2 cards have been selected and you are checking to see if they are matched... You are then going to want to set the "selected" flag on both back to false. If you can't understand C programming syntax and logic you can PM me for my AIM sn. I'm not doing too much in the next couple of days >.<:-[ =-----===-----===-----= |
Simon Parzer
Member #3,330
March 2003
![]() |
Quote: @ Simon... dear god don't teach him to write a bunch of if statements like that, that's horrible coding techniques. It's just an example so he sees that the simple (in the sense of "not complicated") way isn't always the right one. And besides that, if I showed him some sophisticated code with "advanced" features like sub-functions arrays and structs he wouldn't have understood. |
luvzjetz16
Member #8,063
December 2006
|
ok first off everyone...i'm a girl so you dont have to call me him or he...haha |
miran
Member #2,407
June 2002
|
Quote: I've tried mouse_x, mouse_y but I dont think I was doin it right...what kind of C code would I need to actually click on a "card" Each card should have the location of the top left corner (x and y) and size (width and height). The mouse cursor is "on-top" of a card when mouse_x is between x and x+width AND mouse_y is between y and y+height. The left mouse button is clicked when mouse_b&1 is true. In code (pseudocode):
-- |
Richard Phipps
Member #1,632
November 2001
![]() |
The series of game tutorials on my homepage might prove useful to you. |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
You really should get a C book and make sure you are perfectly comfortable with loops, if's, switches, structs, functions, pointers, dynamic memory allocation and the operators (+, -, =, ==, *, /, ++,-- etc). Some basic knowledge of the standard library would not hurt either. Make some dull "text-only" programs before you start playing with the beast that is graphical programing But don't worry about it; C is a very simply language (those parts mentioned above is pretty much it, with the exception of function pointers and unions iirc), and im sure you already know most of the parts mentioned above. Well, good luck and have fun!
|
Steve Terry
Member #1,989
March 2002
![]() |
___________________________________ |
luvzjetz16
Member #8,063
December 2006
|
ok guys....everytime i run my program it tells me: 'bool' is undeclared. what exactly is bool? i know int, double, float, char....is bool like those or what is it? and how can i "declare" it so I can run my program? |
miran
Member #2,407
June 2002
|
Sorry, bool is a type found only in C++ but not C. In plain C you can replace bool with int, true with 1 and false with 0. -- |
luvzjetz16
Member #8,063
December 2006
|
ok cool...that worked. ok now for the line: for (each card) { if (mx > card<i>.x && mx < card<i>.x + card<i>.width && my > card<i>.y && my < card<i>.y + card<i>.height) { am i supposed to put like for (card[0]) { if (mx > card[0].x && mx < card[0].x + card[0].width && my > card[0].y && my < card[0].y + card[0].height) { or what should i be putting in the for( ); |
miran
Member #2,407
June 2002
|
Quote: or what should i be putting in the for( ); You really should read a C tutorial or book first. Assuming you have an array of cards defined as something like CARD cards[52]; then you would make your for loop like this: int i; for (i=0; i<52; i++) { /* ...the rest of the code where you use i as an index into the array of cards... */ }
-- |
luvzjetz16
Member #8,063
December 2006
|
well thank you all for your help....and thanks for putting up with me!!!;D |
James Stanley
Member #7,275
May 2006
![]() |
From personal experience I disagree with reading books. I once tried to learn a language by reading a book and I hated it. What you should do is read through very simple programs that other people have made and then try and understand what some of it does. You won't understand it all at first. Then start making your own simple program and slowly take features from other programs until you are competent enough to write something on your own. Then you can start making more advanced stuff. That's much faster than reading books. |
nonnus29
Member #2,606
August 2002
![]() |
Quote:
Miran said: Hmmm, the op says she's a girl and all of a sudden Miran is helpful. I see how it is around here....
|
Jonatan Hedborg
Member #4,886
July 2004
![]() |
People lie about their gender to get a better treatment?
|
Steve Terry
Member #1,989
March 2002
![]() |
I know I mixed C and C++, sorry about that. Bool is short for boolean, with two values, true and false. Use a for loop like I used in the init function: for(int i = 0; i < NUM_CARDS * 2; i++) // do something with card<i>
___________________________________ |
BAF
Member #2,981
December 2002
![]() |
You can use bool on C99, you just have to include stdbool.h or something like that. |
HardTranceFan
Member #7,317
June 2006
![]() |
nonnus29 said:
I see how it is around here.... Sex change, anyone? Does Mian's avatar have a slight smooth look in the eye now? @ James Stanley: Text books give you the what, why, how and the when not to explanations. They give an understanding behind the information that is given. Reading other people's code, unless it's really, really well documented, won't. But trawling through other's code is a great way to learn about [various] implementions, usages and, in cases, more advanced techniques. -- |
miran
Member #2,407
June 2002
|
Quote: Hmmm, the op says she's a girl and all of a sudden Miran is helpful.
I've been helpful from the very beginning. Quote: ...a slight smooth look in the eye now?
Huh? -- |
HardTranceFan
Member #7,317
June 2006
![]() |
Smooth as in suave. -- |
Fladimir da Gorf
Member #1,565
October 2001
![]() |
For beginners, I'd recommend learning Java instead of C... But oh well. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
GullRaDriel
Member #3,861
September 2003
![]() |
For beginners, I'd recommend trying different language and learn the one they understand better than the others. But ... Heh , well ;-) "Code is like shit - it only smells if it is not yours" |
Richard Phipps
Member #1,632
November 2001
![]() |
cough Game Creation Articles.. |
|
1
2
|