Beispiel #1
0
    def __init__(self, wld, robot):
        self.wld = wld
        w = wld.w
        self.robot = robot # Fired by this robot

        self._fuse = None
        self._exploding = False

        r = robot.turret
        pos = r.position
        vel = r.linearVelocity
        ang = r.angle

        blocalvel = box2d.b2Vec2(conf.bulletspeed, 0)
        bwvel = r.GetWorldVector(blocalvel)
        bvel = bwvel + vel
        #print bvel, bvel.length

        bodyDef = box2d.b2BodyDef(type=box2d.b2_dynamicBody,)
        blocalpos = box2d.b2Vec2(.1, 0)
        bwpos = r.GetWorldVector(blocalpos)
        bpos = bwpos + pos
        bodyDef.position = bpos
        bodyDef.angle = ang
        bodyDef.isBullet = True
        bodyDef.linearDamping = 0
        bodyDef.userData = {}

        body = w.CreateBody(bodyDef)
        #print body
        #print 'IB', body.isBullet
        body.linearVelocity = bvel
        body.CreatePolygonFixture(
                    box=(0.1,0.1),
                    friction=0,
                    density=conf.bullet_density,
                    restitution=0,
                    filter = box2d.b2Filter(
                                groupIndex = -robot.n,))

        body.userData['actor'] = self
        body.userData['kind'] = 'bullet'
        body.userData['shooter'] = robot

        self.body = body

        v = wld.v.addbullet(pos)
        self.v = v
Beispiel #2
0
    def __init__(self, wld, kind, name, pos, ang):
        w = wld.w

        Robot.nrobots += 1
        self.n = Robot.nrobots

        self.alive = True
        self.health = conf.maxhealth
        self.kind = kind
        self.name = name

        self._enable_debug = None

        self._pingtype = 'w'
        self._pingangle = 0
        self._pingdist = 0

        self._pinged = -5 # Tick most recently pinged by another robot's radar

        self._cannonheat = 0
        self._cannonreload = 0

        self._outlasted = 0 # number of robots killed while this one is still alive
        self._damage_caused = 0
        self._kills = 0 # number of robots this one delivered the final damage to

        bodyDef = box2d.b2BodyDef(type=box2d.b2_dynamicBody,)
        bodyDef.position = pos
        bodyDef.angle = ang

        bodyDef.linearDamping = conf.robot_linearDamping
        bodyDef.angularDamping = conf.robot_angularDamping
        bodyDef.userData = {}

        body = w.CreateBody(bodyDef)
        body.CreatePolygonFixture(
                box=(1, 1),
                density=conf.robot_density,
                friction=conf.robot_friction,
                restitution=conf.robot_restitution,
                filter = box2d.b2Filter(
                            groupIndex = -self.n,))

        body.userData['actor'] = self
        body.userData['kind'] = 'robot'

        self.body = body

        turretDef = box2d.b2BodyDef(type=box2d.b2_dynamicBody,)
        turretDef.position = pos
        turretDef.angle = ang

        turretDef.linearDamping = 0
        turretDef.angularDamping = 0
        turret = w.CreateBody(bodyDef)

        turret.CreatePolygonFixture(
                    box=(.1, .1),
                    density=1,
                    friction=0,
                    restitution=0,
                    filter = box2d.b2Filter(
                        groupIndex = -self.n,))
        self.turret = turret

        jointDef = box2d.b2RevoluteJointDef()
        jointDef.Initialize(body, turret, pos)
        jointDef.maxMotorTorque = conf.turret_maxMotorTorque
        jointDef.motorSpeed = 0.0
        jointDef.enableMotor = True
        self.turretjoint = w.CreateJoint(jointDef)
        self._turret_torque = 0

        v = wld.v.addrobot(pos, ang)
        self.v = v

        i = wld.v.addrobotinfo(self.n, name)
        self.i = i