コード例 #1
0
ファイル: enemies.py プロジェクト: jochem4207/fifengine-demos
    def update(self):
        if self._dir == 1:
            self.applyThrust(fife.DoublePoint(0, -0.5))
        elif self._dir == 0:
            self.applyThrust(fife.DoublePoint(0, 0.5))

        if self._time >= 1000:
            if self._dir == 1:
                self._dir = 0
            elif self._dir == 0:
                self._dir = 1

            self._time = 0

        self._time += self._scene.timedelta

        super(Saucer1, self).update()

        self.fire(fife.DoublePoint(-1, 0))
コード例 #2
0
ファイル: enemies.py プロジェクト: jochem4207/fifengine-demos
    def update(self):
        super(Boss, self).update()

        playerloc = self._scene.player.location.getExactLayerCoordinates()
        bossloc = self.location.getExactLayerCoordinates()

        playerloc.x -= bossloc.x
        playerloc.y -= bossloc.y

        self.fire(fife.DoublePoint(playerloc.x, playerloc.y))
コード例 #3
0
ファイル: weapons.py プロジェクト: jochem4207/fifengine-demos
	def fire(self, direction):
		velocity = fife.DoublePoint(direction)
		velocity.normalize()
		velocity.x = velocity.x * self._projectileVelocity
		velocity.y = velocity.y * self._projectileVelocity
	
		if (self._scene.time - self._lastfired) > self._firerate:
			pjctl = Projectile(self._scene, self._ship, "fireball", 6000 )
			pjctl.run(velocity, self._ship.location)
			self._lastfired = self._scene.time
			self._scene.addObjectToScene(pjctl)	
			if self._soundclip:
				self._soundclip.play()
コード例 #4
0
ファイル: weapons.py プロジェクト: jochem4207/fifengine-demos
	def fire(self, direction):
		velocity = fife.DoublePoint(direction)
		velocity.normalize()
		velocity.x = velocity.x * self._projectileVelocity
		velocity.y = velocity.y * self._projectileVelocity
	
		if (self._scene.time - self._lastfired) > self._firerate:
			pjctl = Projectile(self._scene, self._ship, "bullet1", 3000 )
			pjctl.run(velocity, self._ship.location)
			self._lastfired = self._scene.time
			self._scene.addObjectToScene(pjctl)
			if self._soundclip:
				location = self._ship.location.getExactLayerCoordinates()
				self._soundclip.position = (location.x, location.y)
				self._soundclip.play()
コード例 #5
0
ファイル: weapons.py プロジェクト: CyberSys/fifengine-demos
    def fire(self, direction):

        if (self._scene.time - self._lastfired) > self._firerate:
            velocity = fife.DoublePoint(direction)
            velocity.normalize()
            velocity.x = velocity.x * self._projectileVelocity
            velocity.y = velocity.y * self._projectileVelocity

            origin = fife.DoublePoint(0, 0)

            p2 = fife.DoublePoint(velocity)
            p3 = fife.DoublePoint(velocity)
            p4 = fife.DoublePoint(velocity)
            p5 = fife.DoublePoint(velocity)
            p6 = fife.DoublePoint(velocity)

            p2.rotate(origin, -10)
            p3.rotate(origin, -5)
            p4.rotate(origin, 0)
            p5.rotate(origin, 5)
            p6.rotate(origin, 10)

            pjctl2 = Projectile(self._scene, self._ship, "bullet1", 3000)
            pjctl2.run(p2, self._ship.location)
            self._scene.addObjectToScene(pjctl2)

            pjctl3 = Projectile(self._scene, self._ship, "bullet1", 3000)
            pjctl3.run(p3, self._ship.location)
            self._scene.addObjectToScene(pjctl3)

            pjctl4 = Projectile(self._scene, self._ship, "bullet1", 3000)
            pjctl4.run(p4, self._ship.location)
            self._scene.addObjectToScene(pjctl4)

            pjctl5 = Projectile(self._scene, self._ship, "bullet1", 3000)
            pjctl5.run(p5, self._ship.location)
            self._scene.addObjectToScene(pjctl5)

            pjctl6 = Projectile(self._scene, self._ship, "bullet1", 3000)
            pjctl6.run(p6, self._ship.location)
            self._scene.addObjectToScene(pjctl6)

            if self._soundclip:
                location = self._ship.location.getExactLayerCoordinates()
                self._soundclip.setPosition(location)
                self._soundclip.play()

            self._lastfired = self._scene.time
コード例 #6
0
    def is_in_region(self, location, region):
        """Checks if a given point is inside the given region

        Args:
            location: A fife.DoublePoint instance or a tuple with 2 elements

            region: The name of the region

        Raises:
            :class:`fife_rpg.map.NoSuchRegionError` if the specified region
            does not exist.
        """
        if isinstance(location, tuple) or isinstance(location, list):
            location = fife.DoublePoint(location[0], location[1])
        if region not in self.regions:
            raise NoSuchRegionError(self.name, region)
        else:
            return self.regions[region].contains(location)
コード例 #7
0
    def __init__(self,
                 gamecontroller,
                 layer,
                 typename,
                 baseobjectname,
                 instancename,
                 instanceid=None,
                 createInstance=False):
        """
		@param gamecontroller: A reference to the master game controller
		@param instancename: The name of the object to load.  The object's XML file must
		be part of the map file or added with fife.extensions.loaders.loadImportFile
		@param instanceid: used if you want to give a specific ID to the instance to
		differenciate it from other instances
		@param createInstance: If this is True it will attempt to be loaded from disk and not
		use one that has already been loaded from the map file.  See the note about the 
		instancename paramater above.
		"""
        self._gamecontroller = gamecontroller
        self._fifeobject = None

        self._typename = typename
        self._type = GameObjectTypes[typename]
        self._baseobjectname = baseobjectname

        self._name = instancename
        if instanceid:
            self._id = instanceid
        else:
            self._id = self._name

        self._instance = None
        self._position = fife.DoublePoint(0.0, 0.0)

        self._actionlistener = None

        self._layer = layer

        if createInstance:
            self._createFIFEInstance(self._layer)
        else:
            self._findFIFEInstance(self._layer)

        self._activated = True
コード例 #8
0
    def applyThrust(self, vector):
        """
		Applies a thrust vector to the object.  
		
		@note: Objects do not have mass and therefore no inertia.
		
		@param vector A vector specifying the direction and intensity of thrust.
		@type vector: L{fife.DoublePoint}
		"""
        self._velocity.x += (vector.x *
                             (self._scene.timedelta / 1000.0)) / self._xscale
        self._velocity.y += (vector.y *
                             (self._scene.timedelta / 1000.0)) / self._yscale

        if self._velocity.length() > self._maxvelocity:
            norm = fife.DoublePoint(self._velocity)
            norm.normalize()
            self._velocity.x = norm.x * self._maxvelocity
            self._velocity.y = norm.y * self._maxvelocity
コード例 #9
0
    def mouseDragged(self, event):  # pylint: disable=C0103,W0221
        """Called when the mouse is moved while a button is being pressed.

        Args:
            event: The mouse event
        """
        self.middle_container.activate()
        application = self.gamecontroller.application
        for callback_data in self.callbacks["mouse_dragged"]:
            func = callback_data["func"]
            click_point = fife.ScreenPoint(event.getX(), event.getY())
            func(click_point, event.getButton())
        if event.getButton() == fife.MouseEvent.MIDDLE:
            current_map = application.current_map
            if self.old_mouse_pos is None or current_map is None:
                return
            cursor = application.engine.getCursor()
            cursor.setPosition(int(self.old_mouse_pos.getX()),
                               int(self.old_mouse_pos.getY()))
            cur_mouse_pos = fife.DoublePoint(event.getX(), event.getY())
            offset = cur_mouse_pos - self.old_mouse_pos
            offset *= self.DRAG_SPEED
            offset.rotate(current_map.camera.getRotation())
            current_map.move_camera_by((offset.getX(), offset.getY()))
コード例 #10
0
ファイル: player.py プロジェクト: lynxis/fifengine
	def update(self):
	
		NSkey = False
		EWkey = False
		
		#player is no longer invulnerable
		if not self._flashing and self._invulnerable and not self._dead:
			self._invulnerable = False

		oldpos = self.location
		
		if not self._dead:
			if self._scene.keystate['UP']:
				self.applyThrust(fife.DoublePoint(0,-1*self._acceleration))
				NSkey = True
			if self._scene.keystate['DOWN']:
				self.applyThrust(fife.DoublePoint(0,self._acceleration))
				NSkey = True
			if self._scene.keystate['LEFT']:
				self.applyThrust(fife.DoublePoint(-1*self._acceleration,0))
				EWkey = True
			if self._scene.keystate['RIGHT']:
				self.applyThrust(fife.DoublePoint(self._acceleration,0))
				EWkey = True
		
			if NSkey and not EWkey:
				if self._velocity.x != 0:
					vel = self._acceleration * cmp(self._velocity.x, 0) * -1
					self.applyThrust(fife.DoublePoint(vel, 0))
			elif EWkey and not NSkey:
				if self._velocity.y != 0:
					vel = self._acceleration * cmp(self._velocity.y, 0) * -1
					self.applyThrust(fife.DoublePoint(0, vel))
			elif not NSkey and not EWkey:
				self.applyBrake(self._acceleration)
		
			#fire the currently selected gun
			if self._scene.keystate['SPACE']:
				self.fire(fife.DoublePoint(1,0))
			
		if self._dead and self._velocity.length() > 0:
			self.applyBrake(self._acceleration)
		
		super(Player, self).update()
		
		#set up the players camera bounds
		#@todo: grab screen resolution from somewhere
		topleft = self._scene.camera.toMapCoordinates(fife.ScreenPoint(0,0))
		bottomright = self._scene.camera.toMapCoordinates(fife.ScreenPoint(1024,768))

		camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y)
	
		#add the padding to the edge
		camrect.x += self._boundingBox.w
		camrect.y += self._boundingBox.h
		camrect.w -= 2*self._boundingBox.w
		camrect.h -= 2*self._boundingBox.h
		
		pos = oldpos.getExactLayerCoordinates()
		
		newpos = oldpos
		
		if not self._boundingBox.intersects(camrect):
			if (self._boundingBox.x + self._boundingBox.w) < camrect.x:
				if self._velocity.x < 0:
					self._velocity.x = 0
				pos.x += (camrect.x - (self._boundingBox.x + self._boundingBox.w))/self._xscale + 0.03
				
				if not ((self._boundingBox.y + self._boundingBox.h) < camrect.y) and not (self._boundingBox.y > (camrect.y + camrect.h)):
					pos.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale
					
				newpos.setExactLayerCoordinates(pos)
			if self._boundingBox.x > ( camrect.x + camrect.w ):
				self._velocity.x = 0

			if (self._boundingBox.y + self._boundingBox.h) < camrect.y:
				if self._velocity.y < 0:
					self._velocity.y = 0
				pos.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale
				newpos.setExactLayerCoordinates(pos)			
			if self._boundingBox.y > (camrect.y + camrect.h):
				if self._velocity.y > 0:
					self._velocity.y = 0
				pos.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale
				newpos.setExactLayerCoordinates(pos)

			self.location = newpos
			
		if oldpos != self.location:
			self._changedPosition = True
		else:
			self._changedPosition = False
コード例 #11
0
	def update(self):	
		self.applyThrust(fife.DoublePoint(-0.25,self._ythrust))
		super(DiagSaucer, self).update()

		self.fire(fife.DoublePoint(-1,0))