Nibbles (src included)

This is a discussion on Nibbles (src included) within the Game Programming forums, part of the General Programming Boards category; well, i got bored one night last week so i decided to write a low quality nibbles hack. I dont ...

  1. #1
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640

    Nibbles (src included)

    well, i got bored one night last week so i decided to write a low quality nibbles hack. I dont plan on doing anything more with the project so feel free to hack on the source if you want (just give credit to "Perspective from the cboard" or something like that in your src/readme).

    Known Crappyness:
    - Parts of Nibbles.cpp should be refactored into a Board class
    - Colours should be associated with GraphicObject's, not hard-coded
    - Game-play code is border line non-existant, this game runs and follows the general nibbles ideology, but it isnt fun.
    - Theres no commenting (hey, one evening of bordom coding, what do you expect?)
    - the graphics are about as basic as the possibly can get.
    - no pause functionality
    - key commands should be queued in a game like this, if they are entered faster than an update can execute, only the last one has any effect.
    - I used an STL vector to hold the items This should be a list structure like the snake itself.

    How to Do Stuff:
    -press Q to quit, R to restart, and arrow keys to steer your snake.
    -on linux boxes, extract source and type make to build.
    -on windows, create a project with whatever it is you use, add #include <windows.h> to any file that includes GLUT and you should be set. (though i havent tried this on windows)

    bon apetite!
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    ok, 23 downloads, i think its fair to poke a bit

    i think most of you guys use windows, anyone compiled/run it successfully on windows?
    anyone planning on messing around with the source? new front end or gameplay? i have some ideas for mods of the traditional game, i was also considering writing AI for a compeditor snake. (so much for me not planning to continue with this project )
    any questions / comments are welcome.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by Perspective
    anyone compiled/run it successfully on windows?
    Here's a how-to for dev-cpp (windows), if anyone's interested:
    1. If you don't already have GLUT then download GLUT for Mingw32 from this page. Follow the readme.txt in the glutming.zip download to add relevant headers, libs and glut32.dll to their respective directories.
    2. Open up dev-cpp and create a new console, c++ or windows c++ project
    3. Add Perspective's source files to your project (project menu--> Add to project). No modifications to those files are required.
    4. Now add the libs: project menu --> project options, select 'parameters' tab. Add the following to the 'linker' field:
      Code:
      -lglut32 
      -lopengl32 
      -lglu32
    5. A couple of options need to be passed to the compiler; the first is mandatory the second may not be (it isn't if you build from the command line). Open the 'projects' dialog (if you have closed it) to the 'parameters' tab as described for 'libs' above and add the following to the 'C++ Compiler' field:
      Code:
      -DGLUT_DISABLE_ATEXIT_HACK
      -D_WCHAR_T_DEFINED
    6. Compile the project

    If you built as a console project you'll get a console and a window; the console displays some information about game progress.
    Quote Originally Posted by Perspective
    any questions / comments
    Question - Why GLUT? [/rhetorical]
    Comment - I hate GLUT.

    A score would be nice but it's very playable all the same. Good stuff.

    edit: Made some corrections - it's ok to build as a windows project and not just as a console as I originally had.
    Last edited by Ken Fitlike; 07-30-2004 at 07:39 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Ken Fitlike
    Here's a how-to for dev-cpp (windows), if anyone's interested:
    wow, thanks Ken.

    Quote Originally Posted by Ken Fitlike
    Question - Why GLUT? [/rhetorical]
    Comment - I hate GLUT.
    heh, basically i used glut because 1) i wanted to keep the project simple. 2) i like linux, most users here on the game board use windows, glut is a pretty nice multi-platform solution.

    Quote Originally Posted by Ken Fitlike
    A score would be nice but it's very playable all the same. Good stuff.
    Hmmm, music eh? might be worth the time. thanks for the feedback

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >Hmmm, music eh?
    I think he means keeping score, so you can compare how much you 0wnz0r vs other people on the board.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,199
    Just for your info, VS.NET 2002 complained about only const static integral data members is allowed to be initialized inside a class or struct. It is easily fixed though (if anybody else has this problem):
    Code:
    // Change this in Item.h
    class Item : public GraphicObject {
    
     protected:
      int points;
      int lifeTime;
      int creationTime;
      const static float len = 1.0f / (2*(WIDTH+5)); // 1/2 length of drawable width/height
    
     public:
    	 Item() { init(); }
      Item(Point2i p) { setPos(p.x, p.y); init(); }
      Item(int x, int y) { setPos(x, y); init(); }
     ~Item() {}
    
      void init() { points = 0; }
      void setPoints(int p) { points = p; }
      int getPoint() { return points; }
    
      virtual void draw();
    };
    
    // to
    
    class Item : public GraphicObject {
    
     protected:
      int points;
      int lifeTime;
      int creationTime;
      const float len; // 1/2 length of drawable width/height
    
     public:
    	 Item():len(1.0f / (2*(WIDTH+5))) { init(); }
      Item(Point2i p):len(1.0f / (2*(WIDTH+5))) { setPos(p.x, p.y); init(); }
      Item(int x, int y):len(1.0f / (2*(WIDTH+5))) { setPos(x, y); init(); }
      ~Item() {}
    
      void init() { points = 0; }
      void setPoints(int p) { points = p; }
      int getPoint() { return points; }
    
      virtual void draw();
    };
    And
    Code:
    // In file SnakeBit.h change
    class SnakeBit : public GraphicObject {
    
      SnakeBit* next;
      const static float len = 1.0f / (2*WIDTH); // 1/2 length of drawable width/height
    
     public:
    	SnakeBit() { next = NULL; }
        SnakeBit(const Point2i p) { setPos(p.x, p.y); next = NULL; }
        SnakeBit(int x, int y) { setPos(x, y); next = NULL; }
        ~SnakeBit() {}
    
        SnakeBit* getNext() { return next; }
    
    
        void setNext(SnakeBit* n) { next = n; }
    
        void moveVertical(int amount) { pos.y += amount; }
        void moveHorizontal(int amount) { pos.x += amount; }
    
        virtual void draw();
    };
    
    // to
    class SnakeBit : public GraphicObject {
    
      SnakeBit* next;
      const float len; // 1/2 length of drawable width/height
    
     public:
    	SnakeBit():len(1.0f / (2*WIDTH)) { next = NULL; }
        SnakeBit(const Point2i p):len(1.0f / (2*WIDTH)) { setPos(p.x, p.y); next = NULL; }
        SnakeBit(int x, int y):len(1.0f / (2*WIDTH)) { setPos(x, y); next = NULL; }
        ~SnakeBit() {}
    
        SnakeBit* getNext() { return next; }
    
    
        void setNext(SnakeBit* n) { next = n; }
    
        void moveVertical(int amount) { pos.y += amount; }
        void moveHorizontal(int amount) { pos.x += amount; }
    
        virtual void draw();
    };
    This was the only way I could get the game running (if I copied it correctly ) but otherwise it is nice!
    Last edited by Shakti; 07-31-2004 at 12:17 PM.

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by XSquared
    >Hmmm, music eh?
    I think he means keeping score, so you can compare how much you 0wnz0r vs other people on the board.
    heh, yeah. that was my attempt at dry sarcasm

    Quote Originally Posted by Shakti
    VS.NET 2002 complained about only const static integral data members is allowed to be initialized inside a class or struct
    hmm, i thought const static members were allowed to be initialized that way. gcc doesnt complain, and it looks like dev-cpp doesnt complain either. Im not entirely sure what the standard is but i think id put my money with gcc over microsoft

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    1,199
    Yah so would I but just thought you would like to know.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. (autotools) make does not decent to src
    By kroiz in forum Linux Programming
    Replies: 3
    Last Post: 01-29-2009, 01:12 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Fully Realized Nibbles Game--Please Comment!
    By SmashBro in forum Game Programming
    Replies: 4
    Last Post: 02-07-2003, 03:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21