Moving through water on a roguelike.

This is the place for queries that don't fit in any of the other categories.

Moving through water on a roguelike.

Postby jeremyflexer » Wed Jan 22, 2014 10:48 pm

Hey so currently I am working on a roguelike, all was going good until I tried to make the player move through water.

My goal is to make it so when the player moves through apart of the grid that is water, it will remember the symbol that was there and when the player moves off the part of the grid the water is placed again.
I started used git but I am still pretty clueless as to how to use it efficiently but you can view the full program at https://github.com/snakesoftworks/cavesofthesnakes I will post the movement method below. Sorry for the uncommented code I am very new so I am not a good documentor at all.
Code: Select all
    def movePlayer(self, key_pressed):
        self.key_pressed = key_pressed
        self.directions = {'up':(-1, 0), 'down':(1, 0), 'left':(0, -1), 'right':(0, +1)}
        self.grid_copy = []
        if (self.key_pressed in self.directions.keys()):
            if ((self.grid_player[0] + self.directions[self.key_pressed][0],
                 self.grid_player[1] + self.directions[self.key_pressed][1]) in
                 self.grid_final.keys()):
                if (self.grid_final[(self.grid_player[0] + self.directions[self.key_pressed][0],
                                     self.grid_player[1] + self.directions[self.key_pressed][1])] not in
                                    (self.wall['symbol'], self.rock['symbol'])):
                    self.grid_last = self.grid_final[(self.grid_player[0] + self.directions[self.key_pressed][0],
                                                      self.grid_player[1] + self.directions[self.key_pressed][1])]
                    self.grid_copy = [self.grid_player[0], self.grid_player[1]]
                    self.grid_final[tuple(self.grid_player)] = self.floor['symbol']
                    self.grid_player = [self.grid_player[0] + self.directions[self.key_pressed][0],
                                        self.grid_player[1] + self.directions[self.key_pressed][1]]
                elif (self.grid_final[(self.grid_player[0] + self.directions[self.key_pressed][0],
                                       self.grid_player[1] + self.directions[self.key_pressed][1])]
                                       == self.rock['symbol']):
                    self.message_move = "A rock is blocking your path."
                else:
                    self.message_move = "A wall is blocking your path."
            else:
                self.message_move = "A wall is blocking your path."
        if (self.key_pressed in self.directions.keys()):
            self.grid_final[tuple(self.grid_player)] = self.player['symbol']
            self.grid_final[tuple(self.grid_copy)] = self.grid_last
            self.message_move = "You move to the {}".format(self.key_pressed)


Where you see self.grid_last I was trying to make it work but I am definitly not doing something right, I also tried other ways but this is the closest I could come, please help :(.
User avatar
jeremyflexer
 
Posts: 23
Joined: Fri Jan 17, 2014 6:36 pm

Re: Moving through water on a roguelike.

Postby Mekire » Wed Jan 22, 2014 11:37 pm

Just make a copy of your map (grid_final) before placing the player and place the player on the copy instead of the original. Draw the screen based on the copy. Don't change the original. Do this every frame.

Not familiar with your specific gui/whatever you are using, but that should work fine.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Moving through water on a roguelike.

Postby jeremyflexer » Thu Jan 23, 2014 12:03 am

Mekire wrote:Just make a copy of your map (grid_final) before placing the player and place the player on the copy instead of the original. Draw the screen based on the copy. Don't change the original. Do this every frame.

Not familiar with your specific gui/whatever you are using, but that should work fine.

-Mek

Thanks, I guess when the grid is edited in-game I will make it affect grid_copy and not grid_final :D.
User avatar
jeremyflexer
 
Posts: 23
Joined: Fri Jan 17, 2014 6:36 pm

Re: Moving through water on a roguelike.

Postby metulburr » Thu Jan 23, 2014 5:56 am

Might i suggest a readme describing how to run your code/requirements/explanations. I cant even figure out how to run your code.

Code: Select all
metulburr@arch ~/Downloads/cavesofthesnakes-master/cots/alpha $ python2 CotS_alpha_v1-07.py
Traceback (most recent call last):
  File "CotS_alpha_v1-07.py", line 37, in <module>
    import libtcodpy as libtcod
  File "/home/metulburr/Downloads/cavesofthesnakes-master/cots/alpha/libtcodpy.py", line 47, in <module>
    _lib = ctypes.cdll['./libtcod.so']
  File "/usr/lib/python2.7/ctypes/__init__.py", line 440, in __getitem__
    return getattr(self, name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 435, in __getattr__
    dll = self._dlltype(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: ./libtcod.so: wrong ELF class: ELFCLASS32
metulburr@arch ~/Downloads/cavesofthesnakes-master/cots/alpha $
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1476
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Moving through water on a roguelike.

Postby jeremyflexer » Thu Jan 23, 2014 10:09 pm

metulburr wrote:Might i suggest a readme describing how to run your code/requirements/explanations. I cant even figure out how to run your code.

Code: Select all
metulburr@arch ~/Downloads/cavesofthesnakes-master/cots/alpha $ python2 CotS_alpha_v1-07.py
Traceback (most recent call last):
  File "CotS_alpha_v1-07.py", line 37, in <module>
    import libtcodpy as libtcod
  File "/home/metulburr/Downloads/cavesofthesnakes-master/cots/alpha/libtcodpy.py", line 47, in <module>
    _lib = ctypes.cdll['./libtcod.so']
  File "/usr/lib/python2.7/ctypes/__init__.py", line 440, in __getitem__
    return getattr(self, name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 435, in __getattr__
    dll = self._dlltype(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: ./libtcod.so: wrong ELF class: ELFCLASS32
metulburr@arch ~/Downloads/cavesofthesnakes-master/cots/alpha $

I think it is because I had only put the 32bit version in there. I updated the repository the 64 one should be located in /cots/alpha/64/
Also I am assuming from that message you are using 64. So if that doesn't work please tell me.
User avatar
jeremyflexer
 
Posts: 23
Joined: Fri Jan 17, 2014 6:36 pm

Re: Moving through water on a roguelike.

Postby metulburr » Thu Jan 23, 2014 10:21 pm

Yeah that was it
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1476
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: snippsat and 4 guests