Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- _____ ____ __ __ ___ ______ __ __ ___ ___ __ __ ___ ___ ____
- / ___/ / T| T | / _] | T| T T / _] / \ | T T / _] / _]| \
- ( \_ Y o || | | / [_ | || l | / [_ Y Y| | | / [_ / [_ | _ Y
- \__ T| || | |Y _] l_j l_j| _ |Y _] | Q || | |Y _]Y _]| | |
- / \ || _ |l : !| [_ | | | | || [_ | || : || [_ | [_ | | |
- \ || | | \ / | T | | | | || T l |l || T| T| | |
- \___jl__j__j \_/ l_____j l__j l__j__jl_____j \__,_j \__,_jl_____jl_____jl__j__j
- """
- # heading font http://patorjk.com/software/taag/#p=display&h=0&v=0&f=Crawford&t=testing
- # sub heading font http://patorjk.com/software/taag/#p=display&h=2&v=2&f=Small%20Slant&t=testing
- # This game was inspired by Nishant in the Pygame Facebook group (fb.com/groups/pygame)
- # Shoot the enemies [LMB] before they touch the queen. If it's getting too much drop a bomb [RMB]!
- # Coding by Anthony Cook fb.com/anthony.cook78
- import math, random, sys, time
- import pygame
- from pygame.locals import *
- from pygame import gfxdraw
- """
- ___ __
- / _ \_______ _______ ___/ /_ _________ ___
- / ___/ __/ _ \/ __/ -_) _ / // / __/ -_|_-<
- /_/ /_/ \___/\__/\__/\_,_/\_,_/_/ \__/___/
- """
- def quit():
- for event in pygame.event.get():
- if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
- return True
- return False
- def threshold_table(size, steps, reverse = False, opposite = False):
- t = 2.0 * size / (steps * (steps - 1))
- a = 0
- table = []
- for i in range(steps):
- a += t * i
- if opposite: table.append(size - a)
- else: table.append(a)
- if reverse: table.reverse()
- return table
- """
- _____ ____ __
- / ___/__ ___ _ ___ / __/__ / /___ _____
- / (_ / _ `/ ' \/ -_) _\ \/ -_) __/ // / _ \
- \___/\_,_/_/_/_/\__/ /___/\__/\__/\_,_/ .__/
- /_/
- """
- # define display surface
- W, H = 1280, 720
- HW, HH = W / 2, H / 2
- # initialise display
- pygame.init()
- FONT = pygame.font.SysFont(None, 72)
- DS = pygame.display.set_mode((W, H))
- pygame.display.set_caption("Kill The Queen")
- pygame.mouse.set_visible(False)
- # start FPS monitoring
- FPS = 120
- SPF = 1.00 / FPS
- FPSTime = time.time()
- FRAME_COUNT = 0
- """
- _____ __
- / ___/__ / /__ _______
- / /__/ _ \/ / _ \/ __(_-<
- \___/\___/_/\___/_/ /___/
- """
- FUCHSIA = (255, 0, 255)
- PURPLE = (128, 0, 128)
- TEAL = ( 0, 128, 128)
- LIME = ( 0, 255, 0)
- GREEN = ( 0, 128, 0)
- OLIVE = (128, 128, 0)
- YELLOW = (255, 255, 0)
- ORANGE = (255, 165, 0)
- RED = (255, 0, 0)
- MAROON = (128, 0, 0)
- SILVER = (192, 192, 192)
- GRAY = (128, 128, 128)
- BLUE = ( 0, 0, 255)
- NAVY = ( 0, 0, 128)
- AQUA = ( 0, 255, 255)
- DARK_GRAY = ( 25, 25, 25)
- WHITE = (255, 255, 255)
- BLACK = ( 0, 0, 0)
- VECTOR_TABLE = [[math.cos(math.radians(degrees)), math.sin(math.radians(degrees))] for degrees in range(360)]
- """
- ____ __ ______ ______
- / __/__ ___ / /_ / __/ /___ __/ _/ _/
- / _// _ \/ _ \/ __/ _\ \/ __/ // / _/ _/
- /_/ \___/_//_/\__/ /___/\__/\_,_/_//_/
- """
- BLOCKY_FONT = {
- 'a' : "10 0 10 6 6 6 6 11 12 11 12 6 10 6 10 0 19 0 19 22 12 22 12 17 6 17 6 22 0 22 0 0",
- 'b' : "0 0 0 22 19 22 19 15 13 15 13 16 7 16 7 14 13 14 13 15 19 15 19 7 13 7 13 8 7 8 7 6 13 6 13 7 19 7 19 0",
- 'c' : "0 0 0 22 17 22 17 15 7 15 7 6 17 6 17 0",
- 'd' : "0 0 0 24 19 19 19 10 12 10 12 14 6 15 6 6 12 6 12 10 19 10 19 0",
- 'e' : "0 0 0 22 17 22 17 16 6 16 6 14 17 14 17 8 6 8 6 6 17 6 17 0",
- 'f' : "0 0 0 22 6 22 6 14 17 14 17 8 6 8 6 6 17 6 17 0",
- 'g' : "0 0 0 22 17 22 17 8 8 8 8 14 11 14 11 16 6 16 6 6 17 6 17 0",
- 'h' : "0 0 0 22 7 22 7 14 13 14 13 22 19 22 19 0 13 0 13 8 7 8 7 0",
- 'i' : "0 0 0 22 6 22 6 0",
- 'j' : "0 13 0 22 17 22 17 0 11 0 11 16 6 16 6 13",
- 'k' : "0 22 0 0 6 0 6 7 13 0 21 0 10 11 21 22 13 22 6 15 6 22",
- 'l' : "0 0 0 22 18 22 18 16 7 16 7 0",
- 'm' : "0 0 0 22 6 22 6 6 8 6 8 22 14 22 14 6 16 6 16 22 22 22 22 0",
- 'n' : "0 0 0 22 7 22 7 6 13 6 13 22 19 22 19 0",
- 'o' : "0 0 0 22 19 22 19 11 13 11 13 15 7 15 7 6 13 6 13 11 19 11 19 0",
- 'p' : "0 0 0 22 6 22 6 14 19 14 19 0 10 0 10 6 12 6 12 8 6 8 6 6 10 6 10 0",
- 'q' : "0 0 0 22 8 22 13 27 22 27 17 22 19 22 19 0 9 0 9 6 12 6 12 15 6 15 6 6 9 6 9 0",
- 'r' : "0 0 0 22 7 22 7 15 14 22 22 22 14 14 19 14 19 0 11 0 11 6 13 6 13 8 7 8 7 6 11 6 11 0",
- 's' : "0 0 0 14 11 14 11 16 0 16 0 22 17 22 17 8 6 8 6 6 17 6 17 0",
- 't' : "0 0 0 6 7 6 7 22 13 22 13 6 19 6 19 0",
- 'u' : "0 0 0 22 19 22 19 0 13 0 13 16 7 16 7 0",
- 'v' : "0 0 9 22 16 22 24 0 18 0 12 14 7 0",
- 'w' : "0 0 0 22 22 22 22 0 16 0 16 16 14 16 14 0 8 0 8 16 6 16 6 0",
- 'x' : "0 0 9 11 0 22 8 22 13 16 17 22 25 22 17 11 25 0 17 0 13 6 8 0",
- 'y' : "0 0 9 12 9 22 15 22 15 12 24 0 16 0 12 6 8 0",
- 'z' : "3 0 3 6 13 6 0 22 22 22 22 16 13 16 25 0",
- '1' : "0 0 0 6 3 6 3 22 9 22 9 0",
- '2' : "1 0 1 6 11 6 11 8 0 8 0 22 18 22 18 16 7 16 7 14 18 14 18 0",
- '3' : "0 0 0 6 11 6 11 8 0 8 0 14 11 14 11 16 0 16 0 22 17 22 17 0",
- '4' : "0 0 0 17 11 17 11 22 17 22 17 17 19 17 19 11 17 11 17 0 11 0 11 11 6 11 6 0",
- '5' : "0 0 0 14 11 14 11 16 0 16 0 22 17 22 17 8 6 8 6 6 17 6 17 0",
- '6' : "12 16 6 16 6 14 9 14 9 8 6 8 6 6 18 6 18 0 0 0 0 22 18 22 18 8 9 8 9 14 12 14",
- '7' : "3 0 3 6 12 6 0 22 8 22 25 0",
- '8' : "0 0 0 22 10 22 10 16 7 16 7 14 10 14 10 8 7 8 7 6 13 6 13 8 9 8 9 14 13 14 13 16 10 16 10 22 19 22 19 0",
- '9' : "0 0 6 0 6 1 10 1 10 6 6 6 6 8 12 8 12 6 9 6 9 1 12 1 12 0 19 0 19 22 0 22 0 16 12 16 12 14 0 14",
- '0' : "0 0 0 22 19 22 19 0 10 0 10 6 13 6 13 15 7 15 7 6 10 6 10 0",
- '!' : "0 0 6 0 6 14 3 14 3 16 6 16 6 22 0 22 0 16 3 16 3 14 0 14",
- '?' : "0 0 17 0 17 14 3 14 3 16 6 16 6 22 0 22 0 16 3 16 3 14 0 14 0 8 11 8 11 6 0 6",
- ':' : "0 3 6 3 6 9 3 9 3 13 6 13 6 19 0 19 0 13 3 13 3 9 0 9",
- }
- class font:
- def __init__(s, fontData, sizes = []):
- s.font = s.convertRaw(fontData)
- s.rasterFonts = []
- s.rasterFonts.append(s.rasterize())
- for sFactor in sizes:
- s.rasterFonts.append(s.rasterize(sFactor))
- def rasterize(s, sFactor = 1):
- global BLACK, WHITE
- font = {'width' : int(s.font['aw'] * sFactor), 'height' : int(s.font['ah'] * sFactor), 'sWidth' : int(s.font['fw'] * sFactor), 'sHeight' : int(s.font['fh'] * sFactor), 'surfaces' : {}}
- for char, data in s.font['f'].items():
- font['surfaces'][char] = {'width' : int(data['w'] * sFactor), 'height' : int(data['h'] * sFactor)}
- font['surfaces'][char]['surface'] = pygame.Surface((int(s.font['fw'] * sFactor) + 1, int(s.font['fh'] * sFactor) + 1))
- font['surfaces'][char]['surface'].set_colorkey(BLACK, pygame.RLEACCEL)
- points = []
- for p in s.font['f'][char]['p']:
- points.append([int(p[0] * sFactor), int(p[1] * sFactor)])
- pygame.draw.polygon(font['surfaces'][char]['surface'], WHITE, points)
- return font
- def stringSurface(s, t, color = None, sIndex = 0):
- global BLACK
- surface = pygame.Surface((s.getSurfaceWidth(t, sIndex), s.rasterFonts[sIndex]['sHeight']))
- if color:
- surface2 = surface.copy()
- surface2.fill(color)
- cx = 0
- for char in t:
- if char != " ":
- surface.blit(s.rasterFonts[sIndex]['surfaces'][char]['surface'], (cx, 0))
- if s.rasterFonts[sIndex]['surfaces'][char]['width'] > s.rasterFonts[sIndex]['width']: cx += int(s.rasterFonts[sIndex]['width'] * 1.4)
- else: cx += int(s.rasterFonts[sIndex]['width'] * 1.2)
- else: cx += s.rasterFonts[sIndex]['width']
- if color:
- surface.blit(surface2, (0, 0), None, pygame.BLEND_MULT)
- surface.set_colorkey(BLACK, pygame.RLEACCEL)
- return surface
- def getSurfaceWidth(s, t, sIndex):
- cx = 0
- for char in t:
- if char != " ":
- if s.rasterFonts[sIndex]['surfaces'][char]['width'] > s.rasterFonts[sIndex]['width']: cx += int(s.rasterFonts[sIndex]['width'] * 1.4)
- else: cx += int(s.rasterFonts[sIndex]['width'] * 1.2)
- else: cx += s.rasterFonts[sIndex]['width']
- return cx
- def convertRaw(s, fD):
- f = {}
- p = []
- ms = {'w' : {}, 'h' : {}}
- fw, fh = 0, 0
- for k, v in fD.items():
- pL = []
- w, h = 0, 0
- for d in v.split(' '):
- c = int(d)
- p.append(int(d))
- if len(p) == 2:
- pL.append(list(p))
- p = []
- if c > h: h = c
- elif c > w: w = c
- f[k] = {'p' : list(pL), 'w' : w, 'h' : h}
- if w > fw: fw = w
- if h > fh: fh = h
- if w in ms['w']: ms['w'][w] += 1
- else: ms['w'][w] = 1
- if h in ms['h']: ms['h'][h] += 1
- else: ms['h'][h] = 1
- mw, mh = None, None
- for k, v in ms['w'].items():
- if not mw: mw = k
- elif v > ms['w'][mw]: mw = k
- for k, v in ms['h'].items():
- if not mh: mh = k
- if v > ms['h'][mh]: mh = k
- return {'aw' : mw, 'ah' : mh, 'fh' : fh, 'fw' : fw, 'f' : f}
- """
- ____ ___ _ __
- / __/__ ___ __ _ __ __ / _ )(_) /_
- / _// _ \/ -_) ' \/ // / / _ / / __/
- /___/_//_/\__/_/_/_/\_, / /____/_/\__/
- /___/
- """
- ENEMY_SIZE = 20
- ENEMY_GROW_STEPS = 25
- ENEMY_SIZE_TABLE = threshold_table(ENEMY_SIZE, ENEMY_GROW_STEPS)
- class enemy:
- def __init__(s):
- global HW, HH, WHITE
- global VECTOR_TABLE
- s.color = WHITE
- degrees = random.randint(0, 359)
- dx = random.randint(HW - 50, HW)
- s.x = HW + VECTOR_TABLE[degrees][0] * dx
- dy = random.randint(HH - 50, HH)
- s.y = HH + VECTOR_TABLE[degrees][1] * dy
- s.angle = int(math.degrees(math.atan2(HH - s.y, HW - s.x))) % 360
- s.sizeIndex = 0
- s.dead = False
- s.stopped = False
- def howClose(s):
- global HW, HH
- global QUEEN_SIZE, ENEMY_SIZE
- return int(math.hypot(s.x - HW, s.y - HH))
- def move(s):
- global VECTOR_TABLE
- if s.stopped: return
- if s.sizeIndex < ENEMY_GROW_STEPS - 1:
- s.sizeIndex += 1
- return
- s.x += VECTOR_TABLE[s.angle][0]
- s.y += VECTOR_TABLE[s.angle][1]
- def draw(s):
- global DS
- global ENEMY_SIZE_TABLE
- pygame.draw.circle(DS, s.color, (int(s.x), int(s.y)), int(ENEMY_SIZE_TABLE[s.sizeIndex]))
- class enemies:
- def reset(s):
- global FRAME_COUNT
- s.container = []
- s.frameCounter = FRAME_COUNT
- s.newTimer()
- def newTimer(s):
- global FPS
- s.nextEnemyTimer = random.randint(FPS/5, FPS)
- def do(s):
- global HW, HH
- global RED, WHITE
- global FRAME_COUNT
- global QUEEN_SHAKE_RADIUS, QUEEN_SIZE, ENEMY_SIZE
- global queenHandler, crosshairHandler, explosionHandler
- queenHandler.shakeRadius = 0
- deleteEnemies = []
- for e in s.container:
- if e.dead:
- deleteEnemies.append(e)
- continue
- distanceToCrossHair = math.hypot(crosshairHandler.x - e.x, crosshairHandler.y - e.y)
- if distanceToCrossHair <= ENEMY_SIZE:
- e.color = RED
- crosshairHandler.enemyInSight = e
- elif crosshairHandler.enemyInSight == e:
- e.color = WHITE
- crosshairHandler.enemyInSight = None
- e.draw()
- e.move()
- distanceToQueen = e.howClose()
- if distanceToQueen < QUEEN_SHAKE_RADIUS:
- queenHandler.shakeRadius = QUEEN_SHAKE_TABLE[distanceToQueen]
- if distanceToQueen < QUEEN_SIZE + ENEMY_SIZE and not queenHandler.dead:
- e.stopped = True
- queenHandler.dead = True
- explosionHandler.add(HW, HH, 32)
- for dead in deleteEnemies:
- s.container.remove(dead)
- if FRAME_COUNT - s.frameCounter > s.nextEnemyTimer:
- s.frameCounter = FRAME_COUNT
- s.newTimer()
- s.container.append(enemy())
- """
- ____ ___ _ __
- / __ \__ _____ ___ ___ / _ )(_) /_
- / /_/ / // / -_) -_) _ \ / _ / / __/
- \___\_\_,_/\__/\__/_//_/ /____/_/\__/
- """
- QUEEN_SIZE = 32
- QUEEN_SHAKE_RADIUS = 300
- QUEEN_SHAKE_SIZE = 10
- QUEEN_SHAKE_TABLE = threshold_table(QUEEN_SHAKE_SIZE, QUEEN_SHAKE_RADIUS, True)
- class queen:
- def reset(s):
- global HW, HH
- s.dead = False
- s.shakeRadius = 0
- s.x, s.y = HW, HH
- def draw(s):
- global DS, HW, HH
- global QUEEN_SIZE
- if not s.dead: pygame.draw.circle(DS, ORANGE, (int(s.x), int(s.y)), QUEEN_SIZE)
- def move(s):
- global HW, HH
- global VECTOR_TABLE
- if s.shakeRadius == 0:
- s.x, s.y = HW, HH
- return
- angle = random.randint(0, 359)
- s.x = HW + VECTOR_TABLE[angle][0] * s.shakeRadius
- s.y = HH + VECTOR_TABLE[angle][1] * s.shakeRadius
- def do(s):
- s.move()
- s.draw()
- """
- _____ __ _ ___ _ __
- / ___/______ ___ ___ / / ___ _(_)___ / _ )(_) /_
- / /__/ __/ _ \(_-<(_-</ _ \/ _ `/ / __/ / _ / / __/
- \___/_/ \___/___/___/_//_/\_,_/_/_/ /____/_/\__/
- """
- CROSS_HAIR_SIZE = 30
- class crosshair:
- def move(s):
- s.x, s.y = pygame.mouse.get_pos()
- def reset(s):
- s.enemyInSight = None
- s.leftButtonStatus = False
- s.rightButtonStatus = False
- s.move()
- def draw(s):
- global DS
- global GREEN
- global CROSS_HAIR_SIZE
- pygame.gfxdraw.hline(DS, s.x - CROSS_HAIR_SIZE, s.x + CROSS_HAIR_SIZE, s.y, GREEN)
- pygame.gfxdraw.vline(DS, s.x, s.y - CROSS_HAIR_SIZE, s.y + CROSS_HAIR_SIZE, GREEN)
- def trigger(s):
- global HW, HH
- global ENEMY_SIZE, QUEEN_SIZE, BULLET_HOLE_SIZE
- global explosionHandler, bulletHoleHandler, enemyHandler, bombHandler, textHandler
- global kills, started, scoreSurface
- mb = pygame.mouse.get_pressed()
- if not s.rightButtonStatus and mb[2]:
- s.rightButtonStatus = True
- if started: bombHandler.useBomb()
- elif s.rightButtonStatus and not mb[2]:
- s.rightButtonStatus = False
- if not s.leftButtonStatus and mb[0]:
- started = True
- s.leftButtonStatus = True
- if s.enemyInSight:
- explosionHandler.add(s.enemyInSight.x, s.enemyInSight.y, ENEMY_SIZE)
- enemyHandler.container.remove(s.enemyInSight)
- s.enemyInSight = None
- kills += 1
- scoreSurface = textHandler.stringSurface("score: {}".format(kills), None, 2)
- else:
- distanceFromQueen = math.hypot(HW - s.x, HH - s.y)
- if distanceFromQueen > QUEEN_SIZE + BULLET_HOLE_SIZE:
- bulletHoleHandler.add(s.x, s.y)
- elif s.leftButtonStatus and not mb[0]:
- s.leftButtonStatus = False
- def do(s):
- s.draw()
- s.move()
- s.trigger()
- """
- ____ __ _ ___ _ __
- / __/_ __ ___ / /__ ___ (_)__ ___ ___ / _ )(_) /_
- / _/ \ \ // _ \/ / _ \(_-</ / _ \/ _ \(_-< / _ / / __/
- /___//_\_\/ .__/_/\___/___/_/\___/_//_/___/ /____/_/\__/
- /_/
- """
- PARTICLE_SIZE = 10
- PARTICLE_COUNT_TABLE = [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360]
- PARTICLE_COUNT_TABLE_INDEX = 13 # 20
- PARTICLE_SPAWN_RADIUS_PERCENT = 0.20
- PARTICLE_MIN_DISTANCE = 25
- PARTICLE_MAX_DISTANCE = 200
- PARTILCE_DISTANCE_STEP = 25
- PARTICLE_DISOLVE_STEP = 20
- PARTICLE_SHRINK_TABLE = threshold_table(PARTICLE_SIZE, PARTICLE_DISOLVE_STEP, True)
- PARTICLE_COLOR_TABLE = threshold_table(255, PARTICLE_DISOLVE_STEP, True)
- PARTICLE_DISTANCE_TABLE = [threshold_table(particleDistance, PARTICLE_DISOLVE_STEP, True, True) for particleDistance in range(PARTICLE_MIN_DISTANCE, PARTICLE_MAX_DISTANCE + PARTILCE_DISTANCE_STEP, PARTILCE_DISTANCE_STEP)]
- PARTICLE_DISTANCE_TABLE_COUNT = len(PARTICLE_DISTANCE_TABLE) - 1
- class particle:
- def __init__(s, a, x, y):
- global PARTICLE_DISTANCE_TABLE_COUNT
- s.angle = a
- s.distance_index = random.randint(0, PARTICLE_DISTANCE_TABLE_COUNT)
- s.originX, s.originY = x, y
- s.x, s.y = s.originX, s.originY
- def draw(s, index):
- global DS, WHITE
- global PARTICLE_SHRINK_TABLE, PARTICLE_COLOR_TABLE
- color = (255, PARTICLE_COLOR_TABLE[index], 0)
- pygame.draw.circle(DS, color, (int(s.x), int(s.y)), int(PARTICLE_SHRINK_TABLE[index]))
- def move(s, index):
- global VECTOR_TABLE, PARTICLE_DISTANCE_TABLE
- s.x = s.originX + VECTOR_TABLE[s.angle][0] * PARTICLE_DISTANCE_TABLE[s.distance_index][index]
- s.y = s.originY + VECTOR_TABLE[s.angle][1] * PARTICLE_DISTANCE_TABLE[s.distance_index][index]
- def do(s, index):
- s.draw(index)
- s.move(index)
- class explosion:
- def __init__(s, x, y, group_radius_size):
- global WHITE
- global VECTOR_TABLE
- global PARTICLE_COUNT_TABLE, PARTICLE_COUNT_TABLE_INDEX, PARTICLE_SPAWN_RADIUS_PERCENT
- s.dead = False
- s.disolveStepCount = 0
- minimum_group_radius = group_radius_size - int(group_radius_size * PARTICLE_SPAWN_RADIUS_PERCENT)
- s.particles = []
- for degrees in range(0, 359, PARTICLE_COUNT_TABLE[PARTICLE_COUNT_TABLE_INDEX]):
- radius = random.randint(minimum_group_radius, group_radius_size)
- px = x + VECTOR_TABLE[degrees][0] * radius
- py = y + VECTOR_TABLE[degrees][1] * radius
- s.particles.append(particle(degrees, px, py))
- def do(s):
- global PARTICLE_DISOLVE_STEP
- if s.dead: return
- for p in s.particles:
- p.do(s.disolveStepCount)
- if s.disolveStepCount < PARTICLE_DISOLVE_STEP - 1:
- s.disolveStepCount += 1
- else:
- s.dead = True
- class explosions:
- def reset(s):
- s.container = []
- def do(s):
- delete_list = []
- for e in s.container:
- e.do()
- if e.dead:
- delete_list.append(e)
- for dead in delete_list:
- s.container.remove(dead)
- def add(s, x, y, size):
- s.container.append(explosion(x, y, size))
- """
- ___ ____ __ __ __ __ ___ _ __
- / _ )__ __/ / /__ / /_ / // /__ / /__ ___ / _ )(_) /_
- / _ / // / / / -_) __/ / _ / _ \/ / -_|_-< / _ / / __/
- /____/\_,_/_/_/\__/\__/ /_//_/\___/_/\__/___/ /____/_/\__/
- """
- BULLET_HOLE_SIZE = 15
- BULLET_HOLE_DURATION = FPS / 4
- BULLET_HOLE_DISSOLVE_STEPS = FPS
- BULLET_HOLE_DISSOLVE_TABLE = threshold_table(BULLET_HOLE_SIZE, BULLET_HOLE_DISSOLVE_STEPS)
- BULLET_HOLE_COLOR = DARK_GRAY
- class bulletHole:
- def __init__(s, x, y):
- global FRAME_COUNT
- s.x, s.y = x, y
- s.spawnTime = FRAME_COUNT
- s.dissolveIndex = 0
- s.dead = False
- def draw(s):
- global DS, BLACK
- global BULLET_HOLE_COLOR, BULLET_HOLE_SIZE, BULLET_HOLE_DISSOLVE_TABLE
- pygame.draw.circle(DS, BULLET_HOLE_COLOR, (s.x, s.y), BULLET_HOLE_SIZE)
- if s.dissolveIndex:
- pygame.draw.circle(DS, BLACK, (s.x, s.y), int(BULLET_HOLE_DISSOLVE_TABLE[s.dissolveIndex]))
- def do(s):
- global FRAME_COUNT
- global BULLET_HOLE_DURATION, BULLET_HOLE_DISSOLVE_STEPS
- s.draw()
- if FRAME_COUNT - s.spawnTime >= BULLET_HOLE_DURATION:
- s.dissolveIndex += 1
- if s.dissolveIndex == BULLET_HOLE_DISSOLVE_STEPS: s.dead = True
- class bulletHoles:
- def reset(s):
- s.container = []
- def add(s, x, y):
- s.container.append(bulletHole(x, y))
- def do(s):
- deleteBulletHole = []
- for bh in s.container:
- bh.do()
- if bh.dead: deleteBulletHole.append(bh)
- for dead in deleteBulletHole:
- s.container.remove(dead)
- """
- ___ __ ___ _ __
- / _ )___ __ _ / / ___ / _ )(_) /_
- / _ / _ \/ ' \/ _ \(_-< / _ / / __/
- /____/\___/_/_/_/_.__/___/ /____/_/\__/
- """
- BOMB_ICON_SIZE = 10
- BOMB_SPACING = 20
- BOMB_COLOR = PURPLE
- BOMB_COUNT = 3
- BOMB_DISSOLVE_STEPS = FPS
- BOMB_DISSOLVE_TABLE = threshold_table(BOMB_ICON_SIZE, BOMB_DISSOLVE_STEPS, True)
- class bomb:
- def __init__(s, x, y):
- s.x, s.y = x, y
- s.dissolveIndex = 0
- s.spent = False
- s.dead = False
- def draw(s):
- global DS
- global BOMB_COLOR, BOMB_ICON_SIZE, BOMB_DISSOLVE_TABLE
- pygame.draw.circle(DS, BOMB_COLOR, (s.x, s.y), int(BOMB_DISSOLVE_TABLE[s.dissolveIndex]))
- class bombs:
- def reset(s):
- global H
- global BOMB_COUNT, BOMB_ICON_SIZE, BOMB_SPACING
- s.live = []
- s.spent = []
- bpx = BOMB_SPACING + BOMB_ICON_SIZE
- bpy = H - BOMB_ICON_SIZE - BOMB_SPACING
- for index in range(BOMB_COUNT):
- s.live.append(bomb(bpx, bpy))
- bpx += BOMB_SPACING + BOMB_ICON_SIZE
- def useBomb(s):
- global ENEMY_SIZE
- global enemyHandler, explosionHandler, crosshairHandler, textHandler
- global kills, scoreSurface
- if not s.live: return
- s.spent.append(s.live.pop())
- for e in enemyHandler.container:
- explosionHandler.add(e.x, e.y, ENEMY_SIZE)
- kills += 1
- scoreSurface = textHandler.stringSurface("score: {}".format(kills), None, 2)
- enemyHandler.container = []
- crosshairHandler.enemyInSight = None
- def do(s):
- global BOMB_DISSOLVE_STEPS
- for b in s.live:
- b.draw()
- deadBomb = None
- for sb in s.spent:
- sb.draw()
- sb.dissolveIndex += 1
- if sb.dissolveIndex == BOMB_DISSOLVE_STEPS - 1:
- deadBomb = sb
- if deadBomb: s.spent.remove(deadBomb)
- """
- _____ _ __ _ __ __
- / ___/__ ___ _ ___ | | / /__ _____(_)__ _/ / / /__ ___
- / (_ / _ `/ ' \/ -_) | |/ / _ `/ __/ / _ `/ _ \/ / -_|_-<
- \___/\_,_/_/_/_/\__/ |___/\_,_/_/ /_/\_,_/_.__/_/\__/___/
- """
- enemyHandler = enemies()
- queenHandler = queen()
- crosshairHandler = crosshair()
- explosionHandler = explosions()
- bulletHoleHandler = bulletHoles()
- bombHandler = bombs()
- textHandler = font(BLOCKY_FONT, [3, 0.8])
- GAME_TITLE = textHandler.stringSurface("save the queen!", ORANGE, 1)
- GAME_TITLE_WIDTH, GAME_TITLE_HEIGHT = GAME_TITLE.get_rect().size
- GAME_TITLE_X = -GAME_TITLE_WIDTH
- GAME_TITLE_STOP_POS_X = HW - GAME_TITLE_WIDTH / 2
- GAME_TITLE_TRAVEL_DISTANCE = GAME_TITLE_STOP_POS_X - GAME_TITLE_X
- GAME_TITLE_TRAVEL_TIME = float(FPS)
- GAME_TITLE_ACCELERATION_THRESHOLD = 2.0 * GAME_TITLE_TRAVEL_DISTANCE / (GAME_TITLE_TRAVEL_TIME * (GAME_TITLE_TRAVEL_TIME - 1))
- SPACE_TITLE = textHandler.stringSurface("press space to start", DARK_GRAY, 0)
- SPACE_TITLE_WIDTH = SPACE_TITLE.get_rect().width
- SPACE_TITLE_X = HW - SPACE_TITLE_WIDTH / 2
- SPACE_TITLE_Y = 300
- YOU_SCORED = textHandler.stringSurface("you scored:")
- YOU_SCORED_WIDTH = YOU_SCORED.get_rect().width
- SPACE_CONTINUE = textHandler.stringSurface("press space to continue", DARK_GRAY)
- SPACE_CONTINUE_WIDTH = SPACE_CONTINUE.get_rect().width
- """
- __ ___ _ __
- / |/ /__ _(_)__ / / ___ ___ ___
- / /|_/ / _ `/ / _ \ / /_/ _ \/ _ \/ _ \
- /_/ /_/\_,_/_/_//_/ /____|___/\___/ .__/
- /_/
- """
- while True:
- gameTitleXOffset = 0
- gameTitleAccelerationIndex = GAME_TITLE_TRAVEL_TIME
- gameTitleDirection = -1
- spacePressed = True
- while True:
- if quit():
- pygame.quit()
- sys.exit()
- frameTime = time.time() - FPSTime
- if frameTime < SPF: continue
- FPSTime += frameTime
- DS.blit(GAME_TITLE, (GAME_TITLE_X + gameTitleXOffset, 200))
- DS.blit(SPACE_TITLE, (SPACE_TITLE_X, SPACE_TITLE_Y))
- pygame.display.update()
- DS.fill(BLACK)
- gameTitleXOffset += GAME_TITLE_ACCELERATION_THRESHOLD * gameTitleAccelerationIndex
- gameTitleAccelerationIndex += gameTitleDirection
- if gameTitleAccelerationIndex == 0:
- gameTitleDirection = 1
- if gameTitleAccelerationIndex == GAME_TITLE_TRAVEL_TIME:
- gameTitleXOffset = 0
- gameTitleDirection = -1
- k = pygame.key.get_pressed()
- if not k[pygame.K_SPACE]: spacePressed = False
- if k[pygame.K_SPACE] and not spacePressed:
- break
- DS.fill(BLACK)
- bulletHoleHandler.reset()
- queenHandler.reset()
- enemyHandler.reset()
- explosionHandler.reset()
- crosshairHandler.reset()
- bombHandler.reset()
- scoreSurface = textHandler.stringSurface("score: 0", None, 2)
- kills = 0
- backToTitle = False
- while True:
- if quit():
- backToTitle = True
- break
- frameTime = time.time() - FPSTime
- if frameTime < SPF: continue
- FPSTime += frameTime
- FRAME_COUNT += 1
- DS.blit(scoreSurface, (10, 10))
- bulletHoleHandler.do()
- queenHandler.do()
- enemyHandler.do()
- explosionHandler.do()
- crosshairHandler.do()
- bombHandler.do()
- pygame.display.update()
- DS.fill(BLACK)
- if queenHandler.dead and not explosionHandler.container: break
- if not backToTitle:
- DS.fill(BLACK)
- finalScore = textHandler.stringSurface("{}".format(kills), ORANGE, 1)
- finalScoreWidth = finalScore.get_rect().width
- spacePressed = True
- while True:
- if quit():
- pygame.quit()
- sys.exit()
- DS.blit(YOU_SCORED, (HW - YOU_SCORED_WIDTH / 2, HH - 50))
- DS.blit(finalScore, (HW - finalScoreWidth / 2, HH + 5))
- DS.blit(SPACE_CONTINUE, (HW - SPACE_CONTINUE_WIDTH / 2, HH + 100))
- pygame.display.update()
- DS.fill(BLACK)
- k = pygame.key.get_pressed()
- if not k[pygame.K_SPACE]: spacePressed = False
- if k[pygame.K_SPACE] and not spacePressed:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement