Ejemplo n.º 1
0
	def __init__(self):
		super().__init__()
	
		# Network Stream Connection and Queue
		self._controlQueue = deque()
		self._eventQueue = deque()
		self._toSendQueue = deque()
		
		# Reentrant Lock Variable, for Monitor Functions
		self._RELock = threading.RLock()
		
		
		# Test 'Messages'
		cMessage1 = {}
		cMessage1['type'] = 'Create'
		cMessage1['entityType'] = 'SpaceJet'
		cMessage1['entityId'] = 0
		cMessage2 = {}
		cMessage2['type'] = 'Update'
		cMessage2['entityId'] = 0
		cMessage2['position'] = vec(0, 200)
		cMessage2['velocity'] = vec(-1, 1)
		cMessage3 = {}
		cMessage3['type'] = 'Update'
		cMessage3['entityId'] = 0
		cMessage3['health'] = 0
		
		self._controlQueue.append(cMessage1)
		self._controlQueue.append(cMessage2)
		#self._controlQueue.append(cMessage3)
		
		# Remote Controlled Entities
		self._entities = {}
Ejemplo n.º 2
0
 def on_client_shoot(self, client, shot_id, gun, fx, fy, fz, tx, ty, tz, hits):
     if client.state.lastshot == -1:
         wait = time.time() - client.state.lastshot
     else:
         wait = client.state.gunwait
     
     pfrom = vec(fx, fy, fz).div(DMF)
     pto = vec(tx, ty, tz).div(DMF)
     
     if not client.state.alive or wait < client.state.gunwait: return
     if gun < weapon_types.GUN_FIST or gun > weapon_types.GUN_PISTOL: return
     if client.state.ammo[gun] <= 0: return
     if guns[gun].range and (pfrom.dist(pto) > guns[gun].range + 1): return
     
     if gun != weapon_types.GUN_FIST:
         client.state.ammo[gun] -= 1
         
     client.state.lastshot = time.time()
     client.state.gunwait = float(guns[gun].attackdelay)/1000.0
     
     with self.broadcastbuffer(1, True, [client]) as cds:
         swh.put_shotfx(cds, client, gun, shot_id, fx, fy, fz, tx, ty, tz)
     
     if gun == weapon_types.GUN_RL:
         client.state.rockets[shot_id] = gun
     elif gun == weapon_types.GUN_GL:
         client.state.grenades[shot_id] = gun
     else:
         for hit in hits:
             self.on_client_hit(client, gun, **hit)
Ejemplo n.º 3
0
	def removeTransform(self):
		t = self._transform
		
		self._transform._removeTransformable(self)
		self._transform = None
		
		self._worldPos 		= vec()
		self._worldRot		= 0.0
		self._worldScale	= vec(1,1)
		
		return t
Ejemplo n.º 4
0
	def __initP__(self, **kwArgs):
		super().__initP__(**kwArgs)
		
		self._transform 	= None
		self._worldPos 		= vec()
		self._worldRot 		= 0.0
		self._worldScale 	= vec(1, 1)
		self._lastTransformation = [False, [0,0,0]]
		
		'''		Temporary Fix		'''
		self.isDrawn = True
Ejemplo n.º 5
0
	def __initC__(self, **kwArgs):
		self._localPos		= getDictValue(kwArgs, vec(), ['lp', 'localPos'])
		self._localRot		= getDictValue(kwArgs, 0.0, ['lr', 'localRot'])
		self._localScale	= getDictValue(kwArgs, vec(1, 1), ['ls', 'localScale'])

		t = getDictValue(kwArgs, None, ['t', 'transform'])
		if(t):
			self.setTransform(t)
			self._onTransformation(self._lastTransformation[1])
		
		super().__initC__(**kwArgs)
Ejemplo n.º 6
0
 def damage_client(self, target, client, damage, gun, dx, dy, dz):
     v = vec(dx, dy, dz).div(DMF).rescale(DNF)
     
     target.state.receive_damage(damage)
     
     with self.broadcastbuffer(1, True) as cds:
         swh.put_damage(cds, target, client, damage)
         
         if target == client:
             #target.state.setpushed()
             pass
         elif not v.iszero():
             if target.state.health <= 0:
                 swh.put_hitpush(cds, target, gun, damage, v)
             else:
                 with target.sendbuffer(1, True) as cds:
                     swh.put_hitpush(cds, target, gun, damage, v)
             #target.state.setpushed()
             
         if target.state.health < 1:
             target.state.state = client_states.CS_DEAD
             
             target.state.deaths += 1
             if self.gamemode.hasteams and client.team == target.team:
                 client.state.frags -= 1
             else:
                 client.state.frags += 1
             
             swh.put_died(cds, target, client)
Ejemplo n.º 7
0
	def __initP__(self, **kwArgs):
		super().__initP__(**kwArgs)
		
		'''	Node and Update Values '''
		self._parent  	= None
		self._children 	= []
		
		'''	Transform Data '''
		self._translate 	= getDictValue(kwArgs, vec(), ['t', 'translate'])
		self._rotateRads 	= getDictValue(kwArgs, 0.0, ['r', 'rotate'])
		self._scale			= getDictValue(kwArgs, vec(1,1), ['s', 'scale'])
		self._gTrans		= self._translate.copy()
		self._gRotRads      = self._rotateRads
		self._gScale		= self._scale.copy()
	
		'''	Transformable Data	'''
		self._transformables  = []
Ejemplo n.º 8
0
    def __initP__(self, **kwArgs):
        super().__initP__(**kwArgs)

        """	Node and Update Values """
        self._parent = None
        self._children = []

        """	Transform Data """
        self._translate = getDictValue(kwArgs, vec(), ["t", "translate"])
        self._rotateRads = getDictValue(kwArgs, 0.0, ["r", "rotate"])
        self._scale = getDictValue(kwArgs, vec(1, 1), ["s", "scale"])
        self._gTrans = self._translate.copy()
        self._gRotRads = self._rotateRads
        self._gScale = self._scale.copy()

        """	Transformable Data	"""
        self._transformables = []
Ejemplo n.º 9
0
	def __init__(self, yFaceDirection, **kwArgs):
		super().__init__(**kwArgs)
		
		rm = ResourceManager.activeManager

		#	Set Systems
		self._yFaceDirection = yFaceDirection
		
		#	Set Characteristics
		self._alive = True
		self._armor  = 3
		self._health = 1000
		self._speed = 550
		self._velocity = vec(0,0)
		
		#	Set Rendering and Physics Data
		self._sprite = Sprite(rm.request("SpaceJet.anim"), t=self.getTransform().createChild())
		self._sprite.setFrame(1+3)
		
		self._explosionSprite = Sprite(rm.request("Explosion.anim"), t=self.getTransform().createChild())
		self._explosionSprite.isDrawn = False
		self._explosionSound = rm.request("Explosion.mp3")
		
		self._bounds = CollisionRect(self._sprite.getWidth(), self._sprite.getHeight(), t=self.getTransform().createChild())
		self._bounds.addEntity(self)
		
		#self._boundsDisplay = SceneObject(dataSrc = self._bounds, t=self._bounds.getTransform(), color=Color.Green, \
		#	batch=pyglet.graphics.Batch(), group=LinePolygonMode)
		
		#	Set Flight Area
		self._flightAreaEdges = [-400+self._sprite.getWidth()/2, 400-self._sprite.getWidth()/2, \
			yFaceDirection*(-300+self._sprite.getHeight()/2), -100*yFaceDirection]
		if yFaceDirection == -1:
			s = self._flightAreaEdges[2]
			self._flightAreaEdges[2] = self._flightAreaEdges[3]
			self._flightAreaEdges[3] = s
		
		#	Create the default weapon
		from Weapon import LaserGun
		from Weapon import MissleLauncher
		
		self._velocity = vec(0,0)
		self._weapon = LaserGun(self, t=self.getTransform().createChild())
		self._secondaryWep = MissleLauncher(self, t=self.getTransform().createChild())
Ejemplo n.º 10
0
    def __init__(self, ship, **kwArgs):
        super().__init__(ship, **kwArgs)

        # 	General Stats
        self._firePoints = [self.getTransform().createChild()]

        # 	Firing Statistics
        self._capacity = 5
        self._fireRate = 0.25
        self._cooldown = 0

        # 	Bullet Statistics
        self._deltaAccel = vec(0, 300)
        self._bulletAccel = vec(0, 0)
        self._bulletVel = vec(0, 30)
        self._maxBulletVel = vec(0, 1500)
        self._bulletDamage = 200
        self._bulletAnimation = rm.activeManager.request("Missle.anim")
        self._fireSound = rm.activeManager.request("MissileLauncherLaunch.wav")
Ejemplo n.º 11
0
    def __init__(self, ship, **kwArgs):
        super().__init__(**kwArgs)

        # 	General Stats
        self._ship = ship
        self._firePoints = []

        # 	Firing Statistics
        self._capacity = None
        self._fireRate = 0
        self._cooldown = 0

        # 	Bullet Statistics
        self._deltaAccel = vec()
        self._bulletAccel = vec()
        self._bulletVel = vec(0, 0)
        self._maxBulletVel = vec(0, 0)
        self._bulletDamage = 0
        self._bulletAnimation = None
Ejemplo n.º 12
0
	def update(self, dt):
		
		if self._alive:
			# Move according to last received velocity (aka 'Dead Reckoning')
			self.translate(self._velocity*dt)
		
			#	Check Flight Area
			p = self.getPosition();		np = p.copy()
			fa = self._flightAreaEdges
			
			if p.x < fa[0]:
				np.x = fa[0]
			if p.x > fa[1]:
				np.x = fa[1]
			if p.y < fa[2]:
				np.y = fa[2]
			if p.y > fa[3]:
				np.y = fa[3]
				
			if p != np:
				self.setTranslation(np)
			
			# Update Sprite Data
			moving = False;	direc = vec(0, 0)
			if(self._velocity != vec(0,0)):
				moving = True
				if(self._velocity.x != 0):
					direc.x = math.copysign(1, self._velocity.x)
				if(self._velocity.y != 0):
					direc.y = math.copysign(1, self._velocity.y)
			
			# Draw Sprite Accordingly
			self._sprite.setFrame(self._frameMap[vec(direc.x if self._yFaceDirection==1 else -direc.x, direc.y*self._yFaceDirection)])
			if not moving and self._sprite.getFrame() != 4:
				self._sprite.setFrame(4)
		
		# Update Sprite and Bounds
		if self._sprite.update(dt):
			self._updateDimensions()
		
		self._bounds.update(dt)
		self._checkDeath(dt)
Ejemplo n.º 13
0
    def __init__(self, ship, **kwArgs):
        super().__init__(ship, **kwArgs)

        # 	General Stats
        self._powerLevel = 0

        # 	Firing Statistics
        self._fireRate = 0.1
        self._cooldown = 0

        # 	Bullet Statistics
        self._bulletVel = vec(0, 800)
        self._maxBulletVel = vec(0, 1000)
        self._bulletDamage = 30
        self._bulletAnimation = rm.activeManager.request("LaserGunBullet.anim")
        self._fireSound = rm.activeManager.request("LaserGunLaunch.wav")

        # 	Set Power to Lvl3
        self.increasePower()
        self.increasePower()
        self.increasePower()
Ejemplo n.º 14
0
	def readKeyboardInput(self, dt):
		if not self._alive:
			return
			
		actions = Keyboard.localKeyboard.getActions()
		moving = False
		for action in actions:
			if action.name == "Move":
				direc = action.params[0]
				direc = direc*self._yFaceDirection
				
				self._sprite.setFrame(self._frameMap[vec(direc.x if self._yFaceDirection==1 else -direc.x, direc.y*self._yFaceDirection)])
				self.translate(direc*self._speed*dt)
				self._velocity = direc*self._speed
				
				#	Check Flight Area
				p = self.getPosition();		np = p.copy()
				fa = self._flightAreaEdges
				
				if p.x < fa[0]:
					np.x = fa[0]
				if p.x > fa[1]:
					np.x = fa[1]
				if p.y < fa[2]:
					np.y = fa[2]
				if p.y > fa[3]:
					np.y = fa[3]
					
				if p != np:
					self.setTranslation(np)
				moving = True
				
			elif action.name == "FirePrimary":
				self._weapon.fire(vec(0, self._yFaceDirection))
			elif action.name == "FireSecondary":
				self._secondaryWep.fire(vec(0, self._yFaceDirection))
				
		if not moving and self._sprite.getFrame() != 4:
			self._sprite.setFrame(4)
Ejemplo n.º 15
0
	def __init__(self, ship, screenPos):
		super().__init__()
		
		sg = Renderer.activeRenderer.getSceneGraph()
		
		self._ship = ship
		self._maxHealth = ship._health
		self._screenPos = screenPos
		
		tNode = sg.newTransform(t=vec(-280, screenPos*(-300+25)))
		self._barFill = SceneObject(dataSrc = DiscreteRect(200, h=20), t=tNode, 
			color = Color.Green)
		self._border = SceneObject(dataSrc = DiscreteRect(w=200, h=20), t=tNode,	\
			color = Color.Grey, batch=pyglet.graphics.Batch(), group = LinePolygonMode)
Ejemplo n.º 16
0
	def initGame(self):
		# Get Scene Graph
		sg = Renderer.getRenderer().getSceneGraph()
	
		#	Create the Player at 0, -200
		self._player = Player(Keyboard.localKeyboard, 1, t=sg.newTransform(t=vec(0, -200)))
	
		#	Create Entities
		self._entities = []
		self.addEntity(self._player.getShip())
		
		#	Create End-Text Display
		self._endText = None
		self._endText2 = None
Ejemplo n.º 17
0
	def _translateDependents(self):
		pTrans = vec()
		if(self._parent):
			pTrans = self._parent.getTranslation()
			
		newTranslate = self._translate + pTrans
		oldTranslate = self._gTrans.copy()
		if(newTranslate != oldTranslate):	
			self._gTrans = newTranslate
			
			for transformable in self._transformables:
				transformable._onTranslation(newTranslate-oldTranslate)
			for child in self._children:
				child._translateDependents()
Ejemplo n.º 18
0
    def _scaleDependents(self):
        pScale = vec(1.0, 1.0)
        if self._parent:
            pScale = self._parent.getScale()

        newScale = self._scale * pScale
        oldScale = self._gScale

        if newScale != oldScale:
            self._gScale = newScale

            for transformable in self._transformables:
                transformable._onScale(newScale / oldScale)
            for child in self._children:
                child._scaleDependents()
Ejemplo n.º 19
0
	def remoteUpdate(self, controlStruc):
		if(controlStruc):
			# Read Data From Control Structure
			health = controlStruc.get('health', self._health)
			position = controlStruc.get('position', self.getPosition())
			velocity = controlStruc.get('velocity', self._velocity)
			frameNum = controlStruc.get('frame', self._sprite.getFrame())
		
			# Set Alive and Position
			self._health = health
			self.setTranslation(position)
			
			# Set Velocity and Check for Movement
			self._velocity = velocity*self._yFaceDirection
			if(self._health > 0 and self._velocity != vec(0,0)):
				self._sprite.setFrame(frameNum)
Ejemplo n.º 20
0
    def __init__(self, background, pImgs, pSpeeds):
        super().__init__()

        sg = Renderer.activeRenderer.getSceneGraph()
        self._background = Sprite(background, t=sg.newTransform())

        self._pSprites = []
        for i in range(len(pImgs)):
            img = pImgs[i]
            sspeed = pSpeeds[i]

            # 	Create Two for Seamless - Parallax Movement
            s1 = Sprite(img, t=sg.newTransform())
            s2 = Sprite(img, t=sg.newTransform(t=vec(0, img.height)))

            self._pSprites.append([s1, sspeed])
            self._pSprites.append([s2, sspeed])
Ejemplo n.º 21
0
	def _buildActions(self):
		#	Check Movement Action
		moveDirec = vec()
		if self._activeKeys[key.LEFT] or self._activeKeys[key.A]:
			moveDirec.x = -1
		if self._activeKeys[key.RIGHT] or self._activeKeys[key.D]:
			moveDirec.x = 1
		if self._activeKeys[key.DOWN] or self._activeKeys[key.S]:
			moveDirec.y = -1
		if self._activeKeys[key.UP] or self._activeKeys[key.W]:
			moveDirec.y = 1
			
		#	Build Actions
		if self._releasedKeys[key.SPACE]:
			self._actionQueue.put(Action("FirePrimary"))
		if self._releasedKeys[key.LCTRL] or self._releasedKeys[key.RCTRL]:
			self._actionQueue.put(Action("FireSecondary"))
		if moveDirec.x or moveDirec.y:
			self._actionQueue.put(Action("Move", moveDirec))
Ejemplo n.º 22
0
from Renderer import Renderer
from TransformationGraph import Transform

from SceneObject import SceneObject
from DiscretePrimitives import *
from Vector import vec

#-------------------------------------------------------#	

window 			= pyglet.window.Window(800, 600)
winDimensions 	= [800, 600]

rendMan = Renderer(winSize=winDimensions)
sg = rendMan.getSceneGraph()

so1 = SceneObject(t=sg.newTransform(t=vec(150,0)), vs=[vec(-100,-100), vec(100,-100), vec(100,100), vec(-100,100)], ds=GL_LINES,
	vis = (0, 1, 1, 2, 2, 3, 3, 0),	cs = Color.Purple+Color.Blue+Color.Orange+Color.Green)
so2 = SceneObject(t=so1.getTransform().createChild(), dataSrc=DiscreteRect(10, 50))
so3 = SceneObject(t=sg.newTransform(), numVerts=3, drawStyle=GL_TRIANGLES, explicitData=[('v2f/static', [-30, -30, 30, -30, 0, 30])])


def update(dt):
	so2.rotate(.005)
	
@window.event
def on_draw():
	window.clear()
	rendMan.render()

pyglet.clock.schedule(update)
pyglet.app.run()
Ejemplo n.º 23
0
	def __init__(self, w, h, **kwArgs):
		self._width 	= w
		self._height 	= h
		self._diagonal 	= vec(w/2, h/2)
		
		super().__init__(**kwArgs)
Ejemplo n.º 24
0
Renderer.activeRenderer = rendMan

sg = rendMan.getSceneGraph()

rm = ResourceManager("Tests\\data")
ResourceManager.activeManager = rm
rm.registerExtension(".jpg", "img", ["img"], pyglet.image.load)
rm.registerExtension(".bmp", "img", ["img"], pyglet.image.load)
rm.registerExtension(".png", "img", ["img"], pyglet.image.load)
rm.registerExtension(".anim", "anim", ["anim"], Animation)

anim1 = rm.request("CharizardEvolve.anim")
anim2 = rm.request("PShip.anim")

s1 = Sprite(anim1, t=sg.newTransform())
s2 = Sprite(anim2, t=sg.newTransform(t=vec(-200,100)))

s1.setAnimation("Alternating")
s2.setAnimation("Looping")


print("")
rm.debugDisplay()
print("")


def update(dt):
	s1.update(dt)
	s2.update(dt)

Ejemplo n.º 25
0
 def scale2f(self, x, y):
     self._scale *= vec(x, y)
     self._scaleDependents()
Ejemplo n.º 26
0
 def setScale2f(self, x, y):
     self._scale = vec(x, y)
     self._scaleDependents()
Ejemplo n.º 27
0
 def setTranslation2f(self, x, y):
     self._translate = vec(x, y)
     self._translateDependents()
Ejemplo n.º 28
0
	def __init__(self, a, b, **kwArgs):
		self._a = vec(a, 0)
		self._b = vec(0, b)
		
		super().__init__(**kwArgs)
Ejemplo n.º 29
0
 def translate2f(self, x, y):
     self._translate += vec(x, y)
     self._translateDependents()
Ejemplo n.º 30
0
cw = CollisionWorld()

rm = ResourceManager("Tests\\data")
ResourceManager.activeManager = rm
rm.registerExtension(".jpg", "img", ["img"], pyglet.image.load)
rm.registerExtension(".bmp", "img", ["img"], pyglet.image.load)
rm.registerExtension(".png", "img", ["img"], pyglet.image.load)
rm.registerExtension(".anim", "anim", ["anim"], Animation)

anim1 = rm.request("CharizardEvolve.anim")
anim2 = rm.request("PShip.anim")

s1 = Sprite(anim1);	s1.setAnimation("Alternating")
s2 = Sprite(anim2);	s2.setAnimation("Looping")

e1 = Entity(s1, t=sg.newTransform(t=vec(-100,100)));	e2 = Entity(s2, t=sg.newTransform(t=vec(100,-30)))

cw.addPrimitive(e1._collider)
cw.addPrimitive(e2._collider)

print("")
rm.debugDisplay()
print("")


def update(dt):
	cw.update(dt)
	
	e1.update(dt)
	e2.update(dt)