예제 #1
0
def add_shield(self, entity_id):
    pos = defines.ENTITIES[entity_id]['BODY'].position
    if defines.ENTITIES[entity_id]['CATEGORY'] == 'ship':
        category_bits = 0x0002
        mask_bits = (0x0001 | 0x0003)
    else:
        category_bits = 0x0003
        mask_bits = (0x0001 | 0x0002)
    physic_debug, physic_body = new_physic_object(shape='circle',
                                                  scale=1,
                                                  angular_dampning=0,
                                                  linear_dampning=0,
                                                  pos=pos,
                                                  category_bits=category_bits,
                                                  mask_bits=mask_bits,
                                                  den=0.0)
    # help(defines.world)
    defines.world.CreateRevoluteJoint(
        bodyA=defines.ENTITIES[entity_id]['BODY'], bodyB=physic_body)
    new_shield = loadObject('shield.png', scale=1)
    new_shield.setPos(physic_body.position.x, 55, physic_body.position.y)
    physic_body.linearVelocity.Set(
        defines.ENTITIES[entity_id]['BODY'].linearVelocity.x,
        defines.ENTITIES[entity_id]['BODY'].linearVelocity.y)
    physic_body.angularVelocity = defines.ENTITIES[entity_id][
        'BODY'].angularVelocity

    defines.ENTITIES[entity_id]['E_FIELD_BODY'] = physic_body
    defines.ENTITIES[entity_id]['E_FIELD_DEBUG_NODE'] = physic_debug
    defines.ENTITIES[entity_id]['E_FIELD_NODE'] = new_shield
예제 #2
0
def break_asteroid(self, entity_id):
    number = randint(2, 3)
    i = 0
    while i < number:
        asteroid = loadObject("asteroid%d.png" % (randint(1, 3)),
                              scale=defines.AST_INIT_SCALE / number,
                              pos=LPoint3(23, 23))
        physic_debug, physic_body = new_physic_object(
            shape='circle',
            scale=defines.AST_INIT_SCALE / number,
            pos=defines.ENTITIES[entity_id]['BODY'].position)

        physic_body.linearVelocity.Set(
            defines.ENTITIES[entity_id]['BODY'].linearVelocity.x,
            defines.ENTITIES[entity_id]['BODY'].linearVelocity.y)
        physic_body.angularVelocity = defines.ENTITIES[entity_id][
            'BODY'].angularVelocity

        f = physic_body.GetWorldVector(localVector=(randint(-5, 5),
                                                    randint(-5, 5)))
        p = physic_body.GetWorldPoint(localPoint=(0.0, 0))
        physic_body.ApplyLinearImpulse(f, p, True)

        defines.ENTITIES[defines.ENTITY_ID] = {
            'CATEGORY': "asteroid",
            'NODE': asteroid,
            'PHYSIC_NODE': physic_debug,
            'BODY': physic_body,
            'SHIELD': 20,
            'ENERGY': 0
        }
        defines.ENTITY_ID += 1

        i += 1
예제 #3
0
def init_planet(self, pos=(0,0)):
    planet = loadObject("planet0.png", scale=2, pos=LPoint3(0, 0))
    physic_debug, physic_body = new_physic_object( shape='circle', 
                                                    scale=2, 
                                                    pos=pos,
                                                    den=400.0)

    task = taskMgr.doMethodLater(0.5, animate_planet, 'animate planet', extraArgs=[planet, 0, defines.ENTITY_ID], appendTask=True)
    defines.ENTITIES[defines.ENTITY_ID] = {'CATEGORY':"planet", 'NODE':planet, 
                'PHYSIC_NODE':physic_debug,'BODY':physic_body, 'SHIELD':999999, 'ENERGY':0, 'TASK': task}
    defines.ENTITY_ID += 1
예제 #4
0
def init_ship(self, ship_model_path, player2=False):
    if player2 == True:
        pos = LPoint2(12, -8)
        category_bits = 0x0003
        mask_bits = (0x0001 | 0x0002)
    else:
        pos = LPoint2(-12, 8)
        category_bits = 0x0002
        mask_bits = (0x0001 | 0x0003)

    new_ship = loadObject(ship_model_path, scale=0.5)
    physic_debug, physic_body = new_physic_object(shape='box',
                                                  scale=0.5,
                                                  angular_dampning=5,
                                                  linear_dampning=0.1,
                                                  pos=pos,
                                                  category_bits=category_bits,
                                                  mask_bits=mask_bits)
    new_ship.reparentTo(render)
    new_ship.setTexRotate(TextureStage.getDefault(), 90)

    new_weapon = weapon()
    if player2 == True:
        shipname = "ship2"
        self.life_bar2 = loadObject(scale=0.5)
        self.life_bar2.setPos(-0.1, 0, 0.12)
        self.life_bar2.reparentTo(base.a2dBottomRight)
        self.life_bar2.setSz(0.005)
        self.energy_bar2 = loadObject(scale=0.5)
        self.energy_bar2.setPos(-0.1, 0, 0.215)
        self.energy_bar2.reparentTo(base.a2dBottomRight)
        self.energy_bar2.setSz(0.005)
    else:
        shipname = "ship"
        self.life_bar = loadObject(scale=0.5)
        self.life_bar.setPos(-0.1, 0, 0.12)
        self.life_bar.reparentTo(base.a2dBottomLeft)
        self.life_bar.setSz(0.005)
        self.energy_bar = loadObject(scale=0.5)
        self.energy_bar.setPos(-1, 0, 0.215)
        self.energy_bar.reparentTo(base.a2dBottomLeft)
        self.energy_bar.setSz(0.005)

    defines.ENTITIES[defines.ENTITY_ID] = {
        'CATEGORY': shipname,
        'E_FIELD_ENABLED': False,
        'NODE': new_ship,
        'PHYSIC_NODE': physic_debug,
        'BODY': physic_body,
        'SHIELD': 100.0,
        'ENERGY': 100.0,
        'WEAPON': new_weapon
    }
    defines.ENTITY_ID += 1
예제 #5
0
def spawnAsteroids(self, quantity):
    for i in range(quantity):
        asteroid = loadObject("asteroid%d.png" % (randint(1, 3)),
                              scale=defines.AST_INIT_SCALE, pos=LPoint3(23, 23))
        physic_debug, physic_body  = new_physic_object( shape='circle', 
                                                        scale=defines.AST_INIT_SCALE, 
                                                        pos=(randint(-20, 20), randint(-15, 15)))

        f = physic_body.GetWorldVector(localVector=( randint(-40,40), randint(-40,40) ))
        p = physic_body.GetWorldPoint(localPoint=(0.0, 0))
        physic_body.ApplyLinearImpulse(f, p, True)

        defines.ENTITIES[defines.ENTITY_ID] = {'CATEGORY':"asteroid", 'NODE':asteroid, 'PHYSIC_NODE':physic_debug,'BODY':physic_body, 'SHIELD':100, 'ENERGY':0}
        defines.ENTITY_ID += 1
예제 #6
0
    def fire(self, panda3dworld, entity_id):
        now = globalClock.getRealTime()
        if now - self.last_time_fired < self.reload_time:
            if defines.ENTITIES[entity_id]['CATEGORY'] == 'ship':
                panda3dworld.keys["fire"] = 0
            elif defines.ENTITIES[entity_id]['CATEGORY'] == 'ship2':
                panda3dworld.keys["p2fire"] = 0
        else:
            self.last_time_fired = now
            new_bullet = loadObject("bullet.png", scale=0.2)
            pos = defines.ENTITIES[entity_id]["BODY"].position
            angle = 360 - defines.ENTITIES[entity_id]["NODE"].getR() 
            pos_x = pos.x + 0.5 * cos(angle* pi/180)
            pos_y = pos.y + 0.5 * sin(angle* pi/180)

            if defines.ENTITIES[entity_id]['CATEGORY'] == 'ship':
                category_bits = 0x0002
                mask_bits = (0x0001 | 0x0003)
            elif defines.ENTITIES[entity_id]['CATEGORY'] == 'ship2':
                category_bits = 0x0003
                mask_bits = (0x0001 | 0x0002)

            physic_debug, physic_body  = new_physic_object(shape='box', scale=0.2, is_a_bullet=True, pos=(pos_x,pos_y), 
                                                        category_bits=category_bits, mask_bits=mask_bits, den=self.bullet_density)
            # physic_debug.reparentTo(new_bullet)

            new_bullet.setPos(physic_body.position.x, 55, physic_body.position.y)
            physic_body.linearVelocity.Set(defines.ENTITIES[entity_id]['BODY'].linearVelocity.x, defines.ENTITIES[entity_id]['BODY'].linearVelocity.y)
            physic_body.angularVelocity = defines.ENTITIES[entity_id]['BODY'].angularVelocity

            f = physic_body.GetWorldVector(localVector=( self.bullet_speed * cos(angle* pi/180), self.bullet_speed * sin(angle* pi/180)))
            p = physic_body.GetWorldPoint(localPoint=(0.0, 0))
            physic_body.ApplyLinearImpulse(f, p, True)


            sound = base.loader.loadSfx("sounds/fire.ogg")
            sound.setVolume(0.5)
            sound.play()

            defines.ENTITIES[defines.ENTITY_ID] = {'CATEGORY':"bullet", 'EXPIRE': now + 3, 'NODE':new_bullet, 'PHYSIC_NODE':physic_debug ,'BODY':physic_body, 'SHIELD':0, 'ENERGY':0}
            defines.ENTITY_ID += 1
            defines.ENTITIES[entity_id]['ENERGY'] -= 20
            if defines.ENTITIES[entity_id]['CATEGORY'] == 'ship':
                panda3dworld.keys["fire"] = 0
            elif defines.ENTITIES[entity_id]['CATEGORY'] == 'ship2':
                panda3dworld.keys["p2fire"] = 0
예제 #7
0
def init_ship(self, ship_model_path, player2=False):
    if player2 == True:
        pos = LPoint2(12,-8)
        category_bits = 0x0003
        mask_bits = (0x0001 | 0x0002)
    else:
        pos = LPoint2(-12,8)
        category_bits = 0x0002
        mask_bits = (0x0001 | 0x0003)

    new_ship = loadObject(ship_model_path, scale=0.5)
    physic_debug, physic_body  = new_physic_object(shape='box', scale=0.5, 
                        angular_dampning=5, linear_dampning=0.1, pos=pos, 
                        category_bits=category_bits, mask_bits=mask_bits)
    new_ship.reparentTo(render)
    new_ship.setTexRotate(TextureStage.getDefault(), 90)

    new_weapon = weapon();
    if player2 == True:
        shipname = "ship2"
        self.life_bar2 = loadObject(scale=0.5)
        self.life_bar2.setPos(-0.1,0, 0.12)
        self.life_bar2.reparentTo(base.a2dBottomRight)
        self.life_bar2.setSz(0.005)
        self.energy_bar2 = loadObject(scale=0.5)
        self.energy_bar2.setPos(-0.1,0, 0.215)
        self.energy_bar2.reparentTo(base.a2dBottomRight)
        self.energy_bar2.setSz(0.005)
    else:
        shipname = "ship" 
        self.life_bar = loadObject(scale=0.5)
        self.life_bar.setPos(-0.1,0,0.12)
        self.life_bar.reparentTo(base.a2dBottomLeft)
        self.life_bar.setSz(0.005)
        self.energy_bar = loadObject(scale=0.5)
        self.energy_bar.setPos(-1,0,0.215)
        self.energy_bar.reparentTo(base.a2dBottomLeft)
        self.energy_bar.setSz(0.005)

    defines.ENTITIES[defines.ENTITY_ID] = {'CATEGORY':shipname,'E_FIELD_ENABLED': False, 'NODE':new_ship, 'PHYSIC_NODE':physic_debug, 'BODY':physic_body, 'SHIELD':100.0, 'ENERGY':100.0, 'WEAPON':new_weapon}
    defines.ENTITY_ID += 1
예제 #8
0
def init_planet(self, pos=(0, 0)):
    planet = loadObject("planet0.png", scale=2, pos=LPoint3(0, 0))
    physic_debug, physic_body = new_physic_object(shape='circle',
                                                  scale=2,
                                                  pos=pos,
                                                  den=400.0)

    task = taskMgr.doMethodLater(0.5,
                                 animate_planet,
                                 'animate planet',
                                 extraArgs=[planet, 0, defines.ENTITY_ID],
                                 appendTask=True)
    defines.ENTITIES[defines.ENTITY_ID] = {
        'CATEGORY': "planet",
        'NODE': planet,
        'PHYSIC_NODE': physic_debug,
        'BODY': physic_body,
        'SHIELD': 999999,
        'ENERGY': 0,
        'TASK': task
    }
    defines.ENTITY_ID += 1
예제 #9
0
def break_asteroid(self, entity_id):
    number = randint(2, 3)
    i = 0
    while i < number:
        asteroid = loadObject("asteroid%d.png" % (randint(1, 3)),
                              scale=defines.AST_INIT_SCALE/number, pos=LPoint3(23, 23))
        physic_debug, physic_body  = new_physic_object( shape='circle', 
                                                        scale=defines.AST_INIT_SCALE/number, 
                                                        pos=defines.ENTITIES[entity_id]['BODY'].position)
      

        physic_body.linearVelocity.Set(defines.ENTITIES[entity_id]['BODY'].linearVelocity.x, defines.ENTITIES[entity_id]['BODY'].linearVelocity.y)
        physic_body.angularVelocity = defines.ENTITIES[entity_id]['BODY'].angularVelocity

        f = physic_body.GetWorldVector(localVector=( randint(-5,5), randint(-5,5) ))
        p = physic_body.GetWorldPoint(localPoint=(0.0, 0))
        physic_body.ApplyLinearImpulse(f, p, True)

        defines.ENTITIES[defines.ENTITY_ID] = {'CATEGORY':"asteroid", 'NODE':asteroid, 'PHYSIC_NODE':physic_debug,'BODY':physic_body, 'SHIELD':20, 'ENERGY':0}
        defines.ENTITY_ID += 1

        i += 1
예제 #10
0
def spawnAsteroids(self, quantity):
    for i in range(quantity):
        asteroid = loadObject("asteroid%d.png" % (randint(1, 3)),
                              scale=defines.AST_INIT_SCALE,
                              pos=LPoint3(23, 23))
        physic_debug, physic_body = new_physic_object(
            shape='circle',
            scale=defines.AST_INIT_SCALE,
            pos=(randint(-20, 20), randint(-15, 15)))

        f = physic_body.GetWorldVector(localVector=(randint(-40, 40),
                                                    randint(-40, 40)))
        p = physic_body.GetWorldPoint(localPoint=(0.0, 0))
        physic_body.ApplyLinearImpulse(f, p, True)

        defines.ENTITIES[defines.ENTITY_ID] = {
            'CATEGORY': "asteroid",
            'NODE': asteroid,
            'PHYSIC_NODE': physic_debug,
            'BODY': physic_body,
            'SHIELD': 100,
            'ENERGY': 0
        }
        defines.ENTITY_ID += 1
예제 #11
0
def add_shield(self, entity_id):
    pos = defines.ENTITIES[entity_id]['BODY'].position
    if defines.ENTITIES[entity_id]['CATEGORY'] == 'ship':
        category_bits = 0x0002
        mask_bits = (0x0001 | 0x0003)
    else:
        category_bits = 0x0003
        mask_bits = (0x0001 | 0x0002)
    physic_debug, physic_body  = new_physic_object(shape='circle', scale=1, 
                        angular_dampning=0, linear_dampning=0, pos=pos, 
                        category_bits=category_bits, mask_bits=mask_bits, den=0.0)
    # help(defines.world)
    defines.world.CreateRevoluteJoint(
            bodyA=defines.ENTITIES[entity_id]['BODY'],
            bodyB=physic_body
        )
    new_shield = loadObject('shield.png', scale=1)
    new_shield.setPos(physic_body.position.x, 55, physic_body.position.y)
    physic_body.linearVelocity.Set(defines.ENTITIES[entity_id]['BODY'].linearVelocity.x, defines.ENTITIES[entity_id]['BODY'].linearVelocity.y)
    physic_body.angularVelocity = defines.ENTITIES[entity_id]['BODY'].angularVelocity

    defines.ENTITIES[entity_id]['E_FIELD_BODY'] = physic_body
    defines.ENTITIES[entity_id]['E_FIELD_DEBUG_NODE'] = physic_debug
    defines.ENTITIES[entity_id]['E_FIELD_NODE'] = new_shield
예제 #12
0
    def fire(self, panda3dworld, entity_id):
        now = globalClock.getRealTime()
        if now - self.last_time_fired < self.reload_time:
            if defines.ENTITIES[entity_id]["CATEGORY"] == "ship":
                panda3dworld.keys["fire"] = 0
            elif defines.ENTITIES[entity_id]["CATEGORY"] == "ship2":
                panda3dworld.keys["p2fire"] = 0
        else:
            self.last_time_fired = now
            new_bullet = loadObject("bullet.png", scale=0.2)
            pos = defines.ENTITIES[entity_id]["BODY"].position
            angle = 360 - defines.ENTITIES[entity_id]["NODE"].getR()
            pos_x = pos.x + 0.5 * cos(angle * pi / 180)
            pos_y = pos.y + 0.5 * sin(angle * pi / 180)

            if defines.ENTITIES[entity_id]["CATEGORY"] == "ship":
                category_bits = 0x0002
                mask_bits = 0x0001 | 0x0003
            elif defines.ENTITIES[entity_id]["CATEGORY"] == "ship2":
                category_bits = 0x0003
                mask_bits = 0x0001 | 0x0002

            physic_debug, physic_body = new_physic_object(
                shape="box",
                scale=0.2,
                is_a_bullet=True,
                pos=(pos_x, pos_y),
                category_bits=category_bits,
                mask_bits=mask_bits,
                den=self.bullet_density,
            )
            # physic_debug.reparentTo(new_bullet)

            new_bullet.setPos(physic_body.position.x, 55, physic_body.position.y)
            physic_body.linearVelocity.Set(
                defines.ENTITIES[entity_id]["BODY"].linearVelocity.x,
                defines.ENTITIES[entity_id]["BODY"].linearVelocity.y,
            )
            physic_body.angularVelocity = defines.ENTITIES[entity_id]["BODY"].angularVelocity

            f = physic_body.GetWorldVector(
                localVector=(self.bullet_speed * cos(angle * pi / 180), self.bullet_speed * sin(angle * pi / 180))
            )
            p = physic_body.GetWorldPoint(localPoint=(0.0, 0))
            physic_body.ApplyLinearImpulse(f, p, True)

            sound = base.loader.loadSfx("sounds/fire.ogg")
            sound.setVolume(0.5)
            sound.play()

            defines.ENTITIES[defines.ENTITY_ID] = {
                "CATEGORY": "bullet",
                "EXPIRE": now + 3,
                "NODE": new_bullet,
                "PHYSIC_NODE": physic_debug,
                "BODY": physic_body,
                "SHIELD": 0,
                "ENERGY": 0,
            }
            defines.ENTITY_ID += 1
            defines.ENTITIES[entity_id]["ENERGY"] -= 20
            if defines.ENTITIES[entity_id]["CATEGORY"] == "ship":
                panda3dworld.keys["fire"] = 0
            elif defines.ENTITIES[entity_id]["CATEGORY"] == "ship2":
                panda3dworld.keys["p2fire"] = 0