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 - joeclark77

Pages: 1 ... 4 5 [6]
76
Programming / Re: game loops and information screens
« on: February 27, 2013, 09:17:26 PM »
I have a feeling that the finite state machine idea could be the way to go... I like that it reminds me of Markov chains from probability theory and simulation.  But to really do it right I need to figure out how to do object-oriented programming in this language... it's been years since I did anything like that.  I've got about 10 more chapters of "Learning Python" before I get to that section!

77
Programming / Re: some getting-started python questions
« on: February 27, 2013, 09:13:47 PM »
Thanks, I'm starting to get the hang of using pyglet.  One thing that bugs the heck out of me, though, is that x and y coordinates in pyglet start from the bottom left.  That's the way it works in math, of course, but doesn't click with me.  I'm used to thinking of data structures as being in rows and columns starting from the top left.  So either I have to structure my map data "backwards" or program my display function to read the data backwards.

This admittedly ugly code works to produce a simple @ moving around a hex map (to run it, you need to steal a sprite set from dwarf fortress and put it in a 'resources' folder).  The nice thing about pyglet is that it has no dependencies, so you don't need to install SDL or any other libraries.

import pyglet
from pyglet.window import key
pyglet.resource.path = ['resources','resources/tiles']

window = pyglet.window.Window()

# IMPORT GRAPHICS
sprites = pyglet.resource.image("curses_800x600.png")
spriteset = pyglet.image.ImageGrid(sprites,16,16)
# re-organize the list because pyglet reads it in a bizarre way
spriteset = [spriteset[x:x+16] for x in range(0,len(spriteset),16)] #chunk into "rows"
spriteset = spriteset[::-1] # reverse the order of columns
#access by [row][column]

# figure out map dimensions and make a hex map of the background sprite(s)
w,h = sprites.width//16, sprites.height//16 # sprite dimensions
ww, wh = window.width, window.height # window dimensions
ncol, nrow = ww//w, wh//h # maximum columns/rows we could squeeze onto the screen
mapbatch = pyglet.graphics.Batch()
maptiles = []
for r in range(nrow):
    if r % 2:   # odd rows are shorter
        for c in range(ncol-1):
            maptiles.append( pyglet.sprite.Sprite( spriteset[15][10], x=(w*c)+(w//2), y=h*r, batch=mapbatch ) )
    else: # even rows are longer
        for c in range(ncol):
            maptiles.append( pyglet.sprite.Sprite( spriteset[15][10], x=w*c, y=h*r, batch=mapbatch ) )


atsign = pyglet.sprite.Sprite(spriteset[4][0],x=window.width//2, y=window.height//2)

fps_display = pyglet.clock.ClockDisplay()
  
@window.event
def on_draw():
    window.clear()
    mapbatch.draw()
    atsign.draw()
    fps_display.draw()

@window.event
def on_key_press(symbol, modifiers):
    moves = { key.LEFT:(-w,0), # num-lock off
              key.RIGHT:(w,0),
              key.HOME:(-w//2,h),
              key.PAGEUP:(w//2,h),
              key.END:(-w//2,-h),
              key.PAGEDOWN:(w//2,-h),
              key.NUM_4:(-w,0), # num-lock on
              key.NUM_6:(w,0),
              key.NUM_7:(-w//2,h),
              key.NUM_9:(w//2,h),
              key.NUM_1:(-w//2,-h),
              key.NUM_3:(w//2,-h)
              }  # symbol : (x move,y move)
    # these next lines break if the symbol isn't in the dictionary just created
    atsign.x += moves[symbol][0]  # horizontal movement
    atsign.y += moves[symbol][1]  # vertical movement
    print("key "+str(symbol)+": move "+str(moves[symbol]))

   
pyglet.app.run()



78
Programming / game loops and information screens
« on: February 27, 2013, 04:35:50 PM »
Another newbie question here. I've been able to import a sprite-font, get a basic @ moving around the screen in response to key presses or automatic animation. 

As a complete newbie to game programming, I'm now trying to figure out the fine points of the game loop.  I'm using Python with the pyglet library and it implements its own game loop which you can attach event handlers to.  What I'm now scratching my head over is how to architect the program so that it can have alternate "screens" like an inventory screen.  When you guys do this in your games, do you implement each screen with its own game loop, and switch between them somehow?  Or do you use one game loop with "if/then" statements to correctly implement events/graphics for whichever screen is active?  Or is there some other way that's more sensible than either of these?  I don't need python-specific answers, just looking for the general idea.

79
Programming / Re: emulating a terminal, and how to create a custom font?
« on: February 26, 2013, 03:46:27 PM »
All right, well, I was hoping there was some way in one of the popular libraries to use sprites as text without writing basic text functions from scratch.  Thanks for your input.  If I can get this working in python, maybe I'll share it as a library of my own.

80
Classic Roguelikes / Re: Dwarf fortress
« on: February 25, 2013, 10:41:34 PM »
That said, people should be honest about ripping off Toady's work. Don't pretend you're coming up with something new.

If you check their websites, both of the games mentioned make it very clear that they're borrowing from DF.
Quote from: Gnomoria
For Gnomoria, the biggest influence has of course been Dwarf Fortress.
Quote from: Towns
...we have taken cues from our favorite games. Diablo, Dungeon Keeper, Evil Genius, and even Theme Hospital are in the mix, although an honorable mention must be made to the absolutely gigantic elephant in the room, Dwarf Fortress.

I'm not sure how you'd classify DF.  I've been calling it a "settlement simulator" genre.  It's got a "people simulator" like the Sims, a "supply chain simulator" like the Anno games, a "fortress architecture simulator" and a multi-character roguelike "RPG/combat simulator".  Oh yeah, plus a world generator that actually simulates the geological processes and mineral content shaping the planet up to a couple hundred layers deep. 

I would imagine you could make good games in the same genre without nearly as much complexity.

My (still vague) idea is to do one with a medieval theme, like you're an order of missionaries and crusader knights building a monastery-fort in heathen lands.

81
Programming / Re: emulating a terminal, and how to create a custom font?
« on: February 25, 2013, 10:25:05 PM »
All right, I can see how to use a bitmap grid of characters as a set of sprites.  I can even see how I could make a new "print" function that uses for loops to arrange an array of sprites as a "word" on the screen.  But how about getting multi-character text input from the player? For example, how would you ask the player to enter the name of their character?  I mean, without reinventing the wheel.

82
Programming / Re: emulating a terminal, and how to create a custom font?
« on: February 25, 2013, 09:17:46 PM »
A grid of letters is a grid of images, usually. The easiest way to have a font is to make a bitmap font, which is usually either 16 or 32 characters wide(I prefer 16) and contains everything in it's proper place. Most roguelikes use Code Page  437. Then you just draw characters one at a time into the grid.

As for why I like 16 wide, the coordinates line up with the hex value of the character. 0x20, which is a space, would be at [0,2] on the grid, for example.
16 or 32 characters wide... do you mean the entire font is represented as a bitmap graphic?  BMP, or PNG or what?  I have tried downloading bitmap fonts and what I found was a .FON file, which I couldn't find any way to open and look at without installing it to my operating system.

This is exactly what I want to do, is take an editable bitmap image and import it as a font.

83
Programming / Re: emulating a terminal, and how to create a custom font?
« on: February 25, 2013, 09:12:31 PM »
You might also consider looking around for existing character maps (like the ones available for dwarf fortress) that may give you a good starting point for how to work with the images. And there are many player-created bitmap fonts available to look at.

Yes! The maps that Dwarf Fortress uses are exactly the kind that I'd like to use in my game.  I can see how you would use pyglet (for example) to import them as a grid of sprites/images.  What I cannot find out is how you would transform them into a bitmap font. 

Drawing the game map and sprites is one thing, we can use images there.  But what about printing status messages to the screen?  What about getting text input from the character?  It seems that some internal representation as a font is necessary.

84
Programming / emulating a terminal, and how to create a custom font?
« on: February 25, 2013, 08:07:31 PM »
I've decided that rather than deal with curses, I'm going to create a fake/emulated terminal.  For those who have done this, I have two questions:

(1) Do you generally display your map as a grid of "letters" or as a grid of "images" that look like letters?  Which would you expect to work better/faster in a roguelike?

(2) In python, how can I create a font from an image file (i.e. a graphic containing all the ASCII symbols in a grid)?  I know libtcod can do this, but it's written in C and the code is way too complicated for me to be able to figure out.  I want to use custom ascii characters to control my game's look, and perhaps enable modding.

85
Classic Roguelikes / Re: Dwarf fortress
« on: February 25, 2013, 03:01:10 PM »
Eh, I'm not specifically looking for high-quality or low-quality, just alternative takes on the genre that could help me generate ideas (or avoid pitfalls) as I conceive of my own variation.  I had heard of Gnomoria.  Towns looks interesting, thanks.

86
Classic Roguelikes / Re: Dwarf fortress
« on: February 24, 2013, 01:14:23 PM »
Are any of you aware of other roguelikes in the same genre as Dwarf Fortress? (I would call it a "settlement simulation" genre, but that's just me.)  I can of course see similarities to other games (the sims, the anno series, etc).  Would be nice to sample a few other takes on the genre, as I plan out my own settlement simulation game.

87
Programming / Re: some getting-started python questions
« on: February 24, 2013, 12:47:24 PM »
I can appreciate choosing a minimal library. Fwiw, I always liked the API of Pyglet over Pygame.

Thanks, that's one I haven't heard of.  The website provides a "hello world" example, too, which is just what I was hoping for.  Do we know of any examples of roguelikes written with pyglet?  (It would be nice to confirm that it works across platforms without too much hassle.)

88
Programming / Re: some getting-started python questions
« on: February 23, 2013, 09:32:43 PM »
Libtcod is the go-to RL library for a lot of people using Python.
I've heard that, but I don't like the fact that it has so much stuff (pathfinding, map generation algorithms, etc) built in.  I'd rather go with something minimalist so that I program those things myself at least once.  I'm looking more for a learning experience than for efficiency.

I'm wary of Pygame for the same reason -- does it do too much stuff that I don't need?  This one is a harder call.

I appreciate the feedback.

89
Programming / Re: Replayability
« on: February 23, 2013, 04:06:07 AM »
One thing that helps is if you can tell a different story after playing the game multiple times.  Nethack for example got old after a couple ascensions, simply because the sequence of stuff you do is the same every time.  It was an amazing and addictive challenge to figure it all out, but then it was a yawn to replay.

90
Programming / some getting-started python questions
« on: February 23, 2013, 03:36:57 AM »
Hi all.  I've set out to create my first roguelike in Python, which I'm learning as I go.  I have many years of programming experience with web scripts, statistical stuff in R, etc, but never with stand-alone applications or graphics, so I'm not very familiar with game programming.  I'd like to pose a few questions to those who know something about this, in order to help me get started.

First: I don't want to use curses but would rather make a simulated-ascii game (i.e. use tiles that just look like ASCII characters).  This is because in the long run I want to use alternate tilesets, let the user resize the window, and do some funny stuff like arrange my map on a hexagonal grid. 

What librar(y/ies) should I use to implement this?  A "graphics" library like SDL or OpenGL?  Or a "GUI" library like tkinter?  I really have no idea about this stuff.
Bonus points: Can you get me started by showing me, in 3 or 4 lines of python, how to open a window and paint a tile to the screen with your recommended library?

Second: One problem I anticipate is that it might be difficult to print text to the screen, and to receive text input (eg. "enter a name for your character:") when I'm not really using text but actually a sequence of little graphical tiles.  Is this a major challenge, or is there an easy solution?

I guess those are my only questions to start with.  FYI, my vision is for a kind of settlement-simulator in the genre of Dwarf Fortress, but with a medieval theme.

Pages: 1 ... 4 5 [6]