Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 55 56 [57] 58 59 ... 72

Author Topic: The Roguelike Development Megathread  (Read 245580 times)

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: The Roguelike Development Megathread
« Reply #840 on: November 23, 2012, 03:34:50 pm »

I don't have my code in front of me(I'm at work), but I seem to remember I do something similar to the following:

1)  Have a list of lists of Tile objects.  Tile objects contain the character they render as, and some other minor things like if the tile blocks movement,etc.  the first list represents the X, the second represents the Y.  (or maybe the other way around?  Doesn't matter).  I can access an individual tile like : tiles[34][98]
2)  I've got two other important variables.  redraw_all(boolean) and redraw_list (a list). 
3)  If redraw_all is set to true, the entire map(only within the boundaries of the visible screen) is redrawn.
4)  If redraw_all is set to false, then I only redraw the tiles inside the redraw_list.  These tiles are marked for redrawing whenever something happens(like a monster moves).
5)  All of these are drawn to a temporary buffer.  As the last step, I copy the entire buffer to the actual "Screen".  This is MUCH faster than drawing each tile directly to the screen individually in libtcod, and probably is true for other libraries as well.
« Last Edit: November 23, 2012, 03:39:47 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: The Roguelike Development Megathread
« Reply #841 on: November 23, 2012, 03:45:25 pm »

alright thanks, I'll experiment with that idea a bit and tell you how it goes.

EDIT:

I hope you're familiar with Slick. If not I'm sure I can provide some pseudo-code or something.

Code: [Select]
package aldaron;

import java.util.Arrays;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input; //unused
import org.newdawn.slick.SlickException;


 
public class Aldaron extends BasicGame {
   
     int mapSize = 5;//this is the # of both rows and columns
     int sizeCompare;
     int colInc;
     Image Tiles[][] = new Image[mapSize][mapSize];

     public Aldaron() {
        //text in upper left corner
        super("Aldaron - A World Apart");
    }
 
    @Override
    public void init(GameContainer gc) throws SlickException {
           //generates the player and characters
           //empty
        for(sizeCompare =0; sizeCompare < mapSize; sizeCompare++) {
           
            Arrays.fill(Tiles[sizeCompare], mapLocal.Image());
           
        }
       
    }
 
    @Override
    public void update(GameContainer gc, int delta) throws SlickException {
        //updates the game
        //currently updates player movement <<outdated desc>>
        //empty
   
        }
 
    public void render(GameContainer gc, Graphics g) throws SlickException {
        //renders tiled map and characters
        for(sizeCompare = 0; sizeCompare < mapSize; sizeCompare++) {
           
            for(colInc = 0; colInc < mapSize; sizeCompare++) {
               
                Tiles[sizeCompare][colInc].draw(0 + 20 * colInc, 580 - 20 * sizeCompare, mapLocal.globalSc);
               
            }
           
        }
       
    }
   
    public static void main(String[] args) throws SlickException {
        //sets window and starts the game
         AppGameContainer app =
new AppGameContainer(new Aldaron());
 
         app.setDisplayMode(800, 600, false);
         app.start();
    }
}

Anyways, the Tile Images are stored in a 2-Dimensional array (the one named 'Tiles') which retrieves the images from another class (mapLocal) and using the for loop(s) under 'render' the tiles should be positioned in order from left-to-right and bottom-to-top. It SHOULD set the coordinates (and scale) for the tile from the bottom left first then going right. After it reachs the fifth tile, it should increase the row and restart that process until all the tiles are out, the problem is I'm getting an OutOfBounds exception and I'm not sure why. Did I not properly define the limit of the loops? or does the problem lay within 'render' itsself? (In which case I'd have to rewrite the code)

Once again, all help appreciated

This is the main class for the "game" sorry that some of the descriptive text is out of date, I didn't update it as this is still kind of a test.

If you guys would also like pseudo-code, other classes, or more desciptions i'd be glad to offer it.
« Last Edit: November 23, 2012, 06:46:38 pm by Urist McScoopbeard »
Logged
This conversation is getting disturbing fast, disturbingly erotic.

jhxmt

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #842 on: November 23, 2012, 06:55:29 pm »

Probably not related to the issue, but aren't you making the Tiles arrays one item bigger than you need?  You're setting them as Tiles[5][5], which means a total of 36 items (right?  I'm assuming Slick counts from zero too), but then you only ever access it when sizeCompare < 5.  So the items in column [5] and row [5] don't ever get set or accessed or used?

Or am I entirely misreading the syntax?  Never run into Slick before, and my brain's in Friday mode.  ;)
Logged
Quote from: beefsupreme
Try slaughtering a ton of animals, meat makes less decisions than animals.

Why Your Ramps Don't Work
How To Breach A Volcano Safely

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: The Roguelike Development Megathread
« Reply #843 on: November 23, 2012, 07:04:12 pm »

I was under the impression that '5' was the length and each 'column' in a 'row' went '0' '1' '2' '3' '4'

Did I say this was in Java? well it is. Im pretty sure that by setting mapSize equal to 5 and setting the physical size of Tiles array to mapSize and setting the loop to < mapSize that it's all contained as the 1st stored instance in the array is 0 and the last 4.
« Last Edit: November 23, 2012, 07:10:21 pm by Urist McScoopbeard »
Logged
This conversation is getting disturbing fast, disturbingly erotic.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #844 on: November 23, 2012, 07:07:57 pm »

Tiles[5][5] declares a 5 by 5 rectangular array (I think). The problem here is that in the inner loop you are still increasing sizeCompare, not colInc, so sizeCompare will increase without being checked against the map size.
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: The Roguelike Development Megathread
« Reply #845 on: November 23, 2012, 07:11:38 pm »

ooooooooooh, whoops. I see, well let me change that around and see if it renders properly

EDIT: well the application now runs without giving an OutOfBounds exception, but the tiles do not render. I will explore this and give an update soon.

once again thanks for the help guys!

EDITEDIT: I feel like this is a bit weird, is their a more common way of rendering Tiles? Ya see: Slick goes through LWJGL which goes through openGL (as I'm sure some of you know) so should I be rendering it with those libraries? I have heard alot of explanations using buffers and quads, but I feel like they've gone right over my head!
« Last Edit: November 23, 2012, 07:21:57 pm by Urist McScoopbeard »
Logged
This conversation is getting disturbing fast, disturbingly erotic.

Kerbobotat

  • Escaped Lunatic
    • View Profile
Re: The Roguelike Development Megathread
« Reply #846 on: November 24, 2012, 08:11:12 am »

I wonder if the working directory has changed when using NP++?  Then it might be looking for libtcod-VS.dll elsewhere instead of in your code directory.  Might be worth looking around for an NP++ path config option.


Thanks, Ill check that out.


Quote
Yeah, I ran into a similar error when I shifted my working directories around (trying to lend a bit of structure to my floundering) and forgot to copy the libtcod DLL along with everything else.  All files where they should be?


I've got the font.png, the libtcodVS.dll and the SDL.dll in there with it, been playing around with it all morning, but still no luck. It seems I can run the program, by double-clicking on the python file itself in windows explorer. Everything executes fine then. I guess I'll just use this method for now. Thanks for all the help guys!
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: The Roguelike Development Megathread
« Reply #847 on: November 24, 2012, 10:05:17 am »

UPDATE: I asked over on the slick forums and an amiable chap suggested using a spritesheet, I rewrote the code and the tiles now render, and very efficiently, I can fill the whole 800*600 screen with 20*20 tiles (1200 tiles?) with 700+ ping.

Next, I'll be working on a menu, this'll take a while, so I'll proabably be back. Thanks to all the chaps who helped out!
Logged
This conversation is getting disturbing fast, disturbingly erotic.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: The Roguelike Development Megathread
« Reply #848 on: November 24, 2012, 10:59:39 am »

UPDATE: I asked over on the slick forums and an amiable chap suggested using a spritesheet, I rewrote the code and the tiles now render, and very efficiently, I can fill the whole 800*600 screen with 20*20 tiles (1200 tiles?) with 700+ ping.

Woot! 
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: The Roguelike Development Megathread
« Reply #849 on: November 24, 2012, 11:06:06 am »

Ya, slick is an ultra-lightweight graphics library. You should check it out, google 'slick2D'  ;)

I've been fleshing out the Idea, I'm going to be creating a politcally-adventurery-hopefully cinematic roguelike.

It'll have some strategy elements, fighting elements, and realm-managing elements (cities & eventually duchies/kingdoms, or vice versa, im not sure what I want to do first) in addition to dungeons and a procuderal story.

I'm working on game states right now, then I'll work the opening splash and menu.
Logged
This conversation is getting disturbing fast, disturbingly erotic.

Abalieno

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #850 on: November 29, 2012, 11:52:42 pm »

I've been messing for a while with libtcod and C++ as well, though I really just started to read a couple of C++ books and learning completely on my own.

Even if I know almost nothing about C++ and programming in general, I still was able to figure out some stuff.

Currently working with implementing different font sizes into libtcod (which is not supported).

Logged
 HRose / Abalieno
cesspit.net

jhxmt

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #851 on: November 30, 2012, 05:49:23 am »

I'm giving myself a headache trying to implement a player-focussed scrolling map, rather than a static map that the player moves around on.  I'm not even trying anything fancy like saving/loading new areas - I'm trying the simplest possible form (I hope)!  :-\

I've got my gameworld map, BigMap, which is a multidimensional list of Tiles - BigMap[500][500], for example, contains 250,000 Tiles.

One of these Tiles contains the player character, 'player'.  Player has, as a property, the Tile that it is in.  The Tile has the player as a property (because it contains it).

Given that BigMap is 500 by 500 characters, I obviously need a smaller section of that map to display on a typical 81-by-43 character screen (for example).  I call this VisMap.  It too is a multidimensional list (i.e. VisMap[81][43]) which contains those Tiles that are meant to be displayed on screen at any given time.

Traditionally Awful Paint Representation:
Spoiler (click to show/hide)

Now, I want VisMap to be centred on the player.  I therefore need to do a transformation to take the coordinates of the player's Tile (on BigMap), and from that calculate which Tiles in BigMap belong in VisMap, and in what position.

I thought I'd cracked this, but turns out my 3am brain is evidently a little dull, because it's not working as expected.  The code I have for the transformation (and subsequent rendering of the visual map) is this:
Spoiler (click to show/hide)

In this, VISI_HEIGHT and VISI_WIDTH are the dimensions of the displayed map (i.e. 41 and 83), if that wasn't obvious.

What I get when I render this is, indeed, a screen of the map:
Spoiler (click to show/hide)

...but moving the player, while apparently working fine on BigMap, is not represented correctly on VisMap.  For example, moving one step to the right...
Spoiler (click to show/hide)
...successfully increases the X value on BigMap by one (see messages at the bottom), and the X value on VisMap remains at 41 (as it should, as the player should still be centred on the screen), but visually what happens is that the entire view shifts one character to the left, so the player (and the map) appear to be drifting off towards the left of the window.

I'm sure I've made some stupidly simple error here, and I just know that I'll spot it as soon as I click Post and feel like an idiot.  :P

I've been staring at this for too long to be able to see exactly where I've screwed up.  I need more caffeine.  Sigh.

Edit: okay, weirder and weirder, moving the player UP or DOWN behaves differently to moving them left or right.  BigMap coordinates change as expected, VisMap coordinates stay the same as expected, but visually the player character moves up and down the screen while the tiles appear to stay in the same place...like a normal, non-scrolling map.  *headdesk*

Edit 2: right, I've now managed to fix the above problems my somewhat simplifying the code (hooray!)  I now have my little @ wandering merrily around the Tiles that I've designated as floor tiles.  When I get my @ to step off the floor tiles into the vacuum of space, however, suddenly every tile that is designated as vacuum (rather than floor) starts to display as @s.

...well, it's an improvement, at least!
« Last Edit: November 30, 2012, 10:06:41 am by jhxmt »
Logged
Quote from: beefsupreme
Try slaughtering a ton of animals, meat makes less decisions than animals.

Why Your Ramps Don't Work
How To Breach A Volcano Safely

BlindKitty

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #852 on: November 30, 2012, 10:50:19 am »

I'm using C#, so it might be completely irrelevant (and in this case, it should be completely ignored) - but I had once a similar problem. It was caused by calling a property 'static' (I have probably mentioned it somewhere in here, it was with used skills). It made all instances of a creature class use common skill, instead of every one using different. Maybe if something similar to 'static' keyword is in... Python, I believe, is what you are using? - it can be the cause of your problem. Or maybe all those tiles are really pointers to one of them or something?

On a completely unrelated note: I'm closing to alpha-status for Forgotten Maze (my little game got a new name :D). It will get posted (with some screenshots, no less!) soon. When exactly depends on how strong would be my urge to play Civ IV: Beyond the Sword: Rise of Mankind: A New Dawn (I had to write this; sorry), 'cos I just recently bought my own copy. :)
Logged
My little roguelike craft-centered game thread. Check it out.

GENERATION 10: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: The Roguelike Development Megathread
« Reply #853 on: November 30, 2012, 11:15:06 am »

Edit 2: right, I've now managed to fix the above problems my somewhat simplifying the code (hooray!)  I now have my little @ wandering merrily around the Tiles that I've designated as floor tiles.  When I get my @ to step off the floor tiles into the vacuum of space, however, suddenly every tile that is designated as vacuum (rather than floor) starts to display as @s.

...well, it's an improvement, at least!

My guess is that all those patches of empty space are the same tile object that's just displayed several times.
Logged

Fayrik

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #854 on: November 30, 2012, 11:25:30 am »

Given that BigMap is 500 by 500 characters, I obviously need a smaller section of that map to display on a typical 81-by-43 character screen (for example).  I call this VisMap.  It too is a multidimensional list (i.e. VisMap[81][43]) which contains those Tiles that are meant to be displayed on screen at any given time.
Is there any reason that VisMap is itself an array? Would it not be faster to just draw the tiles out from the BigMap itself?
For instance, all the VisMap equivalent data can be extracted from BigMap with this code:
Spoiler: Pseudo Code Loop (click to show/hide)
And using similar logic, everything visible is determinable relative to the player's position rather than having to reference a copy of the original array.
Logged
So THIS is how migrations start.
"Hey, dude, there's this crazy bastard digging in the ground for stuff. Let's go watch."
Pages: 1 ... 55 56 [57] 58 59 ... 72