def update(self): if self.serpent.stats.hp == 0 and not self.buildbrige: sound.playMusic("music/Existing.s3m") sound.achievement.Play() system.engine.addCaptions(Caption('Serpent defeated!')) savedata['finalbattledone'] = 'True' self.buildbrige = True self.time = 100 #wait 1 second before starting to build the bridge if self.buildbrige: if self.time == 0: self.time = 20 l = ika.Map.FindLayerByName('B1.5') if self.row == 27: ol = ika.Map.FindLayerByName('B2') for y in range(27, 18, -1): #haaaack if y == 19 or y == 27: obs = [0, 0, 0, 0, 0] else: obs = [1, 0, 0, 0, 1] for x, o in enumerate(obs): ika.Map.SetObs(x + 21, y, ol, o) for x in range(5): ika.Map.SetTile(x + 21, self.row, l, icebridge[self.row][x]) if self.row > 19: ika.Map.SetTile(x + 21, self.row - 1, l, temp[x]) self.row -= 1 if self.row < 19: return True #done else: self.time -= 1
def update(self): if self.yeti.stats.hp == 0: e = ika.Entity(315, 320, 2, 'unityrune.ika-sprite') e.name = 'unityrune' system.engine.addEntity(UnityRune(e)) sound.playMusic("music/lampoons.it") savedata.finalrune = 'True' system.engine.addCaptions(Caption('Rune Guardian defeated.')) return True
def update(self): assert self.flagName not in self.__dict__, 'Already have this. Why are we updating?' if self.touches(system.engine.player): setattr(savedata, self.flagName, 'True') system.engine.player.stats.tnt += 1 system.engine.player.stats.totaltnt += 1 system.engine.destroyEntity(self) system.engine.addCaptions(Caption('Got a stick of dynamite!')) automap.map.SetCollected('TNT')
def update(self): if self.touches(system.engine.player): system.engine.destroyEntity(self) captlist = [] r = g = b = 255 if self.element in ['Strength', 'Guard', 'Power']: if self.element == 'Strength': system.engine.player.stats.strengthrunes += 1 if self.element == 'Power': system.engine.player.stats.powerrunes += 1 if self.element == 'Guard': system.engine.player.stats.guardrunes += 1 captlist.append( Caption('%s Rune collected!' % self.element, y=160, duration=400)) else: r, g, b = colors[self.element] captlist.append( Caption('You got the %s Rune!' % self.element, y=160, duration=400, r=r, g=g, b=b)) captlist.append( Caption('%s' % self.effect, y=170, duration=400, r=r, g=g, b=b)) captlist.append( Caption('%s' % self.effect2, y=180, duration=400, r=r, g=g, b=b)) system.engine.addCaptions(captlist) setattr(savedata, self.name, 'True') automap.map.SetCollected(self.element) self.apply()
def update(self): if self.yeti.stats.hp == 0: if 'windrune' not in savedata.__dict__: e = ika.Entity(304, 304, 2, 'windrune.ika-sprite') e.name = 'windrune' system.engine.addEntity(WindRune(e)) else: setattr(savedata, 'windguard', 'True') system.engine.addCaptions(Caption('Rune Guardian defeated.')) sound.playMusic('music/winter.ogg') return True
def gameOver(self): c = Caption('G A M E O V E R', duration=1000000, y=(ika.Video.yres - self.font.height) / 2) t = 80 i = 0 self.fields = [] while True: i = min(i + 1, t) c.update() self.tick() self.draw() # darken the screen, draw the game over message: o = i * 255 / t ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, o), True) c.draw() ika.Video.ShowPage() ika.Delay(4) if i == t and (controls.attack() or controls.joy_attack() or controls.ui_accept() or controls.ui_cancel() or controls.cancel() or controls.joy_cancel()): break
def AutoExec(): engine.background = ika.Image('gfx/sky_bg.png') engine.bgThings.append( Clouds('gfx/sky_clouds.png', speed=(0.1, 0.025), tint=ika.RGB(255, 255, 255, 220))) engine.mapThings.append( ClippedClouds('stencils/green_00.ika-map.png', 'gfx/sky_shadows.png', tint=ika.RGB(255, 5, 5, 255))) if 'firstconvo' in engine.saveData: engine.things.append(Caption("Anastasia's House", font=engine.font2))
def saveMenu(): title = gui.TextFrame(text='Save Game') title.Position = (16, 16) saves = readSaves() m = SaveLoadMenu(saves, saving=True) if len(saves)==0: m.offset = 6 #hack to position cursor properly when no saves exist bg = ika.Image('gfx/mountains.png') def draw(): #ika.Video.ClearScreen() # fix this ika.Video.TintBlit(bg, 0,0, ika.RGB(128, 128, 128, 255)) #fixed it! m.draw() title.draw() xi.effects.fadeIn(50, draw=draw) i = None while i is None: i = m.update() draw() ika.Video.ShowPage() if i is not Cancel: s = SaveGame.currentGame() if i is New: for j in range(100): try: f=file('saves/Save %i' % j, 'rt') f.close() except IOError, e: #found a slot that doesn't exist. Bad hack! ika.Log(str(e)) s.save('saves/Save %i' % j) system.engine.addCaptions(Caption('Game saved.', duration=100)) break else: filename=saves[i].fname s.save(filename) system.engine.addCaptions(Caption('Game saved.', duration=100))
def AutoExec(): engine.background = ika.Image('gfx/sky_bg.png') engine.bgThings.append( Clouds('gfx/sky_clouds.png', speed=(0.1, 0.025), tint=ika.RGB(255, 255, 255, 220))) engine.mapThings.append( ClippedClouds('stencils/green_03.ika-map.png', 'gfx/sky_shadows.png', tint=ika.RGB(255, 5, 5, 255))) engine.things.append(Caption("Haven Town", font=engine.font2)) if engine.player: engine.player.stats.hp = engine.player.stats.maxhp if 'rescued' not in engine.saveData: del ika.Map.entities["friedrich"]
def levelUp(self): #sound.achievement.Play() while self.stats.exp >= 100: self.stats.maxhp += ika.Random(14, 20) self.stats.maxmp += ika.Random(2, 5) statlist = [] for n in range(8 + self.stats.level / 3): if not statlist: statlist = ['att', 'mag', 'pres', 'mres'] s = statlist[ika.Random(0, len(statlist))] setattr(self.stats, s, getattr(self.stats, s) + 1) statlist.remove(s) self.stats.level += 1 self.stats.exp -= 100 self.stats.exp = self.stats.exp * (self.exponent**( self.stats.level - 2)) / (self.exponent **(self.stats.level - 1)) engine.things.append(Caption('Level %i!' % self.stats.level))
def firstConvo(): #if 'firstconvo' not in engine.saveData: if False: xwin = ika.Map.xwin ywin = ika.Map.ywin stone = ika.Entity(110, 60, 1, 'artifact.ika-sprite') fish = Fish(ika.Entity(110, 60, 2, 'fish.ika-sprite')) fish.ent.mapobs = fish.ent.entobs = fish.ent.isobs = False fish.ent.speed = 300 engine.addEntity(fish) fried = Friedrich(ika.Entity(176, 60, 1, 'friedrich.ika-sprite')) fried.ent.speed = 120 fried.ent.mapobs = fried.ent.entobs = fried.ent.isobs = False fried.anim = 'fly' engine.addEntity(fried) engine.player.stop() engine.saveData['firstconvo'] = True engine.beginCutScene() ana = engine.player.ent ana.specframe = 0 engine.synchTime() text( "left", "anastasia3", "Pfft! I can't believe I came away empty handed today! If it wasn't for that flock of gulls I'd still have that seventy-pounder." ) delay(33) ana.specframe = 24 text("left", "anastasia3", "You hear me?! Give me back my fish!") sound.fall.Play() delay(75) fish.x, fish.y, fish.layer = (110, -20, ana.layer + 1) fish.move(dir.DOWN, 200) tick() while fish.isMoving(): tick() draw() engine.things.append(Quake(20)) ana.specframe = 23 apos = (ana.x, ana.y + 16 - ywin) text(apos, "anastasia2", "left", "Ouch!!!") delay(80) fried.x, fried.y = 176, 60 fried.move(dir.DOWN, 70) delay(1) while fried.isMoving(): delay(1) fpos = (160, fried.y + 24 - ywin) text(fpos, "Dropped something?") delay(100) text((ana.x - 8, ana.y + 24 - ywin), '...') delay(50) text((ana.x - 8, ana.y + 24 - ywin), 'Mmph..') ana.specframe = 1 fish.move(dir.DOWN, 32) fried.move(dir.DOWN, 70) delay(1) while fried.isMoving(): delay(1) ana.specframe = 3 text("left", "anastasia3", "That thing is heavy.. ") text( "left", "anastasia", "Oh, Friedrich! Did you scare that fish out of the gulls? It's good to see you, it's been almost a week!" ) text( "right", "friedrich", "Indeed! It has been quite some time. Oh, but I've got some stories for you!" ) text("left", "anastasia", "Yeah? Did you find any new treasure on that deserted island?") text( "right", "friedrich", "It was a very enlightening experience. I shall have to take you there someday. We'll plan a trip!" ) text("left", "anastasia", "Ooooh! Sounds like fun!") text( "right", "friedrich", "As a matter of fact, there is something I found that I'd like to show you at my shop. Swing by when you get a chance." ) text("left", "anastasia", "Sure! I need to get this fish down to Yolander anyway.") text("right", "friedrich", "Oh do take your time, dear.") engine.destroyEntity(fish) fried.move(dir.UP, 160) fried.anim = 'fly' tick() while fried.isMoving(): tick() draw() engine.destroyEntity(fried) engine.endCutScene() engine.synchTime() engine.things.append(Caption("Anastasia's House", font=engine.font2))
def main(args): print("Loading selfies") idx2selfies, selfies2idx = load_selfies(args.selfies_vocab) print("Selfies loaded.\nVocab size {}".format(len(idx2selfies))) print("Loading Model") if args.cuda: device = "cuda" else: device = "cpu" device = torch.device(device) start_epoch = 1 model = Caption(device) if args.cuda: pass #model = nn.DataParallel(model) if args.freeze_encoder: for param in model.encoder[0].parameters(): param.requires_grad = False param_dicts = [{"params": [p for n, p in model.named_parameters() if p.requires_grad],"lr": args.lr,},] optimizer = torch.optim.AdamW(param_dicts, lr=args.lr, weight_decay=args.weight_decay) scheduler = torch.optim.lr_scheduler.StepLR(optimizer, args.lr_step_size) if args.load_model: checkpoint = torch.load(args.model_path) model = checkpoint print("Model has {} parameters".format(sum(p.numel() for p in model.parameters() if p.requires_grad))) model = model.to(device) criterion = torch.nn.CrossEntropyLoss() set_seed(args.seed) if args.do_train: print("Loading training data") wandb.init(project="MoleculeCaptioning") trainingData = MoleculeCaption(args.train_data_dir, args.max_length) #MoleculeCaption(args.training_data_dir, args.max_length) sampler = torch.utils.data.RandomSampler(trainingData) batch_sampler_train = torch.utils.data.BatchSampler(sampler, args.batch_size, drop_last=True) data_loader_train = DataLoader(trainingData, batch_sampler=batch_sampler_train, num_workers=args.num_workers) print("Training data loaded successfully it has {} samples".format(len(trainingData))) if args.do_eval: print("Loading eval data") evalData = MoleculeCaption(args.eval_data_dir, args.max_length, args.eval_data_size) sampler = torch.utils.data.SequentialSampler(evalData) data_loader_eval = DataLoader(evalData, args.batch_size, sampler=sampler, drop_last=False, num_workers=args.num_workers) print("Eval data loaded successfully it has {} samples".format(len(evalData))) if args.do_train: for epoch in range(start_epoch, args.epochs): if args.do_eval: eval_loss = evaluate(model, criterion, data_loader_eval, device) print("Eval Loss at epoch {}:{}".format(epoch, eval_loss)) save_model(model, optimizer, scheduler, epoch, args) print("Starting Training for epoch :{}".format(epoch)) train_loss = train(args, model, criterion, data_loader_train,optimizer, device, epoch, args.clip_max_norm, scheduler, data_loader_eval) print("Epoch Loss:{}".format(train_loss)) save_model(model, optimizer, scheduler, epoch, args) if args.do_eval: eval_loss = evaluate(model, criterion, data_loader_eval, device) save_model(model, optimizer, scheduler, 0, args) print("Eval Loss:{}".format(eval_loss)) if args.do_predict: if args.predict_list != 'None': image_paths = load_image(args.predict_list) print("Predicting smiles for {} images".format(len(image_paths))) predict_images(args,image_paths, model, device, idx2selfies, selfies2idx) else: predict_image(args,model, device, idx2selfies, selfies2idx)
def SaveState(self): s = SaveGame.currentGame() s.save('saves/quicksave') self.addCaptions(Caption('Quicksaved!'))
def levelUp(self): sound.achievement.Play() while self.stats.exp >= self.stats.next: lev5 = int(self.stats.level / 5) #every 5 levels, increase potential hp gain hpup = ika.Random(2, 4 + lev5) + (lev5*2) mpup = ika.Random(1, 4 + lev5) + lev5 self.stats.maxhp += hpup self.stats.maxmp += mpup statlist = ['att', 'mag', 'pres'] statsup = {'att':0, 'mag':0, 'pres':0} statnames = {'att':'Attack', 'mag':'Magic', 'pres':'Defense'} statpoints = 1 if lev5>0: statpoints+=ika.Random(0, lev5+1) #every 5 levels, potentially gain another stat point for n in range(statpoints): #random chance of any stat increase. s = statlist[ika.Random(0,len(statlist))] self.stats[s]+= 1 statsup[s]+=1 self.stats.level += 1 self.stats.maxhp = min(self.stats.maxhp, 285) self.stats.maxmp = min(self.stats.maxmp, 285) self.stats.exp -= self.stats.next self.stats.next = self.stats.level * (self.stats.level + 1) * 5 d = 300 starty=165 shade=100 red=250 green=200 blue=30 appendlist=[] appendlist.append(Caption('Level %i!' % self.stats.level, y=starty, duration=d, r=red,g=green,b=blue)) if self.stats.maxhp==285: appendlist.append(Caption('HP Maxed!', y=starty+10, duration=d, r=red,g=green,b=blue)) else: appendlist.append(Caption('HP +%i' % hpup, y=starty+10, duration=d, r=red,g=green,b=blue)) if self.stats.maxmp==285: appendlist.append(Caption('MP Maxed!', y=starty+10, duration=d, r=red,g=green,b=blue)) else: appendlist.append(Caption('MP +%i' % mpup, y=starty+20, duration=d, r=red,g=green,b=blue)) i=0 numlines=3 bgw = gui.default_font.StringWidth('Level %i!' % self.stats.level) for s in statlist: if statsup[s]: appendlist.append(Caption(statnames[s] +' +%i' % statsup[s], y=starty+30 + (10*i), duration=d, r=red,g=green,b=blue)) bgw = max(gui.default_font.StringWidth(statnames[s] +' +%i' % statsup[s]), bgw) numlines+=1 i+=1 bgw+=8 bgh = (numlines)*10 + 6 bgx = 160-(bgw/2) bgy = starty-4 #appendlist = [BGRect(bgx,bgy,bgw,bgh, duration=d)]+appendlist system.engine.addCaptions(appendlist) appendlist = [] line1=line2='' if self.stats.level in [SLASH_LEVEL, BACK_LEVEL, THRUST_LEVEL]: if self.stats.level == SLASH_LEVEL: line1= 'Slash skill learned!' line2= 'Press attack twice to combo.' elif self.stats.level == BACK_LEVEL: line1= 'Backdash skill learned!' line2= 'Press opposite direction after attacking.' elif self.stats.level == THRUST_LEVEL: line1= 'Thrust skill learned!' line2= 'Attack again a moment after a slash.' appendlist.append(Caption(line1, y=starty, duration=d, r=red,g=green,b=blue)) appendlist.append(Caption(line2, y=starty+10, duration=d, r=red,g=green,b=blue)) bgw = gui.default_font.StringWidth(line2) + 8 bgh = 21 + 4 bgx = 160-(bgw/2) #bgy = starty-2 #appendlist = [BGRect(bgx,bgy,bgw,bgh, delay=d+150, duration=d)]+appendlist system.engine.addCaptions(appendlist)
def update(self): if self.yeti.stats.hp == 0: sound.playMusic("music/wind.ogg") savedata.waterguard = 'True' system.engine.addCaptions(Caption('Rune Guardian defeated.')) return True