Author Topic: Python FOV Help  (Read 6294 times)

Hashiba

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Python FOV Help
« on: May 22, 2012, 10:02:27 PM »
Hi folks!  I've been dabbling at learning to program and have set my sights on a roguelike.
I've been half-following the  "Complete Roguelike Tutorial using Python and libtcod", except I'm not using libtcod.  I'm using Python 3.2.3, Pygcurse and Pygame.
Call me crazy, but I figure converting a tutorial to a new library is a better learning experience than just copying code and hoping I understand it.

Its working so well I am stumped!  I am not experienced enough to write my own FOV algo and obviously I can't used the ones included with libtcod.  So...

I found a Python permissive FOV implementation on RogueBasin @
http://roguebasin.com/index.php/Permissive_Field_of_View_in_Python

Well I can't make it work!  Specifically it does something I am not familiar with.  You call to calculate FOV with a fuction call that takes 7 arguments, 5 or which are variables and 2 are "user functions".  The variables make sense but I have no idea how you pass a function as an argument to a function.  I've tired Google and some Python documentation without any luck.

If someone can be kind enough to enlighten me, I can finish up the basic 'engine'.

Thanks in advance!

P.S. I'm not really stubborn about what type of FOV I use at this point in my Roguelike career.  Any helpful adivce on another implementation would also be helpful.

george

  • Rogueliker
  • ***
  • Posts: 201
  • Karma: +1/-1
    • View Profile
    • Email
Re: Python FOV Help
« Reply #1 on: May 23, 2012, 03:20:19 AM »
Quote
The variables make sense but I have no idea how you pass a function as an argument to a function.  I've tired Google and some Python documentation without any luck.

Code: [Select]

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: def funA(x, y, z, f1, f2):
   ...:     return (x, y, z, f1(x), f2(y))
   ...:

In [2]: def funB(x):
   ...:     return x*x
   ...:

In [3]: def funC(x):
   ...:     return x*x*x
   ...:

In [4]: funA(1, 2, 3, funB, funC)
Out[4]: (1, 2, 3, 1, 8)