Exemplo n.º 1
1
    def tick(self) :
            
        if self.inputLeft.pressed() :
            self.getActor().adjustDirection( self.rotationSpeed )
            
        if self.inputRight.pressed() :
            self.getActor().adjustDirection( -self.rotationSpeed )

        if self.inputThrust.pressed() :
            theta = self.getActor().getHeadingRadians()
            self.vx += math.cos(theta) * self.thrust
            self.vy += math.sin(theta) * self.thrust
            heading = self.getActor().getDirection()
            
            ExplosionBuilder(self.getActor()) \
                .projectiles(4).follow().projectilesPerTick(1) \
                .spread(heading+160, heading+200).distance(40) \
                .randomSpread().speed(1,2,0,0).fade(3).eventName("spark") \
                .create()

        if self.fireTimer == None or self.fireTimer.isFinished() :
        
            if self.inputFire.pressed() :
                if self.fireTimer is None :
                    firePeriod = self.actor.costume.getCompanion(self.bulletName).costumeFeatures.firePeriod
                    self.fireTimer = Timer.createTimerSeconds(firePeriod)

                self.fire()
                self.fireTimer.reset()

            if self.inputWeapon1.pressed() :
                self.bulletName = "bullet-1"
                self.fireTimer = None

            if self.inputWeapon2.pressed() :
                self.bulletName = "bullet-2"
                self.fireTimer = None

        # Move and wrap from one edge of the world to the opposite.
        Moving.tick(self)
        
        if self.collided("deadly") :
            self.explode()

        # For debugging.
        if self.inputCheat.pressed() :
            game.getSceneDirector().addRocks(-1)
Exemplo n.º 2
0
    def __init__(self):
        try:
            self.camera = PiCamera()
            self.camera.resolution = (320, 240)
            self.camera.framerate = 30
            self.camera.start_preview()
            self.m = None
            try:
                self.m = Moving()
            except:
                print("Moving not possible")
                self.m = None
            time.sleep(2)
            self.t = tick(self.camera, self.m)
            self.t.start()
            self.m.start()

    #        self.m.setMotorPlan([[100,100],[100,100],[100,100],[100,100],[100,100],[100,100],[100,100],[100,100],[100,100],[100,100]])
        except:
            print("FAILED")
            traceback.print_exc()
Exemplo n.º 3
0
class DataServer:
    def __init__(self):
        try:
            self.camera = PiCamera()
            self.camera.resolution = (320, 240)
            self.camera.framerate = 30
            self.camera.start_preview()
            self.m = None
            try:
                self.m = Moving()
            except:
                print("Moving not possible")
                self.m = None
            time.sleep(2)
            self.t = tick(self.camera, self.m)
            self.t.start()
            self.m.start()

    #        self.m.setMotorPlan([[100,100],[100,100],[100,100],[100,100],[100,100],[100,100],[100,100],[100,100],[100,100],[100,100]])
        except:
            print("FAILED")
            traceback.print_exc()

    def current_time(self):
        return str(time.time())

    def current_image(self):
        image_stream = io.BytesIO()
        self.camera.capture(image_stream, 'jpeg', use_video_port=True)
        response = make_response(image_stream.getvalue())
        response.headers.set('Content-Type', 'image/jpeg')
        return response

    def get_data(self):
        data = {}
        data["startRequest"] = time.time()
        data["data"] = self.t.getData()
        data["endRequestTime"] = time.time()
        return jsonify(data)

    def set_current_plan(self, motorPlan):
        self.m.setMotorPlan(motorPlan)

    def stop(self):
        try:
            self.camera.stop_preview()
            self.camera.close()
        except:
            pass
        try:
            self.m.stop()
        except:
            pass
        try:
            self.t.stop()
        except:
            pass
Exemplo n.º 4
0
 def __init__(self) :
     Moving.__init__(self)
     self.lifeIcon = []
     self.bulletName = "bullet-1"
Exemplo n.º 5
0
 def tick(self):
     Moving.tick(self)
     self.actor.appearance.direction += self.rotationSpeed
Exemplo n.º 6
0
 def onAttach(self):
     Moving.onAttach(self)
     self.addTag("shootable")
     self.addTag("deadly")
Exemplo n.º 7
0
 def __init__(self) :
     Moving.__init__(self)
     self.strength = 1
     self.rotationSpeed = 0
     self.hits = 0
Exemplo n.º 8
0
 def __init__(self) :
     Moving.__init__(self)
     self.speed = 1
Exemplo n.º 9
-1
 def tick(self) :
     Moving.tick(self)
     if self.actor.appearance.alpha < 20 :
         self.actor.kill()
         return
     
     for role in self.collisions("shootable") :
         if not role.getActor().isDying() :
             role.shot(self)
             self.getActor().kill()
             return