Exemple #1
0
 def renderSelf(self, time, renderer, xMin, yMin):
     if (self.xPos + self.width - xMin <
             0) or (self.yPos + self.height - yMin < 0):
         return
     elif (self.xPos > xMin + 800) or (self.yPos > yMin + 600):
         return
     if self.title is 'pizza' or self.title is 'heart' or self.title is 'carrot' or self.title is 'bombObject':
         time1 = ((int(time / 250)) % 4)  #slowish
         spriteFrame = sdl.Rect((time1 * 50, 0, 50, 50))
         sdl.renderCopy(renderer, self.texture, spriteFrame,
                        self.getRect(xMin, yMin))
     elif self.title is 'explosion':
         time1 = ((int(time / 250)) % 8)
         if time1 is not self.currentTime:
             self.currentFrame += 1
             spriteFrame = sdl.Rect((self.currentFrame * 200, 0, 200, 200))
             sdl.renderCopy(renderer, self.texture, spriteFrame,
                            self.getRect(xMin, yMin))
             if self.currentFrame is 8:
                 self.used = True
             self.currentTime = time1
         else:
             spriteFrame = sdl.Rect((self.currentFrame * 200, 0, 200, 200))
             sdl.renderCopy(renderer, self.texture, spriteFrame,
                            self.getRect(xMin, yMin))
     elif self.title is 'blackScreen':
         self.updateAlpha(1)
         sdl.setTextureAlphaMod(self.texture, int(self.alpha))
         sdl.renderCopy(renderer, self.texture, None,
                        self.getRect(xMin, yMin))
     else:
         sdl.renderCopy(renderer, self.texture, None,
                        self.getRect(xMin, yMin))
    def renderLight(self, renderer, xMin, yMin):
        mod = 1
        texture = driver.lightTextures[7]  # default red
        if self.attacking is 1:
            texture = driver.lightTextures[6]  # change to green
            sdl.setTextureAlphaMod(texture, 64)
            mod = 10
        elif self.attacking is 2:
            texture = driver.lightTextures[3]  # change to orange
            sdl.setTextureAlphaMod(texture, 64)
        elif self.attacking is 3:
            texture = driver.lightTextures[4]  # change to purple
            sdl.setTextureAlphaMod(texture, 64)
        if self.hurt:
            texture = driver.lightTextures[5]  # change to blue
            sdl.setTextureAlphaMod(texture, 64)
        if self.dying:
            color = (self.currentFrame % 5) + 3
            texture = driver.lightTextures[
                color]  # change to self.currentFrame % len(driver.lightTextures)
            sdl.setTextureAlphaMod(texture, 255)
            if color is 6:
                mod = 10

        textureW, textureH = chef.textureSize(texture)
        textureW *= mod
        textureH *= mod
        lightRect = sdl.Rect((0, 0, textureW, textureH))
        sdl.setTextureBlendMode(texture, sdl.BLENDMODE_ADD)

        posRect = sdl.Rect(
            (int(self.xPos) - int(xMin) + int(self.width / 2) -
             int(textureW / 2), int(self.yPos) - int(yMin) +
             int(self.height / 2) - int(textureH / 2), textureW, textureH))
        sdl.renderCopy(renderer, texture, lightRect, posRect)
 def renderSelf(self, time, xMin, yMin):
     if self.title is 'green':
         currentFrame = ((int(time / 125)) % 6)
         spriteFrame = sdl.Rect((currentFrame * 60, 0, 60, 60))
         sdl.renderCopy(self.renderer, self.texture, spriteFrame,
                        self.getRect(xMin, yMin))
     elif self.title is 'purple':
         newTime = ((int(time / 400)) % 6)
         if newTime is not self.currentTime:
             self.currentFrame += 1
         if self.currentFrame > 5:
             self.currentFrame = 5
         spriteFrame = sdl.Rect((self.currentFrame * 400, 0, 400, 200))
         sdl.renderCopy(self.renderer, self.texture, spriteFrame,
                        self.getRect(xMin, yMin))
     elif self.title is 'knife':
         tempRect = self.getRect(xMin, yMin)
         sdl.renderCopyEx(self.renderer, self.texture, None, tempRect,
                          math.degrees(self.degree) + 90,
                          sdl.Point((tempRect.w // 2, tempRect.h // 2)),
                          sdl.FLIP_NONE)
     elif self.title is 'fire' or self.title is 'fireSlow':
         currentFrame = ((int(time / 125)) % 4)
         spriteFrame = sdl.Rect((currentFrame * 50, 0, 50, 150))
         tempRect = self.getRect(xMin, yMin)
         sdl.renderCopyEx(self.renderer, self.texture, spriteFrame,
                          tempRect,
                          math.degrees(self.degree) - 90,
                          sdl.Point((tempRect.w // 2, tempRect.h // 2)),
                          sdl.FLIP_NONE)
Exemple #4
0
 def getRect(self, xMin, yMin, xVal, xdt, yVal, ydt):
     if self.identity is "bluePipe" or self.identity is "redPipe":
         return sdl.Rect((int(50 * self.xPos) - int(xMin),
                          int(50 * self.yPos) - ydt - int(yMin), 50, yVal))
     else:
         return sdl.Rect(
             (int(50 * self.xPos) - int(xMin) - xdt,
              int(50 * self.yPos) - 25 - int(yMin) - ydt, xVal, yVal))
 def renderHealthPvp(self, renderer):
     if self.title is None:
         for i in range(self.health):
             spot = sdl.Rect((10 + i * 55, 10, 50, 50))
             sdl.renderCopy(renderer, self.textures[1][0], None, spot)
     else:
         for i in range(self.health):
             spot = sdl.Rect(((16 * 50) - 65 - i * 55, 10, 50, 50))
             sdl.renderCopy(renderer, self.textures[1][0], None, spot)
 def getRect(self, xMin, yMin):
     if self.attacking is not 2:
         return sdl.Rect(
             (int(self.xPos) - int(xMin), int(self.yPos) - int(yMin),
              self.width, self.height))
     else:
         return sdl.Rect((int(self.xPos - 200) - int(xMin),
                          int(self.yPos - 200) - int(yMin),
                          self.width + 400, self.height + 400))
 def renderLight(self, renderer, xMin, yMin):
     if 'carrot' in driver.chef.items:
         textureW, textureH = chef.textureSize(driver.lightTextures[0])
         lightRect = sdl.Rect((0, 0, textureW, textureH))
         sdl.setTextureBlendMode(driver.lightTextures[0], sdl.BLENDMODE_ADD)
         sdl.setTextureAlphaMod(driver.lightTextures[0], 128)
         posRect = sdl.Rect(
             (int(self.xPos) - int(xMin) + int(self.width / 2) -
              int(textureW / 2), int(self.yPos) - int(yMin) +
              int(self.height / 2) - int(textureH / 2), textureW, textureH))
         sdl.renderCopy(renderer, driver.lightTextures[0], lightRect,
                        posRect)
Exemple #8
0
 def renderLight(self, renderer, xMin, yMin):
     for particle in self.particles:
         if self.type is "explosion":
             if not particle.isAlive():
                 self.particles.remove(particle)
             else:
                 expRect = sdl.Rect((0, 0, 10, 10))
                 pixSize = particle.getTimeFraction()
                 pixSize = (pixSize**3) // 2
                 sdl.renderCopy(
                     renderer, self.expLight, None,
                     sdl.Rect(
                         (int(particle.xPos) - int(xMin) - int(pixSize / 2),
                          int(particle.yPos) - int(yMin) - int(pixSize / 2),
                          int(pixSize), int(pixSize))))
 def overlayblack(self):
     if 'carrot' not in driver.chef.items:
         blackRect = sdl.Rect(
             (int(self.chef.xPos - 800) - int(self.xMin),
              (self.chef.yPos - 600) - int(self.yMin), 1600, 1200))
     else:
         blackRect = sdl.Rect(
             (int(self.chef.xPos - 1200) - int(self.xMin),
              (self.chef.yPos - 900) - int(self.yMin), 2400, 1800))
     if self.level is 5:
         blackRect = sdl.Rect(
             (int(self.chef.xPos - 1800) - int(self.xMin),
              (self.chef.yPos - 1350) - int(self.yMin), 3600, 2700))
     sdl.renderCopy(driver.renderer, self.blackScreenTexture, None,
                    blackRect)
 def getRect(self, xMin, yMin):
     if self.title is 'green':
         return sdl.Rect((int(self.xPos) - int(xMin),
                          int(self.yPos) - int(yMin), 60, 60))
     elif self.title is 'purple':
         return sdl.Rect((int(self.xPos) - int(xMin),
                          int(self.yPos) - int(yMin), 400, 200))
     elif self.title is 'knife':
         return sdl.Rect(
             (int(self.xPos) - int(xMin), int(self.yPos) - int(yMin),
              self.height, self.width))
     elif self.title is 'fire' or self.title is 'fireSlow':
         return sdl.Rect(
             (int(self.xPos) - int(xMin), int(self.yPos) - int(yMin),
              self.width, self.height))
    def renderDamage(self, renderer, xMin, yMin):

        #if there has been any change in health
        if (self.changeInHp != 0):
            #create the string
            stringDamage = str(self.changeInHp)
            #make it red
            color = sdl.Color((255, 0, 0)).cdata[0]
            #but if the "damage" is positive (ie, healing)
            if (self.changeInHp > 0):
                #show that it is positive
                stringDamage = "+" + str(self.changeInHp)
                #and make it green
                color = sdl.Color((0, 255, 0)).cdata[0]

            dmgSurf = sdl.ttf.renderText_Solid(driver.scoreFont, stringDamage,
                                               color)
            dmgTexture = renderer.createTextureFromSurface(dmgSurf)
            textureW, textureH = chef.textureSize(dmgTexture)
            dmgRect = sdl.Rect()
            dmgRect.x = int(self.xPos + textureW // 6 - xMin)
            dmgRect.y = int(self.yPos - textureH - yMin)
            dmgRect.w = textureW
            dmgRect.h = textureH
            dmgRect.x = int(dmgRect.x)
            dmgRect.y = int(dmgRect.y)
            sdl.renderCopy(renderer, dmgTexture, None, dmgRect)
            sdl.freeSurface(dmgSurf)
            sdl.destroyTexture(dmgTexture)
 def renderItems(self, renderer):
     for x in range(len(self.items)):
         spot = sdl.Rect((10 + x * 55, 65, 50, 50))
         if self.items[x] is 'key':
             sdl.renderCopy(renderer, self.textures[1][1], None, spot)
         elif self.items[x] is 'carrot':
             sdl.renderCopy(renderer, self.textures[1][2], None, spot)
Exemple #13
0
 def __init__(self):
     self.window = None
     self.renderer = None
     self.background = None
     self.sprite = None
     self.sprite_rect = sdl.Rect()
     self.scale_direction = 0
 def renderHealth(self, renderer, xMin, yMin):
     for i in range(self.health):
         spot = sdl.Rect(
             (int(self.xPos) - int(xMin) + 14 * i -
              int(14 * (self.health / 2)) + int(self.width / 2),
              int(self.yPos) - int(yMin) + int(self.height) - 10, 12, 12))
         sdl.renderCopy(renderer, self.bossTextures[11], None, spot)
 def renderLight(self, renderer, xMin, yMin):
     return
     textureW, textureH = chef.textureSize(driver.lightTextures[1])
     lightRect = sdl.Rect((0, 0, textureW, textureH))
     sdl.setTextureBlendMode(driver.lightTextures[1], sdl.BLENDMODE_ADD)
     if 'carrot' not in driver.chef.items:
         posRect = sdl.Rect(
             (int(self.xPos) - int(xMin) + int(self.width / 2) -
              int(textureW / 2), int(self.yPos) - int(yMin) +
              int(self.height / 2) - int(textureH / 2), textureW, textureH))
     else:
         posRect = sdl.Rect(
             (int(self.xPos) - int(xMin) + int(self.width / 2) -
              int(textureW), int(self.yPos) - int(yMin) +
              int(self.height / 2) - int(textureH), textureW * 2,
              textureH * 2))
     sdl.renderCopy(renderer, driver.lightTextures[1], lightRect, posRect)
 def getRect5(self, xMin, yMin):  #when a ball
     if self.ballWidth > 10:
         self.ballWidth = self.ballWidth - 5
     if self.ballHeight > 10:
         self.ballHeight = self.ballHeight - (5 * (190.0 / 150.0))
     return sdl.Rect((int(self.xPos - 37) + int(
         (150.0 - self.ballWidth) / 2) - int(xMin),
                      int(self.yPos - 37) + int(
                          (150.0 - self.ballHeight) / 2) - int(yMin),
                      int(self.ballWidth), int(self.ballHeight)))
    def renderLight(self, renderer, xMin, yMin):
        # textureW, textureH = chef.textureSize(driver.lightTextures[1])
        # lightRect = sdl.Rect((0, 0, textureW, textureH))
        # sdl.setTextureBlendMode(driver.lightTextures[1], sdl.BLENDMODE_ADD)
        # sdl.setTextureAlphaMod(driver.lightTextures[1], 128)
        # posRect = sdl.Rect((int(self.xPos) - int(xMin) + int(self.width/2) - int(textureW/2) ,int(self.yPos) - int(yMin) + int(self.height/2) - int(textureH/2), textureW, textureH))
        # sdl.renderCopy(renderer, driver.lightTextures[1], lightRect, posRect)

        mod = 1
        texture = driver.lightTextures[5]  # default blue
        if self.hurt:
            texture = driver.lightTextures[7]  # change to red
            sdl.setTextureAlphaMod(texture, 255)
        elif self.summoning:
            texture = driver.lightTextures[6]  # change to green
            sdl.setTextureAlphaMod(texture, 64)
            mod = 10
        elif self.transforming:
            texture = driver.lightTextures[3]  # change to orange
            sdl.setTextureAlphaMod(texture, 64)
        elif self.transformed:
            texture = driver.lightTextures[7]  # change to red
            sdl.setTextureAlphaMod(texture, 64)

        if self.dying:
            color = (self.currentFrame % 5) + 3
            texture = driver.lightTextures[color]
            sdl.setTextureAlphaMod(texture, 255)
            if color is 6:
                mod = 10

        textureW, textureH = chef.textureSize(texture)
        textureW *= mod
        textureH *= mod
        lightRect = sdl.Rect((0, 0, textureW, textureH))
        sdl.setTextureBlendMode(texture, sdl.BLENDMODE_ADD)

        posRect = sdl.Rect(
            (int(self.xPos) - int(xMin) + int(self.width / 2) -
             int(textureW / 2), int(self.yPos) - int(yMin) +
             int(self.height / 2) - int(textureH / 2), textureW, textureH))
        sdl.renderCopy(renderer, texture, lightRect, posRect)
 def renderWeapons(self, renderer):
     for x in range(len(self.weapons)):
         spot = sdl.Rect((10 + x * 55, 120, 50, 50))
         if self.weapons[x] is 'ladles':
             sdl.renderCopy(renderer, self.textures[1][3], None, spot)
         if self.weapons[x] is 'graters':
             sdl.renderCopy(renderer, self.textures[1][4], None, spot)
         if self.weapons[x] is 'bomb':
             sdl.renderCopy(renderer, self.textures[1][5], None, spot)
         if self.weapons[x] is 'knives':
             sdl.renderCopy(renderer, self.textures[1][9], None, spot)
Exemple #19
0
    def render(self, renderer):
        viewport = sdl.Rect()
        renderer.renderGetViewport(viewport)

        # Only render those tiles inside our viewport with a little overlap
        ranges = []
        for (pos, tile_size, dimension, ceiling) in \
            ((self.pos[0], self.tile_size[0], viewport.w, self.tmx.width),
             (self.pos[1], self.tile_size[1], viewport.h, self.tmx.height)):
            start = max(0, pos // tile_size)
            end = min(start + dimension // tile_size + 2, ceiling)
            ranges.append(xrange(start, end))

        dest_rect = sdl.Rect((0, 0, 16, 16))
        for x, y in itertools.product(*ranges):
            for layer in self.tmx.visible_tile_layers:
                image = self.tmx.get_tile_image(x, y, layer)
                if not image:
                    continue
                ts, bounds, flags = image
                dest_rect.x = (x * 16) - self.pos[0]
                dest_rect.y = (y * 16) - self.pos[1]
                rot = 90 if (flags & TRANS_ROT) else 0
                renderer.renderCopyEx(
                    ts.texture,
                    (bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1]),
                    dest_rect, rot, None,
                    (flags & (TRANS_FLIPX ^
                              (rot and TRANS_FLIPX)) and sdl.FLIP_HORIZONTAL) |
                    (flags & (TRANS_FLIPY) and sdl.FLIP_VERTICAL))

        for ob in self.tmx.objects:
            ts, bounds, flags = self.tmx.get_tile_image_by_gid(ob.gid)
            renderer.renderCopyEx(
                ts.texture,
                (bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1]),
                (int(ob.x) - self.pos[0], int(ob.y) - self.pos[1],
                 bounds[1][0], bounds[1][1]), 0, None, 0)
Exemple #20
0
 def renderSelf(self, renderer, xMin, yMin, dt):
     for particle in self.particles:
         if self.type is "rat":
             particle.update(dt)
             if not particle.isAlive():
                 self.particles.remove(particle)
             else:
                 pixSize = particle.getTimeFraction()
                 sdl.renderCopy(
                     renderer, self.tex, None,
                     sdl.Rect((int(particle.xPos) - int(xMin),
                               int(particle.yPos) - int(yMin), pixSize,
                               pixSize)))
         elif self.type is "explosion":
             particle.update(dt)
             if not particle.isAlive():
                 self.particles.remove(particle)
             else:
                 pixSize = particle.getTimeFraction()
                 if particle.life > 900:
                     sdl.renderCopy(
                         renderer, self.tex3, None,
                         sdl.Rect((int(particle.xPos) - int(xMin),
                                   int(particle.yPos) - int(yMin), pixSize,
                                   pixSize)))
                 elif particle.life > 800:
                     sdl.renderCopy(
                         renderer, self.tex2, None,
                         sdl.Rect((int(particle.xPos) - int(xMin),
                                   int(particle.yPos) - int(yMin), pixSize,
                                   pixSize)))
                 elif particle.life > 0:
                     sdl.renderCopy(
                         renderer, self.tex1, None,
                         sdl.Rect((int(particle.xPos) - int(xMin),
                                   int(particle.yPos) - int(yMin), pixSize,
                                   pixSize)))
 def renderLight(self, renderer, xMin, yMin):
     texture = driver.lightTextures[7]
     modX = 1
     modY = 1
     if self.title is 'green':
         texture = driver.lightTextures[6]  # change to green
     elif self.title is 'purple':
         texture = driver.lightTextures[4]  # change to purple
         modX = 1
         modY = 1
     elif self.title is 'knife':
         texture = driver.lightTextures[1]  # change to green
         return
     textureW, textureH = chef.textureSize(texture)
     textureW = textureW / modX
     textureH = textureH / modY
     lightRect = sdl.Rect((0, 0, int(textureW), int(textureH)))
     sdl.setTextureBlendMode(texture, sdl.BLENDMODE_ADD)
     sdl.setTextureAlphaMod(texture, 128)
     posRect = sdl.Rect((int(self.xPos) - int(xMin) + int(self.width / 2) -
                         int(textureW / 2), int(self.yPos) - int(yMin) +
                         int(self.height / 2) - int(textureH / 2),
                         int(textureW), int(textureH)))
     sdl.renderCopy(renderer, texture, None, posRect)
 def draw_column(self, column, ray, angle, game_map):
     """
     Check if a hit occurs in the ray.  Then itterate through each step
     of the ray (in reverse).  A hit will be rendered
     (including its shadow).  Rain drops will be drawn for each step.
     """
     texture = game_map.wall_texture
     left = int(math.floor(column * self.spacing))
     width = int(math.ceil(self.spacing))
     hit = 0
     while hit < len(ray) and ray[hit].height <= 0:
         hit += 1
     for ray_index in range(len(ray) - 1, -1, -1):
         step = ray[ray_index]
         if ray_index == hit:
             texture_x = int(math.floor(texture.width * step.offset))
             wall = self.project(step.height, angle, step.distance)
             image_location = sdl.Rect((texture_x, 0, 1, texture.height))
             scale_rect = sdl.Rect(
                 tuple(
                     int(x) for x in (left, wall.top, width, wall.height)))
             renderer.renderCopy(texture.image, image_location, scale_rect)
             self.draw_shadow(step, scale_rect, game_map.light)
         self.draw_rain(step, angle, left, ray_index)
Exemple #23
0
 def renderLight(self, renderer, xMin, yMin):
     if (self.identity is "redPipe" or self.identity is "bluePipe"
         ) and self.used is False and 'carrot' in driver.chef.items:
         if self.identity is "redPipe":
             texture = driver.lightTextures[7]
         else:
             texture = driver.lightTextures[5]
         textureW = 100
         textureH = 100
         sdl.setTextureBlendMode(texture, sdl.BLENDMODE_ADD)
         sdl.setTextureAlphaMod(texture, 128)
         xP = int(self.xPos * 50) - int(xMin) + 25 - int(textureW / 2)
         yP = int(self.yPos * 50) - int(yMin) + 25 - int(textureH / 2)
         posRect = sdl.Rect((xP, yP, textureW, textureH))
         sdl.renderCopy(renderer, texture, None, posRect)
     else:
         return
 def renderSelf(self, time, renderer, xMin, yMin, ratTextures):
     if (self.xPos + self.width - xMin <
             0) or (self.yPos + self.height - yMin < 0):
         return
     elif (self.xPos > xMin + 800) or (self.yPos > yMin + 600):
         return
     time = ((int(time / 125)) % 4)
     spriteFrame = sdl.Rect((time * 50, 0, 50, 60))
     if not self.hurt:  # if not hurt
         if self.attacking is 0:  # if not attacking
             if self.direction == 'n' or self.direction == 'ne' or self.direction == 'nw':
                 sdl.renderCopy(renderer, ratTextures[1], spriteFrame,
                                self.getRect(xMin, yMin))
             elif self.direction == 's' or self.direction == 'se' or self.direction == 'sw':
                 sdl.renderCopy(renderer, ratTextures[3], spriteFrame,
                                self.getRect(xMin, yMin))
             elif self.direction == 'e':
                 sdl.renderCopy(renderer, ratTextures[2], spriteFrame,
                                self.getRect(xMin, yMin))
             elif self.direction == 'w':
                 sdl.renderCopy(renderer, ratTextures[4], spriteFrame,
                                self.getRect(xMin, yMin))
         else:  # if attacking
             if self.attacking == 1:
                 sdl.renderCopy(renderer, ratTextures[5], spriteFrame,
                                self.getRect(xMin, yMin))
             if self.attacking == 2:
                 sdl.renderCopy(renderer, ratTextures[6], spriteFrame,
                                self.getRect(xMin, yMin))
             if self.attacking == 3:
                 sdl.renderCopy(renderer, ratTextures[7], spriteFrame,
                                self.getRect(xMin, yMin))
             if self.attacking == 4:
                 sdl.renderCopy(renderer, ratTextures[8], spriteFrame,
                                self.getRect(xMin, yMin))
     elif self.hurt:  # if hurt
         sdl.renderCopy(renderer, ratTextures[0], spriteFrame,
                        self.getRect(xMin, yMin))
     self.renderHealth(renderer, xMin, yMin, ratTextures)
Exemple #25
0
def Draw(s):
    viewport = sdl.Rect()
    sdl.renderGetViewport(s.renderer, viewport)

    # Draw the background
    sdl.renderCopy(s.renderer, s.background, None, None)

    # Scale and draw the sprite
    s.sprite_rect.w += s.scale_direction
    s.sprite_rect.h += s.scale_direction
    if s.scale_direction > 0:
        if s.sprite_rect.w >= viewport.w or s.sprite_rect.h >= viewport.h:
            s.scale_direction = -1
    else:
        if s.sprite_rect.w <= 1 or s.sprite_rect.h <= 1:
            s.scale_direction = 1
    s.sprite_rect.x = (viewport.w - s.sprite_rect.w) // 2
    s.sprite_rect.y = (viewport.h - s.sprite_rect.h) // 2

    sdl.renderCopy(s.renderer, s.sprite, ffi.NULL, s.sprite_rect)

    # Update the screen!
    sdl.renderPresent(s.renderer)
    def run(self):
        cursor1 = MC.Chef(220, 190, 50, 80, 'none', 0, 0, 0, 0.001, 0.001,
                          cursorTexture, True, 0, 0, 100, True, 1)
        cursor2 = MC.Chef(535, 190, 50, 80, 'none', 0, 0, 0, 0.001, 0.001,
                          cursorTexture, True, 0, 0, 100, True, 1)

        running = True
        currentTime = 0
        lastTime = 0
        time = 0

        cursorPos = 0
        brightnessPos = 10
        volumePos = round((driver.volume - 8) / 12)

        event = sdl.Event()

        textureW, textureH = game.textureSize(optionsTexture)
        textureRect = game.centeredRect(game.width, game.height, textureW,
                                        textureH)
        sdl.renderClear(driver.renderer)
        sdl.renderCopy(driver.renderer, optionsTexture, None, textureRect)

        # render cursor in
        time1 = ((int(time / 125)) % 4)
        time2 = ((int(time / 500)) % 4)
        # the rectangle that defines which sprite part the sprites
        spriteFrame = sdl.Rect((time1 * 48, 0, 48, 80))
        spriteFrame2 = sdl.Rect((time2 * 48, 0, 48, 80))
        sdl.renderCopy(driver.renderer, cursorTexture, spriteFrame2,
                       cursor1.getRect(0, 0))
        sdl.renderCopy(driver.renderer, cursorTexture, spriteFrame2,
                       cursor2.getRect(0, 0))

        #render in brightness indicators
        for i in range(brightnessPos):
            spot = sdl.Rect((280 + 25 * i, 357, 18, 18))
            sdl.renderCopy(driver.renderer, indTexture, None, spot)

        #render in volume indicators
        for i in range(volumePos):
            spot = sdl.Rect((280 + 25 * i, 242, 18, 18))
            sdl.renderCopy(driver.renderer, indTexture, None, spot)

        sdl.renderPresent(driver.renderer)

        while running:
            hover = None
            clicked = None
            #### TIME MANAGEMENT ####
            currentTime = sdl.getTicks()
            dt = currentTime - lastTime
            time += dt
            lastTime = currentTime

            #### TEXTURE MEASUREMENTS ####
            textureW, textureH = game.textureSize(optionsTexture)
            textureRect = game.centeredRect(game.width, game.height, textureW,
                                            textureH)

            #### HANDLE INPUT ####
            while sdl.pollEvent(event):
                if event.type == sdl.QUIT:
                    running = False
                    game.turnOff()
                elif event.type == sdl.KEYUP:
                    if event.key.keysym.sym in [sdl.K_q, sdl.K_ESCAPE]:
                        running = False
                        game.turnOff()
                elif event.type == sdl.MOUSEBUTTONDOWN:
                    if event.button.button == sdl.BUTTON_LEFT:
                        for i in range(len(boxes)):
                            if clicked is None:
                                sdl.mixer.playChannel(0, selectSound, 0)
                                clicked = boxes[i].checkEvent(
                                    event.motion.x, event.motion.y)
                        for i in range(len(volumeBoxes)):
                            here = volumeBoxes[i].checkEvent(
                                event.motion.x, event.motion.y)
                            if here is not None:
                                volumePos = here
                elif event.type == sdl.MOUSEMOTION:
                    for i in range(len(boxes)):
                        if (boxes[i].checkMotion(event.motion.x,
                                                 event.motion.y)):
                            hover = boxes[i].cursorPos
                if event.type == sdl.KEYDOWN:
                    if event.key.keysym.sym == sdl.K_UP:
                        sdl.mixer.playChannel(1, scrollSound, 0)
                        cursorPos -= 1
                        if cursorPos <= -1:
                            cursorPos = 2
                    elif event.key.keysym.sym == sdl.K_DOWN:
                        sdl.mixer.playChannel(1, scrollSound, 0)
                        cursorPos = (cursorPos + 1) % 3
                    elif event.key.keysym.sym == sdl.K_RIGHT:
                        sdl.mixer.playChannel(1, scrollSound, 0)
                        if cursorPos is 1:
                            if sdl.getWindowBrightness(driver.window) < 1:
                                brightnessPos += 1
                                sdl.setWindowBrightness(
                                    driver.window,
                                    sdl.getWindowBrightness(driver.window) +
                                    0.05)
                        elif cursorPos is 0:
                            if volumePos < 10:
                                volumePos += 1
                                sdl.mixer.volume(-1, volumePos * 12)
                                driver.volume = volumePos * 12
                    elif event.key.keysym.sym == sdl.K_LEFT:
                        sdl.mixer.playChannel(1, scrollSound, 0)
                        if cursorPos is 1:
                            if sdl.getWindowBrightness(driver.window) > .5:
                                brightnessPos -= 1
                                sdl.setWindowBrightness(
                                    driver.window,
                                    sdl.getWindowBrightness(driver.window) -
                                    0.05)
                        elif cursorPos is 0:
                            if volumePos > 1:
                                volumePos -= 1
                                sdl.mixer.volume(-1, volumePos * 12)
                                driver.volume = volumePos * 12
                    elif event.key.keysym.sym == sdl.K_RETURN:
                        if (cursorPos == 0):
                            # Call to play game
                            sdl.mixer.playChannel(1, scrollSound, 0)
                        elif (cursorPos == 1):
                            #ADD IN OPTIONS
                            sdl.mixer.playChannel(1, scrollSound, 0)
                        elif (cursorPos == 2):
                            #Call to controls screen
                            sdl.mixer.playChannel(0, selectSound, 0)
                            running = False
                            self.next = "menu"
                        while (sdl.getTicks() - currentTime < 300):
                            pass

                if (hover is not None):
                    cursorPos = hover

                if clicked is not None:
                    if cursorPos is 2:
                        sdl.mixer.playChannel(0, selectSound, 0)
                        running = False
                        self.next = "menu"
                cursor1.updateY(190 + 115 * cursorPos)
                cursor2.updateY(190 + 115 * cursorPos)

                #### RENDER ####
                sdl.renderClear(driver.renderer)
                sdl.renderCopy(driver.renderer, optionsTexture, None,
                               textureRect)

                # render cursor in
                time1 = ((int(time / 125)) % 4)
                time2 = ((int(time / 500)) % 4)
                # the rectangle that defines which sprite part the sprites
                spriteFrame = sdl.Rect((time1 * 48, 0, 48, 80))
                spriteFrame2 = sdl.Rect((time2 * 48, 0, 48, 80))
                sdl.renderCopy(driver.renderer, cursorTexture, spriteFrame2,
                               cursor1.getRect(0, 0))
                sdl.renderCopy(driver.renderer, cursorTexture, spriteFrame2,
                               cursor2.getRect(0, 0))

                for i in range(brightnessPos):
                    spot = sdl.Rect((280 + 25 * i, 357, 18, 18))
                    sdl.renderCopy(driver.renderer, indTexture, None, spot)
                for i in range(volumePos):
                    spot = sdl.Rect((280 + 25 * i, 242, 18, 18))
                    sdl.renderCopy(driver.renderer, indTexture, None, spot)
                sdl.renderPresent(driver.renderer)
 def renderHealth(self, renderer, xMin, yMin, texture):
     for i in range(self.health):
         spot = sdl.Rect(
             (int(self.xPos) - int(xMin) + 14 * i,
              int(self.yPos) - int(yMin) + int(self.height) - 30, 12, 12))
         sdl.renderCopy(renderer, texture, None, spot)
    def renderSelf(self, time, renderer, xMin, yMin, bossTextures):
        if (self.xPos + self.width - xMin <
                0) or (self.yPos + self.height - yMin < 0):
            return
        elif (self.xPos > xMin + 800) or (self.yPos > yMin + 600):
            return
        frameTime = ((int(time / 125)) % 4)
        spriteFrame = sdl.Rect((frameTime * 300, 0, 300, 400))
        if self.dead:
            return
        if self.dying:
            frameTime = ((int(time / 500)) % 4)
            if self.currentTime is not frameTime:
                self.currentFrame += 1
                self.currentTime = frameTime
                spriteFrame = sdl.Rect((self.currentFrame * 300, 0, 300, 400))
                sdl.renderCopy(renderer, bossTextures[9], spriteFrame,
                               self.getRect(xMin, yMin))

                # once the animation for attacking runs through, set him back to not attacking
                # and reset the current frame to -1 (so it starts at frame 0 next run)
                if self.currentFrame is 10:
                    self.currentFrame = -1
                    self.attacking = 0
                    self.currentTime = -1
                    self.dead = True
                    self.dying = False
            else:
                self.currentTime = frameTime
                spriteFrame = sdl.Rect((self.currentFrame * 300, 0, 300, 400))
                sdl.renderCopy(renderer, bossTextures[9], spriteFrame,
                               self.getRect(xMin, yMin))

        elif not self.hurt:  # if not hurt
            if self.attacking is 0:  # if not attacking
                if self.direction == 'e':
                    sdl.renderCopy(renderer, bossTextures[1], spriteFrame,
                                   self.getRect(xMin, yMin))  #right
                elif self.direction == 'w':
                    sdl.renderCopy(renderer, bossTextures[2], spriteFrame,
                                   self.getRect(xMin, yMin))  #left
                elif self.direction == 's':
                    sdl.renderCopy(renderer, bossTextures[8], spriteFrame,
                                   self.getRect(xMin, yMin))  #idle
            else:  # if attacking
                if self.attacking == 1:  # GREEN ATTACK
                    frameTime = ((int(time / 125)) % 4)
                    if self.currentTime is not frameTime:
                        self.currentFrame += 1
                        self.currentTime = frameTime
                        spriteFrame = sdl.Rect(
                            (self.currentFrame * 300, 0, 300, 400))
                        sdl.renderCopy(renderer, bossTextures[3], spriteFrame,
                                       self.getRect(xMin, yMin))
                        if self.currentFrame is 4:
                            self.projectiles.append(
                                Projectile(
                                    int(self.xPos) + 100,
                                    int(self.yPos) + 400, 60, 60, 'green',
                                    bossTextures[4], renderer, 0, 0, 0))

                        # once the animation for attacking runs through, set him back to not attacking
                        # and reset the current frame to -1 (so it starts at frame 0 next run)
                        if self.currentFrame >= 6:
                            self.currentFrame = -1
                            self.attacking = 0
                            self.currentTime = -1
                    else:
                        self.currentTime = frameTime
                        spriteFrame = sdl.Rect(
                            (self.currentFrame * 300, 0, 300, 400))
                        sdl.renderCopy(renderer, bossTextures[3], spriteFrame,
                                       self.getRect(xMin, yMin))

                elif self.attacking == 2:  # ORANGE ATTACK
                    frameTime = ((int(time / 125)) % 4)
                    if self.currentTime is not frameTime:
                        self.currentFrame += 1
                        self.currentTime = frameTime
                        spriteFrame = sdl.Rect(
                            (self.currentFrame * 700, 0, 700, 800))
                        sdl.renderCopy(renderer, bossTextures[5], spriteFrame,
                                       self.getRect(xMin, yMin))

                        # once the animation for attacking runs through, set him back to not attacking
                        # and reset the current frame to -1 (so it starts at frame 0 next run)
                        if self.currentFrame >= 8:
                            self.currentFrame = -1
                            self.attacking = 0
                            self.currentTime = -1
                            self.endOfOrange = True
                    else:
                        self.currentTime = frameTime
                        spriteFrame = sdl.Rect(
                            (self.currentFrame * 700, 0, 700, 800))
                        sdl.renderCopy(renderer, bossTextures[5], spriteFrame,
                                       self.getRect(xMin, yMin))

                elif self.attacking == 3:  # PURPLE ATTACK
                    frameTime = ((int(time / 125)) % 4)
                    if self.currentTime is not frameTime:
                        self.currentFrame += 1
                        self.currentTime = frameTime
                        spriteFrame = sdl.Rect(
                            (self.currentFrame * 300, 0, 300, 400))
                        sdl.renderCopy(renderer, bossTextures[6], spriteFrame,
                                       self.getRect(xMin, yMin))

                        if self.currentFrame is 4:
                            self.projectiles.append(
                                Projectile(
                                    int(self.xPos) - 100,
                                    int(self.yPos) + 400, 400, 200, 'purple',
                                    bossTextures[7], renderer, 0, 0, 0))

                        # once the animation for attacking runs through, set him back to not attacking
                        # and reset the current frame to -1 (so it starts at frame 0 next run)
                        if self.currentFrame >= 6:
                            self.currentFrame = -1
                            self.attacking = 0
                            self.currentTime = -1
                    else:
                        self.currentTime = frameTime
                        spriteFrame = sdl.Rect(
                            (self.currentFrame * 300, 0, 300, 400))
                        sdl.renderCopy(renderer, bossTextures[6], spriteFrame,
                                       self.getRect(xMin, yMin))

                if self.attacking == 4:
                    sdl.renderCopy(renderer, bossTextures[8], spriteFrame,
                                   self.getRect(xMin, yMin))
        elif self.hurt:  # if hurt
            sdl.renderCopy(renderer, bossTextures[0], spriteFrame,
                           self.getRect(xMin, yMin))
        self.renderHealth(renderer, xMin, yMin, bossTextures[10])
def run():
    running = True
    lastTime = 0
    time = 0

    up = False
    down = False
    left = False
    right = False

    event = sdl.Event()
    xPos = 100
    yPos = 100
    size = 200
    while running:

        currentTime = sdl.getTicks()
        dt = currentTime - lastTime
        time += dt / 1000.0
        lastTime = currentTime

        textureW, textureH = textureSize(texture)
        textureRect = centeredRect(width, height, textureW, textureH)

        #Figure out what keys are being pressed
        while sdl.pollEvent(event):
            if event.type == sdl.QUIT:
                running = False
            elif event.type == sdl.KEYUP:
                if event.key.keysym.sym in [sdl.K_q, sdl.K_ESCAPE]:
                    running = False
                if event.key.keysym.sym == sdl.K_UP: up = False
                elif event.key.keysym.sym == sdl.K_DOWN: down = False
                elif event.key.keysym.sym == sdl.K_LEFT: left = False
                elif event.key.keysym.sym == sdl.K_RIGHT: right = False
            if event.type == sdl.KEYDOWN:
                if event.key.keysym.sym == sdl.K_UP: up = True
                elif event.key.keysym.sym == sdl.K_DOWN: down = True
                elif event.key.keysym.sym == sdl.K_LEFT: left = True
                elif event.key.keysym.sym == sdl.K_RIGHT: right = True

            #movement based on what keys are being pressed down
            if up and left:
                yPos -= 10
                xPos -= 10
            elif up and right:
                yPos -= 10
                xPos += 10
            elif down and left:
                yPos += 10
                xPos -= 10
            elif down and right:
                yPos += 10
                xPos += 10
            elif up:
                yPos -= 10
            elif down:
                yPos += 10
            elif left:
                xPos -= 10
            elif right:
                xPos += 10

        testRect = sdl.Rect((xPos, yPos, size, size))
        sdl.renderClear(renderer)
        sdl.renderCopy(renderer, texture, None, textureRect)
        sdl.renderCopy(renderer, chefTexture, None, testRect)

        testRect = sdl.Rect((xPos, yPos, 250, 250))

        sdl.renderClear(renderer)

        sdl.renderCopy(renderer, texture, None, textureRect)

        sdl.renderCopy(renderer, chefTexture, None, testRect)
        sdl.renderPresent(renderer)
Exemple #30
0
 def getRect(self, xMin, yMin):
     return sdl.Rect((int(self.xPos) - int(xMin),
                      int(self.yPos) - int(yMin), self.width, self.height))