Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - chasm

Pages: [1]
1
Programming / Re: Basic game programming concepts
« on: October 15, 2013, 02:15:32 PM »
Quote from: Quendus
To get help with problems in code and software, it's best to provide specific information about what went wrong - no-one can say much about something that "doesn't work", but if you say what doesn't work, when, whether there was an error message at runtime or compile time, what the error messages were, etc., then often there will be someone who's had a similar problem in the past.

You're totally right. I was just thinking it might not be an ncurses thing, but rather a problem of the implementation itself. So maybe someone who never used ncurses might be able to help as well.

This is the actual error that I don't understand:
I used getch() to capture the keyboard input, however it will only return "Press 'q' to quit", even when a key is pressed that I defined to do something else (like the arrow keys or u, h, n, j).
Even though I implemented while (key != 'q') in the function Action(), the program terminates after the second key is pressed.


Quote from: Vanguard
Making "hero" a tile type is a Real Bad Idea.  It's confusing and it'll lead to more than a few problems.  Instead you should have heroX and heroY integers to track their location.  Better yet, make arrays of integers to store the x and y locations of every man, animal, and monster in the dungeon.

I worried about that, too. Would it make sense to write a function like GetLocation() that returns both coordinates? I actually wanted to do this at first, but I didn't really know how to do that (if it makes sense, I will again try to implement it by myself), so I chose the simplest thing I could think of.
What do you mean by arrays of integers? I would have rather thought about a list or a 2-dim. vector. Could you give an example?


Quote from: Vanguard
Even though programming a game is about manipulating abstract data, imo the best way to do it is to think about everything in terms of concrete nouns and verbs (with objects and variables being nouns and functions/methods being verbs).  The tile array describes different segments of the building the game is taking place in.  That description doesn't fit the hero, so he or she shouldn't be tracked by that variable.

This is very interesting.
I've never thought like that. I admit that I rather have a hard time to actually imagine variables and functions like this as I still think of (tile) arrays as tensors rather than actual maps.
But as I'm still a beginner with game programming, I'm not beyond hope, I think.

2
Programming / Re: Basic game programming concepts
« on: October 09, 2013, 06:09:06 AM »
Ok, I still cannot get the code working. Maybe there's someone here more capable of ncurses and C who likes to give me some input.
Nevertheless, I put my code here, maybe I used some wrong approaches in the first place.

Code: [Select]
#include<stdio.h>
#include<stdbool.h>
#include<time.h>
#include<ncurses.h>

#define MAX_X 40
#define MAX_Y 70

int tile[MAX_X][MAX_Y];

// Tile Properties:
const int empty = 0;
const int wall = 1;
const int open_door = 2;
const int closed_door = 3;
const int locked_door = 4;
const int hero = 5;

// Passable objects
bool Passable(int tx, int ty)
{
  bool successful;
  if(tile[tx][ty]==empty || tile[tx][ty]==open_door)
    {successful = true;}
  else
    {successful = false;}

  return successful;
}

// Move
void Move(int x, int y)
{
  if (tile[x][y]==hero)
    {
      if(Passable(x,y+1)==true)
{tile[x][y] = tile[x][y+1];} 
      if(Passable(x-1,y)==true)
{tile[x][y] = tile[x-1][y];}
      if(Passable(x+1,y)==true)
{tile[x][y] = tile[x+1][y];}
      if(Passable(x,y-1)==true)
{tile[x][y] = tile[x][y-1];}
      else
{mvaddstr(0,0,"You cannot pass");}
    }
}

// Open Doors
bool OpenDoor(int tx, int ty)
{
  bool successful;

  if(tile[tx][ty]==closed_door)
    {
      tile[tx][ty] = open_door;
      successful = true;
      mvaddstr(0,0,"The door is opened");
    }
  else
    {
      successful = false;
      if(tile[tx][ty]==empty || tile[tx][ty]==wall)
{mvaddstr(0,0,"There is no door to open");}
      if(tile[tx][ty]==open_door)
{mvaddstr(0,0,"The door is already open");}
      if(tile[tx][ty]==locked_door)
{mvaddstr(0,0,"The door is locked");}
    }
  return successful;
}

// Generate the dungeon
void MakeMap()
{
  for (int x=1;x<=MAX_X;x++)
   {
     for (int y=1;y<=MAX_Y;y++)
      {
tile[x][y]=empty;
int x0 = MAX_X/2;
int y0 = MAX_Y/2;
tile[x0][y0]=wall;    //begin at (x0,y0)
       
for (int i=0;i<=N;i++)
  {
   // here should be a dungeon algorithm
           // just make some random distribution of
   // tile[x][y]=empty;tile[x][y]=closed_door;tile[x][y]=wall;
  }
      }
   }
}

// Put the hero
void Hero()
{
  tile[MAX_X/2][MAX_X/2]=hero;
}


void ShowMap()
{ //ncurses stuff here
  initscr();
  start_color();
  clear();
  cbreak();
  noecho();

  for (int ix=1; ix<MAX_X;ix++)
    {
      for (int iy=1; iy<=MAX_Y;iy++)
{
  switch(tile[ix][iy])
    {
    case 0:
      mvaddstr(ix,iy,"#");
break;
    case 1:
      mvaddstr(ix,iy,".");
break;     
    case 2:
      mvaddstr(ix,iy,"/");
break;
    case 3:
      mvaddstr(ix,iy,"+");
break;
    case 4:
      mvaddstr(ix,iy,"+");
break;
    case 5:
      mvaddstr(ix,iy,"@");
break;
    }
}
    }
  refresh();
  getch();
}
   
 
void Action()
{
  //starting point
  int x = MAX_X/2;
  int y = MAX_Y/2;
  wmove(stdscr,x,y);
  keypad(stdscr, true);   
  int key=getch();
 
  while (key != 'q')
  {
  switch(key)
    {
    case 'KEY_DOWN':
      Move(x,y+1);
      break;
    case KEY_LEFT:
      Move(x-1,y);
      break;
    case KEY_RIGHT:
      Move(x+1,y);
      break;
    case KEY_UP:
      Move(x,y-1);
      break;
    case 'h':
      OpenDoor(x-1,y);
      break;
    case 'j':
      OpenDoor(x+1,y);
      break;
    case 'u':
      OpenDoor(x,y-1);
      break;
    case 'n':
      OpenDoor(x,y+1);
      break;
    case 'q':
      endwin();
    default:
      mvaddstr(0,0,"Press 'q' to quit");
break;
    }
  }
}

int main()
{
  srand(time(0));
  MakeMap();
  Hero();
  ShowMap();
  Action();
  return 0;
}


3
Programming / Re: Basic game programming concepts
« on: October 03, 2013, 09:59:13 PM »
Wow, this is great, thanks a lot.
I guess, I got the idea (or just an idea) how to set tile properties via integers and functions.

I haven't responded yet as I've been trying to implement it to show the result here, but I'm having some minor problems with ncurses and key capture.

I have begun with just one (simple) dungeon, the hero moving around and opening doors. I will put the code here, when I have succeeded.
I also made a boolean fuction similar to the door opening one above to determine wether a tile is passable or not.

4
Programming / Re: Basic game programming concepts
« on: September 30, 2013, 10:04:53 PM »
Ok, I think I got it now, I have just hoped that there acutally would be something 'general' to begin with.
So it's difficult to specify the question I originally asked.
Although your short explanations already helped me.


Quote from: Krice
You are talking about save and load game, right? It really is implementation specific. In C++ and with classes it's actually quite easy, when you build the structure of game as tree-like, with possibly Game World class as the owner of everything else.

This approach sounds comprehensible. I surely will give it a try to follow your code you mentioned.


Quote from: Cfyz
That's why your question looks like "any tutorial on concepts about everything?".

Yes, I now admit that it actually reads like this.
I was mostly referring to concepts that are used by traditional roguelikes. But now I see that even then there are plenty of possibilities do implement this.


Quote from: Vanguard
You could store every tile as a single integer or a char in a multidimensional array and that will work fine.  Open a door and that tile's variable changes from the closed door value to the open door value.  You could make your tiles objects with isPassable, isDoor, isOpen, etc. variables for each one and that would work too.  You could program doors so that they're special objects on tiles instead of being the tiles themselves.  There are any number of possible implementations.

This also sounds very comprehensible and a good approach to begin with.
Do you know by chance a text-based roguelike that uses this approach?


Quote from: Vanguard
Is any specific thing giving you trouble?

Currently, it's basically those examples I mentioned, because I know how to make the hero move and how to generate a dungeon (classical terminal output). It's how to make him interact within the dungeon and its objects.
Moreover I don't want to simply implement something, but also understand why and how it is working.

5
Programming / Re: Basic game programming concepts
« on: September 25, 2013, 11:42:13 AM »
Quote from: george
However your post is a bit paradoxical. You want tutorials that talk about things in a general way, but your example (vectors, arrays, etc.) is implementation details of specific languages.

I think such a tutorial should specify ideas at some point. You need to store information about tiles, like position, properties, etc., so I think there also should be examples how to do that, array was my first idea (a vector is just similar idea-wise), maybe there are other (and better or more general) methods. But with the information “You need to store information” only, it's too general and diffictult to actually implement.

Quote from: george
Have you gone through a complete roguelike tutorial like the Python one at Roguebasin? Many times what seems obvious in observation (i.e. skimming through a tutorial) is only learned through practice (i.e. actually doing the tutorial).

I have read through the one that uses the libtcod library. However, I didn't find it useful to understand game programming profoundly. There were a couple of things that were already implemented within the library, so it wasn't explained how exactly this was coded and why it was done like that.


Quote from: Zirael
You could try using an existing engine such as T-Engine. I believe you could make an interactive fiction game using the engine easily, just making dialogs and buttons.

I don't want to use existing engines as they already have implemented those thing I want to understand.
I'm actually not really interested in interactive fiction either, but I thought that writing something simple like that could help me understand the processes behind.


Quote from: Trystan
The implementation details don't really matter. Pick one approach (like storing the dungeon as an array of chars, or a dictionary of Points and Tiles, or a 2d array of Terrain instances) and play with it for a while. As long as it's encapsulated and other code isn't looking into the details of it, you'll be able to change it when you need to. Clean code hides those details anyway. So I often have a World class with methods like isOpenDoor(x,y), isClosedDoor(x,y), blocksVision(x,y), getCreature(x,y), etc. How that's handled within the Wold class (vector, arrays, etc) doesn't really matter and if it does (performance reasons, torus shaped worlds, blood splatters, etc) then I swap the implementation out for something more complex

Your short explanation quite describes what I'm looking for, like those examples you mentioned.
I just need something to begin with.

6
Programming / Basic game programming concepts
« on: September 24, 2013, 10:12:01 AM »
I know how to implement some basic RL components such as displaying characters in a terminal and make them moving or different kinds of dungeon algorithms. I have also written a lot of numerical programs, so it's not like I'm a complete beginner.
But when it comes to actual gameplay, I'm stuck how to do this.

Things like how (vectors, arrays, etc.) to store information about tiles (like open/closed for a door or traversable/non-traversable, etc.) or loading a new dungeon when leaving the screen, etc. So actually things that are not unique to roguelikes, but are necessary for games in general.
I haven't found any tutorial that stresses such concepts in a more general fashion, i.e. simply the ideas how to do this rather than giving instructions how to write this in a certain programming language with a certain library.

Do you know any good tutorials or even a book about this?
What would you consider the best to begin with?

I have thought about writing something similar to interactive fiction, just to get an idea how to implement acting within the game, would this be a reasonable start?

Thank you in advance.

Pages: [1]