from game import balloflight from game.gameobject import GameObject ### Constants ################################################################## ENEMY_STATES = ('IDLE', 'APPEARING', 'LOWERING', 'ACTIVE', 'DYING', 'CHEERING') FRAMES = tuple(Rect(32 * i, 32, 32, 32) for i in range(4)) LOWER_INCREMENT = 16 START_POS = (32.0, 32.0) ENEMY_FRAMES = color.get_colored_objects(FRAMES, True, False, True) ENEMY_FRAMES_COLOR_BLIND = color.get_colored_objects(FRAMES, True, True, True) del FRAMES ################################################################################ ### Globals #################################################################### _hurt = config.load_sound('enemyhit.wav') ################################################################################ class Enemy(GameObject): STATES = config.Enum(*ENEMY_STATES) anim = 0.0 base_speed = 0.5 GROUP = None shoot_odds = 0.002 should_flip = False start_time = None velocity = [0.5, 0.0] def __init__(self, form_position): super().__init__()
and deleted over and over, but to be reused by the ship (so we don't take as much time creating and destroying bullets). ''' import pygame.rect from core import config from game.bullet import Bullet from game.enemy import Enemy from game.ufo import UFO from game import gamedata ### Constants ################################################################## ''' @var SHOOT: The sound that plays when the player fires ''' SHOOT = config.load_sound('shoot.wav') ################################################################################ class ShipBullet(Bullet): SPEED = -8 START_POS = pygame.Rect(30, config.SCREEN_HEIGHT * 2, 26, 19) GROUP = None def __init__(self): super().__init__() self.hit_enemy = False def start_moving(self): SHOOT.play() super().start_moving() self.hit_enemy = False
from game import balloflight from game.gameobject import GameObject ### Constants ################################################################## ENEMY_STATES = ('IDLE', 'APPEARING', 'LOWERING', 'ACTIVE', 'DYING', 'CHEERING') FRAMES = tuple(Rect(32 * i, 32, 32, 32) for i in range(4)) LOWER_INCREMENT = 16 START_POS = (32.0, 32.0) ENEMY_FRAMES = color.get_colored_objects(FRAMES, True, False, True) ENEMY_FRAMES_COLOR_BLIND = color.get_colored_objects(FRAMES, True, True , True) del FRAMES ################################################################################ ### Globals #################################################################### _hurt = config.load_sound('enemyhit.wav') ################################################################################ class Enemy(GameObject): STATES = config.Enum(*ENEMY_STATES) anim = 0.0 base_speed = 0.5 GROUP = None shoot_odds = 0.002 should_flip = False start_time = None velocity = [0.5, 0.0] def __init__(self, form_position): super().__init__() ### Local variables ####################################################
from core import color from core import config from core.config import screen, _limit_frame from core.gamestate import GameState from game.hudobject import HudObject from game.mainmenu import MainMenu ### Groups ##################################################################### DIAMOND = Group() ################################################################################ ### Constants ################################################################## LOGO = config.load_image('logo.png') BOOT = config.load_sound('boot.ogg') ################################################################################ ### Preparation ################################################################ ################################################################################ class SplashScreen(GameState): def __init__(self): self.alpha_percent = 0.0 self.group_list = (DIAMOND,) self.logo = HudObject(LOGO, [0, 0]) self.start_time = 5 * 60 #In frames BOOT.play() self.logo.rect.center = config.SCREEN_RECT.center
from math import sin from random import choice, uniform, expovariate from pygame import Rect from core import color from core import config from core.particles import ParticleEmitter from game.block import get_block from game.gameobject import GameObject from game import gamedata ### Constants ################################################################## AVG_WAIT = 9000 #Expected time in frames between UFO appearance DEATH = config.load_sound('ufo_explosion.wav') FRAMES = tuple( Rect(64 * (i % 4), 192 + 32 * (i // 4), 64, 32) for i in range(10, -1, -1)) INVADE = config.load_sound('ufo.wav') START_POS = (640, 16) UFO_FRAMES = color.get_colored_objects(FRAMES) UFO_STATES = ('IDLE', 'APPEARING', 'ACTIVE', 'DYING', 'LEAVING', 'LOWERING', 'GAMEOVER') ################################################################################ class UFO(GameObject): STATES = config.Enum(*UFO_STATES) GROUP = None BLOCK_GROUP = None def __init__(self):
import pygame.mixer from core import config from core import color from core import settings from core.particles import ParticlePool, ParticleEmitter from game.gameobject import GameObject from game import blockgrid from game import gamedata ### Constants ################################################################## BLOCK_STATES = ('IDLE', 'APPEARING', 'ACTIVE', 'START_FALLING', 'FALLING', 'IMPACT', 'DYING') FRAMES = tuple(pygame.Rect(32 * i, 160, 32, 32) for i in range(8)) GRAVITY = 0.5 MAX_SPEED = 12.0 UFO_BLOCK = config.load_sound('ufo_block.wav') ################################################################################ ### Globals #################################################################### _blocks_set = set() _bump = config.load_sound('bump.wav') _block_frames = color.get_colored_objects(FRAMES, True, False, True) _block_frames_color_blind = color.get_colored_objects(FRAMES, True, True , True) ################################################################################ ### Functions ################################################################## def clean_up(): ''' Removes every Block from memory.
from core import color from core import config from core.config import screen, _limit_frame from core.gamestate import GameState from game.hudobject import HudObject from game.mainmenu import MainMenu ### Groups ##################################################################### DIAMOND = Group() ################################################################################ ### Constants ################################################################## LOGO = config.load_image('logo.png') BOOT = config.load_sound('boot.ogg') ################################################################################ ### Preparation ################################################################ ################################################################################ class SplashScreen(GameState): def __init__(self): self.alpha_percent = 0.0 self.group_list = (DIAMOND, ) self.logo = HudObject(LOGO, [0, 0]) self.start_time = 5 * 60 #In frames BOOT.play()
''' from pygame.display import get_surface from pygame import Rect from pygame import Surface from pygame.sprite import GroupSingle, Sprite from core import config from core import color from game import gamedata ### Constants ################################################################## ALARM_LINE = 2 BLOCK_TYPE = None CELL_SIZE = (32, 32) COMBOS = tuple(config.load_sound('combo%d.wav' % i) for i in range(1, 6)) SIZE = (20, 12) #(width, height) RECT = Rect(0, 0, get_surface().get_width(), SIZE[1] * CELL_SIZE[1]) ################################################################################ ### Globals #################################################################### blocks = None block_buffer = GroupSingle(Sprite()) _blocks_to_check = set() _blocks_to_clear = set() _block_clear = config.load_sound('clear.wav') block_buffer.sprite.rect = Rect(0, 0, 0, 0) ################################################################################
from math import sin from random import choice, uniform, expovariate from pygame import Rect from core import color from core import config from core.particles import ParticleEmitter from game.block import get_block from game.gameobject import GameObject from game import gamedata ### Constants ################################################################## AVG_WAIT = 9000 #Expected time in frames between UFO appearance DEATH = config.load_sound('ufo_explosion.wav') FRAMES = tuple( Rect(64 * (i % 4), 192 + 32 * (i // 4), 64, 32) for i in range(10, -1, -1) ) INVADE = config.load_sound('ufo.wav') START_POS = (640, 16) UFO_FRAMES = color.get_colored_objects(FRAMES) UFO_STATES = ('IDLE', 'APPEARING', 'ACTIVE', 'DYING', 'LEAVING', 'LOWERING', 'GAMEOVER') ################################################################################ class UFO(GameObject): STATES = config.Enum(*UFO_STATES) GROUP = None BLOCK_GROUP = None def __init__(self):
#if config.DEBUG: import core.vartracker ### Groups ##################################################################### BG = OrderedUpdates() BLOCKS = Group() ENEMIES = Group() ENEMY_BULLETS = Group() HUD = Group() PARTICLES = Group() PLAYER = Group() UFO_GROUP = Group() ################################################################################ ### Constants ################################################################## rect = config.SCREEN_RECT ALARM = config.load_sound('alarm.wav') DEBUG_KEYS = (K_u, K_c, K_f, K_F1, K_e, K_k, K_i) FADE_TIME = 2500 #In milliseconds FIRE_LOCATION = (rect.centerx - 192, rect.centery ) GAME_OVER_LOC = (rect.centerx - 64 , rect.centery - 64) HUD_TEXT = namedtuple('Hud', 'score lives time game_over press_fire wave pause') LIVES_LOCATION = (rect.width - 160, 16) MODULE_CLEANUP = (balloflight, blockgrid, block, enemybullet, enemysquadron, gamedata) MOUSE_ACTIONS = {1:color.RED, 2:color.YELLOW, 3:color.BLUE} MUSIC_PATHS = {-1:'music.ogg', 120:'2.ogg', 300:'5.ogg'} NULL_FUNC = lambda: None GAME_TEXT = None GAME_OVER_PATH = 'gameover.ogg' SCORE_LOCATION = (16, 16) TIME_FORMAT = "{}:{:0>2}" TIME_LOCATION = (rect.centerx, 32)
if percent == 1: #If we've reached our target location... self.change_state(Particle.STATES.LEAVING) else: dx = (percent**2) * (3-2*percent) ddx = 1 - dx position[0] = (self.startpos[0] * ddx) + (START_POS.centerx * dx) position[1] = (self.startpos[1] * ddx) + (START_POS.centery * dx) self.rect.topleft = (position[0] + .5, position[1] + .5) ################################################################################ ### Constants ################################################################## PART_IMAGE = Rect(4, 170, 4, 4) APPEAR = config.load_sound('appear.wav') APPEAR_POOL = ParticlePool(config.get_sprite(PART_IMAGE), _radius_move, _radius_appear) DEATH = config.load_sound('death.wav') DEATH_POOL = ParticlePool(config.get_sprite(PART_IMAGE), appear_func=_burst_appear) FRAMES = tuple(config.get_sprite(Rect(32 * i, 128, 32, 32)) for i in range(5)) GRAVITY = 0.5 SHIP_STATES = ('IDLE', 'SPAWNING', 'ACTIVE', 'DYING', 'DEAD', 'RESPAWN') SPEED = 4 START_POS = Rect(config.SCREEN_WIDTH / 2, config.SCREEN_HEIGHT * .8, 32, 32) ################################################################################ ### Preparation ################################################################ for i in FRAMES: i.set_colorkey(color.COLOR_KEY, config.BLIT_FLAGS) ################################################################################ class FlameTrail(GameObject):
and deleted over and over, but to be reused by the ship (so we don't take as much time creating and destroying bullets). ''' import pygame.rect from core import config from game.bullet import Bullet from game.enemy import Enemy from game.ufo import UFO from game import gamedata ### Constants ################################################################## ''' @var SHOOT: The sound that plays when the player fires ''' SHOOT = config.load_sound('shoot.wav') ################################################################################ class ShipBullet(Bullet): SPEED = -8 START_POS = pygame.Rect(30, config.SCREEN_HEIGHT * 2, 26, 19) GROUP = None def __init__(self): super().__init__() self.hit_enemy = False def start_moving(self): SHOOT.play() super().start_moving()
### Groups ##################################################################### GRID_BG = OrderedUpdates() MENU = Group() ################################################################################ ### Constants ################################################################## ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' BACK_CHAR = '\u2190' #Left arrow UP_ARROW = '\u2191' #Up arrow DOWN_ARROW = '\u2193' #Down arrow BLANK_CHAR = '\u2192' #Right arrow DONE_CHAR = '\u0180' #Normally a special b, but I modified it to say 'OK' CHAR_LIMIT = 20 DEFAULTS = DEFAULT_HIGH_SCORES ENTRY_NAME_POS = (32, config.SCREEN_HEIGHT - 32) ERROR = config.load_sound('error.wav') METHOD = 'POST' OK_CHARS = ''.join((ALPHABET, digits, BLANK_CHAR, '-\'', DONE_CHAR, BACK_CHAR)) ONLINE_TEXT = namedtuple('ONLINE', 'prompt send get cancel ok fail') ROW_WIDTH = 32 SCORE_FORMAT = "{:.<24}.{:.>7}" SCORE_TABLE_X = (config.SCREEN_RECT.midtop[0] - 64, 16) INSTRUCTIONS_X = (32, 10 * 32) INSTRUCT_DIST_APART = 40 TABLE_CORNER = (16, 64) TIME_OUT = 10 V_SPACE = 24 URL = 'http://www.corundumgames.com/cgi-bin/game/invasodado/hs.py' ################################################################################ ### Globals ####################################################################
if percent == 1: #If we've reached our target location... self.change_state(Particle.STATES.LEAVING) else: dx = (percent**2) * (3 - 2 * percent) ddx = 1 - dx position[0] = (self.startpos[0] * ddx) + (START_POS.centerx * dx) position[1] = (self.startpos[1] * ddx) + (START_POS.centery * dx) self.rect.topleft = (position[0] + .5, position[1] + .5) ################################################################################ ### Constants ################################################################## PART_IMAGE = Rect(4, 170, 4, 4) APPEAR = config.load_sound('appear.wav') APPEAR_POOL = ParticlePool(config.get_sprite(PART_IMAGE), _radius_move, _radius_appear) DEATH = config.load_sound('death.wav') DEATH_POOL = ParticlePool(config.get_sprite(PART_IMAGE), appear_func=_burst_appear) FRAMES = tuple(config.get_sprite(Rect(32 * i, 128, 32, 32)) for i in range(5)) GRAVITY = 0.5 SHIP_STATES = ('IDLE', 'SPAWNING', 'ACTIVE', 'DYING', 'DEAD', 'RESPAWN') SPEED = 4 START_POS = Rect(config.SCREEN_WIDTH / 2, config.SCREEN_HEIGHT * .8, 32, 32) ################################################################################ ### Preparation ################################################################ for i in FRAMES: i.set_colorkey(color.COLOR_KEY, config.BLIT_FLAGS)
### Groups ##################################################################### GRID_BG = OrderedUpdates() MENU = Group() ################################################################################ ### Constants ################################################################## ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' BACK_CHAR = '\u2190' #Left arrow UP_ARROW = '\u2191' #Up arrow DOWN_ARROW = '\u2193' #Down arrow BLANK_CHAR = '\u2192' #Right arrow DONE_CHAR = '\u0180' #Normally a special b, but I modified it to say 'OK' CHAR_LIMIT = 20 DEFAULTS = DEFAULT_HIGH_SCORES ENTRY_NAME_POS = (32, config.SCREEN_HEIGHT - 32) ERROR = config.load_sound('error.wav') METHOD = 'POST' OK_CHARS = ''.join((ALPHABET, digits, BLANK_CHAR, '-\'', DONE_CHAR, BACK_CHAR)) ONLINE_TEXT = namedtuple('ONLINE', 'prompt send get cancel ok fail') ROW_WIDTH = 32 SCORE_FORMAT = "{:.<24}.{:.>7}" SCORE_TABLE_X = (config.SCREEN_RECT.midtop[0] - 64, 16) INSTRUCTIONS_X = (32 , 10 * 32) INSTRUCT_DIST_APART = 40 TABLE_CORNER = (16, 64) TIME_OUT = 10 V_SPACE = 24 URL = 'http://www.corundumgames.com/cgi-bin/game/invasodado/hs.py' ################################################################################ ### Globals ####################################################################
from core import config from core import color from core import settings from core.particles import ParticlePool, ParticleEmitter from game.gameobject import GameObject from game import blockgrid from game import gamedata ### Constants ################################################################## BLOCK_STATES = ('IDLE', 'APPEARING', 'ACTIVE', 'START_FALLING', 'FALLING', 'IMPACT', 'DYING') FRAMES = tuple(pygame.Rect(32 * i, 160, 32, 32) for i in range(8)) GRAVITY = 0.5 MAX_SPEED = 12.0 UFO_BLOCK = config.load_sound('ufo_block.wav') ################################################################################ ### Globals #################################################################### _blocks_set = set() _bump = config.load_sound('bump.wav') _block_frames = color.get_colored_objects(FRAMES, True, False, True) _block_frames_color_blind = color.get_colored_objects(FRAMES, True, True, True) ################################################################################ ### Functions ################################################################## def clean_up(): '''