Пример #1
0
 def run(self):
   """Execute this state's main loop."""
   self.done = False
   
   clock = Clock()
   time = 0
   while not self.done:
     self._pm.run(time)
     time = clock.elapsed_time.milliseconds
     clock.restart()
Пример #2
0
 def __init__(self, world, gameView, faction, SUController):
   self.world = world
   self.gameView = gameView
   self.faction = faction
   self.SUController = SUController
   
   self.clicked = False
   self.clickedPos = None
   self.doubleClickClock = Clock()
   self.dragClock = Clock()
   self.dragRect = Rectangle()
   
   self.gameView.addView(self)
Пример #3
0
    class Cursor(_UI):
        # A blinking line.

        #################################
        # PUBLIC

        def __init__(self):
            _UI.__init__(self)
            self._init_Box()

        def draw(self, target, states):
            self._parent_Box(target, states)
            self._flicker_Box()
            _UI.draw(self, target, states)
            self._draw_Box(target, states)

        #################################
        # PRIVATE

        w, h = 2, 15
        _Box = None
        _Flicker_Clock = None

        def _init_Box(self):
            self._Box = RectangleShape(self.size)
            self._Flicker_Clock = Clock()
            self._Box.fill_color = Color.BLACK

        def _parent_Box(self, target, states):
            x_move = self.x - self.old_pos[0]
            y_move = self.y - self.old_pos[1]
            self._Box.position = \
            self._Box.position[0]+x_move, self._Box.position[1]+y_move

        def _draw_Box(self, target, states):
            self._Box.draw(target, states)

        def _flicker_Box(self):
            if self._Flicker_Clock.elapsed_time.seconds >= 0.5:
                if self._Box.fill_color.a != 0:
                    c = self._Box.fill_color
                    c.a = 0
                    self._Box.fill_color = c
                else:
                    a = self.alpha
                    c = self._Box.fill_color
                    c.a = a
                    self._Box.fill_color = c
                self._Flicker_Clock.restart()
Пример #4
0
	class Cursor(_UI):
	# A blinking line.
		
		#################################
		# PUBLIC

		def __init__(self):
			_UI.__init__(self)
			self._init_Box()

		def draw(self, target, states):
			self._parent_Box(target, states)
			self._flicker_Box()
			_UI.draw(self, target, states)
			self._draw_Box(target, states)

		#################################
		# PRIVATE

		w,h = 2,15
		_Box = None
		_Flicker_Clock = None

		def _init_Box(self):
			self._Box = RectangleShape(self.size)
			self._Flicker_Clock = Clock()
			self._Box.fill_color = Color.BLACK

		def _parent_Box(self, target, states):
			x_move = self.x - self.old_pos[0]
			y_move = self.y - self.old_pos[1]
			self._Box.position = \
			self._Box.position[0]+x_move, self._Box.position[1]+y_move

		def _draw_Box(self, target, states):
			self._Box.draw(target, states)

		def _flicker_Box(self):
			if self._Flicker_Clock.elapsed_time.seconds >= 0.5:
				if self._Box.fill_color.a != 0:
					c=self._Box.fill_color;c.a=0;self._Box.fill_color=c
				else:
					a = self.alpha
					c=self._Box.fill_color;c.a=a;self._Box.fill_color=c
				self._Flicker_Clock.restart()
Пример #5
0
logg.info('Drawable functions imported')

from raycaster import Raycaster

logg.info('Raycaster class imported')

from hud import Hud

logg.info('Hud class imported')

###
# DEBUG FUNCTIONS
##

clock = Clock()
frame = 0
fps = 0
average_fps = 0
all_frames = 0


def draw_fps(framein):
    global frame, fps, all_frames, average_fps

    frame += 1
    time = clock.elapsed_time.as_milliseconds()
    if time >= 1000:
        clock.restart()
        time = time / 1000
        fps = int(framein / time) + 1
Пример #6
0
class particle_generator:
#Makes lots of little particles.
#Has a few handy presets.

# WIP - only catered for dust effects.

	def __init__(self):
		self.particles = []

		self.clock = Clock()
		self.interval = 0

	# MAKE (public)

	def create(self, amt=1, area=(0,0,0,0)):
	#Randomly speckle the sprites within an area.
		
		#Only allow it to do so in the proper intervals.
		if self.clock.elapsed_time.seconds < self.interval:
			return

		self.clock.restart()

		#Create the particles.
		texture = MyTexture("assets/effects/dust.PNG")
		for i in range(amt):
			sprite = MySprite(texture)
			sprite.clip.set(10,10)

			#random CLIP
			c = random_int(0,3)
			sprite.clip.use(c,0)

			#Random AREA.
			x1, y1, x2, y2 = area
			x2 -= sprite.w
			y2 -= sprite.h
			if x2 < x1: x2 = x1
			if y2 < y1: y2 = y1

			x = random_int(x1, x2)
			y = random_int(y1, y2)
			sprite.x, sprite.y = x, y
			#

			#animate
			self._jump(sprite)
			self._fade(sprite)
			#

			self.particles.append(sprite)


	def draw(self):
	#Animate, Draw, Delete
		self._play()
		for i, particle in enumerate(self.particles):
			particle.draw()

			if particle.color.a == 0:
				del self.particles[i]


	# ANIMATE

	def _play(self): #draw
		for particle in self.particles:
			particle.animation.play()

	def _jump(self, particle): #create
		speed = 1.0
		s = random_int(10,20)
		s = float(s/10)

		particle.animation.y.speed = -s
		particle.animation.y.vel = 0.1

	def _fade(self, particle): #create
		particle.animation.alpha.vel = -1
Пример #7
0
	def __init__(self):
		self.particles = []

		self.clock = Clock()
		self.interval = 0
Пример #8
0
 def _init_Box(self):
     self._Box = RectangleShape(self.size)
     self._Flicker_Clock = Clock()
     self._Box.fill_color = Color.BLACK
Пример #9
0
class SelectionController:
  
  SELECT_DISTANCE = 20
  DOUBLE_CLICK_INTERVAL = 200
  DRAG_START_DURATION = 50
  DRAG_RECT_LAYER = 20
  
  def __init__(self, world, gameView, faction, SUController):
    self.world = world
    self.gameView = gameView
    self.faction = faction
    self.SUController = SUController
    
    self.clicked = False
    self.clickedPos = None
    self.doubleClickClock = Clock()
    self.dragClock = Clock()
    self.dragRect = Rectangle()
    
    self.gameView.addView(self)

  def onMouseDownEvent(self, dispatcher, event):
    if event.button != Mouse.LEFT:
      return False
    
    self.clicked = True
    self.clickedPos = event.position
    self.dragClock.restart()
    return True
  
  def onMouseMoveEvent(self, dispatcher, event):
    if not self.clicked:
      return False
    
    if self.dragClock.elapsed_time.milliseconds >= SelectionController.DRAG_START_DURATION:
      p = self.gameView.viewToWorld(self.clickedPos)
      s = self.gameView.scaleViewToWorld(event.position - self.clickedPos)
      self.dragRect = Rectangle(p, s)
    
  
  def onMouseUpEvent(self, dispatcher, event):
    if event.button != Mouse.LEFT:
      return False
    
    if not self.clicked:
      return False
    
    self.clicked = False
    
    if self.dragRect != Rectangle(): # Dragging
      units = self.world.getUnitsWithinRectangle(self.dragRect, self.faction)
      if not Input.isKeyPressed(Keyboard.L_SHIFT) and not Input.isKeyPressed(Keyboard.L_ALT):
        self.SUController.deselectAll()
      if Input.isKeyPressed(Keyboard.L_ALT):
        self.SUController.removeUnits(units)
      else:
        self.SUController.addUnits(units)
      self.dragRect = Rectangle()
      return True
    
    # If the mouse moved too much, don't do anything
    if Util.vectorToDistance(event.position - self.clickedPos) > SelectionController.SELECT_DISTANCE:
      return False 
    
    # If clicked is true and a mouseUp event was caught here, it means we 
    # we haven't stacked another controller on top of this one. So it's safe
    # to pick a single entity.
    worldPos = self.gameView.viewToWorld(event.position)
    unit = self.world.getClosestUnit(worldPos, self.faction)
    dist = Util.vectorToDistance(unit.getComponent(PositionComponent).p - worldPos)
    # Stop if closest unit was too far away from mouse
    if self.gameView.scaleWorldToView(Vector2(dist, 0)).x > SelectionController.SELECT_DISTANCE:
      if not Input.isKeyPressed(Keyboard.L_SHIFT):
        self.SUController.deselectAll()
      return True
    
    # Definitely changing selection
    if not Input.isKeyPressed(Keyboard.L_SHIFT) and not Input.isKeyPressed(Keyboard.L_ALT):
      self.SUController.deselectAll()
    if self.doubleClickClock.elapsed_time.milliseconds > SelectionController.DOUBLE_CLICK_INTERVAL: # SINGLE CLICK
      if Input.isKeyPressed(Keyboard.L_ALT):
        self.SUController.removeUnit(unit)
      else:
        self.SUController.addUnit(unit)
    else: # DOUBLE CLICK
      rect = self.gameView.camera.viewRect
      units = self.world.getUnitsWithinRectangle(rect, self.faction)
      units = [u for u in units if u.name == unit.name]
      if Input.isKeyPressed(Keyboard.L_ALT):
        self.SUController.removeUnits(units)
      else:
        self.SUController.addUnits(units)
      
      
    self.doubleClickClock.restart()
    
    return True
  
  def tick(self, dt):
    pass
  
  def draw(self, view):
    if self.dragRect == None:
      return
    sprite = RectangleShape(self.dragRect.size)
    sprite.position = self.dragRect.position
    sprite.fill_color = Color.TRANSPARENT
    sprite.outline_color = Color.RED
    sprite.outline_thickness = 0.1
    view.drawList[SelectionController.DRAG_RECT_LAYER].append(sprite)
Пример #10
0
		def _init_Box(self):
			self._Box = RectangleShape(self.size)
			self._Flicker_Clock = Clock()
			self._Box.fill_color = Color.BLACK