Author Topic: Implementing stairs  (Read 20704 times)

Vanguard

  • Rogueliker
  • ***
  • Posts: 1112
  • Karma: +0/-0
    • View Profile
Implementing stairs
« on: April 25, 2009, 09:59:50 PM »
Hey everyone!

I'm working on a roguelike project, but I'm still pretty inexperienced as a programmer, so I thought I would ask for advice on this.

How should I connect the stairs in different floors with each other?  I'm going to have persistent levels and sometimes the dungeons will have branching paths, so I can't just have a depth variable that I add or subtract 1 from.  The best thing I can come up with is by making each floor its own subclass of the stage class, something like this:

class Tower1 extends Stage {

    Tower1() {
        int numberOfStairs = 2;
        stairs[0] = worldMap;
        stairs[1] = tower2;
    }
}

class Tower2 extends Stage {

    Tower2() {
        int numberOfStairs = 3;
        stairs[0] = tower1
        stairs[1] = tower3;
        stairs[2] = tower4;
    }
}

worldMap, tower1, tower2, etc would all be constant variables for referencing each map.

Oh, and I'm using Java if that makes a difference.

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: Implementing stairs
« Reply #1 on: April 26, 2009, 10:11:20 AM »
Looks reasonable and I am sure it will work. There are no best ways to do this, yours is good.
Next problem is linking the tile with stairs in it to the correct stairs[X] reference.

This could easily be extended for multiple stairs to the same area if needed.
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Implementing stairs
« Reply #2 on: April 26, 2009, 02:57:13 PM »
Create stairs object that has destination level and destination stairs id stored in it.

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: Implementing stairs
« Reply #3 on: April 27, 2009, 10:35:51 AM »
Step 2 Create Roguelike.  ;D
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Implementing stairs
« Reply #4 on: May 07, 2009, 07:13:31 AM »
The real problem is determining the connections between level branches. I'm having problems with that myself, because the tree structure is too much for me to handle. Maybe the dungeon could be divided into theme based areas (one or more level) with connections to other areas (level themes). Or then the branches itself could be named so they know where to connect.

Darren Grey

  • Rogueliker
  • ***
  • Posts: 2027
  • Karma: +0/-0
  • It is pitch black. You are likely to eat someone.
    • View Profile
    • Games of Grey
Re: Implementing stairs
« Reply #5 on: May 07, 2009, 05:45:58 PM »
Just treat them as different dungeons.  D20 connects to D21 and L1, L5 connects to U1, U15 connects to D40, etc.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Implementing stairs
« Reply #6 on: May 08, 2009, 03:40:11 PM »
Just treat them as different dungeons.  D20 connects to D21 and L1, L5 connects to U1, U15 connects to D40, etc.

That is the theory. In practice it's always a bit more complex. By the way, I'm implementing stairs (and dungeon structure) in Agduria. I managed to make some kind of system with stairs between sections (themes) but still have to figure out how to connect themes to each other. Check out the source code of latest Agduria version (world.cpp contains the level node connection code):

http://koti.mbnet.fi/paulkp/agduria/Agduria0509n.zip

Vanguard

  • Rogueliker
  • ***
  • Posts: 1112
  • Karma: +0/-0
    • View Profile
Re: Implementing stairs
« Reply #7 on: May 08, 2009, 11:11:39 PM »
I appreciate everyone's advice.  It's up and working now.  I did it essentially the way it's done in my post.

I connected the stairs to each other by checking where you're coming from up against where you're going to, and it sets the player character's location to that of the matching set of stairs.  As long as I don't make two sets of stairs in one level that both lead to the same level there won't be any problems with this, and I don't think I'll ever have any reason to do that.

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: Implementing stairs
« Reply #8 on: May 09, 2009, 12:12:59 AM »
My stairs are usually just standard objects with a destination level and location. The stairs are always generated in pairs though, so if I want to link level 5 and 10, I would generate a corresponding staircase in each, pointed to the level and location of the other.