def moveDown(self): if self.facingMode: self.selectedUnit.setFacing(Constants.S) return if self.y < self.map.height - 1: self.y += 1 ScenarioGUI.get().scrollTo((self.x, self.y))
def moveUp(self): if self.facingMode: self.selectedUnit.setFacing(Constants.N) return if self.y > 0: self.y -= 1 ScenarioGUI.get().scrollTo((self.x, self.y))
def moveRight(self): if self.facingMode: self.selectedUnit.setFacing(Constants.E) return if self.x < self.map.width - 1: self.x += 1 ScenarioGUI.get().scrollTo((self.x, self.y))
def update(self, time): if self.selectedUnit != None: enabled = False for i in xrange(0, len(self.options)): enoughSP = (self.selectedUnit.sp() >= self._abilities[i].cost()) correctWeapon = self._abilities[i].correctWeapon( self.selectedUnit.weapon()) enable = enoughSP and correctWeapon self.setOptionEnabled(i, enable) if enable: enabled = True if self._showing and enabled: ability = self.getSelection() ScenarioGUI.get().setTopText(ability.description() + _(" (%d SP)") % ability.cost())
def drawFloatingText(texture, aspectRatio, height, alpha): scale = 0.5 glPushMatrix() glTranslatef(0, 0, height) glScale(scale, scale, scale) glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) glBindTexture(GL_TEXTURE_2D, texture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) glColor4f(1.0, 1.0, 1.0, alpha) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0); glVertex3f( 0.5*aspectRatio, 1.0, 0.0) glTexCoord2f(0.0, 1.0); glVertex3f(-0.5*aspectRatio, 1.0, 0.0) glTexCoord2f(0.0, 0.0); glVertex3f(-0.5*aspectRatio, 0.0, 0.0) glTexCoord2f(1.0, 0.0); glVertex3f( 0.5*aspectRatio, 0.0, 0.0) glEnd() glPopMatrix()
def draw(self): glDisable(GL_LIGHTING) glPushMatrix() GLUtil.mapTrans(self.x, self.y, 0.0) glColor4f(0.0, 0.0, 0.75, ScenarioGUI.get().highlightAlpha()) GLUtil.makeCubeTop(self.mapSquare().z, self.mapSquare().cornerHeights) glPopMatrix() glEnable(GL_LIGHTING)
def makeStatus(texture, color = (1.0, 1.0, 1.0, 1.0) ): global s, t, lastTime (r, g, b, a) = color glPushMatrix() glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) glBindTexture(GL_TEXTURE_2D, texture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTranslatef(0.3, 0.5, 0.0) glBegin(GL_QUADS) glColor4f(r, g, b, a) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(0.5*s, 1.0/t); glVertex3f( 0.5, 1.0, 0.0) glTexCoord2f(0.5*s - 0.5, 1.0/t); glVertex3f(-0.5, 1.0, 0.0) glTexCoord2f(0.5*s - 0.5, 1.0/t - 0.5); glVertex3f(-0.5, 0.0, 0.0) glTexCoord2f(0.5*s, 1.0/t - 0.5); glVertex3f( 0.5, 0.0, 0.0) glEnd() glPopMatrix() # The frame change after enough time if lastTime == None: lastTime = time.time() elif time.time() - lastTime > 0.15: lastTime = time.time() if s == 1.0: s = 2.0 else: if t == 2.0: s, t = 1.0, 1.0 else: s, t = 1.0, 2.0
def drawFloatingText(texture, aspectRatio, height, alpha): scale = 0.5 glPushMatrix() glTranslatef(0, 0, height) glScale(scale, scale, scale) glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) glBindTexture(GL_TEXTURE_2D, texture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) glColor4f(1.0, 1.0, 1.0, alpha) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0) glVertex3f(0.5 * aspectRatio, 1.0, 0.0) glTexCoord2f(0.0, 1.0) glVertex3f(-0.5 * aspectRatio, 1.0, 0.0) glTexCoord2f(0.0, 0.0) glVertex3f(-0.5 * aspectRatio, 0.0, 0.0) glTexCoord2f(1.0, 0.0) glVertex3f(0.5 * aspectRatio, 0.0, 0.0) glEnd() glPopMatrix()
def __init__(self, unit, delay=0.0, attackStyle="melee"): # Number of frames of the attack animation self._maxFrame = unit.getSprites(attackStyle).__len__() if self._maxFrame == 0: attackStyle = 'standing' self._maxFrame = unit.getSprites(attackStyle).__len__() # Load the textures self._unitHand = [] self._texture = [] for image in unit.getSprites(attackStyle): self._texture.append(GLUtil.makeTexture(Resources.image(image))[0]) self._unitHand.append(Resources.spriteConfig.hand(image)) # Load the weapon textures self._wtexture = None self._weapGrip = None if unit.weapon() != None: wimage = unit.weapon().getSprites('standing')[0] if wimage != None: self._wtexture = GLUtil.makeTexture(Resources.image(wimage))[0] self._weapGrip = Resources.spriteConfig.grip(wimage) else: wimage = None # Load the over textures self._otexture = [] if wimage != None: oimages = unit.getOverSprites(attackStyle) if len(oimages) < self._maxFrame: oimages = [] for image in oimages: self._otexture.append( GLUtil.makeTexture(Resources.image(image))[0]) self._unitdisplayer = ScenarioGUI.get().unitDisplayer(unit) self._unitdisplayer.Acting() self._time = -delay self._frame = 0
def makeUnit(texture, wtexture=None, otexture=None, color=(1.0, 1.0, 1.0, 1.0), unitHand=None, weaponGrip=None): (r, g, b, a) = color scale = 1.4 glPushMatrix() glScale(scale, scale, scale) glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) #glRotatef(-90.0, 1.0, 0.0, 0.0) #glRotatef(-GUI.get().camera.pitch()/2.0, 1.0, 0.0, 0.0) #glRotatef(90.0, 1.0, 0.0, 0.0) glBindTexture(GL_TEXTURE_2D, texture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) glColor4f(r, g, b, a) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0) glVertex3f(0.5, 1.0, 0.0) glTexCoord2f(0.0, 1.0) glVertex3f(-0.5, 1.0, 0.0) glTexCoord2f(0.0, 0.0) glVertex3f(-0.5, 0.0, 0.0) glTexCoord2f(1.0, 0.0) glVertex3f(0.5, 0.0, 0.0) glEnd() glPopMatrix() if wtexture != None: if unitHand == None: unitHand = (32, 45, -45, False) if weaponGrip == None: weaponGrip = (32, 32, -45, False) (gripx, gripy, gripr, weaponOrientation) = weaponGrip (handx, handy, handr, handOrientation) = unitHand # Change coordinates (move origin from top left to bottom center and flip y-axis) gripx -= 32.0 gripy = 64.0 - gripy handy = 64.0 - handy handx -= 32.0 zoff = 0.001 if handOrientation != weaponOrientation: # flip coords if needed #handx = - handx gripr = -gripr zoff = -zoff # Find the necessary rotation for the weapon rot = handr - gripr rad = math.radians(rot) # Get the hand postion in the rotated coordinates #if handOrientation != weaponOrientation:# flip coords if needed # r_handy = handy * math.cos(rad) + handx * math.sin(rad) # r_handx = handx * math.cos(rad) - handy * math.sin(rad) r_handy = handy * math.cos(rad) + handx * math.sin(rad) r_handx = handx * math.cos(rad) - handy * math.sin(rad) if handOrientation != weaponOrientation: # flip coords if needed r_handx = -r_handx # Get the offsets for adjusting weapon position xoff = (r_handx - gripx) / 64.0 yoff = (r_handy - gripy) / 64.0 glPushMatrix() glScale(scale, scale, scale) glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) # Match hand and weapon direction glRotatef(rot, 0.0, 0.0, -1.0) if handOrientation != weaponOrientation: # flip weapon if needed glRotatef(180, 0.0, 1.0, 0.0) glBindTexture(GL_TEXTURE_2D, wtexture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) glColor4f(r, g, b, a) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0) glVertex3f(0.5 + xoff, 1.0 + yoff, zoff) glTexCoord2f(0.0, 1.0) glVertex3f(-0.5 + xoff, 1.0 + yoff, zoff) glTexCoord2f(0.0, 0.0) glVertex3f(-0.5 + xoff, 0.0 + yoff, zoff) glTexCoord2f(1.0, 0.0) glVertex3f(0.5 + xoff, 0.0 + yoff, zoff) glEnd() glPopMatrix() if otexture != None: glPushMatrix() glScale(scale, scale, scale) glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) #glRotatef(-90.0, 1.0, 0.0, 0.0) #glRotatef(-GUI.get().camera.pitch()/2.0, 1.0, 0.0, 0.0) #glRotatef(90.0, 1.0, 0.0, 0.0) glBindTexture(GL_TEXTURE_2D, otexture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) glColor4f(r, g, b, a) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0) glVertex3f(0.5, 1.0, 0.002) glTexCoord2f(0.0, 1.0) glVertex3f(-0.5, 1.0, 0.002) glTexCoord2f(0.0, 0.0) glVertex3f(-0.5, 0.0, 0.002) glTexCoord2f(1.0, 0.0) glVertex3f(0.5, 0.0, 0.002) glEnd() glPopMatrix()
def makeUnit(texture, wtexture=None, otexture=None, color=(1.0, 1.0, 1.0, 1.0), unitHand=None, weaponGrip=None): (r, g, b, a) = color scale = 1.4 glPushMatrix() glScale(scale, scale, scale) glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) #glRotatef(-90.0, 1.0, 0.0, 0.0) #glRotatef(-GUI.get().camera.pitch()/2.0, 1.0, 0.0, 0.0) #glRotatef(90.0, 1.0, 0.0, 0.0) glBindTexture(GL_TEXTURE_2D, texture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) glColor4f(r, g, b, a) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0); glVertex3f( 0.5, 1.0, 0.0) glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 1.0, 0.0) glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, 0.0, 0.0) glTexCoord2f(1.0, 0.0); glVertex3f( 0.5, 0.0, 0.0) glEnd() glPopMatrix() if wtexture != None: if unitHand == None: unitHand = (32, 45, -45, False) if weaponGrip == None: weaponGrip = (32, 32, -45, False) (gripx, gripy, gripr, weaponOrientation) = weaponGrip (handx, handy, handr, handOrientation) = unitHand # Change coordinates (move origin from top left to bottom center and flip y-axis) gripx -= 32.0 gripy = 64.0 - gripy handy = 64.0 - handy handx -= 32.0 zoff = 0.001 if handOrientation != weaponOrientation:# flip coords if needed #handx = - handx gripr = - gripr zoff = - zoff # Find the necessary rotation for the weapon rot = handr - gripr rad = math.radians(rot) # Get the hand postion in the rotated coordinates #if handOrientation != weaponOrientation:# flip coords if needed # r_handy = handy * math.cos(rad) + handx * math.sin(rad) # r_handx = handx * math.cos(rad) - handy * math.sin(rad) r_handy = handy * math.cos(rad) + handx * math.sin(rad) r_handx = handx * math.cos(rad) - handy * math.sin(rad) if handOrientation != weaponOrientation:# flip coords if needed r_handx = - r_handx # Get the offsets for adjusting weapon position xoff = (r_handx - gripx) / 64.0 yoff = (r_handy - gripy) / 64.0 glPushMatrix() glScale(scale, scale, scale) glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) # Match hand and weapon direction glRotatef(rot, 0.0, 0.0, -1.0) if handOrientation != weaponOrientation:# flip weapon if needed glRotatef(180, 0.0, 1.0, 0.0) glBindTexture(GL_TEXTURE_2D, wtexture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) glColor4f(r, g, b, a) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0); glVertex3f( 0.5 + xoff, 1.0 + yoff, zoff) glTexCoord2f(0.0, 1.0); glVertex3f(-0.5 + xoff, 1.0 + yoff, zoff) glTexCoord2f(0.0, 0.0); glVertex3f(-0.5 + xoff, 0.0 + yoff, zoff) glTexCoord2f(1.0, 0.0); glVertex3f( 0.5 + xoff, 0.0 + yoff, zoff) glEnd() glPopMatrix() if otexture != None: glPushMatrix() glScale(scale, scale, scale) glRotatef(-ScenarioGUI.get().camera.mapRotation(), 0.0, 0.0, 1.0) glRotatef(-ScenarioGUI.get().camera.pitch(), 1.0, 0.0, 0.0) #glRotatef(-90.0, 1.0, 0.0, 0.0) #glRotatef(-GUI.get().camera.pitch()/2.0, 1.0, 0.0, 0.0) #glRotatef(90.0, 1.0, 0.0, 0.0) glBindTexture(GL_TEXTURE_2D, otexture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) glColor4f(r, g, b, a) glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0); glVertex3f( 0.5, 1.0, 0.002) glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 1.0, 0.002) glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, 0.0, 0.002) glTexCoord2f(1.0, 0.0); glVertex3f( 0.5, 0.0, 0.002) glEnd() glPopMatrix()