Temple of The Roguelike Forums

Development => Programming => Topic started by: jofadda on October 01, 2011, 06:34:46 AM

Title: newbie asking for help
Post by: jofadda on October 01, 2011, 06:34:46 AM
i want to create a roguelike as i have a few ideas for one(and a complete theoreticall "near freeform" spell system for said roguelike), i decided on using python and libtcod and as i have no programming skills, i am using this tutorial
http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod but this tutorial doesnt seem explanitory enough, and it just makes me feel like im copying and pasting code, is there a better tutorial, or could someone explain some of the lines of code, and what they do in more detail,
im just in the first part, just finished character movement, but an explaination from start would be better, thanks in advance for either a better tutorial, or a better explination of this one
Title: Re: newbie asking for help
Post by: RogueMaster on October 01, 2011, 08:04:39 AM
i want to create a roguelike as i have a few ideas for one(and a complete theoreticall "near freeform" spell system for said roguelike), i decided on using python and libtcod and as i have no programming skills, i am using this tutorial
http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod but this tutorial doesnt seem explanitory enough, and it just makes me feel like im copying and pasting code, is there a better tutorial, or could someone explain some of the lines of code, and what they do in more detail,
im just in the first part, just finished character movement, but an explaination from start would be better, thanks in advance for either a better tutorial, or a better explination of this one


Something that may help you:
http://roguebasin.roguelikedevelopment.org/index.php/How_to_Write_a_Roguelike_in_15_Steps (http://roguebasin.roguelikedevelopment.org/index.php/How_to_Write_a_Roguelike_in_15_Steps)
Title: Re: newbie asking for help
Post by: jofadda on October 01, 2011, 08:22:03 AM
sorry, that didnt help, i have almost no coding knowledge, i was hoping for more of an explanitory coding tutorial
Title: Re: newbie asking for help
Post by: RogueMaster on October 01, 2011, 05:57:29 PM
sorry, that didnt help, i have almost no coding knowledge, i was hoping for more of an explanitory coding tutorial

Then what you need is to do is to read a beginner tutorial of the programming language you want to use.

For python, you can find various manuals here: http://www.awaretek.com/tutorials.html (http://www.awaretek.com/tutorials.html)

Enjoy.
Title: Re: newbie asking for help
Post by: jofadda on October 01, 2011, 11:16:04 PM
ok, im currently reading python for dummies, and, i was really hoping for code explination of the tutorial, rather than python tutorials, thanks anyway
Title: Re: newbie asking for help
Post by: jofadda on October 02, 2011, 12:54:01 AM
http://www.mediafire.com/?i2aqh3cohp6fj99
this is what ive got so far, currently im just messing around with the tutorial i mentioned earlier, but i seem to have an error to do with movement that i cant find within the code, could someone please find said error, tell me what it is, what ive done wrong, and what i should have done?
thanks in advance, and sorry for the double post
Title: Re: newbie asking for help
Post by: TheExpert on October 02, 2011, 01:23:38 AM
line 85 of your code.

Code: [Select]
libtcod.console_print_left(0, playerx, playery, libtcod.BKGND_NONE, ' ')
should be

Code: [Select]
libtcod.console_print_left(0, player.x, player.y, libtcod.BKGND_NONE, ' ')
you left out the period between player.x and player.y, so instead of looking at the the x and y attributes of the Object Instance known as 'player', the program was looking for variables named playerx and playery, variables that don't exist. Since those variables don't exist, the program crashes when it is told to use them.
Title: Re: newbie asking for help
Post by: jofadda on October 02, 2011, 05:03:48 AM
ok, thanks, you probly think its a really noobie mistake, ::) but that helps me alot
also another one here,
where is the error in this?


import libtcodpy as libtcod


SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50

MAP_WIDTH = 80
MAP_HEIGHT = 45

color_dark_wall = libtcod.Color(0, 0, 100)
color_dark_ground = libtcod.Color(50, 50, 150)


class Tile:
    #a tile of the map and its properties
    def __init__(self, blocked, block_sight = None):
        self.blocked = blocked
 
        #by default, if a tile is blocked, it also blocks sight
        if block_sight is None: block_sight = blocked
        self.block_sight = block_sight

class Object:
    #this is a generic object: the player, a monster, an item, the stairs...
    #it's always represented by a character on screen.
    def __init__(self, x, y, char, color):
        self.x = x
        self.y = y
        self.char = char
        self.color = color
 
    def move(self, dx, dy):
        if not map[self.x + dx][self.y + dy].blocked:
        self.x += dx
        self.y += dy
 
    def draw(self):
        libtcod.console_set_foreground_color(con, self.color)
        libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
 
    def clear(self):
        libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE)

def make_map():
    global map
 
    #fill map with "unblocked" tiles
    map = [[ Tile(False)
        for y in range(MAP_HEIGHT) ]
            for x in range(MAP_WIDTH) ]

    map[30][22].blocked = True
    map[30][22].block_sight = True
    map[50][22].blocked = True
    map[50][22].block_sight = True

def render_all():
    global color_light_wall
    global color_light_ground

    #go through all tiles, and set their background color
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            wall = map
            if wall:
                libtcod.console_set_back(con, x, y, color_dark_wall, libtcod.BKGND_SET )
            else:
                libtcod.console_set_back(con, x, y, color_dark_ground, libtcod.BKGND_SET )


    #draw all objects in the list
    for object in objects:
        object.draw()

    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

def handle_keys():
    key = libtcod.console_wait_for_keypress(True)  #turn-based
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    elif key.vk == libtcod.KEY_ESCAPE:
        return True  #exit game
 
    #movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        player.move(0, -1)
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        player.move(0, 1)
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        player.move(-1, 0)
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        player.move(1, 0)

 
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'test', False)
con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)


player = Object(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, '@', libtcod.white)
 

npc = Object(SCREEN_WIDTH/2 - 5, SCREEN_HEIGHT/2, '@', libtcod.yellow)
 

objects = [npc, player]

make_map()

 
while not libtcod.console_is_window_closed():

    #render the screen
    render_all()

    libtcod.console_flush()

    #erase all objects at their old locations, before they move
    for object in objects:
        object.clear()

 
    #handle keys and exit game if needed
    exit = handle_keys()
    libtcod.console_print_left(0, player.x, player.y, libtcod.BKGND_NONE, ' ')
    if exit:
        break
Title: Re: newbie asking for help
Post by: guest509 on October 02, 2011, 09:16:39 AM
  Wow man what's the error message? What's the behavior problem? I have never used this language before but these 2 locations look wacky.
 
for x in range(MAP_WIDTH):
            wall = map

    [y].block_sight      //there is a weird dot at the beginning of this line.

AND HERE

libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
  //That '|' symbol seems a bit out of place...

  Sorry I cannot be of more help. But I tell you man. If you want to write in python you need to know what the code is saying. You don't have to be an expert. But a few weeks hitting a python tutorial will do you wonders. You need to know what a programming language is to be able to even edit someone else's code.
  Many many people write a Roguelike as a way to learn a language. I highly recommend it.
Title: Re: newbie asking for help
Post by: guest509 on October 02, 2011, 09:27:22 AM
  Crap please ignore the '|' suggestion. I went through the python code you are copying and they are using it as an operator there. Unless it is also an error there. I dunno.
  As far as explaining the code. The guy is doing a pretty good job in that tutorial. I don't know how I could explain it better without starting from the beginning and telling you how programming languages work. And there are PLENTY of better resources than me for that. I don't even know python.
Title: Re: newbie asking for help
Post by: jofadda on October 02, 2011, 09:43:18 AM
  Wow man what's the error message? What's the behavior problem? I have never used this language before but these 2 locations look wacky.
 
for x in range(MAP_WIDTH):
            wall = map

    [y].block_sight      //there is a weird dot at the beginning of this line.

AND HERE

libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
  //That '|' symbol seems a bit out of place...

  Sorry I cannot be of more help. But I tell you man. If you want to write in python you need to know what the code is saying. You don't have to be an expert. But a few weeks hitting a python tutorial will do you wonders. You need to know what a programming language is to be able to even edit someone else's code.
  Many many people write a Roguelike as a way to learn a language. I highly recommend it.
the wierd dot is an x within square brackets [] and i still have not found the error
Title: Re: newbie asking for help
Post by: 7h30n on October 02, 2011, 09:47:28 AM
In render_all function:

Code: [Select]
   for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            wall = map[x][y].block_sight

Shouldn't it be like that (though I haven't started on Python yet...)?

Edit: Nvm, it seems the forum displays a dot when you have [letter] [letter] without spaces in between them.
Title: Re: newbie asking for help
Post by: jofadda on October 02, 2011, 09:54:04 AM
also if this helps, when i exicute the code, i get no error, it just opens a  command line with no text, then closes
Title: Re: newbie asking for help
Post by: Krice on October 02, 2011, 01:24:04 PM
is there a better tutorial

Yeah, it's called "learn programming". That's the tutorial you want to do first.
Title: Re: newbie asking for help
Post by: guest509 on October 03, 2011, 08:17:59 AM
is there a better tutorial

Yeah, it's called "learn programming". That's the tutorial you want to do first.

  Agreed. Even if you are using a drag and drop program like Gamemaker or RPG Maker you'll want to learn the scripting languages. You'll not need to get advanced. Basic stuff cannot be avoided though.
  When I was learning I really liked the 'Learn to Use XYZ in 21 Days' line of books. Quick and dirty.
Title: Re: newbie asking for help
Post by: jofadda on October 03, 2011, 08:32:51 AM
is there a better tutorial

Yeah, it's called "learn programming". That's the tutorial you want to do first.

  Agreed. Even if you are using a drag and drop program like Gamemaker or RPG Maker you'll want to learn the scripting languages. You'll not need to get advanced. Basic stuff cannot be avoided though.
  When I was learning I really liked the 'Learn to Use XYZ in 21 Days' line of books. Quick and dirty.
ok well im reading python for dummies and im also using the python site to better understand on peices of the code i dont understand within the tutorial. i also "fixed" that error, i used a copy of the program i had made prior to starting that part of the tutorial and i went from there
Title: Re: newbie asking for help
Post by: UltimaRatioRegum on October 03, 2011, 10:04:28 PM
The Python tutorial you linked to got me, in about two weeks, from having never touched a programming language to understanding enough to lay the basis for my own roguelike, which is coming along in leaps and bounds. I cannot possibly recommend that tutorial enough! It gives you all of the basics, and everything else you should be able to extrapolate from what's there. You might not produce new parts in a particularly programming-efficient way at first (I certainly didn't!) but that tutorial is a great start.
Title: Re: newbie asking for help
Post by: guest509 on October 04, 2011, 01:09:13 AM
is there a better tutorial

Yeah, it's called "learn programming". That's the tutorial you want to do first.

  Agreed. Even if you are using a drag and drop program like Gamemaker or RPG Maker you'll want to learn the scripting languages. You'll not need to get advanced. Basic stuff cannot be avoided though.
  When I was learning I really liked the 'Learn to Use XYZ in 21 Days' line of books. Quick and dirty.
ok well im reading python for dummies and im also using the python site to better understand on peices of the code i dont understand within the tutorial. i also "fixed" that error, i used a copy of the program i had made prior to starting that part of the tutorial and i went from there

   Sweet man! Welcome aboard. Game making can be a lifelong and rewarding hobby. I don't know how old you are, but us old fogies have been doing it for years (decades) and we still love it!
Title: Re: newbie asking for help
Post by: jofadda on October 04, 2011, 04:23:36 AM
well im about to start dungeon generation, but i want two "levels" with the same dungeon once ive worked though the tutorial(im hoping to do two "planes" one physical, the other spectral, think kinda like soul reaver on ps1/pc)
could anyone post the "logic code" on how to do that, by that i dont mean pythons code but the logic steps in said processes, e.g for movement the "logic code" would be: display "@" on screen, when movement key is pressed create second instance left, right, above or below first instance, delete first instance
Title: Re: newbie asking for help
Post by: guest509 on October 05, 2011, 09:37:17 AM
  Like the same level but like mirrored or something? Light world and dark world like in SNES Zelda? Well the process would be to make a second level identical to the first, but switch up the color of the tiles to something 'dark' and then switch up the  enemies to something 'dark'. If you want it mirrored then you could flip the level on the vertical line.
Title: Re: newbie asking for help
Post by: jofadda on October 05, 2011, 10:43:29 PM
  Like the same level but like mirrored or something? Light world and dark world like in SNES Zelda? Well the process would be to make a second level identical to the first, but switch up the color of the tiles to something 'dark' and then switch up the  enemies to something 'dark'. If you want it mirrored then you could flip the level on the vertical line.

so the logic behind that is, create dungeon, save dungeon, copy dungeon, use copy of dungeon to generate spectral dungeon?
Title: Re: newbie asking for help
Post by: guest509 on October 06, 2011, 11:06:59 AM
  If I am understanding what you want to do, yes.
  But really this gets into the specifics of game design. You can do lots of stuff with alternate worlds. I think there was a 7DRL on the topic this last go around. IT was called The Man in The Mirror. I think it won! I think the download link is down...
Title: Re: newbie asking for help
Post by: UltimaRatioRegum on October 06, 2011, 12:27:11 PM
Well, I suppose you'd just have different objects or terrain types show up as different things in different worlds. In the normal world, grass is green; in the other, it is dead and grey. In the normal, you might have water, but in the other, it turns into lava, or sludge, or something of that sort. I think you could very easily just tell the game to recognise the same tiles in different ways depending on which world you're in (and you certainly good, from the Python libtcod tutorial!)
Title: Re: newbie asking for help
Post by: jofadda on October 18, 2011, 10:37:09 AM
Im finding that i dont really understand the tutorials enough to code my roguelike, tbh the only part of the code i truely understand is the player movement which in "non-code" termanology is left arrow button creates copy of "@" one tile left of itself whilest at the same time deleting itself, right arrow does the same on rightside, up does the same above, down does the same below, anyway im going to put my rl coding on hold just until i learn enough coding to create one
but if anyone could post any coding the coding tutorials they started with up to the ones that helped them make a roguelike, that would be a major help, thanks in advance
im also open to a change in programming language as i havent dipped too far into python to feel like it must be the language that i use, and if anyone can spare time i would be very grateful for a programming tutor(unpaid though)
Title: Re: newbie asking for help
Post by: Pueo on November 30, 2011, 08:01:58 PM
i want to create a roguelike as i have a few ideas for one(and a complete theoreticall "near freeform" spell system for said roguelike), i decided on using python and libtcod and as i have no programming skills, i am using this tutorial
http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod but this tutorial doesnt seem explanitory enough, and it just makes me feel like im copying and pasting code, is there a better tutorial, or could someone explain some of the lines of code, and what they do in more detail,
im just in the first part, just finished character movement, but an explaination from start would be better, thanks in advance for either a better tutorial, or a better explination of this one

I don't know, I've read over that, and it seems pretty explanatory to me.  What specifically do you want explained?
Title: Re: newbie asking for help
Post by: Pueo on December 06, 2011, 08:05:19 PM
well im about to start dungeon generation, but i want two "levels" with the same dungeon once ive worked though the tutorial(im hoping to do two "planes" one physical, the other spectral, think kinda like soul reaver on ps1/pc)
could anyone post the "logic code" on how to do that, by that i dont mean pythons code but the logic steps in said processes, e.g for movement the "logic code" would be: display "@" on screen, when movement key is pressed create second instance left, right, above or below first instance, delete first instance

I think what you mean by 'logic' is known as pseudo-code.  Try to use that for clarity's sake. 

For the 'mirror world' type of thing, think of something like this:

Make dungeon; //Make the dungeon
RealWorld = true; //If the value is true, you're in the real world, if its false, you're in the spirit world
if steponspiritportal, RealWorld = false; //If you step on the portal, it changes the RealWorld value to false, thus putting you in the SpiritWorld
if RealWorld = false, run SpiritWorldShift; //When you change to the SpiritWorld run a function that changes the world (grass dies, water turns to lava, etc)

Then compose a changing back to regular world function

RealWorld = false; //You are now in the spirit world
if steponrealportal, RealWorld = true; //If you step on a portal in the spirit world, you shift to the real world
if RealWorld = true, run RealWorldShift; //When you shift from spirit to real world, turn dead grass back to living, lava back to water, etc

Now, being pseudo-code, it's obviously not going to look exactly like that, but that could be a general outline.