This is the archive of the old Colorless! Go to the new Colorless →

C. (Thread)

Any C/C++ programmers/people who want to learn C out there? Let's chill here and talk some code! This is where you can share codes, or ask questions, about one of the most successful programming languages out there!

Here's something very interesting to read for you guys about a particularly amazing and famous piece of C code:

Very interesting indeed. Hope more people show up on this topic.

Today, I finished my exam project, written in C++. It's a Pokémon Fight Simulator where you get to choose between Charizard, Venusaur and Blastoise and then battle another human player. I chose to make this program using graphics, which was included in the (SFML) library.

What I've written is well above the standards in my class. It's around 9 files and above 1000 lines of code, so I won't post the code here xD

The sfml library is a PAIN to install. However, if you succeed with the install, it's a very easy and useful library, that I can only recommend ;)

Feel free to ask questions about my program. I'll try to zip all the pictures, music and .dll's if I can manage to find them all ;o)

Here's a screenshot:


yeah, that's great and all BUT WHERE IS YOUR PHYSICS ENGINE?!? XD Just Kiddn' it's awesome XD

and I thought this was going to be about the anime ;S

Ooh, nicely done @RangleGoose GUIs always impress me! For your C++ Pokemon code, how'd you organize the data for each Pokemon? I have a few guesses on how to do it with structs or classes but I'm curious on your approach to it. Do you have an output file or executable to distribute for running it?

Also for C++, what compiler do you use? I personally use Cygwin for general purposes but for certain specialized compilations, such as my DS programming, I use MinGW.

I'm working on DS programming a bit right now actually, using <nds.h> The hard part I had was getting the Makefile to actually convert the code into and NDS output. I'll hopefully have something cool to show on that soon for you guys ^^


I'm pretty sure I'm organizing my code pretty ridiculously stupid. Almost ALL of my declarations of sf::String (Text strings that can be output in the RenderWindow), sf::Sprite etc. etc. is in int main(). This is however mostly because I had some trouble with multiple definitions in my header file.

Anyway, my pokemons are written in classes, like this:

class Pokemon  
        char Name;  
        int Health;  
        EnumType PType;  
        PAttack Attacks[4];  
        void HealthDeduction();  
class Charizard: public Pokemon  
            Name = 'C';  
            Health = 200;  
            PType = FIRE;  
        void init(PAttack p1,PAttack p2,PAttack p3,PAttack p4);  

I then declared one of each pokemon and Player1 + Player2 of the Pokemon class. In my "ChooseWindow" I then set Player1 to be equal the pokemon player1 would choose. That way, I don't have to declare multiple Charizards if both players choose Charizard.

In school, we were told to get Bloodshed Dev-C++, which uses MinGW. However, when I wanted to create a GUI with SFML, I was forced to install Code::Blocks, also using MinGW.

My friend found these programming languages. And... They're pretty hilarious xD


vv  <      <  
    ^  v<  
    ^   ^  
>  >?>  ?>5^  
    v   v  
    v  v<  
 .  >  >   ^  

This code right here generates an endless stream of random numbers xD

Ah, Code Blocks I never really enjoyed too much since I couldn't get it to support arguments properly ever. I guess I'm a traditionalist in that I enjoy the feel of Unix shells a bunch.

I think I understand how you did the Pokemon classes. I'm curious in terms of the Charizard one, did you include type flying for him, or no? I guess the easiest thing I can think of would be PType1=FIRE; PType2=FLYING; or something similar, and for Pokemon will one type just PType2=NONE; or that. It's pretty cool you managed to make it all though, I'm impressed.

Also LOLCODE should be taught at universities everywhere.

This is an example of some fundamental code using <nds.h>

void initVideo(){  
    vramSetBankC( VRAM_C_SUB_BG_0x06200000);  

Basically now I can just call initVideo(); in my main function and it'll do everything. Here's a good page on DS visual RAM so you can avoid nasty visual overwrites:

I'll hopefully get a picture or something up for you to enjoy soon!

As of now, I only gave each pokémon 1 type and the gameplay is pretty bad too. But it's for my exam, so it's more about showing off my code rather than gameplay. I have to finish the program and write a paper due 2 weeks time. Besides this, I have to make a webpage and a paper for that too. Because of this, I'll probably not add anything new to the program, but it's likely that I'll expand it in the future.

I originally planned to make it possible for the player to "create" there own pokémons by inputting data into a class, but it'd take too much time I recon.

Anyway, I'm always happy to learn more, as this is what I plan to do in the future. (I'm going to study Computer Science at the university next year)

P.S. I have absolutely NO idea what that code does. I'll probably look into it later though ;o)

P.P.S. I kinda like BloodShed Dev-C++ more than Code::Blocks too... But I was kinda forced by SFML into using it ;o). For what I've been writing, it's not bad at all though.

As I couldn't find any compiler for LOLCODE, I found this online JavaScript interpreter instead, should anyone want to try it out ;D

Haha, the code first off sets the top and bottom screens of the DS to video mode 5, which is pretty standard. Then I prepare three visual RAM banks, two for the top screen and one for the bottom screen, all three for 256x192 backgrounds (defined later). The two backgrounds for the top screen I get to overlap (defined later). I end up having custom libraries made for all the graphics (kinda a pain) which ends up looking like this:

#include "pokewall.h"  
#include "topwall.h"  
#include "gold.h"  
#include "bianca.h"  
#include "hilda.h"  
#include "misty.h"  
#include "bottom.h"

And the final result of the code is something similar to this:

Right now I'm working on getting more functionality into it. Currently I just have it so you hit up/down and it'll scroll through different character graphics on the top screen. I know how to do touch screen controls but haven't really delved into sprites yet, so I'm working on all that for a more polished final product.

I should have something more soon! ;D

Also that online compiler is great ahahaha.

Oh, that seem really interesting! I'm looking forward to seeing the end result. Or at least your progress ;o).

I don't really know whether I should try to add more functions to my current pokémon program, start on another project or optimize my code.

As I said, I'm pretty sure my code is NOT written in any good way (Almost everything is declared in in main()). So it'd be great for me to optimize my code. However, I've been thinking and I really want to write a card game simulator thing. Like, it's a table where you can move cards around as you wish and you can load your own decks (ANY kind of card game). There's no rules in the program, so you and your opponent is free to do whatever (Like if you're playing in real life).

That sounds like you'll need to have pretty strong databases to remember whatever the rules are when you set them. It's a difficult project from the sounds of it, but I'm definitely interested in seeing that play out.


Hopefully I'll be done with this simple test tonight. I had a great idea for something last night and I want to dive into that soon. XD

Wow, that looks really cool. Where do you get your sprites? Do you crop them from screenshots or make them yourself? Or something else entirely? I got mine by taking screenshots from varius YouTube videos, so the quality wary a lot xD

WHUT. I don't even...
All this...coding, can't comprehend. OTL

Oh dude you're going to love me for introducing you to this:

@Haikku |D

This NDS game stuff reminds me of the beginning of this school year because the project was to make a NDS game. =P In the end my team only had an unfinished crappy platform/shooter because of dropout problems etc. But it was a fun project nonetheless!
But the biggest problem everybody in my class had was the lack of documentation which could be found online. So most people had to put more time in finding out how everything worked compared to really making the game. xD Did you have any problems with that?

Oh believe me I have problems with that even as we speak, specifically with the DS' lacking audio system and it's really just absurd way of dealing with sprites. XD I don't see myself going too far with the DS beyond this really. It's fun, but without a legitimate development kit from Nintendo themselves, incredibly tedious.



You are on the old site. New site is here:

The site has been updated on the 24th December 2011. Please go there when you are finished with the archives.

  • 481,435 posts
  • 2,075 threads
  • 23,121 users