Posted By: ventilator
python wrapper - 06/05/09 20:24
when cleaning up the mess on my harddisk recently i came across my python wrapper which i started for a6 but never really finished. i played around with it a bit again and updated it to a7.
is there anyone interested in something like that? i think there aren't many python users here?
currently it wraps about 75% of the engine api so it still would need some work...
here is an example:
with python it's also possible to do a scheduler:
functions that use wait() need to be decorated with @schedule and wait() = yield() in python but otherwise it works just like in lite-c.
is there anyone interested in something like that? i think there aren't many python users here?
currently it wraps about 75% of the engine api so it still would need some work...
here is an example:
Code:
# python version of e_tutorial.cpp from a7 import * lesson = 3 ############################################################################### if lesson == 1: e = Engine("earth.mdl -nwnd -nc") while e.frame(): pass e.close() ############################################################################### if lesson == 2: e = Engine("-nwnd -nc") e.fps_max = 50 camera = e.camera add_folder("C:\Program Files (x86)\GStudio7\samples") level_load("small.hmp") while e.frame(): camera.pan += -3 * e.key_force.x camera.tilt += 3 * e.key_force.y move = Vector() move.x = 6 * (e.key_w - e.key_s) move.y = 6 * (e.key_a - e.key_d) camera.position += move.rotate(camera.orientation) e.close() ############################################################################### if lesson == 3: def plop(): ball.playsound(pong, 100) def kick(): speed = Vector(150, 0, 0) speed = speed.rotate(camera.orientation) speed.z = 75 ball.ph_addvelcentral(speed) plop() e = Engine("-nwnd -nc") e.shadow_stencil = 4 e.sound_vol = 100 camera = e.camera add_folder("C:\Program Files (x86)\GStudio7\samples") pong = Sound("tap.wav") splash = Panel() splash.bmap = Bitmap("digital.pcx") splash.scale_x = float(e.screen_size.x) / splash.bmap.width() splash.scale_y = float(e.screen_size.y) / splash.bmap.height() splash.flags |= VISIBLE for i in range(3): e.frame() level_load("small.hmp") ticks = 0 while ticks < 16: ticks += e.time_step e.frame() splash.remove() Entity("blood_gsmall+6.tga", flags2=SKY|CUBE, layer=0) ball = Entity("earth.mdl", (0, 0, 100), None) ball.ph_settype(PH_RIGID, PH_SPHERE) ball.ph_setmass(1, PH_SPHERE) ball.ph_setfriction(90) ball.ph_setelasticity(75, 100) ball.ph_setdamping(30, 5) ball.ph_addvelcentral((2, 2, 0)) ball.flags |= SHADOW|CAST ball.event = plop ball.emask |= ENABLE_FRICTION ph_setgravity((0, 0, -500)) e.on_space = kick speed = Vector() angular_speed = Vector() while e.frame(): force = Vector() force.x = -5 * (e.key_force.x + e.mouse_force.x) force.y = 5 * (e.key_force.y + e.mouse_force.y) move = vec_accelerate(angular_speed, force, 0.8) camera.orientation += move force.x = 6 * (e.key_w - e.key_s) force.y = 6 * (e.key_a - e.key_d) force.z = 6 * (e.key_home - e.key_end) move = vec_accelerate(speed, force, 0.5) camera.position += move.rotate(camera.orientation) e.close()
with python it's also possible to do a scheduler:
Code:
from a7_scheduler import * @schedule def rotate_entity(): while 1: e.my.pan += 5 * e.time_step yield(1) # wait 1 frame @schedule def move_camera(): camera = e.camera speed = Vector() angular_speed = Vector() while 1: force = Vector() force.x = -5 * (e.key_force.x + e.mouse_force.x) force.y = 5 * (e.key_force.y + e.mouse_force.y) move = vec_accelerate(angular_speed, force, 0.8) camera.orientation += move force.x = 6 * (e.key_w - e.key_s) force.y = 6 * (e.key_a - e.key_d) force.z = 6 * (e.key_home - e.key_end) move = vec_accelerate(speed, force, 0.5) camera.position += move.rotate(camera.orientation) yield(1) # wait 1 frame @schedule def main(): add_folder("C:\Program Files (x86)\GStudio7\samples") e.video_mode = 8 yield(3) # wait 3 frames level_load("small.hmp") Entity("blood_gsmall+6.tga", flags2=SKY|CUBE, layer=0) Entity("earth.mdl", (0, 0, 100), rotate_entity) move_camera() main() scheduler()
functions that use wait() need to be decorated with @schedule and wait() = yield() in python but otherwise it works just like in lite-c.