Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Mon Sep 01, 2014 11:11 am

All times are UTC




Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Fri Dec 07, 2012 3:08 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
Hello,

I'm a first year student in IT and have been given an assignment as homework.

The assignment is simple, to make a game. The deadline is early Januari (so a one month deadline).
My goal is to make a top-down adventure game, nothing fancy graphically, not a huge amount of content.
So far I've taken the approach of using the console(purely text based), but encountered a couple of problems.

The major one is that when refreshing a screen full of characters from an array, the screen flashes erratically. This woud give anyone a headache, thus making the (not yet a game) game unplayable.
Considering that i've yet to have a course on OOP, what option would you suggest? Are there any API's out there that are relatively easy to use for someone with little to no experience with OOP?

Thanks for your help.


Top
 Profile  
 
PostPosted: Fri Dec 07, 2012 3:42 pm 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 364
Location: Here (where else?)
If the screen can be seen getting refreshed you're not doing it fast enough :p
How do you output your character array, with one 'printf' ?

Note that consoles in a graphical environment are usually VERY slow, usually they convert your characters to a bitmap using some anti-alias rendering engine, and then blit the resulting bitmaps to the console area, ie you are not using 'text' at all :p

Do you clear the screen before hand? (scrolling can be a cause too, perhaps the console has a setting for 'smooth' scrolling??).
It may be useful to walk through the console options, and check whether they are optimized for fast drawing.

If these ideas do not work, you could consider switching to curses, a library to manage text-displays.
Alternatively, you can switch to a simple graphical library to draw your output, like SDL.

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
PostPosted: Fri Dec 07, 2012 3:58 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
Alberth wrote:
If the screen can be seen getting refreshed you're not doing it fast enough :p
How do you output your character array, with one 'printf' ?

Note that consoles in a graphical environment are usually VERY slow, usually they convert your characters to a bitmap using some anti-alias rendering engine, and then blit the resulting bitmaps to the console area, ie you are not using 'text' at all :p

Do you clear the screen before hand? (scrolling can be a cause too, perhaps the console has a setting for 'smooth' scrolling??).
It may be useful to walk through the console options, and check whether they are optimized for fast drawing.

If these ideas do not work, you could consider switching to curses, a library to manage text-displays.
Alternatively, you can switch to a simple graphical library to draw your output, like SDL.


I use cout to print out the characters from the array.
First let me show how to test this in code:
Spoiler: show
Code:
int main()
{
    system("mode 120, 60");

    for(int r = 0; r < 1000; r++)
    {
        system("CLS");
        for(int i = 0; i < 60; i++)
        {
            for(int j = 0; j < 120; j++)
            {
                if(r % 2 == 0)
                {
                    cout << 'e';
                }
                else
                {
                    cout << 'B';
                }
            }
            if(i == 59)
            {

            }
            else
            {
                cout << endl;
            }
        }
    }
    return 0;
}


The problem persists even using cear screen.
But only one post and I have some useful advice already.

So far I have on my to-do:
-check out ncurses
-check out this link: http://www.tomshardware.co.uk/forum/65918-25-technique-fast-win32-console-drawing

Since it's friday I'll probably only get to checking it out tomorrow.


Top
 Profile  
 
PostPosted: Fri Dec 07, 2012 4:09 pm 
BANNED

Joined: Sun Jun 24, 2012 12:49 am
Posts: 504
The greatest solution is: Don't make text games...

Quote:
The assignment is simple, to make a game.

... Unless you can make a narrated game, like:

"- Do you want to go down the spooky hollow?
1. Yes.
2. No."

*yes*

"- You arrive at an old warehouse next to a great field.
1. Try to open the front door.
2. Enter into the warehouse's cellar.
3. Search the field."

That would be extremely easy!

If your assignment doesn't require a graphical game at all, I highly recommend you just complete your assignment using the approach above -- especially if you're eager for getting your assignment finished on time. That way, your learning curve can be much more managable. You would be much more likely to thoroughly experience new concepts as your teacher really expected you to, rather than finding yourself wasting time in a frantic and rushed (and potentially harmful) experience. You might not think *narrated* games are much fun, but just do it anyway...

Quote:
Considering that i've yet to have a course on OOP, what option would you suggest? Are there any API's out there that are relatively easy to use for someone with little to no experience with OOP?

OOP doesn't matter much, but you at least need to understand the concept of, well... I forgot the name for it, but guess what I'm doing here:

Code:
struct Banana
{
   float ripeness;
   int monkeyValue;
   bool edibleByCodeheads;
};

(this isn't considered OOP at all, in fact, C++ isn't exactly considered an OOP language anyway)

Now, have a look down here to observe the basic concepts behind utilizing this "Banana" structure that I defined above:
Code:
int main()
{
   Banana sexyBanana; // This is called an 'instance' of the "Banana" class.

   sexyBanana.ripeness = 83.5f; // This is called 'member access' to the "sexyBanana" instance.
   printf("Ripeness of the sexy banana: %f\n", sexyBanana.ripeness);

   // Pause at end.
   getchar();

   return 0;
}

Can you guess how the basics you've (hopefully) learned from that introduction may be helpful for game progammers? Just for example, imagine an array that describes the scenery & objects that compose a scene in a graphical game. What would you put into that array? Well usually, you want to describe the location of these objects. It is also a good idea to track the assets which are used by such objects to compose the scene, such as which picture each object is associated with (also known as an image, and especially in terms of computer graphics and game development: a 'sprite'). Here is a very basic example of how you might do that:

Code:
struct Object
{
   // These coordinates store the position of a scene object.
   float x;
   float y;

   // The "spriteIndex" remembers which picture you have loaded into your game that is drawn by an object.
   unsigned int spriteIndex;
};


If you're wondering what the "spriteIndex" member is for, imagine the activity of loading all the sprites (pictures) into your game and tracking what they are. In a very simple implementation, a way to handle & track your sprite assets is:

Code:
unsigned int bananaSprite = LoadSprite("assets/sprites/banana.png");
// Notice how LoadSprite() returns an unsigned integer. This is in fact an array index (i.e. arrayValue[index] = value;)

Tip: If you are wondering where "LoadSprite" is from, please get used to the notion of things in example code that imply generic features which you may or may not need to create yourself. So, it is helpful to remember when you're learning how to program to understand how you should read code you find on the internet or in books, and recognize between example code (code that is just meant for illustrative purposes) and real, practical, useful and compilable code.

Quote:
Alternatively, you can switch to a simple graphical library to draw your output, like SDL.

SDL sucks horse carrots. I've never used Allegro, but I have looked at the code behind some of it examples. I think it looks much more preferrable to SDL, especially for beginners. Allegro gets my nomination, though I've never really used any of these "beginner level game programming libraries." Just going to hell with it and starting raw with OpenGL or Direct3D for-the-win!

Here is a link to Allegro:
http://alleg.sourceforge.net/

DrDima, if there's any chance that you aren't satisfied with our suggestions and you would rather do a little research yourself, maybe this wiki-page is a good start to find resources:
http://content.gpwiki.org/index.php/Game_Engines

If you still aren't certain about where to go from here, please don't be afraid to keep hitting us with your good questions!

Quote:
i've yet to have a course on OOP

Hey!!! School sucks. Teach yourself. Life is much more fun that way. I never knew I could be so interested in *boring* things like anesthesiology, or ancient european history (think stonehenge and barbarians)... or... well a lot of areas of history (in most major geographical regions and almost any time period) -- and I used to think history was so boring. It all takes a self-driven engine to learn! Please be aware that coming to forums like this one (the Game Programming Wiki's forum) is considered a great way to become "self-taught." I mean, it's not formal education, but at least you're not by yourself! So stay here! :)


Last edited by Pieman on Fri Dec 07, 2012 8:38 pm, edited 5 times in total.

Top
 Profile  
 
PostPosted: Fri Dec 07, 2012 4:32 pm 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 364
Location: Here (where else?)
Code:
system("CLS");
Euhm? I thought you were in a hurry; why do you start an external program through the operating system (which looks for it at the disk, finds it, loads the program, runs it, and then clears up the program?) In reality it does even more than what I just described so yes, it is even slower.

Another approach for controlling the screen output would be to use the ANSI escape sequences. At least, they used to work at a windows console, but you may want to check that first.

What I meant with a single printf is something like
Code:
        char buffer[120*60+1]; // A little too long, but I cannot be bother to actually compute the precise length.
        int idx = 0;
        for (int i = 0; i < 59; i++) {
            for (int j = 0; j < 119; j++) {
                buffer[idx] = (r % 2 == 0) ? 'e' : 'B';
                idx++;
            }
            buffer[idx] = '\n';
            idx++;
        }
        buffer[idx] = '\0';
        idx++;
        cout << buffer;
Prepare the output in a buffer, and dump it all in one 'print' onto the screen.

SDL versus Allegro: I have no experience with Allegro, so it might be better. Have a look, and pick the one you like best.


One tip, don't optimize some part too much at first. A month is past before you know it.
As soon as "it works enough", move on to other parts. That can include temporary accepting your flashing output; it may be ugly, but it works.
You can always come back later and improve things.

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
PostPosted: Fri Dec 07, 2012 5:21 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
My brain is melting.

But I have question.
I've never worked with libraries before (I use codeblocks), how would I go about using something like curses together with codeblocks?
The version I downloaded was the latest one: http://www.gnu.org/software/ncurses/.
I just thought I was going to download a couple .h files and just type #include.


Top
 Profile  
 
PostPosted: Fri Dec 07, 2012 6:40 pm 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 364
Location: Here (where else?)
DrDima wrote:
My brain is melting.
:)
Well, yeah, there is a lot of stuff available and a lot of it is useful. I don't think you will fully understand it all in one month though :p

If you really want to be finished in one month, it may be a good idea to have a sort of plan what to do when, to have an idea of how much time you can spend on stuff like this.

DrDima wrote:
But I have question.
I've never worked with libraries before (I use codeblocks), how would I go about using something like curses together with codeblocks?
No idea, I avoid IDEs like the plague, in my experience, they just tend to get in the way. But perhaps that's just me, many people seem to like them.
The manual of codeblocks should explain how to add your own libraries, would be my guess.

DrDima wrote:
The version I downloaded was the latest one: http://www.gnu.org/software/ncurses/.
Oh, a GNU package. Assuming it is a typical GNU package, you'd install it with a "./configure; make; make install" command sequence.
The only trouble is that the "./configure; make; make install" sequence will only sanely work at a unix-like system.

Does the package have install instructions that say something different?


DrDima wrote:
I just thought I was going to download a couple .h files and just type #include.
That's part of the process, but not all. A .h file is like a catalogue from IKEA, it does not contain the actual products, just pretty pictures and other information about the products. To actually use the functionality advertised by the .h file, you need to link against the library file (a .DLL in Windows). To use a library it has to be available. To make it available you have to install it. To install it, you have to compile the source code you got in the ncurses package (at least, I assume you got a source code package, GNU rarely distributes compiled code).

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
PostPosted: Fri Dec 07, 2012 10:31 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
Pieman, I took your advice on allegro, I succeeded in installing it, I'll try it tomorrow.

If anyone has good tutorials for it, would much appreciate. Much thanks for the help so far.


Top
 Profile  
 
PostPosted: Sat Dec 08, 2012 1:44 am 
BANNED

Joined: Sun Jun 24, 2012 12:49 am
Posts: 504
Well, this page seems like it should suffice for you to learn how to use Allegro:
http://wiki.allegro.cc/index.php?title= ... _Tutorials

It merely teaches how to use Allegro for whatever purposes you may have. It doesn't actually provide any tutorials regarding specific game programming practices, like "How to implement a controllable character" for a simple adventure game. Here's a few (though not many) tutorials regarding more specific game programming: http://wiki.allegro.cc/index.php?title=Game_Programming

If I find any more good tutorials around on the WWW, I'll be sure to share them here. You should search the Wiki around a bit because it may have some good resources for Allegro. Good luck. :)


Top
 Profile  
 
PostPosted: Sat Dec 08, 2012 7:47 pm 
Making headway so far. Wrote a function to print out a background with tiles.

Watched some bits of this: https://www.youtube.com/watch?v=-naXNT1qSHQ&list=SP6B459AAE1642C8B4&index=13
But mostly it's google and allegro.cc. I like it though, it's simple and effective and the event system is very understandable.


Top
  
 
PostPosted: Sun Dec 09, 2012 4:26 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
Really happy with allegro.
So far I have the character movement down to what I want it. Next step is implementing the collision tile system.
If only I didn't suck so much at making spritesheets.

EDIT: now have implemented the map walk path and have some ugly working sprites


Top
 Profile  
 
PostPosted: Mon Dec 10, 2012 2:23 am 
BANNED

Joined: Sun Jun 24, 2012 12:49 am
Posts: 504
Woh. :ego

I am so glad Allegro is working out very well for you! You are making amazing progress! 'Also glad to have helped a tad. :)

Quote:
If only I didn't suck so much at making spritesheets.
I'm decent at game art... I may contribute soon if you want help. Just send a PM ("Personal Message") to me.


Top
 Profile  
 
PostPosted: Mon Dec 10, 2012 1:49 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
Pieman wrote:
Woh. :ego

I am so glad Allegro is working out very well for you! You are making amazing progress! 'Also glad to have helped a tad. :)

Quote:
If only I didn't suck so much at making spritesheets.
I'm decent at game art... I may contribute soon if you want help. Just send a PM ("Personal Message") to me.


Thanks for the offer. I'll check with my teacher to see I can get external help with the graphics. I probably want to flesh out the game a bit more first.
Next up is structuring my code a little better. Doing this without data structures is becoming a little messy.
I'll keep my progress posted.

EDIT: code is now structured with a couple functions and structs


Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 1:07 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
I've just encontered a problem.
Right now I have a structure which looks like this:

Spoiler: show
Code:
struct Map
{
    attributes....
}
struct Level
{
    struct Map
    other attributes...
}


Next I have a function that looks like this:
Spoiler: show
Code:
void changesth(Level *level)
{
    dosomethingwith level->map->attribute;
}


After my compiler went haywire I realized that I couldn't use the -> operator on the second struct, since it wasn't a pointer.
My question would be: if I change the map->attribute to map.attribute, will the map attribute still be altered in the Level struct?

Edit: I'm getting the urge to make pointers to everything, I'm wondering if that's really necessary.

Edit2: in the end I solved it with pointers, now the double struct dereference works. Little update, I changed my code to accept any background with dimensions that are /32 pixels, this allows me to make corridors, caves, rooms and such without too much patchwork with bitmaps. Also implemented the traveling from map to map. Next up is putting some enemies on the map.


Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 7:21 pm 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 364
Location: Here (where else?)
DrDima wrote:
After my compiler went haywire I realized that I couldn't use the -> operator on the second struct, since it wasn't a pointer.
My question would be: if I change the map->attribute to map.attribute, will the map attribute still be altered in the Level struct?
Yes.
C++ is very consistent in that respect, things work the same way no matter what type you use:
Code:
struct Y { int j; };

struct X {
   int i;
   Y y;
};

X x;
x.i = 3;
x.y.j = 4;
In 'struct X', 'int i' works exactly like 'Y y', except that inside 'y', you have more fields.

DrDima wrote:
in the end I solved it with pointers, now the double struct dereference works.
That works too, except the pointers take extra space, there is one dereference extra on each access, and you have a little more memory management to handle.

The huge advantage of course is that you found a way to make progress, which is also important.

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 8:06 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
Alberth wrote:
DrDima wrote:
After my compiler went haywire I realized that I couldn't use the -> operator on the second struct, since it wasn't a pointer.
My question would be: if I change the map->attribute to map.attribute, will the map attribute still be altered in the Level struct?
Yes.
C++ is very consistent in that respect, things work the same way no matter what type you use:
Code:
struct Y { int j; };

struct X {
   int i;
   Y y;
};

X x;
x.i = 3;
x.y.j = 4;
In 'struct X', 'int i' works exactly like 'Y y', except that inside 'y', you have more fields.

DrDima wrote:
in the end I solved it with pointers, now the double struct dereference works.
That works too, except the pointers take extra space, there is one dereference extra on each access, and you have a little more memory management to handle.

The huge advantage of course is that you found a way to make progress, which is also important.


The problem is I needed to pass those to a function. Also I wanted it to modify the initial struct, and the struct within the struct.
I also forgot to mention that I was trying to put an array of structs into a struct, and not a single one. I think it works well, most compile errors after that were typoes. If it isn't good my C++ teacher surely will point it out.

Thanks for the feedback though. I had to endure 3 hours of class before I could get back home to solve the problem, that's why I got impatient.


Top
 Profile  
 
PostPosted: Sat Dec 15, 2012 10:29 am 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
A little update

It took a whole lot of time to structure my code a little better, but it payed off. I now have a working level selection screen and finite state machine. Things I still need to do is implement the battle system, but game design wise it has pretty much been decided.
It does look like I'll have good competition though, quite a few of my classmates are rather talented when it comes to game development. The winner of this little contest gets extra grades on his final. It's not that I would need those, but I'm a rather sore loser :evil


Top
 Profile  
 
PostPosted: Sat Dec 15, 2012 7:57 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3806
Location: South Africa
Sounds good man, post some screenshots! :)

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
PostPosted: Sat Dec 15, 2012 9:40 pm 
Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
IGTHORN wrote:
Sounds good man, post some screenshots! :)

Image
Image
Image

Probably all of these are just placeholders for testing, but here it is.

On the bright side you'll get to see Pieman's art appear in game screenshots soon. Thanks a lot to Pieman for offering his help!


Top
 Profile  
 
PostPosted: Sun Dec 16, 2012 7:29 am 
BANNED

Joined: Sun Jun 24, 2012 12:49 am
Posts: 504
I'm really liking the look of this! This is an amazing project. I've actually started working on the character already, but tomorrow I will be accelerating about the plane of air at high velocity. Then after I arrive I will be able to get much more work done. I've completely read your design & art specification document and I'm surprised by the creativity behind your game concept. I really like it. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: AHrefs Bot [Crawler], Exabot [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group