def __init__(self): self.comp = Compositor(self) # self.entities = set() self.renderLayers = [] # Contains Grid[] layers for entire level; rendered in order (farthest -> nearest) self.grid = Grid() # Contains tile info for collision detection self.tile_size = Size(16, 16) self.level_size = Size()
def process_image(self, image): file_converter = FileConverter() #convert the image to byte string image_bytes = file_converter.png_to_jpeg(image) scanner = Scanner() #scan the image and give it a birds eye view, returns a np of pixels that makes up the image scan_np = scanner.scan(image_bytes) #extract the individual answers from the scanned test extractor = Extract() answers = extractor.get_all_answers(scan_np, 5) color = Color() bw_answers = color.all_ans_to_bw(answers) size = Size() DIM = (28, 28) shrunk_images = size.shrink_images(bw_answers, DIM) #convert the answer images to a single array, which we used in training our model answers_flat = file_converter.convert_images( shrunk_images) #returns image as (1, 28, 28, 1) and as type float #now that we have a list of images of the answers as bw 1D numpy arrays, # we can run them through our model and grade them # first we need to load our model model_loader = ModelLoader() MODEL_JSON = 'models/modified_model_98.json' MODEL_WEIGHTS = 'models/modified_model_98.h5' model = model_loader.load_model_2(MODEL_JSON, MODEL_WEIGHTS) #compile model model.compile(optimizer=RMSprop(lr=0.001), loss='categorical_crossentropy', metrics=['accuracy']) grader = Grader() answers = grader.get_answers(answers_flat, model) #get the images as a 784 (28x28) length string so we can store the data in a database ans_strings = file_converter.get_string_images(answers_flat) compressed_images = file_converter.compress_images(ans_strings) #add the images to database so we can create a large dataset of handwritten letters # storage = Storage() # storage.insert(answers, compressed_images) return answers
class GameConstants: SCREEN_SIZE = Size(width=800, height=600) BRICK_SIZE = Size(width=100, height=30) BALL_SIZE = Size(width=32, height=32) PAD_SIZE = Size(width=139, height=13) SPRITE_BALL = os.path.join("Assets", "ball.png") SPRITE_BRICK = os.path.join("Assets", "brick.png") LIFE_BRICK = os.path.join("Assets", "LifeBrick.png") SPEED_BRICK = os.path.join("Assets", "SuperBrickNormal.png") SPRITE_PAD = os.path.join("Assets", "pad.png") SOUND_BRICK_HIT = os.path.join("Assets", "metal_hit.mp3") SOUND_GAME_OVER = os.path.join("Assets", "game_over.wav") def __init__(self): pass
def __init__(self, Pos, Size, Surface): self.pos = Pos self._tetrimino = None self.surface = Surface self.rect = pygame.Rect(Pos.tuple(), Size.tuple()) pygame.draw.rect(self.surface, UiConfig.tetriminoBox['BORDER_COLOR'], \ self.rect, UiConfig.tetriminoBox['BORDER_WIDTH'])
def __init__(self, name="Entity"): self._name = name self._traits = {} self.pos = Vec2d(0, 0) self.vel = Vec2d(0, 0) self.size = Size(0, 0) self.sprite = None self.debug = True
def loadEntities(self): path = sys.path[0] assetdir = os.path.join(path, 'assets') spritesheet = Spritesheet( os.path.join(assetdir, "smb_char_sprites.gif")) self._mario = Entity("mario") self._mario.pos = Vec2d(64, 64) self._mario.size = Size(14, 18) self._mario.sprite = spritesheet.image_at((276, 42, 14, 18)) self._mario.addTrait(Jump()) self._mario.addTrait(Velocity()) self._level.entities.add(self._mario)
def __init__(self, Pos, Size, Surface): self.surface = Surface self.rect = pygame.Rect(Pos.tuple(), Size.tuple()) pygame.draw.rect(self.surface, UiConfig.infoBox['BORDER_COLOR'], \ self.rect, UiConfig.infoBox['BORDER_WIDTH']) self.font = pygame.font.SysFont(self.FONT['font'], self.FONT['size']) self.drawText('Level:', self.TEXT_POS['LevelText']) self.levelText = self.drawText('0', self.TEXT_POS['Level']) self.drawText('Score:', self.TEXT_POS['ScoreText']) self.scoreText = self.drawText('0', self.TEXT_POS['Score']) self._level = 0 self._score = 0
def loadLevel(self): #self._level = Level() path = sys.path[0] assetdir = os.path.join(path, 'assets') self._map = loadTilemap("level_test.tmx", assetdir) self._level = Level() self._level.level_size = Size(self._map.map.map_size) self._level.comp.layers.append(self.backgroundRenderer) #layer = self._map.get_layer("Foreground") dx = int(self.camera.width / self._map.map.tile_size.width) dy = int(self.camera.height / self._map.map.tile_size.height) for layer in self._map.layers: gg = None if layer.name == "Foreground": self.loadSingleLevel(self._level.grid, layer, dx, dy) self._level.renderLayers.append(self._level.grid) else: gg = Grid() self._level.renderLayers.append(gg) self.loadSingleLevel(gg, layer, dx, dy)
from Game import Game from Size import Size from GameOverException import GameOverException size = Size(width=100, height=20) game = Game(size) try: game.play(0.5) except GameOverException: print('Game over...')