Re: ideal way of creating a map parcer?

(Psst: here's my Box2D test. Yes, I made extra variables so I wouldn't have to remember to capitalize true and false. 10 years in Java / _javascript_ / BGT tends to form habits, and I'd rather wait to break them until I know it's worth it.)

from Box2D import *
import pygame
import os.path
from sound_pool import *

pygame.mixer.pre_init()
pygame.mixer.init()

world=b2World(b2Vec2(0, -10), True)
true=True
false=False
none=None
null=None

statdef=b2BodyDef()
statdef.type=b2_staticBody
statdef.position.Set(10, 0)
statbod=world.CreateBody(statdef)
box=b2PolygonShape()
box.SetAsBox(100, 1)
fixdef=b2FixtureDef()
fixdef.shape=box
fixdef.density=1
fix=statbod.CreateFixture(fixdef)

balldef=b2BodyDef()
balldef.position.Set(10, 10)
balldef.type=b2_dynamicBody
ball=world.CreateBody(balldef)
circle=b2CircleShape()
circle.m_radius=1
circdef=b2FixtureDef()
circdef.shape=circle
circdef.density=1
circfix=ball.CreateFixture(circdef)
circfix.restitution=0.25
circfix.friction=0.5

snd=os.path.normpath("c:\\users\\cae\\aviewer\\sounds\\red.wav")
pool=sound_pool()
slot=pool.play_2d(snd, 0, 0, ball.position.x, ball.position.y, True)

frame=0

class CL(b2ContactListener) :
    def BeginContact(this, contact) :
        
        print "Begin Contact..." + str(frame)
        pool.play_stationary("ball.wav", False)
        
    
    def EndContact(this, contact) :
        print "End contact. " + str(frame)
        
    

cl=CL()
world.contactListener=cl

clock=pygame.time.Clock()

while (frame<1000) :
    world.Step(clock.tick(50)*0.001, 8, 3)
    frame+=1
    pose=ball.position
    pool.update_sound_2d(slot, pose.x, pose.y)
    if(frame==500) :
        #help(ball.ApplyLinearImpulse)
        ball.ApplyLinearImpulse(b2Vec2(-30, 50), ball.position, True) # I have no idea what the last value does.
        print "SERVE!\n"
        pool.play_stationary("ball.wav", False)
    # Force.
    

In the above, the ball falls, lands on the rectangle, bounces a bit, then remains motionless until frame 500, at which point a linear impulse throws it up and to the left. According to my calculations at the time, it should have landed on the box again, but it either goes off the edge or through it, and falls out of earshot.
(It uses my port of BGT's sound_pool to manage the audio. I'm still not sure if I scaled the pan correctly.)

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Victorious via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : SoundMUD via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : ctoth via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : dhruv via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : dhruv via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : ogomez92 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : SoundMUD via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : severestormsteve1 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : danny via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : danny via Audiogames-reflector

Reply via email to