On Mon, Nov 4, 2013 at 11:45 AM, Daniel Gillet <[email protected]>wrote:
> Hello,
>
> Thanks for all the comments. As Paul suggested, here is the part of my
> code where I was trying to make some sequence of actions.
>
[code snipped]
FYI:
social engineering hint: if your python code uses more than 40 chars per
line, use a pastebin. ( Web clients like gmail will fold lines a bit longer
than that,making really hard to read)
About the code:
I guess 'self' is something like a level or world entity,
seems you the code is something called from the world update method.
I would say it goes in to low level details; world should delegate the
details to the appropriate objects, by example laser details seems to be
wanted to be something like
self.battle_grid.laser(from, to)
where from, to are world coordinates
similar,
def _remove_ship(ship):
self.battle_ship.remove_actor(ship, effect='explosion')
self.player.remove_ship(ship)
>
>
def attack_ship(self, attacker, defender):
> "Attacker attacks the defender"
> destroyed = attacker.attack(defender) #This returns True if the
> defender is destroyed by the attack
> ox, oy = self.battle_grid.from_pixel_to_grid(attacker.position) #
> Origin in grid coord
> m, n = self.battle_grid.from_pixel_to_grid(defender.position) #
> Defender position in grid coord
>
> def _remove_ship(ship):
>
explosion = cocos.sprite.Sprite(self.battle_grid.explosion_anim,
> position=ship.position) # This is an
> animation of an explosion
> explosion.push_handlers(self) # So we know when the animation
> is finished
>
1. Why is this needed ? the ship will be removed of battle_grid and from
player fleet in the next two lines. What more needs to be done ?
2. This is a very obscure code: it tells : 'explosion object, inspect all
my methods and if you find some named after an event you handle, register
it as a listener for that event". At least register the explicit handler,
maybe self.on_explosion_end
3. It is also prone to failure, especially because self looks as it will
listen to lots of emitters / messages. What if some emitters handle events
with same name ?
4. pyglet events are slow to register / unregister, probably also at
dispatching. I would use some third party publish-subscribe library
(blinker is one like it looks usable and maintained, it its also py2 - 3
compatible).
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.