Lin Parkh | 1 Jan 2009 01:14
Picon

Re: <at>

It is always possible to write game specific languages :-) Like AI 
languages.
----- Original Message ----- 
From: "Noah Kantrowitz" <noah@...>
To: <pygame-users@...>
Sent: Wednesday, December 31, 2008 1:58 PM
Subject: Re: [pygame]  <at> 

> Python _is_ the scripting language to use in your game.
>
> --Noah
>
> On Dec 31, 2008, at 4:56 PM, Lin Parkh wrote:
>
>> Thanks. The game context is I would like to write a scripting  language 
>> on top of pygame/python for my game.
>> ----- Original Message ----- From: "Lenard Lindstrom" <len- l <at> telus.net>
>> To: <pygame-users@...>
>> Sent: Wednesday, December 31, 2008 1:32 PM
>> Subject: Re: [pygame]  <at> 
>>
>>
>>> This is getting off topic for a game oriented mailing list, but  many of 
>>> the things other languages use macro to accomplish come  naturally to 
>>> Python because it is dynamically typed. For instance  the function:
>>>
>>> def do_add(x, y):
>>>   return x + y
>>>
>>> will work with integers, floats, complex numbers, lists and any  other 
(Continue reading)

Noah Kantrowitz | 1 Jan 2009 01:17
Gravatar

Re: <at>

Possible, but not needed. I would recommend looking at either TinyPy  
or LunaticPython to do safe embedded Python or Lua respectively.  
Unless you expect users to running arbitrary downloaded code in your  
game, you can just use python+exec though.

--Noah

On Dec 31, 2008, at 7:14 PM, Lin Parkh wrote:

> It is always possible to write game specific languages :-) Like AI  
> languages.
> ----- Original Message ----- From: "Noah Kantrowitz"
<noah@... 
> >
> To: <pygame-users@...>
> Sent: Wednesday, December 31, 2008 1:58 PM
> Subject: Re: [pygame]  <at> 
>
>
>> Python _is_ the scripting language to use in your game.
>>
>> --Noah
>>
>> On Dec 31, 2008, at 4:56 PM, Lin Parkh wrote:
>>
>>> Thanks. The game context is I would like to write a scripting   
>>> language on top of pygame/python for my game.
>>> ----- Original Message ----- From: "Lenard Lindstrom" <len- l <at> telus.net 
>>> >
>>> To: <pygame-users@...>
(Continue reading)

Jake b | 1 Jan 2009 01:18
Picon

Re: <at>

If it doesn't execute on function call, I don't get what the use is? I
thought if I did this, it would print out "I am decorator"  ( but it
only does it on function declaration )

def dec(f):
    print "I am decorator!", f
    return f

 <at> dec
def fn(x): return x

( And if it doesn't, then the logThisMethodCall() will not be logging
every time it is called, just once on declaration ?: )

On Wed, Dec 31, 2008 at 4:05 PM, Lenard Lindstrom <len-l@...> wrote:
> An instance of function fn is created, then function decorator is called with that instance as its only
argument. > decorator then returns the function instance, which is assigned to identifier fn. So a
decorator is called when a > function declaration is executed, not later when the function is called.
>--
Jake

yanom | 1 Jan 2009 01:22
Picon
Favicon

Re: <at>

oh. They showed up in some basic example code for pyglet:

import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
                          font_name='Times New Roman',
                          font_size=36,
                          x=window.width//2, y=window.height//2,
                          anchor_x='center', anchor_y='center')
@...
def on_draw():
    window.clear()
    label.draw()
pyglet.app.run()

--- On Wed, 12/31/08, Noah Kantrowitz <noah <at> coderanger..net> wrote:

From: Noah Kantrowitz <noah@...>
Subject: Re: [pygame]  <at> 
To: pygame-users@...
Date: Wednesday, December 31, 2008, 1:59 PM

No, as I said, decorators are a rather advanced topic. Until you are  
more comfortable with the whole compiler process, I would just try  
writing a few small ones with various prints to see what happens.

--Noah

On Dec 31, 2008, at 2:57 PM, Yanom Mobis wrote:

(Continue reading)

Nicholas Dudfield | 1 Jan 2009 01:30
Picon
Gravatar

Re: <at>

def decorator(f):
    def decorated(*args, **kw):
        print "I have been decorated!", f.__name__
        return f(*args, **kw)

    return decorated

 <at> decorator
def fn(x):
    return x

print fn(5)

I'm too tired to try and explain, hopefully some else will.  But I think 
that is what you were trying to do.

Don't worry decorators are easy as once it clicks.

> If it doesn't execute on function call, I don't get what the use is? I
> thought if I did this, it would print out "I am decorator"  ( but it
> only does it on function declaration )
>
> def dec(f):
>     print "I am decorator!", f
>     return f
>
>  <at> dec
> def fn(x): return x
>
> ( And if it doesn't, then the logThisMethodCall() will not be logging
(Continue reading)

Noah Kantrowitz | 1 Jan 2009 01:36
Gravatar

Re: <at>

Okay, think about the function classmethod(). It takes a single  
callable as an argument and return a callable. You could write this

   def make_from_str(cls, data):
       newobj = cls()
       newobj.parse(data)
       return newobj
   make_from_str = classmethod(make_from_str)

inside a class. You could also write this

    <at> classmethod
   def make_from_str(cls, data):
       newobj = cls()
       newobj.parse(data)
       return newobj

which does the same thing. Up to you to decide which you think is more  
readable. Other uses for decorators include reducing boilerplate for  
similar functions, central registration of functions (such as  
registering event handlers in a game), and much more.

--Noah

On Dec 31, 2008, at 7:18 PM, Jake b wrote:

> If it doesn't execute on function call, I don't get what the use is? I
> thought if I did this, it would print out "I am decorator"  ( but it
> only does it on function declaration )
>
(Continue reading)

Yanom Mobis | 1 Jan 2009 01:37
Picon
Favicon

Re: <at>

I think I've got it now. But why does this happen?

>>> def a(b):
...   b()
... 
>>>  <at> a
... def eggs():
...   print "spam"
... 
spam
>>> eggs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
>>> 

--- On Wed, 12/31/08, Lenard Lindstrom <len-l@...> wrote:

From: Lenard Lindstrom <len-l@...>
Subject: Re: [pygame]  <at> 
To: pygame-users@...
Date: Wednesday, December 31, 2008, 4:05 PM

A concrete example helps. Unfortunately, knowing how a decorator works 
does nothing to explain how it is being used any more than know how to 
declare a function tells you what all functions do. Anyway, the key 
thing to remember is a function declaration in Python is an executable 
statement, a function instance is created when execution reaches the 
declaration, and that instance is assigned to the variable of the same 
name. So:
(Continue reading)

Noah Kantrowitz | 1 Jan 2009 01:40
Gravatar

Re: <at>

So doing the same conversion we start with

def a(b): b()

 <at> a
def eggs(): print 'spam'

This becomes:

def a(b): b()

def eggs(): print 'spam'
eggs = a(eggs)

If you look your a() function doesn't return anything so eggs is set  
to the default return value which is always None.

--Noah

On Dec 31, 2008, at 7:37 PM, Yanom Mobis wrote:

> I think I've got it now. But why does this happen?
>
>>>> def a(b):
> ...   b()
> ...
>>>>  <at> a
> ... def eggs():
> ...   print "spam"
> ...
(Continue reading)

Michael Phipps | 1 Jan 2009 03:47
Favicon

Background ghosts

I am finishing up my first pygame; everything has been fun and easy except this:

The game is a tetris-like game (with a twist). I have the falling piece as a sprite. The background is just a
bitmap. The pieces that have already fallen, I blit into place. So I have something like (in pseudo code):

def drawBoard():
    blit background to display
    for piece in fallenPieces:
         blit piece to display
   display.flip()

while 1: # game loop
    moveSprite()
    if sprite.nextLocation == taken
        fallenPieces.Append(sprite.asPiece())
        sprite = None
        removeSolidRows() # This removes fallen pieces that have formed complete rows
        drawboard()

The problem that I have is that as the sprite is falling, I can see rows that have been removed. I have
confirmed that drawBoard() is doing the right thing - when the sprite hits the bottom and the screen
redraws, the ghosts disappear. They are only there when the sprite floats over them. It looks like the
sprite is getting the data from the old version of the screen (i.e. before the last piece fell and rows were
removed) to redraw the screen's dirty regions.

Help!

Michael

(Continue reading)

Jake b | 1 Jan 2009 05:12
Picon

Re: Background ghosts

It looks like you never clear the screen. try something like:
def drawBoard():
   self.screen.fill( (128,128,128) )
   blit background to display
   for piece in fallenPieces:
        blit piece to display
  display.flip()

Why do you split sprites into two groups? ( stopped, and moving )

(Not sure if that will exactly integrate into how your code, is, but
this is what I mean):

class TetrisMain():
	def __init__(self):
		"""init pygame, surfaces, sprite groups"""
		self.screen = #pygame screen
		self.pieces_list = #sprite group filled with pieces
		
	def draw(self):
		"""clear, blit background, blit pieces, flip."""
		self.screen.fill((128,128,128))
		self.screen.blit( self.background, (0,0))
		self.pieces_list.draw(self.screen)
		pygame.display.flip()
		
	def loop(self):
		"""main loop"""
		self.pieces_list.update() # update using sprite group
		self.draw()
(Continue reading)


Gmane