Snuka Newbie
Joined: Feb 28 2011 Posts: 2 Offline
|
Posted: Tue Mar 01, 2011 12:25 am Post subject: python module experts? |
|
|
|
|
Addicted to as3 now, just starting to figure things out, never worked with python before.
Decided to mess around with some soccer ball stuff. We have a goal and 4 soccer balls each with there own spawnXY in balls.conf. The first module was just to send arena message on player pick, fire, goal. The next part was a bit more challenging. The ball would respawn back to its original position if not picked up within 7 seconds. This involved setting/clearing timers, moving the ball back. Was using a tuple to pass extra params threw the timers (cool stuff), but relized it wasnt needed. useful info: http://docs.python.org/library/functions.html
The module functions without errors, but someone with more as3/python experience could maybe point out the obvious or better methods.
gball.py
BALL_SPAWN = (
# x, y
(503, 503),
(503, 521),
(521, 503),
(521, 521))
from asss import *
chat = get_interface(I_CHAT)
balls = get_interface(I_BALLS)
def make_drop_timer(initial, interval, arena, bid):
def drop_timer():
chat.SendArenaMessage(arena, "Ball returned (not picked up within limit) - Ball ID: %s" % bid)
move_ball(arena, bid)
return set_timer(drop_timer, initial, interval)
def pick(arena, p, bid):
chat.SendArenaMessage(arena, "Ball picked up by " + p.name + " - Ball ID: %s" % bid)
arena.mytimer[bid] = None
def fire(arena, p, bid):
chat.SendArenaMessage(arena, "Ball fired by " + p.name + " - Ball ID: %s" % bid)
arena.mytimer[bid] = make_drop_timer(700, 0, arena, bid)
def goal(arena, p, bid, x, y):
chat.SendArenaSoundMessage(arena, SOUND_OOO, "Goal scored by " + p.name + " - Ball ID: %s" % bid)
arena.mytimer[bid] = None
def move_ball(arena, bid):
bd = balldata()
bd.state = BALL_ONMAP
bd.x = BALL_SPAWN[bid][0] * 16
bd.y = BALL_SPAWN[bid][1] * 16
bd.xspeed = bd.yspeed = 0
bd.carrier = None
bd.freq = -1
bd.time = current_ticks()
balls.PlaceBall(arena, bid, bd)
def mm_attach(arena):
arena.cb1 = reg_callback(CB_BALLPICKUP, pick)
arena.cb2 = reg_callback(CB_BALLFIRE, fire)
arena.cb3 = reg_callback(CB_GOAL, goal)
arena.mytimer = [None, None, None, None]
def mm_detach(arena):
arena.cb1 = None
arena.cb2 = None
arena.cb3 = None
arena.mytimer = [None, None, None, None]
|
Last edited by Snuka on Tue Mar 01, 2011 2:35 am, edited 2 times in total |
|