def drawscoretable(self): scores = self.beatmaps[self.current_beatmap].scores if len(scores) > 0: percent = int((sum(scores) / (len(scores)*2))*10) / 10.0 misses = 0 okays = 0 goods = 0 perfects = 0 for s in scores: if s == variables.miss_value: misses += 1 elif s == variables.ok_value: okays += 1 elif s == variables.good_value: goods += 1 elif s == variables.perfect_value: perfects += 1 tabletext = str(percent) + "% perfects: " + str(perfects) + \ " goods: " + str(goods) + " okays: " + str(okays) + \ " misses: " + str(misses) + " total: " + str(len(scores)) tablepic = getTextPic( tabletext, variables.gettextsize(), variables.WHITE) tabley = variables.height-tablepic.get_height() tablerect = Rect((variables.width-tablepic.get_width())/2, tabley, tablepic.get_width(), tablepic.get_height()) variables.screen.blit(tablepic, tablerect) variables.dirtyrects.append(tablerect)
def drawmid(y, mheight, color): x = self.pos[0] + middleofnoteoffset if mheight > 0: if self.shape() == "square": pygame.draw.rect(variables.screen, color, [x, y, width, mheight], borderwidth) elif self.shape() == "triangle": fourthx = width/4 pygame.draw.polygon(variables.screen, color, [[x+3*fourthx, y], [x+fourthx, y], [x, y + mheight/2], [x+fourthx, y+mheight], [x+3*fourthx, y+mheight], [x+width, y + mheight/2]], borderwidth) elif self.shape() == "round": ellipsesurface = pygame.Surface((width, mheight), pygame.SRCALPHA) pygame.draw.ellipse(ellipsesurface, color, [0, -20, width, mheight+40], borderwidth) variables.screen.blit(ellipsesurface, [x, y]) # draw the multiplier if it is not 1 if self.scoremultiplier != 1: scorepic = getTextPic("x" + str(self.scoremultiplier), variables.gettextsize(), variables.WHITE) variables.screen.blit(scorepic, (x, y + mheight/2 - variables.gettextsize()/2)) # now draw pink line if it is an accidental if self.accidentalp: pygame.draw.rect(variables.screen, variables.PINK, [x+width/4, y, width/2, mheight]) # don't change border width
def draw(self, ison=False): if ison: rectcolor = variables.BLUE else: rectcolor = variables.BLUEGREY if self.iscentered: xpos = self.x*variables.width - self.width()/2 ypos = self.y*variables.height - self.height()/2 else: xpos = self.x*variables.width ypos = self.y*variables.height textpic = getTextPic(self.text, self.size*variables.height) textpadding = (self.width() - textpic.get_width()) / 2 ypadding = (self.height() - textpic.get_height()) / 2 padding = variables.getbuttonpadding() nopadding = Rect(xpos, ypos, self.width(), self.height()) drawrect = Rect(nopadding.x+padding, nopadding.y+padding, nopadding.width-2*padding, nopadding.height-2*padding) pygame.draw.rect(variables.screen, rectcolor, nopadding) pygame.draw.rect(variables.screen, variables.BLUEWHITE, drawrect) variables.screen.blit(textpic, [xpos + textpadding, ypos+ypadding]) # just always update screen variables.dirtyrects.append(pygame.Rect( xpos-1, ypos-1, self.width()+2, self.height()+2))
def drawscoretable(self): scores = self.beatmaps[self.current_beatmap].scores if len(scores) > 0: percent = int((sum(scores) / (len(scores)*2))*10) / 10.0 misses = 0 okays = 0 goods = 0 perfects = 0 for s in scores: if s == variables.miss_value: misses += 1 elif s == variables.ok_value: okays += 1 elif s == variables.good_value: goods += 1 elif s == variables.perfect_value: perfects += 1 tabletext = str(percent) + "% perfects: " + str(perfects) + \ " goods: " + str(goods) + " okays: " + str(okays) + \ " misses: " + str(misses) + " total: " + str(len(scores)) tablepic = getTextPic(tabletext, variables.gettextsize(), variables.WHITE) tabley = variables.height-tablepic.get_height() tablerect = Rect((variables.width-tablepic.get_width())/2, tabley, tablepic.get_width(), tablepic.get_height()) variables.screen.blit(tablepic, tablerect) variables.dirtyrects.append(tablerect)
def drawcombo(self): currentb = self.beatmaps[self.current_beatmap] totalcombo = self.getcombo() if totalcombo >= 10: combocolor = difficultytocolor( ((totalcombo-9)/variables.numofrounds)/len(currentb.originalnotes)) # find combo height based on the last time it was increased comboheight = variables.gettextsize() deltatcombo = variables.settings.current_time-currentb.timeoflastcomboaddition # threshhold in millis for making the resizing text animation comboanimthreshhold = 100 if deltatcombo < comboanimthreshhold: comboheight *= 1 + (1 - deltatcombo/comboanimthreshhold)*0.5 playerpicandrect = self.getplayerpicandrect() combopic = getTextPic( "COMBO: " + str(totalcombo), comboheight, combocolor) combox = variables.width-combopic.get_width() combodif = combox-(variables.width-playerpicandrect[1].width) if combodif > 0: combox = combox-combodif/2 comborect = Rect( combox, playerpicandrect[1].y-comboheight*1.5, combopic.get_width(), combopic.get_height()) variables.screen.blit(combopic, comborect) variables.dirtyrects.append(comborect)
def drawmid(y, mheight, color): x = p[0] + middleofnoteoffset if mheight > 0: if self.shape() == "square": pygame.draw.rect(variables.screen, color, [x, y, width, mheight], borderwidth) elif self.shape() == "triangle": fourthx = width/4 pygame.draw.polygon(variables.screen, color, [[x+3*fourthx, y], [x+fourthx, y], [x, y + mheight/2], [x+fourthx, y+mheight], [x+3*fourthx, y+mheight], [x+width, y + mheight/2]], borderwidth) elif self.shape() == "round": ellipsesurface = pygame.Surface((width, mheight), pygame.SRCALPHA) pygame.draw.ellipse(ellipsesurface, color, [0, -20, width, mheight+40], borderwidth) variables.screen.blit(ellipsesurface, [x, y]) # draw the multiplier if it is not 1 if self.scoremultiplier != 1: scorepic = getTextPic("x" + str(self.scoremultiplier), variables.gettextsize(), variables.WHITE) variables.screen.blit(scorepic, (x, y + mheight/2 - variables.gettextsize()/2)) # now draw pink line if it is an accidental if self.accidentalp: pygame.draw.rect(variables.screen, variables.PINK, [x+width/4, y, width/2, mheight]) # don't change border width
def drawmenu(time, settings, screen): title = getTextPic("polar invaders", screen.get_height() / 8, color=(255, 255, 255)) titlerect = title.get_rect() titlerect.center = (screen.get_width() / 2, 0) titlerect.top = screen.get_height() / 5 score = getTextPic("high score: : " + str(settings.getgamedata(gamename)), screen.get_height() / 12, color=(255, 255, 255)) scorerect = score.get_rect() scorerect.center = (screen.get_width() / 2, 0) scorerect.top = screen.get_height() / 2 screen.blit(title, titlerect) screen.blit(score, scorerect)
def drawname(self): promptstring = self.nameprompts[self.option] extrabuttonwidth = variables.getmenutextxoffset() / 4 if self.nameprompts[self.option] == "Confirm difficulty level ": reccomendedtext = getTextPic("The reccomended difficulty for new players is 0.", variables.gettextsize(), variables.beginningprompttextcolor) variables.screen.blit(reccomendedtext, [variables.width/2 - reccomendedtext.get_width()/2, variables.gettextsize()*0]) self.yesno.draw() promptstring = promptstring + str(self.tempdifficulty) + "?" textpic = getTextPic(promptstring, variables.gettextsize(), variables.beginningprompttextcolor) typestring = self.namestring typecolor = variables.BLACK if self.option == 2: typestring = str(self.tempdifficulty) typecolor = difficultytocolor(self.tempdifficulty/20.0) typepic = getTextPic(typestring, variables.gettextsize(), typecolor) variables.screen.blit(textpic, [variables.width/2 - textpic.get_width()/2, variables.gettextsize()*1.5]) variables.screen.blit(typepic, [variables.width/2 - typepic.get_width()/2, variables.gettextsize()*2.5])
def drawsun(self, screen): sunh = screen.get_height() * 1 / 15 sunpic = getpicbyheight("sun3", sunh) texth = sunh * 2 / 3 textpic = getTextPic(" " + str(self.sun) + " ", texth) boxrect = Rect( screen.get_width() - textpic.get_width() - sunpic.get_width(), screen.get_height() - sunh, textpic.get_width() + sunpic.get_width(), sunh) screen.fill(variables.GREY, boxrect) screen.blit(sunpic, boxrect) screen.blit(textpic, (boxrect.x + sunpic.get_width(), boxrect.y + (sunh - texth) / 2))
def drawmessage(self): if self.message != None: if variables.settings.current_time - self.messagetime > 1000: self.message = None # blit message on top if self.message != None: if self.message == "saved!": icon = getTextPic("saved", variables.gettextsize(), variables.WHITE) srect = Rect(0, variables.height-icon.get_height(), icon.get_width(), icon.get_height()) variables.screen.blit(icon, [srect.x, srect.y]) variables.dirtyrects.append(srect) else: graphics.drawthismessage(self.message)
def drawmessage(self): if self.message != None: if variables.settings.current_time - self.messagetime > 1000: self.message = None # blit message on top if self.message != None: if self.message == "saved!": icon = getTextPic("saved", variables.gettextsize(), variables.WHITE) srect = Rect(0, variables.height-icon.get_height(), icon.get_width(), icon.get_height()) variables.screen.fill(variables.BLACK, srect) variables.screen.blit(icon, srect) variables.dirtyrects.append(srect) else: graphics.drawthismessage(self.message)
def gettextpic(self, i, keylist): if i > len(keylist)-1: return None else: if i == len(keylist)-1: textstring = keylist[i] elif i == 0: textstring = keylist[i] elif keylist[i] == None: textstring = "none" elif type(keylist[i]) == str: textstring = keylist[i] else: textstring = pygame.key.name(keylist[i]) textpic = getTextPic(textstring, variables.gettextsize(), variables.WHITE) return textpic
def gettextpic(self, i, keylist): if i > len(keylist) - 1: return None else: if i == len(keylist) - 1: textstring = keylist[i] elif i == 0: textstring = keylist[i] elif keylist[i] == None: textstring = "none" elif type(keylist[i]) == str: textstring = keylist[i] else: textstring = pygame.key.name(keylist[i]) textpic = getTextPic(textstring, variables.gettextsize(), variables.WHITE) return textpic
def drawmain(self): extrabuttonwidth = variables.getmenutextxoffset() / 4 opics = [] optionnames = self.options() for o in optionnames: textpic = getTextPic(o, variables.gettextsize(), variables.WHITE) opics.append(textpic) xoffset = variables.getmenutextxoffset() for x in range(len(opics)): textpic = opics[x] if self.mainmenup: xoffset = int(variables.width / 2 - (textpic.get_width() / 2)) pygame.draw.rect(variables.screen, variables.BLACK, pygame.Rect(xoffset-extrabuttonwidth, (x + 1) * variables.getmenutextyspace(), textpic.get_width() + 2*extrabuttonwidth, textpic.get_height())) variables.screen.blit(textpic, [xoffset, (x + 1) * variables.getmenutextyspace()]) dotxoffset = variables.getmenutextxoffset() dotwidth = variables.getmenutextxoffset() * 1/3 if self.mainmenup: dotxoffset = int(variables.width / 2 - (opics[self.option].get_width() / 2)) pygame.draw.rect(variables.screen, variables.WHITE, [dotxoffset - dotwidth, (self.option + 1) * variables.getmenutextyspace(), dotwidth, dotwidth]) if self.mainmenup: enemywidth = self.enemyanimation.pic_width(variables.height/5) self.enemyanimation.draw_topright(variables.screen, variables.height/5, topoffset = (len(opics) + 1) * variables.getmenutextyspace(), rightoffset = int(variables.width/2 - enemywidth/2))
def getfeedbackpic(self, index): color = variables.WHITE if self.feedbackcolor[index] != None: color = self.feedbackcolor[index] s = self.feedback[index] rotatep = False if s == "miss": s = "MISS" rotatep = True elif s == "ok": rotatep = True s = "OK" elif s == "good": s = "GOOD" rotatep = True elif s == "perfect": s = "PERFECT" rotatep = True pic = graphics.getTextPic(s, variables.gettextsize(), color) if rotatep: pic = pygame.transform.rotate(pic, -45) return pic
def ondraw(time, settings, screen): screen.fill((0, 0, 0)) for i in range(len(polargame.starValues)): pygame.draw.rect(screen, polargame.starValues[i][0], polargame.starValues[i][1], 0) for bullet in polargame.eBullets: bullet.display(screen) for enemy in polargame.enemies: enemy.display(screen) for bullet in polargame.pBullets: bullet.display(screen) polargame.count += polargame.animationSpeed * polargame.dTime if polargame.mainBoost: drawboostimg(screen, mainBooster[int(polargame.count) % 4], "main") if polargame.rightBoost: drawboostimg(screen, rightBooster[int(polargame.count) % 4], "right") if polargame.leftBoost: drawboostimg(screen, leftBooster[int(polargame.count) % 4], "left") text = getTextPic("score: " + str(polargame.score) + " health: " + str(polargame.pHealth), int(variables.gettextsize() * 0.6), color=(255, min(max(0, polargame.pHealth * 255 / 30), 255), min(max(0, polargame.pHealth * 255 / 30), 255))) textrect = text.get_rect() textrect.center = (polargame.width / 2, 0) textrect.top = 0 screen.blit(text, textrect) if polargame.gamestate == "menu": drawmenu(time, settings, screen) variables.dirtyupdateall()
def drawcombo(self): currentb=self.beatmaps[self.current_beatmap] totalcombo = self.getcombo() if totalcombo >= 10: combocolor = difficultytocolor(((totalcombo-9)/variables.numofrounds)/len(currentb.originalnotes)) # find combo height based on the last time it was increased comboheight = variables.gettextsize() deltatcombo = variables.settings.current_time-currentb.timeoflastcomboaddition # threshhold in millis for making the resizing text animation comboanimthreshhold = 100 if deltatcombo < comboanimthreshhold: comboheight *= 1 + (1 - deltatcombo/comboanimthreshhold)*0.5 playerpicandrect = self.getplayerpicandrect() combopic = getTextPic("COMBO: " + str(totalcombo), comboheight, combocolor) combox = variables.width-combopic.get_width() combodif = combox-(variables.width-playerpicandrect[1].width) if combodif > 0: combox = combox-combodif/2 comborect = Rect(combox, playerpicandrect[1].y-comboheight*1.5, combopic.get_width(), combopic.get_height()) variables.screen.blit(combopic, comborect) variables.dirtyrects.append(comborect)
def draw(self, ison = False): if ison: rectcolor = variables.GREEN else: rectcolor = variables.WHITE if self.iscentered: xpos = self.x*variables.width - self.width()/2 ypos = self.y*variables.height - self.height()/2 else: xpos = self.x*variables.width ypos = self.y*variables.height textpic = getTextPic(self.text, self.size*variables.height) textpadding = (self.width() - textpic.get_width()) / 2 variables.screen.fill(rectcolor, [xpos, ypos, self.width(), self.height()]) variables.screen.blit(textpic, [xpos + textpadding, ypos]) # just always update screen variables.dirtyrects.append(pygame.Rect(xpos, ypos, self.width(), self.height()))
def drawline(self, keytype, ypos, selectedoption = None): title = getTextPic(keytype + "-", variables.gettextsize(), variables.WHITE) variables.screen.blit(title, (variables.getmenutextxoffset(), ypos)) keylist = ["-"] + self.workingcopy.keydict[keytype] + ["+"] i = self.bindingscroll currentx = variables.getmenutextxoffset()*2 + title.get_width() while i < len(keylist): textpic = self.gettextpic(i, keylist) if i == selectedoption: self.drawdot(currentx) # handle scrolling for next frame if currentx + textpic.get_width() > variables.width: self.bindingscroll += 1 variables.screen.blit(textpic, (currentx, ypos)) currentx += variables.getmenutextxoffset()+textpic.get_width() i += 1 if self.bindingoption < self.bindingscroll: self.bindingscroll -= 1
def drawline(self, keytype, ypos, selectedoption=None): title = getTextPic(keytype + "-", variables.gettextsize(), variables.WHITE) variables.screen.blit(title, (variables.getmenutextxoffset(), ypos)) keylist = ["-"] + self.workingcopy.keydict[keytype] + ["+"] i = self.bindingscroll currentx = variables.getmenutextxoffset() * 2 + title.get_width() while i < len(keylist): textpic = self.gettextpic(i, keylist) if i == selectedoption: self.drawdot(currentx) # handle scrolling for next frame if currentx + textpic.get_width() > variables.width: self.bindingscroll += 1 variables.screen.blit(textpic, (currentx, ypos)) currentx += variables.getmenutextxoffset() + textpic.get_width() i += 1 if self.bindingoption < self.bindingscroll: self.bindingscroll -= 1
def draw(self): if self.current_beatmap<len(self.beatmaps): currentb = self.beatmaps[self.current_beatmap] else: currentb = None h = variables.height w = variables.width b = h * 13 / 16 p = classvar.player # background variables.screen.fill(variables.BLACK) # draw enemy first if self.state != "dance": self.enemy.animation.reset() # if not dancing, use first frame # draw enemy self.enemy.animation.draw_topright(variables.screen, enemypic_height()) playerpicandrect = self.getplayerpicandrect() # draw the player if self.state == "dance": # draw the special animation behind the player self.drawspecialmove() variables.screen.blit(playerpicandrect[0], playerpicandrect[1]) if currentb != None: # now draw the combo if necessary self.drawcombo() if self.enemy.animation.updatealwaysbattle: self.updatescreenforenemy() # draw beatmap if self.state == "dance": self.beatmaps[self.current_beatmap].draw() elif self.state == "attacking": self.beatmaps[self.current_beatmap].draw_pads() if self.state == "choose": # enemy name enemyname = variables.font.render("LV " + str(self.enemy.lv) + " " + self.enemy.name + " appears!", 0, variables.WHITE) enemynamescaled = sscale(enemyname) variables.screen.blit(enemynamescaled, [w / 2 - (enemynamescaled.get_width() / 2), h / 2]) self.battlechoice.draw() # draw the wave above the battlechoice wavex = self.battlechoice.buttons[-2].x * variables.width # the height of the wave waveamp = (self.battlechoice.buttons[-2].height()*3/4) * 0.5 wavelen = self.battlechoice.buttons[-2].width()*3/4 wavey = self.battlechoice.buttons[-2].y*variables.height-waveamp loopbuffer = play_sound.all_tones[variables.settings.soundpack].loopbuffers[0] skiplen = (len(loopbuffer)/25)/wavelen drawwave(loopbuffer, skiplen, wavex, wavey, waveamp, wavelen, (255,255,255)) # draw the scale above battlechoice firstscalex = self.battlechoice.buttons[-1].x * variables.width scalex = firstscalex scaley = self.battlechoice.buttons[-1].y*variables.height - self.battlechoice.buttons[-1].height() scaleintervals = play_sound.scales[self.getscalename()] for i in scaleintervals: tpic = getTextPic(str(i)+" ", variables.gettextsize(), variables.WHITE) variables.screen.blit(tpic, (scalex, scaley)) scalex += tpic.get_width() variables.dirtyrects.append(Rect(firstscalex, scaley, scalex-firstscalex, self.battlechoice.buttons[-1].height())) elif self.state == "lose" or self.state == "win": # button if self.state == "win": conttext = "continue" # button coordinates are multipliers of screen width and height continuebutton = Button(1 / 2, b/h, conttext, variables.gettextsize()/h) continuebutton.iscentered = True continuebutton.draw(True) else: self.retrychoice.draw() # text text = None if self.state == "lose": text = variables.font.render("you lost...", 0, variables.WHITE) else: text = variables.font.render("you win!", 0, variables.WHITE) textscaled = sscale(text) variables.screen.blit(textscaled, [w / 2 - (textscaled.get_width() / 2), h / 2]) self.drawscoretable() elif self.state == "exp" or self.state == "got exp": text = "continue" # continue button continuebutton = Button(1 / 2, b/h, text, variables.gettextsize()/h) continuebutton.iscentered = True continuebutton.draw(True) # text text = variables.font.render("EXP", 0, variables.WHITE) textscaled = sscale(text) exppos = [w / 2 - (textscaled.get_width() / 2), h / 3] variables.screen.blit(textscaled, exppos) variables.dirtyrects.append(Rect(exppos[0], exppos[1], textscaled.get_width(), textscaled.get_height())) text = variables.font.render("Lv " + str(classvar.player.lv()), 0, variables.WHITE) textscaled = sscale(text) lvpos = [0, h / 3 - textscaled.get_height()] variables.screen.blit(textscaled, lvpos) variables.dirtyrects.append(Rect(lvpos[0], lvpos[1], textscaled.get_width(), textscaled.get_height())) # exp bar percentofbar = stathandeling.percentoflevel(p.exp) barrect = Rect(0, h/2, w*percentofbar, h/18) variables.screen.fill(variables.BLUE, barrect) variables.dirtyrects.append(barrect) # level up text if self.state == "got exp" and stathandeling.explv(self.oldexp) < stathandeling.explv(self.newexp): text = variables.font.render(variables.settings.bearname + "'s dance level increased.", 0, variables.GREEN) textscaled = sscale(text) coordinates = [w / 2 - (textscaled.get_width() / 2), h / 3 - textscaled.get_height()] variables.screen.blit(textscaled, coordinates) variables.dirtyrects.append(Rect(coordinates[0], coordinates[1], textscaled.get_width(), textscaled.get_height())) self.drawscoretable() # player health bar playermaxh = stathandeling.max_health(p.lv()) healthh = h * (1 / 18) enemyhealthh = h * (1 / 50) epich = enemypic_height() epicw = self.enemy.animation.pic_width(epich) percenthealthlefte = self.enemy.health / stathandeling.max_health(self.enemy.lv) healthbarcolor = variables.GREEN if p.health != playermaxh: percenthealthleft = p.health / playermaxh barrect = Rect(w - epicw, epich, epicw * (1 - percenthealthleft),enemyhealthh) variables.screen.fill(healthbarcolor, barrect) variables.dirtyrects.append(barrect) if not percenthealthlefte == 1: barrect = Rect(0, h-healthh, w*(1-percenthealthlefte), healthh) variables.screen.fill(healthbarcolor, barrect) variables.dirtyrects.append(barrect) # if they did not miss any in the last beatmap if (self.damage_multiplier > variables.perfect_value and self.state == "attacking"): punscaled = variables.font.render("PERFECT!", 0, variables.WHITE) ptext = sscale_customfactor(punscaled, 1.5) coordinates = [(variables.width / 2) - (ptext.get_width() / 2) - epich, variables.getpadypos() - ptext.get_height() - 10] variables.screen.blit(ptext, coordinates) variables.dirtyrects.append(Rect(coordinates[0], coordinates[1], ptext.get_width(), ptext.get_height()))
def width(self): if self.screenwidthoverride == None: textpic = getTextPic(self.text, self.size*variables.height) return textpic.get_width() + variables.getbuttonpadding()*2 else: return self.screenwidthoverride * variables.width
def linepic(self, index): return getTextPic(self.dialogue[index], variables.gettextsize(), variables.WHITE)
def draw(self): options = self.getoptionlist() if self.state == "main": onscreen = options[self.scroll:self.scroll+self.linesperscreen()] for i in range(len(onscreen)): ypos = i * variables.getmenutextyspace() keytype = onscreen[i] # if it is not a binding if not keytype in self.workingcopy.keydict: title = getTextPic(keytype, variables.gettextsize(), variables.WHITE) variables.screen.blit(title, (variables.getmenutextxoffset(), ypos)) # draw dot if i == self.option-self.scroll and keytype != "mode": self.drawdot(variables.getmenutextxoffset()) if keytype == "volume": for x in range(int(self.workingcopy.volume*10)): xpos = variables.getmenutextxoffset() + variables.gettextsize()*x + title.get_width() variables.screen.fill(variables.BLUE, (xpos + variables.gettextsize()/4, ypos + variables.gettextsize()/4, variables.gettextsize()*(3/4), variables.gettextsize()*(3/4))) elif keytype == "mode": xpos = variables.getmenutextxoffset()*2 + title.get_width() i = 0 for t in self.windowmodes: if i == self.bindingoption: if options[self.option] == "mode": self.drawdot(xpos, ypos) pic = getTextPic(t, variables.gettextsize(), variables.WHITE) variables.screen.blit(pic, (xpos, ypos)) if self.workingcopy.windowmode == t: pygame.draw.rect(variables.screen, variables.BLUE, (xpos-2, ypos+2, pic.get_width()+4, pic.get_height()+2), 2) xpos += variables.getmenutextxoffset() + pic.get_width() i += 1 elif keytype in self.toggleoptions: xpos = variables.getmenutextxoffset()*2 + title.get_width() text = "off" if getattr(self.workingcopy, self.toggleoptionsvars[self.toggleoptions.index(keytype)]): text = "on" pic = getTextPic(text, variables.gettextsize(), variables.WHITE) variables.screen.blit(pic, (xpos, ypos)) if self.workingcopy.autosavep: pygame.draw.rect(variables.screen, variables.BLUE, (xpos-2, ypos+2, pic.get_width()+4, pic.get_height()+2), 1) else: if i == self.option-self.scroll: self.drawline(keytype, ypos, selectedoption = self.bindingoption) else: self.drawline(keytype, ypos) elif self.state == "keychange": text = getTextPic("Press a key to bind to " + options[self.option], variables.gettextsize(), variables.WHITE) variables.screen.blit(text, (variables.width/2 - text.get_width()/2, variables.height/2 - text.get_height()/2)) elif self.state == "confirm": text = getTextPic("Continue with these settings?", variables.gettextsize(), variables.WHITE) variables.screen.blit(text, (variables.width/2 - text.get_width()/2, variables.height/2 - variables.gettextsize()*2)) counter = getTextPic(str(self.confirmsecondsleft()), variables.gettextsize(), variables.WHITE) variables.screen.blit(counter, (variables.width/2 - counter.get_width()/2, variables.height/2 - variables.gettextsize()/2)) yesnoy = variables.height/2 + variables.gettextsize()*2 yes = getTextPic("yes", variables.gettextsize(), variables.WHITE) yesx = variables.width/2 - yes.get_width() - variables.getmenutextxoffset() variables.screen.blit(yes, (yesx, yesnoy)) no = getTextPic("no", variables.gettextsize(), variables.WHITE) nox = variables.width/2 + no.get_width() + variables.getmenutextxoffset() variables.screen.blit(no, (nox, yesnoy)) # draw dot next to yes if self.confirmoption == 0: self.drawdot(yesx, yesnoy) elif self.confirmoption == 1: self.drawdot(nox, yesnoy)
def draw(self): if self.current_beatmap < len(self.beatmaps): currentb = self.beatmaps[self.current_beatmap] else: currentb = None h = variables.height w = variables.width b = h * 13 / 16 p = classvar.player # background if variables.battle_background != None: variables.screen.blit(variables.battle_background, (0, 0)) else: variables.screen.fill(variables.BLACK) # draw enemy first if self.state != "dance": self.enemy.animation.reset() # if not dancing, use first frame # draw enemy self.enemy.animation.draw_topright(variables.screen, enemypic_height()) playerpicandrect = self.getplayerpicandrect() # draw the player if self.state == "dance": # draw the special animation behind the player self.drawspecialmove() variables.screen.blit(playerpicandrect[0], playerpicandrect[1]) if currentb != None: # now draw the combo if necessary self.drawcombo() if self.enemy.animation.updatealwaysbattle: self.updatescreenforenemy() # draw beatmap if self.state == "dance": self.beatmaps[self.current_beatmap].draw() elif self.state == "attacking": self.beatmaps[self.current_beatmap].draw_pads() if self.state == "choose": # enemy name enemyname = variables.font.render("LV " + str(self.enemy.lv) + " " + self.enemy.name + " appears!", 0, variables.WHITE) enemynamescaled = sscale(enemyname) variables.screen.blit( enemynamescaled, [w / 2 - (enemynamescaled.get_width() / 2), h / 2]) self.battlechoice.draw() # draw the wave above the battlechoice wavex = self.battlechoice.buttons[-2].x * variables.width # the height of the wave waveamp = (self.battlechoice.buttons[-2].height()*3/4) * 0.5 wavelen = self.battlechoice.buttons[-2].width()*3/4 wavey = self.battlechoice.buttons[-2].y*variables.height-waveamp loopbuffer = play_sound.all_tones[variables.settings.soundpack].loopbuffers[0] skiplen = (len(loopbuffer)/25)/wavelen drawwave(variables.screen, loopbuffer, skiplen, wavex, wavey, waveamp, wavelen, (255, 255, 255)) # draw the scale above battlechoice firstscalex = self.battlechoice.buttons[-1].x * variables.width scalex = firstscalex scaley = self.battlechoice.buttons[-1].y*variables.height - self.battlechoice.buttons[-1].height() scaleintervals = play_sound.scales[self.getscalename()] for i in scaleintervals: tpic = getTextPic(str(i)+" ", variables.gettextsize(), variables.WHITE) variables.screen.blit(tpic, (scalex, scaley)) scalex += tpic.get_width() variables.dirtyrects.append(Rect(firstscalex, scaley, scalex-firstscalex, self.battlechoice.buttons[-1].height())) elif self.state == "lose" or self.state == "win": # button if self.state == "win": conttext = "continue" # button coordinates are multipliers of screen width and height continuebutton = Button(1 / 2, b/h, conttext, variables.gettextsize()/h) continuebutton.iscentered = True continuebutton.draw(True) else: self.retrychoice.draw() # text text = None if self.state == "lose": text = variables.font.render("you lost...", 0, variables.WHITE) else: text = variables.font.render("you win!", 0, variables.WHITE) textscaled = sscale(text) variables.screen.blit(textscaled, [w / 2 - (textscaled.get_width() / 2), h / 2]) elif self.state == "exp" or self.state == "got exp": text = "continue" # continue button continuebutton = Button(1 / 2, b/h, text, variables.gettextsize()/h) continuebutton.iscentered = True continuebutton.draw(True) # text text = variables.font.render("EXP", 0, variables.WHITE) textscaled = sscale(text) exppos = [w / 2 - (textscaled.get_width() / 2), h / 3] variables.screen.blit(textscaled, exppos) variables.dirtyrects.append(Rect(exppos[0], exppos[1], textscaled.get_width(), textscaled.get_height())) text = variables.font.render("Lv " + str(classvar.player.lv()), 0, variables.WHITE) textscaled = sscale(text) lvpos = [0, h / 3 - textscaled.get_height()] variables.screen.blit(textscaled, lvpos) variables.dirtyrects.append(Rect(lvpos[0], lvpos[1], textscaled.get_width(), textscaled.get_height())) # exp bar percentofbar = stathandeling.percentoflevel(p.exp) barrect = Rect(0, h/2, w*percentofbar, h/18) variables.screen.fill(variables.BLUE, barrect) variables.dirtyrects.append(barrect) # level up text if self.state == "got exp" and stathandeling.explv(self.oldexp) < stathandeling.explv(self.newexp): text = variables.font.render(variables.settings.bearname + "'s dance level increased.", 0, variables.GREEN) textscaled = sscale(text) coordinates = [w / 2 - (textscaled.get_width() / 2), h / 3 - textscaled.get_height()] variables.screen.blit(textscaled, coordinates) variables.dirtyrects.append(Rect(coordinates[0], coordinates[1], textscaled.get_width(), textscaled.get_height())) self.drawscoretable() # player health bar playermaxh = stathandeling.max_health(p.lv()) healthh = h * (1 / 18) enemyhealthh = h * (1 / 50) epich = enemypic_height() epicw = self.enemy.animation.pic_width(epich) percenthealthlefte = self.enemy.health / stathandeling.max_health(self.enemy.lv) healthbarcolor = variables.GREEN if p.health != playermaxh: percenthealthleft = p.health / playermaxh barrect = Rect(w - epicw, epich, epicw * (1 - percenthealthleft),enemyhealthh) variables.screen.fill(healthbarcolor, barrect) variables.dirtyrects.append(barrect) if not percenthealthlefte == 1: barrect = Rect(0, h-healthh, w*(1-percenthealthlefte), healthh) variables.screen.fill(healthbarcolor, barrect) variables.dirtyrects.append(barrect) # if they did not miss any in the last beatmap if (self.damage_multiplier > variables.perfect_value and self.state == "attacking"): punscaled = variables.font.render("PERFECT!", 0, variables.WHITE) ptext = sscale_customfactor(punscaled, 1.5) coordinates = [(variables.width / 2) - (ptext.get_width() / 2) - epich, variables.getpadypos() - ptext.get_height() - 10] variables.screen.blit(ptext, coordinates) variables.dirtyrects.append(Rect(coordinates[0], coordinates[1], ptext.get_width(), ptext.get_height())) if self.state == "lose" or self.state == "win" or self.state == "exp" or self.state == "got exp": self.drawscoretable()
def width(self): if self.screenwidthoverride == None: textpic = getTextPic(self.text, self.size*variables.height) return textpic.get_width() + variables.getbuttonpadding() else: return self.screenwidthoverride * variables.width
def draw(self): options = self.getoptionlist() if self.state == "main": onscreen = options[self.scroll:self.scroll + self.linesperscreen()] for i in range(len(onscreen)): ypos = i * variables.getmenutextyspace() keytype = onscreen[i] # if it is not a binding if not keytype in self.workingcopy.keydict: title = getTextPic(keytype, variables.gettextsize(), variables.WHITE) variables.screen.blit( title, (variables.getmenutextxoffset(), ypos)) # draw dot if i == self.option - self.scroll and keytype != "mode": self.drawdot(variables.getmenutextxoffset()) if keytype == "volume": for x in range(int(self.workingcopy.volume * 10)): xpos = variables.getmenutextxoffset( ) + variables.gettextsize() * x + title.get_width( ) variables.screen.fill( variables.BLUE, (xpos + variables.gettextsize() / 4, ypos + variables.gettextsize() / 4, variables.gettextsize() * (3 / 4), variables.gettextsize() * (3 / 4))) elif keytype == "mode": xpos = variables.getmenutextxoffset( ) * 2 + title.get_width() i = 0 for t in self.windowmodes: if i == self.bindingoption: if options[self.option] == "mode": self.drawdot(xpos, ypos) pic = getTextPic(t, variables.gettextsize(), variables.WHITE) variables.screen.blit(pic, (xpos, ypos)) if self.workingcopy.windowmode == t: pygame.draw.rect( variables.screen, variables.BLUE, (xpos - 2, ypos + 2, pic.get_width() + 4, pic.get_height() + 2), 2) xpos += variables.getmenutextxoffset( ) + pic.get_width() i += 1 elif keytype in self.toggleoptions: xpos = variables.getmenutextxoffset( ) * 2 + title.get_width() text = "off" if getattr( self.workingcopy, self.toggleoptionsvars[ self.toggleoptions.index(keytype)]): text = "on" pic = getTextPic(text, variables.gettextsize(), variables.WHITE) variables.screen.blit(pic, (xpos, ypos)) if self.workingcopy.autosavep: pygame.draw.rect( variables.screen, variables.BLUE, (xpos - 2, ypos + 2, pic.get_width() + 4, pic.get_height() + 2), 1) else: if i == self.option - self.scroll: self.drawline(keytype, ypos, selectedoption=self.bindingoption) else: self.drawline(keytype, ypos) elif self.state == "keychange": text = getTextPic("Press a key to bind to " + options[self.option], variables.gettextsize(), variables.WHITE) variables.screen.blit( text, (variables.width / 2 - text.get_width() / 2, variables.height / 2 - text.get_height() / 2)) elif self.state == "confirm": text = getTextPic("Continue with these settings?", variables.gettextsize(), variables.WHITE) variables.screen.blit( text, (variables.width / 2 - text.get_width() / 2, variables.height / 2 - variables.gettextsize() * 2)) counter = getTextPic(str(self.confirmsecondsleft()), variables.gettextsize(), variables.WHITE) variables.screen.blit( counter, (variables.width / 2 - counter.get_width() / 2, variables.height / 2 - variables.gettextsize() / 2)) yesnoy = variables.height / 2 + variables.gettextsize() * 2 yes = getTextPic("yes", variables.gettextsize(), variables.WHITE) yesx = variables.width / 2 - yes.get_width( ) - variables.getmenutextxoffset() variables.screen.blit(yes, (yesx, yesnoy)) no = getTextPic("no", variables.gettextsize(), variables.WHITE) nox = variables.width / 2 + no.get_width( ) + variables.getmenutextxoffset() variables.screen.blit(no, (nox, yesnoy)) # draw dot next to yes if self.confirmoption == 0: self.drawdot(yesx, yesnoy) elif self.confirmoption == 1: self.drawdot(nox, yesnoy)