def draw(self): if not self.text: return text.write(self.text[0], self.fontname, self.size, self.color, (self.x, self.y), (0, 0, 0), self.hanchor, self.vanchor, alpha=self.alpha) text.write(self.text[1], self.fontname, int(self.size/3), self.color, (self.x, self.y - self.size), (0, 0, 0), self.hanchor, self.vanchor, alpha=self.alpha)
def tick_numbers(self, start_loc, start_tick_ten): loc = start_loc tick_ten = start_tick_ten unit_apart = self.knot_unit # glLineWidth(2.0) for i in range(10): # Put in numbers if (tick_ten >=4) & (tick_ten % 2 == 0): #Must be multiple of 20 and above 0 knots #Print out number print glPushMatrix() #if tick_ten >=10: # glTranslatef(8.0, loc - 6.0, 0.0) # glScalef(0.13,0.13,1) #Scale text, also done in else statement below. #c = (tick_ten / 10) + 48 #glutStrokeCharacter(GLUT_STROKE_ROMAN, c) # text.write(self.knot_text[tick_ten/2]) #else: # glTranslatef(18.0, loc - 6.0, 0.0) #Move over since no hundreds digit # glScalef(0.13,0.13,1) #Don't forget to scale text #c = (tick_ten % 10) + 48 #glutStrokeCharacter(GLUT_STROKE_ROMAN, c) #Tens digit #glutStrokeCharacter(GLUT_STROKE_ROMAN, 48) # Ones Digit glTranslatef(-40.0, loc, 0.0) glScalef(0.13,0.13,1.0) text.write(self.knot_text[tick_ten/2]) glPopMatrix() elif (tick_ten == 3): #Put in V Speed Text #self.V_Speeds(air_spd, loc - 12.0) pass tick_ten = tick_ten +1 loc = loc + (unit_apart * 10)
def draw(self): if self.x <= -1.5 * self.width: return if self.point: boxcolor = self.pointcolor else: boxcolor = self.boxcolor0 x, y = self.x + self.indent, self.y w, h = self.width, self.size * 1.2 w2 = w * self.frac f = h * 0.2 d = h * 0.1 boxcolor0 = self.boxcolor0 boxcolor1 = self.boxcolor1 glDisable(GL_TEXTURE_2D) glBegin(GL_QUADS) glColor(*boxcolor0) glVertex(x-w, y) glVertex(x+w+f, y) glVertex(x+w, y-h) glVertex(x-w, y-h) glColor(*boxcolor1) glVertex(x-w, y+d) glVertex(x+w2-d+f, y+d) glVertex(x+w2-d, y-h+d) glVertex(x-w, y-h+d) glEnd() glEnable(GL_TEXTURE_2D) glColor(1, 1, 1) text.write(self.words, self.fontname, self.size, self.color, (x, y), None, 0, 1)
def draw_inv(player_inv, surface): global button_flags, cached_len, cached_buttons text.write("Inventory", surface, 0, 0) text.write("Status", surface, 190, 0, True) for i, item in enumerate(player_inv): # Do the mousoverbutton sprite_box = pygame.Rect(830, 30 * (i + 1) + 30, 25, 25) info_box = pygame.Rect(1110, 30 * (i + 1) + 20, 50, 30) bounding_box = pygame.Rect(810, 30 * (i + 1) + 20, 380, 30) if item in settings.player.equip.values(): pygame.draw.rect(surface, (99, 99, 99), pygame.Rect(18, 30 * (i + 1) + 18, 29, 29)) if sprite_box.collidepoint(pygame.mouse.get_pos()): pygame.draw.rect(surface, (255, 255, 255), pygame.Rect(18, 30 * (i + 1) + 18, 29, 29)) if info_box.collidepoint(pygame.mouse.get_pos()): text.write("Info", surface, 300, 20 + 30 * (i + 1)) elif bounding_box.collidepoint(pygame.mouse.get_pos()): text.write("Info", surface, 300, 20 + 30 * (i + 1), True) surface.blit(item.sprite, (20, 30 * (i + 1) + 20)) text.write("- " + str(item.count) + " " + item.name + (item.count > 1 and "s" or ""),\ surface, 60, 30 * (i + 1) + 20)
def draw(self): if not self.text: return y = self.y for t, color in self.text: text.write(t, self.fontname, self.size, color, (self.x, y), (0, 0, 0), self.hanchor, self.vanchor) y -= int(self.size * 1.4)
def draw(self, screen): for team in self.team_names: pygame.draw.rect(screen, self.team_colors[team], self.team_rects[team]) write(screen, self.team_amounts[team], self.team_rects[team].center, centered=True)
def airspeed_mach_text(self, value, x=0, y=0): # Text on top common.color.set(common.color.white) #Draw Text Part glPushMatrix() glTranslatef(x, y, 0.0) glScalef(0.13,0.13,1.0) text.write("M", 100) text.write(("%3.3f" %value)[1:], 90) glPopMatrix()
def draw_selected(self, loc): #Always draw located below airspeed tape glPushMatrix() glTranslatef(-35.0, loc, 0.0) glScalef(0.15,0.15,1.0) if self.visible.value: text.write("%s %3d" %(self.name, self.value.value)) else: text.write("%s ---" %(self.name)) glPopMatrix()
def draw_indicator(self, loc): if self.y_pos + loc > -165: glPushMatrix() glTranslatef(-35.0, self.y_pos + loc, 0.0) glScalef(0.15,0.15,1.0) if self.visible.value: text.write("%s %3d" %(self.name, self.value.value)) else: text.write("%s" %(self.name)) glPopMatrix()
def speedbugind_draw(self, x=0,y=0): common.color.set(common.color.purple) glPushMatrix() glTranslatef(x,y,0) self.speedbug_shape.draw() glTranslatef(30,0,0) glScalef(0.15,0.15,1.0) text.write("%3d" %(100)) glPopMatrix()
def alt_bug_text(self, bug): common.color.set(common.color.purple) #glLineWidth(2.0) glPushMatrix() glTranslatef(25, 200, 0.0) #Move to start of digits glScalef(0.16,0.16,1.0) text.write("%2d" %(bug // 1000)) glScalef(0.80,0.80,1.0) #Scale digits 85% glTranslatef(0,-13,0) text.write("%03d" %(bug % 1000)) glPopMatrix()
def tick_marks(self, altitude): #Draw the tick mark #Every 20 ft is 13 units apart #altitude = aircraft.altitude #glColor3f(1.0, 1.0, 1.0) #glLineWidth(2.0) start_tick_ten = (altitude / 20) - 13 tick_ten = start_tick_ten start_loc = -((altitude - (tick_ten * 20)) * self.pixel_per_foot) #Small ticks loc = start_loc glPushMatrix() glTranslatef(0,loc,0) self.smticks_shape.draw() glPopMatrix() loc = start_loc tick_ten = start_tick_ten #glLineWidth(2.0) for i in range(28): # Put in numbers if (tick_ten >=-50) & (tick_ten % 5 == 0): #Must be multiple of 200 and above 0 feet #Print out number print glPushMatrix() temp = abs(tick_ten / 5 ) % 10 #if tick_ten<0: temp = 10 - temp h = 16.0 if temp ==0: #Need to be lines above and below altitude glPushMatrix() glTranslatef(52.0, loc, 0.0) self.thousand_shape.draw() glPopMatrix() elif temp ==5: #Need lines above and below 500' marks also glPushMatrix() glTranslatef(52.0, loc, 0.0) self.fivehund_shape.draw() glPopMatrix() glTranslatef(58.0, loc , 0.0) #glLineWidth(2.0) glScalef(0.15,0.15,1) #Scale text, also done in else statement below. s = str(temp) + "00" text.write(s) glPopMatrix() tick_ten = tick_ten +1 loc = loc + 13.0
def alt_setting_disp(self, setting): common.color.set(common.color.cyan) glPushMatrix() glTranslatef(15,-165,0) #Text out setting glPushMatrix() glScalef(0.14,0.15,0) #value = round(setting,2) #value += 0.01 if setting <35: #Must be inches of HG if under 35 text.write("%5.2f" %setting, 90) #Round it to 2 places after decimal point 0.01 is slight correction. (Rouding Error?) else: text.write("%4d" %setting, 90) glPopMatrix() #Text 29.92 #Display IN if setting <35: #Must by HG if under 35 HPA if not. glTranslatef(58,-1,0) #move for In display glScalef(0.12,0.12,0) text.write("I N",40) else: #Must be HPA glTranslatef(53, -1,0) glScalef(0.12,0.12,0) text.write("HPA",90) glPopMatrix()
def draw(self, screen): screen.blit(self.image, (self.rect)) # pygame.draw.rect(screen, self.bg_color, self.rect, 0) if self.selected: pygame.draw.rect(screen, WHITE, self.rect, 3) write(screen, self.inhabitants, (self.rect.center), centered=True) # write(screen, "team: {}".format(self.team), # (self.rect.right + 5, self.rect.top), font_cat = 'std_small' ) # write(screen, "to transfer: {}".format(self.to_transfer_amount), # (self.rect.right + 5, self.rect.top + 10 ), font_cat='std_small') # write(screen, "in transfer: {}".format(self.in_transfer_amount), # (self.rect.right + 5, self.rect.top + 20), font_cat='std_small') for creature in self.released_creatures: creature.draw(screen)
def draw_bug(self, airspeed, knot_unit): if self.visible.value: diff = (self.value.value- airspeed) * knot_unit noshow = 168 #If out of this range then don't show if abs(diff) <= noshow: glPushMatrix() glTranslatef(17.5, diff, 0.0) #Move to point of V speed bug #Draw Line glBegin(GL_LINES) glVertex2f(-35.0,0.0) glVertex2f(-7.5,0.0) glEnd() #Draw Text next to line 1,2,R,T glScalef(0.12,0.12,1.0) text.write(self.name[1]) #Only do 2nd character glPopMatrix()
def radar_scale(aag): def tick_line(w,loc): #Just draw the tick line glBegin(GL_LINES) glVertex2f(0.0, loc) glVertex2f(w, loc) glEnd() start_tick = (aag // 100) - 3 start_loc = -((aag - (start_tick * 100.0)) * self.pixel_per_foot) loc = start_loc tick = int(start_tick) - 1 #Makes sure tick is integer for glText1 command below w = 6 fifty_offset = 50 * self.pixel_per_foot #The fifty foot offset #if DH.notify:#If DH notifer is on, change color to yellow, insted of default green # glColor(yellow) #else: glColor(green) common.color.set(common.color.green) glLineWidth(2.0) fifty_flag=True loc -= fifty_offset for i in range(14): if abs(loc) <=160: if (10 > tick >=0): tick_line(w,loc) #Draw tick at 100' # tick_line(w, loc - fifty_offset) # Draw tick at 50' mark below it. if not fifty_flag and tick: glPushMatrix() glTranslatef(w + 7, loc, 0.0) glScalef(0.13,0.13,1.0) text.write("%d" %tick) #Ok since number will only be 1-9 glPopMatrix() #elif tick == 10: #Special case to add the 950' mark # tick_line(w, loc - fifty_offset) if fifty_flag: fifty_flag=False tick+=1 else: fifty_flag=True loc += fifty_offset
def draw_equip(surface): global first_time text.write("Equipment", surface, 10, 10) for row in equip_slots: # Draw a white square equip_rect = pygame.Rect(row[1][0] - 2, row[1][1] - 2, 29, 29) pygame.draw.rect(surface, (255, 255, 255), equip_rect) if settings.player.equip[row[0]] == None: # Draw the blank sprite surface.blit(blank_sprite, row[1]) else: surface.blit(settings.player.equip[row[0]].sprite, row[1]) if equip_rect.collidepoint(\ (pygame.mouse.get_pos()[0] - 810),\ (pygame.mouse.get_pos()[1] - 410)): text.write(row[2], surface, 10, 40) if settings.player.equip[row[0]] != None: text.write(settings.player.equip[row[0]].name, surface, 20, 80) # Initialize buttons if first_time: my_button = button.Button( pygame.Rect(808 + row[1][0], 408 + row[1][1], 29, 29), equip_button, row[0]) settings.buttons.append(my_button) first_time = False
def draw_menu(surface): pygame.draw.rect(surface, (255, 255, 255), pygame.Rect(200, 100, 800, 70)) pygame.draw.rect(surface, constants.COLOR_BG, pygame.Rect(210, 110, 780, 50)) text.write("Welcome to WebSlash!", surface, 470, 120) start_button = pygame.Rect(450, 400, 300, 70) quit_button = pygame.Rect(450, 500, 300, 70) pygame.draw.rect(surface, (255, 255, 255), start_button) pygame.draw.rect(surface, (255, 255, 255), quit_button) pygame.draw.rect(surface, constants.COLOR_BG, pygame.Rect(460, 410, 280, 50)) pygame.draw.rect(surface, constants.COLOR_BG, pygame.Rect(460, 510, 280, 50)) text.write("Start", surface, 565, 420) text.write("Quit", surface, 570, 520) if settings.game_state == constants.FIRST_TIME: # Register buttons settings.buttons.append(button.Button(start_button, build_character)) settings.buttons.append(button.Button(quit_button, quit_game)) settings.game_state = constants.MAIN_MENU
for timer in timers: start_time = int(timer["start_time"]) start_duration_seconds = int(timer["start_duration_sec"]) start_time_value = "%02d:%02d:00" % (start_time / 60, start_time % 60) schedule.every().day.at(start_time_value).do(Timer_Settings_Start, data=timer) stop_time = start_time + (start_duration_seconds / 60) stop_time_value = "%02d:%02d:%02d" % (stop_time / 60, stop_time % 60, start_duration_seconds % 60) schedule.every().day.at(stop_time_value).do(Timer_Settings_Stop, data=timer) text.write("start_time: " + start_time_value + " stop_time: " + stop_time_value) Setup_Default_Settings() schedule.every(15).seconds.do(Check_Settings_Changed) schedule.every(7).seconds.do(Update_Hardware_Status) Update_Hardware_Status() while True: tick = int(time.time()) dt = datetime.datetime.fromtimestamp(tick) dt_seconds = ( dt - dt.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds()
def text_out(d, blank_zero = False): #Just output the text. if ((d>0) or (not blank_zero)): glScalef(0.20, 0.22, 1.0) text.write("%2d" %d)
def thousands(): # This does the thousands and ten thousands digit alt = altitude thou = (alt // 1000) roll=False def text_out(d, blank_zero = False): #Just output the text. if ((d>0) or (not blank_zero)): glScalef(0.20, 0.22, 1.0) text.write("%2d" %d) def altdigit_draw(value,y_nextdigit,y_digit, x, blank_zero = False): #Next digit if rolling if y_nextdigit: glPushMatrix() glTranslatef(x, 45.0-y_nextdigit, 0.0) text_out((value+1)%10, blank_zero) glPopMatrix() #Current digit glPushMatrix() glTranslatef(x, -y_digit, 0.0) text_out(value, blank_zero) glPopMatrix() #Check to see if near change in thousand above 900 feet alt_1000 = alt % 1000 glPushMatrix() if thou <0: #negative number no rolling #Display yellow NEG in place of number self.rollingblacksmall_shape.draw() common.color.set(common.color.yellow) #glDisable(GL_SCISSOR_TEST) #Turn off so text will show up glTranslatef(28.0, 12.0, 0.0) glScalef(0.10, 0.10, 1.0) text.write("N") glTranslatef(-85.0, -120.0, 0.0) text.write("E") glTranslatef(-85.0, -120.0, 0.0) text.write("G") #Bottom digit starts moving and top digit appears at 900. #--Top digit goes twice as fast about as lower digit. #--Digits hit at 950, then bottom digit goes twice as fast as top digit. else: #Altitude positive. if (alt_1000 >= 900): # Close to change in thousand will roll digits roll=True thou_diff = 1000- alt_1000 diff100 = 100-thou_diff if thou_diff <=50: diff50 = 50-thou_diff else: diff50 = 0 rate = 0.3 #pixel per foot for movement of digits y_digit = (diff100+diff50) * rate #y position of current lower digit y_nextdigit = (2*diff100-diff50) * rate#y position of next upper digit else: #No rolling <900 y_digit=0 y_nextdigit= 0 #1's thounsands digit altdigit_draw(thou%10, y_nextdigit, y_digit, 12) #10's thousand digit if thou%10 != 9: #Don't roll it y_nextdigit=0 y_digit =0 altdigit_draw(thou//10, y_nextdigit, y_digit, -6, True) #Draw black box to conver up rolling numbers if roll: if thou_diff<=30:#used to gradually cover up lower digit, without covering thousands tick marks. self.rollingblack_shape.draw() else: self.rollingblackhalf_shape.draw() else: self.rollingblacksmall_shape.draw() glPopMatrix()
def draw_stats(player, surface): text.write("Inventory", surface, 0, 0, True) text.write("Status", surface, 190, 0) text.write( player.name + " the " + get_class_name(player.str, player.dex, player.wis), surface, 20, 40) text.write("HP: " + str(player.hp) + "/" + str(player.max_hp), surface, 20, 80) text.write("MP: " + str(player.mp) + "/" + str(player.max_mp), surface, 20, 100) text.write("AC: " + str(player.ac), surface, 20, 130) text.write("LVL: " + str(player.lvl), surface, 190, 80) text.write("XP: " + str(player.xp) + "/" + str(calc_xp(player.lvl)), surface, 190, 100) text.write("STR: " + str(player.str), surface, 190, 130) text.write("DEX: " + str(player.dex), surface, 190, 150) text.write("WIS: " + str(player.wis), surface, 190, 170)
screen.blit(surface_inv, (810, 10)) # Draw equip equip.draw_equip(surface_equip) screen.blit(surface_equip, (810, 410)) # If we have a dialog, draw it if settings.dialog_busy: screen.blit(surface_dialog_cover, (0, 0)) pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(250, 200, (len(settings.dialog_message) * 13) + 100, 120)) pygame.draw.rect(screen, constants.COLOR_BG, pygame.Rect(260, 210, (len(settings.dialog_message) * 13) + 80, 100)) text.write(settings.dialog_message, screen, 300, 250) pygame.display.flip() # handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # If busy (popup), we don't process any more events. if settings.dialog_busy: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: settings.dialog_busy = False # UGLY HACK if settings.player.hp <= 0:
def pitch_marks(self, roll, pitch, line_width): def get_width(pitch): x = int(round(pitch / 2.5)) if x==0: w = 115 #Horizon is draw during in draw_horizon() elif (x % 4) == 0: w = 30 elif (x % 2) ==0: w = 15 else: w = 5 return w glPushMatrix() #Rotate with roll glRotatef(roll,0,0,1) #Draw the pitch marks #Uses pitch to determine which pitch lines need to be drawn #pixel_per_degree = 7.25 Starts 12.5 degrees down and goes up 11 lines start_point = 12.5 num_lines = 11 glColor3f(1.0,1.0,1.0) glLineWidth(line_width) #pitch = pitch * -1 #Round pitch to nearest 2.5 degrees y_center = round(pitch / 2.5) * 2.5 offset = (y_center -pitch) y_center = y_center - start_point # Go down 25 degrees y = (offset - start_point) * self.pixel_per_degree #glTranslatef(0.0, start * pixel_per_degree, 0.0) point_l = [] #print y_center, y, offset for i in range(num_lines): w = get_width(y_center) if w>0: #glBegin(GL_LINES) #glVertex2f(-w, 0.0) #glVertex2f(w, 0.0) #glEnd() point_l.extend([-w,y,w,y]) if (w==30): #Draw number for degrees glPushMatrix() glTranslatef(35.0, y, 0.0) #Move over to right (Numbers only on right side) glPushMatrix() glScalef(0.12, 0.12, 1.0) #Scale down for numbers text.write(str(int(abs(y_center)))) glPopMatrix() glPopMatrix() y+=2.5 * self.pixel_per_degree #glTranslatef(0.0, 2.5 * pixel_per_degree, 0.0) y_center += 2.5 pyglet.graphics.draw(len(point_l)/2, pyglet.gl.GL_LINES, ('v2f', point_l )) if abs(roll)> 30.0: self.yellow_triangle.draw() #Translation for slip indicator glTranslatef(2,0,0) self.yellow_slip.draw() else: self.white_triangle.draw() #Translation for slip indicator glTranslatef(0,0,0) self.white_slip.draw() glPopMatrix()
def draw_character_builder(surface): pygame.draw.rect(surface, (255, 255, 255), pygame.Rect(400, 105, 400, 54)) pygame.draw.rect(surface, constants.COLOR_BG, pygame.Rect(402, 107, 396, 50)) name_and_class = settings.player.name + " the " + player.get_class_name( settings.player.str, settings.player.dex, settings.player.wis) text.write(name_and_class, surface, 700 - len(name_and_class) * 12, 120) pygame.draw.rect(surface, (255, 255, 255), pygame.Rect(500, 255, 200, 214)) pygame.draw.rect(surface, constants.COLOR_BG, pygame.Rect(502, 257, 196, 210)) text.write("STR: " + str(settings.player.str), surface, 555, 280) text.write("DEX: " + str(settings.player.dex), surface, 555, 320) text.write("WIS: " + str(settings.player.wis), surface, 555, 360) spare_points = 30 - settings.player.str - settings.player.dex - settings.player.wis text.write("Q", surface, 520, 280, settings.player.str == 6) text.write("A", surface, 520, 320, settings.player.dex == 6) text.write("Z", surface, 520, 360, settings.player.wis == 6) text.write("W", surface, 670, 280, spare_points == 0 or settings.player.str == 18) text.write("S", surface, 670, 320, spare_points == 0 or settings.player.dex == 18) text.write("X", surface, 670, 360, spare_points == 0 or settings.player.wis == 18) text.write("Points: " + str(spare_points), surface, 520, 430) start_button = pygame.Rect(450, 500, 300, 70) pygame.draw.rect(surface, (255, 255, 255), start_button) pygame.draw.rect(surface, constants.COLOR_BG, pygame.Rect(460, 510, 280, 50)) text.write("Start", surface, 570, 520)
def draw(self): if not self.text: return text.write(self.text, self.fontname, self.size, self.color, (self.x, self.y), (0, 0, 0), self.hanchor, self.vanchor, alpha=self.alpha)
def draw_character_namer(surface): pygame.draw.rect(surface, (255, 255, 255), pygame.Rect(400, 105, 500, 54)) pygame.draw.rect(surface, constants.COLOR_BG, pygame.Rect(402, 107, 496, 50)) text.write("Your name: " + settings.player.name + "_", surface, 470, 120)
def write(t, dsize, color, fontname=None): text.write(t, (fontname or self.fontname), int(self.size * dsize), color, (self.x, y[0]), (0, 0, 0), self.hanchor, self.vanchor, alpha=self.alpha) y[0] -= int(self.size * dsize * 1.5)