Author Topic: where to go now?  (Read 21261 times)

bocochoco

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Email
where to go now?
« on: September 08, 2009, 07:44:56 PM »
Makes a little @ run around the screen... I honestly am not sure how to continue at this point. Whats the next best logical step?

Code: [Select]
#include <stdio.h>
#include <curses.h>
#include <string.h>

using namespace std;

int main()
{
    int rows, cols;
    char msg[] = "Press wasd to move around. Shift+E to exit";

    int px = 15;
    int py = 15;
    bool running = true;

    initscr(); // Begin Curses
    curs_set(0);
    getmaxyx(stdscr, rows, cols);

    init_pair(1, COLOR_GREEN, COLOR_BLACK);
    init_pair(2, COLOR_CYAN, COLOR_BLACK);
    init_pair(3, COLOR_MAGENTA, COLOR_BLACK);

    attron(COLOR_PAIR(2));
    mvprintw(rows / 2, (cols / 2) - (strlen(msg) / 2), "%s", msg);\
    attroff(COLOR_PAIR(2));

    while(running)
    {
        int ch;
        ch = getch();

        switch(ch)
        {
            case 0x77:              // w key
                if(px > 0)
                    px -= 1;
                break;
            case 0x73:              // s key
                if(px < rows - 1)
                    px += 1;
                break;
            case 0x61:              // a key
                if(py > 0)
                    py -= 1;
                break;
            case 0x64:              // d key
                if(py < cols - 1)
                    py += 1;
                break;
            case 0x57:              // W key
                px = 0;
                break;
            case 0x53:              // S key
                px = rows - 1;
                break;
            case 0x41:              // A key
                py = 0;
                break;
            case 0x44:              // D key
                py = cols - 1;
                break;
            case 0x45:              // E key
                running = false;
                break;

        }
        clear();
        attron(COLOR_PAIR(1));
        mvprintw(px, py, "@");
        attroff(COLOR_PAIR(1));

        refresh();
    }

    endwin(); // End Curses
    return 0;
}

magellan

  • Rogueliker
  • ***
  • Posts: 91
  • Karma: +0/-0
    • View Profile
    • Email
Re: where to go now?
« Reply #1 on: September 08, 2009, 08:35:26 PM »
I'd go with a map. either hardcoded for starters, or generated.
Next step Items
Then Monsters
Then you have a finished roguelike :)

freeofme

  • Newcomer
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Email
Re: where to go now?
« Reply #2 on: September 08, 2009, 09:03:01 PM »
This is actualy a pretty good basic guide.

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: where to go now?
« Reply #3 on: September 08, 2009, 11:41:46 PM »
Definitely a map next. Use an array, loop over it for display like: for(i=0;i<80;i++)for(j=0;j<25;j++)Map[ i][j]; Then monsters, etc.. :)

Fenrir

  • Rogueliker
  • ***
  • Posts: 473
  • Karma: +1/-2
  • The Monstrous Wolf
    • View Profile
Re: where to go now?
« Reply #4 on: September 09, 2009, 01:19:21 AM »
You included string.h but you use c-style strings. You do need c-style strings for the curses functions, but you can use c_str() to convert c++ strings to c-style strings.

Code: [Select]
string msg = "Press wasd to move around. Shift+E to exit";

mvaddstr(rows / 2, (cols / 2) - (msg.length()/ 2),msg.c_str());
That should work.

bocochoco

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Email
Re: where to go now?
« Reply #5 on: September 09, 2009, 01:51:53 PM »
You included string.h but you use c-style strings. You do need c-style strings for the curses functions, but you can use c_str() to convert c++ strings to c-style strings.

Code: [Select]
string msg = "Press wasd to move around. Shift+E to exit";

mvaddstr(rows / 2, (cols / 2) - (msg.length()/ 2),msg.c_str());
That should work.

I tried that before, gave me a lot of errors. Replaced #include <string.h> with nothing, errors for missing string header. #include <string> however exploded:

include\c++\3.4.5\bits\char_traits.h|117|macro "move" passed 3 arguments, but takes just 2|
include\c++\3.4.5\bits\char_traits.h|184|macro "move" passed 3 arguments, but takes just 2|
include\c++\3.4.5\bits\char_traits.h|185|error: invalid function declaration|
include\c++\3.4.5\bits\char_traits.h|265|macro "move" passed 3 arguments, but takes just 2|
include\c++\3.4.5\bits\char_traits.h|266|error: invalid member function declaration|
include\c++\3.4.5\bits\char_traits.h|335|macro "move" passed 3 arguments, but takes just 2|
include\c++\3.4.5\bits\char_traits.h|336|error: invalid member function declaration|
include\c++\3.4.5\bits\basic_string.h|604|error: expected `)' before '->' token|
include\c++\3.4.5\bits\basic_string.h|1039|macro "erase" passed 2 arguments, but takes just 0|
include\c++\3.4.5\bits\basic_string.h|1040|error: invalid member function declaration|
include\c++\3.4.5\bits\basic_string.h|1052|macro "erase" passed 1 arguments, but takes just 0|
include\c++\3.4.5\bits\basic_string.h|1053|error: invalid member function declaration|
include\c++\3.4.5\bits\basic_string.h|1072|macro "erase" passed 2 arguments, but takes just 0|
include\c++\3.4.5\bits\basic_string.h|1073|error: invalid member function declaration|
include\c++\3.4.5\bits\basic_string.tcc|280|macro "move" passed 3 arguments, but takes just 2|
include\c++\3.4.5\bits\basic_string.tcc|415|macro "move" passed 3 arguments, but takes just 2|
include\c++\3.4.5\bits\basic_string.tcc|581|macro "erase" passed 1 arguments, but takes just 0|
||=== Build finished: 17 errors, 0 warnings ===|



I'm still quite new to c++, since I haven't used it in over a year. Figured it would be a good way to learn it again to do something that I enjoy in it. Are there any code examples for how to implement a map? Or little helpful tidbits of information? The thing that I know I'm going to have the most difficulty with is making a map that is bigger than the console window centering on the player.

Thanks ^_^
« Last Edit: September 09, 2009, 02:03:07 PM by bocochoco »

Z

  • Rogueliker
  • ***
  • Posts: 905
  • Karma: +0/-0
    • View Profile
    • Z's Roguelike Stuff
Re: where to go now?
« Reply #6 on: September 09, 2009, 04:03:19 PM »
You included string.h but you use c-style strings. You do need c-style strings for the curses functions, but you can use c_str() to convert c++ strings to c-style strings.

What's the problem? <string.h> is a string library for C, he uses C-style strings in his program and Curses use C-style strings. It's alright.

Of course C++ strings from <string> are much better (especially for newbies, as C strings are very low level).

I tried that before, gave me a lot of errors. Replaced #include <string.h> with nothing, errors for missing string header. #include <string> however exploded:

I think you should #include <string> before curses (i.e., the order of inclusion matters here). You also have to add "include namespace std;".

Fenrir

  • Rogueliker
  • ***
  • Posts: 473
  • Karma: +1/-2
  • The Monstrous Wolf
    • View Profile
Re: where to go now?
« Reply #7 on: September 10, 2009, 12:34:14 AM »
What's the problem?
I don't know as much as I thought I did. That is the problem. Sorry....