def __init__(self, x, y): self.x = x self.y = y self.font = Font("resources/fonts/VCR_OSD_MONO_1.001.ttf", 30) # pygame.font.SysFont('Comic Sans MS', 30) # self._text = self.font.render("", True, Color("white"), Color("black")) self._text_rect = self._text.get_rect()
def __init__(self): self.gameSurf = display.get_surface().copy() self.drawWindow = display.get_surface() backgroundColor = (31, 97, 141, 150) title = SysFont('lucidaconsole', 35) subtitle = SysFont('lucidaconsole', 25) #distance between title and subtitle text textMargin = 10 #distance between edge of text and full opacity background textBackgroundMargin = 10 self.titleSurf = title.render("Cheat mode", True, Color('black')) self.subtitleSurf = subtitle.render("Click to exit", True, Color('black')) self.textBackgroundSurf = surface.Surface( (self.subtitleSurf.get_width() + 2 * textBackgroundMargin + 75, self.titleSurf.get_height() + self.subtitleSurf.get_height() + textMargin + 2 * textBackgroundMargin + 25), constants.SRCALPHA) self.textBackgroundSurf.fill(backgroundColor) self.titlePos = (self.drawWindow.get_width() / 2 - self.titleSurf.get_width() / 2, self.drawWindow.get_height() / 2 - self.titleSurf.get_height() - textMargin / 2) self.subtitlePos = (self.drawWindow.get_width() / 2 - self.subtitleSurf.get_width() / 2, self.drawWindow.get_height() / 2 + textMargin / 2) self.textBackgroundPos = (self.drawWindow.get_width() / 2 - self.textBackgroundSurf.get_width() / 2, self.drawWindow.get_height() / 2 - self.textBackgroundSurf.get_height() / 2)
def init(): """Init display and others""" setfonts() global screen, resolution, center, background, char_color, charnext_color, fix, fixbox, fix_think, fixbox_think, izq, der, quest, questbox pygame.init() # soluciona el error de inicializacion de pygame.time pygame.display.init() pygame.display.set_caption("EEG") pygame.mouse.set_visible(False) if FullScreenShow: resolution = (pygame.display.Info().current_w, pygame.display.Info().current_h) screen = pygame.display.set_mode(resolution, FULLSCREEN) else: try: resolution = pygame.display.list_modes()[3] except: resolution = (1280, 720) screen = pygame.display.set_mode(resolution) center = (int(resolution[0] / 2), int(resolution[1] / 2)) izq = (int(resolution[0] / 8), (int(resolution[1] / 8) * 7)) der = ((int(resolution[0] / 8) * 7), (int(resolution[1] / 8) * 7)) background = Color('gray20') char_color = Color('white') charnext_color = Color('lightgray') fix = bigchar.render('+', True, char_color) fixbox = fix.get_rect(centerx=center[0], centery=center[1]) fix_think = bigchar.render('+', True, Color('red')) fixbox_think = fix.get_rect(centerx=center[0], centery=center[1]) quest = bigchar.render('?', True, char_color) questbox = quest.get_rect(centerx=center[0], centery=center[1]) screen.fill(background) pygame.display.flip()
def __init__(self): self.surface = None self.color = Color(0, 0, 0) self.clearColor = Color(0, 0, 0) self.transform = Transform() self.antialiasing = False
def Draw(self, TB, ccolor=Color("red"), tcolor=Color("black")): pygame.draw.rect(TB.background, ccolor, Rect(self.pos, (self.width, self.height))) TB.RenderText( 14, self.caption, (self.pos[0] + self.width / 2, self.pos[1] + self.height / 2), tcolor)
def draw_scoreboard(self, screen, screen_size, score): """Draws a box with the score in it onto the screen.""" screenw, screenh = screen_size wellx, welly = self.well_pixel_coords(screen_size) wellw, wellh = self.well_size() border_size = 5 padding = 20 height = 50 left = wellx + wellw + padding right = screenw - padding top = welly #bottom = top + height width = right - left + 1 pygame.draw.rect( screen, Color(255, 255, 255, 255), Rect(left - border_size, top - border_size, width + border_size * 2, height + border_size * 2)) pygame.draw.rect(screen, Color(0, 0, 0, 255), Rect(left, top, width, height)) text = str(score) font = pygame.font.SysFont("Lucida Console", 32, 1, 0) text_surface = font.render(text, False, Color(255, 255, 255, 255)) screen.blit(text_surface, (left + (width - text_surface.get_width()) / 2, top + (height - text_surface.get_height()) / 2))
def set_mouse_selection(item, mpos): # Marks the MenuItem the mouse cursor hovers on if item.is_mouse_selection(mpos): item.set_font_color(Color('red')) item.set_italic(True) else: item.set_font_color(Color('white')) item.set_italic(False)
def get_color(cls): """ Return bright color varying over time. """ hue = pygame.time.get_ticks() / 50 % 360 color = Color('white') color.hsva = (hue, 100, 100, 100) return color
def render(self, window_srf): self.map_srf.fill((255, 255, 255)) for i, row in enumerate(self.map): for j, tile in enumerate(row): r = pygame.Rect(j * self.TILE_SIZE, i * self.TILE_SIZE, self.TILE_SIZE, self.TILE_SIZE) if tile == 1: self.map_srf.fill(Color('red'), r) else: self.map_srf.fill(Color('blue'), r) window_srf.blit(self.map_srf, (0, 0))
def get_color(cls): """ Return bright color varying over time. """ col = Color('white') hue = pygame.time.get_ticks() / 50 % 360 col.hsva = (hue, 100, 100, 50) return Color(col.r, col.g, col.b)
def __init__(self): """Constructor class. This is executed when an instance of the class is created """ self.screen_width = 800 self.screen_height = 480 self.initial_angle = 30 self.frames_per_second = 60 self.wind = 0 self.white = Color("white") self.red = Color("red") self.green = Color("green") self.background = pg.image.load(path.join('images', 'bg_cropped.png')) self.show_instructions = True self.sound_on = True self.game_over = False
def draw_well(self, screen, screen_size): border_size = 5 borderx, bordery = self.well_pixel_coords(screen_size) borderx = borderx - border_size bordery = bordery - border_size borderw, borderh = self.well_size_in_pixels() borderw = borderw + (2 * border_size) borderh = borderh + (2 * border_size) pygame.draw.rect(screen, Color(255, 255, 255, 255), Rect(borderx, bordery, borderw, borderh)) wellx, welly = self.well_pixel_coords(screen_size) wellw, wellh = self.well_size_in_pixels() pygame.draw.rect(screen, Color(0, 0, 0, 255), Rect(wellx, welly, wellw, wellh))
def __init__(self, name: str, cost: int, energy_per_second: int, image, coords: tuple): pygame.sprite.Sprite.__init__(self) self.font = pygame.font.Font(None, 20) self.name = name self.text_color = Color('black') self.cost = cost self.energy_per_second = energy_per_second self._count = 0 self.image = image abs_coords = in_pixels(coords) self.rect = self.image.get_rect(center=abs_coords) self.count_sprite = pygame.sprite.Sprite() self.count_sprite.image = self.font.render("0", 0, self.text_color) count_coords_abs = (self.rect.x, self.rect.y + self.rect.h) self.count_sprite.rect = self.count_sprite.image.get_rect( center=count_coords_abs) self.cost_sprite = pygame.sprite.Sprite() self.cost_sprite.image = self.font.render(f"{self.cost} Joules", 0, self.text_color) cost_coords_abs = (self.count_sprite.rect.x, self.count_sprite.rect.y + 2 * self.count_sprite.rect.h) self.cost_sprite.rect = self.count_sprite.image.get_rect( center=cost_coords_abs) self.count = 0
def drawNeedle(self, value): (x, y)=self.center beta_r=deg2rad(270+(value-self.valMin)*self.factor-self.alpha/2) self.drawScale() pygame.draw.line(self.screen, Color("red"), (x+self.x0+2,y+self.y0+2), (x+self.x0+self.arc_r*math.cos(beta_r)+2, y+self.y0+self.arc_r*math.sin(beta_r)+2), 4) pygame.display.update(self.rect)
def render_game(self, game_board): self.background.fill(Color(0, 0, 0)) x0 = self.OFFSET[0] - self.SCALE / 2 - 3 y0 = self.OFFSET[1] - 10 x1 = self.OFFSET[0] + 8 + 9 * self.SCALE y1 = self.OFFSET[1] + 8 + 19 * self.SCALE b2 = self.SCALE * 13 #x offset for second board line_endpoints = [((x0, y0), (x0, y1)), ((x0, y1), (x1, y1)), ((x1, y1), (x1, y0)), ((x1, y0), (x0, y0)), ((x0, y1 - 16), (x1, y1 - 16)), ((x0, y1 - 31), (x1, y1 - 31))] for p1, p2 in line_endpoints: pygame.draw.line(self.background, self.color_deref("white"), p1, p2) pygame.draw.line(self.background, self.color_deref("white"), (p1[0] + b2, p1[1]), (p2[0] + b2, p2[1])) x_mid = (x0 + x1) / 2 + self.SCALE pygame.draw.line(self.background, self.color_deref("white"), (x_mid, y1 - 16), (x_mid, y1 - 31)) pygame.draw.line(self.background, self.color_deref("white"), (x_mid + b2, y1 - 16), (x_mid + b2, y1 - 31)) for (x, y) in game_board: disp_x = x if x >= 10: disp_x += 3 pygame.draw.circle(self.background, self.color_deref(game_board[(x, y)]), (self.OFFSET[0] + disp_x * self.SCALE, self.OFFSET[1] + y * self.SCALE), self.RADIUS) self.screen.blit(self.background, (0, 0)) pygame.display.flip()
def __init__(self, x_dim, y_dim): init() # Dimensions Game Screen (grid) self.x_dim = x_dim self.y_dim = y_dim self.MARGIN = 8 self.HEADER_BAR = 70 self.SPACE_PIXELS = 32 if (self.SPACE_PIXELS*self.x_dim + 2 * self.MARGIN) < 550 : self.WIDTH = 550 else: self.WIDTH = self.SPACE_PIXELS*self.x_dim + 2 * self.MARGIN self.HEIGHT = self.SPACE_PIXELS*self.y_dim + 2 * self.MARGIN + self.HEADER_BAR self._screen = display.set_mode((self.WIDTH, self.HEIGHT)) display.set_caption("BitSweeper") if (self.x_dim*self.SPACE_PIXELS) < self.WIDTH : self.GAME_SCREEN_LEFT = (self.WIDTH / 2) - ((self.x_dim* self.SPACE_PIXELS) / 2) else : self.GAME_SCREEN_LEFT = self.MARGIN # Dimensions buttons self.BUTTON_WIDTH = math.floor(self.WIDTH/3) # Dimensions timer and flag counter self.TIMER_WIDTH = 150 self.FLAG_COUNTER_HEIGHT = 20 self.FLAG_COUNTER_WIDTH = 150 # Game Screen (grid) self._gameScreen = self._screen.subsurface( Rect(self.GAME_SCREEN_LEFT, self.HEADER_BAR + self.MARGIN, self.SPACE_PIXELS*self.x_dim, self.SPACE_PIXELS*self.y_dim) ) # Reset button self._reset = self._screen.subsurface( Rect(self.MARGIN, self.MARGIN, self.BUTTON_WIDTH, self.HEADER_BAR-self.MARGIN) ) # Timer and flag counter self._timer = self._screen.subsurface( Rect(self.MARGIN + self.BUTTON_WIDTH + self.MARGIN, self.MARGIN, self.TIMER_WIDTH, self.FLAG_COUNTER_HEIGHT) ) self._flagCounter = self._screen.subsurface( Rect(self.MARGIN + self.BUTTON_WIDTH + self.MARGIN, self.MARGIN + self.FLAG_COUNTER_HEIGHT, self.FLAG_COUNTER_WIDTH, self.FLAG_COUNTER_HEIGHT) ) self._screen.fill(Color('light grey')) # Cheat Mode button self.CHEATMODE_WIDTH = math.floor(self.WIDTH/3) self._cheatMode = self._screen.subsurface( Rect(self.MARGIN + self.BUTTON_WIDTH + self.MARGIN + self.TIMER_WIDTH + self.MARGIN, self.MARGIN, self.CHEATMODE_WIDTH, self.HEADER_BAR-self.MARGIN) ) display.flip()
def __init__(self, filename, rect, count, colorkey=None, loop=False, frames=1): """construct a SpriteStripAnim filename, rect, count, and colorkey are the same arguments used by spritesheet.load_strip. loop is a boolean that, when True, causes the next() method to loop. If False, the terminal case raises StopIteration. frames is the number of ticks to return the same image before the iterator advances to the next image. """ colorkey = Color(96, 128, 192) #colorkey = image.get_at((0,0)) colorkey = -1 self.filename = filename #ss = spritesheet.spritesheet(filename) ss = spritesheet(filename) self.images = ss.load_strip(rect, count, colorkey) self.i = 0 self.loop = loop self.frames = frames self.f = frames
def __init__(self, x_size_init=9, y_size_init=9, numMines_init=10): init() #limits on board size selections self.min_size = 2 self.max_y = 20 self.max_x = 40 #initialize member variables with initial values self.x_size = x_size_init self.y_size = y_size_init self.numMines = numMines_init #create a new display window of size (x, y) self.window = display.set_mode((600, 500)) self.window_margin = 20 #define subsurfaces for rendering different menu components self.sizeSurface = self.window.subsurface( Rect(self.window_margin, self.window_margin, self.window.get_width() / 2 - 1.5 * self.window_margin - 1, self.window.get_height() - 2 * self.window_margin - 100)) self.mineSurface = self.window.subsurface( Rect((self.window.get_width() / 2) + .5 * self.window_margin, self.window_margin, self.window.get_width() / 2 - 1.5 * self.window_margin, self.window.get_height() - 2 * self.window_margin - 100)) self.startSurface = self.window.subsurface( Rect(self.window_margin, 400, self.window.get_width() - 2 * self.window_margin, 100 - self.window_margin)) #initialize colors of the surfaces self.window.fill(Color('light grey')) self.sizeSurface.fill(Color('dark grey')) self.mineSurface.fill(Color('dark gray')) #intialize different font sizes self.title = font.SysFont('lucidaconsole', 30) self.subtitle = font.SysFont('lucidaconsole', 25) #initialize the Drawer self.drawer = Drawer() #initialize the ready flag self.gameReady = False
def show_game_over(self, screen, screen_size): pygame.mixer.music.stop() text = "Game Over" font = pygame.font.SysFont("Courier New", 32, 1, 0) text_surface = font.render(text, False, Color(255, 255, 0, 255)) surface = pygame.Surface( (text_surface.get_width() + 80, text_surface.get_height() + 80)) surface.fill(Color(255, 0, 0, 255)) w, h = screen_size screen.blit(surface, (((w - surface.get_width()) / 2), ((h - surface.get_height()) / 2))) screen.blit(text_surface, (((w - text_surface.get_width()) / 2), ((h - text_surface.get_height()) / 2))) pygame.display.update() self.pause_for(5000)
def __init__(self): pygame.sprite.Sprite.__init__(self) self.font = pygame.font.Font self.font.set_bold(1) self.color = Color("red") self.last_lives = -1 self.update() self.rect = self.image.get_rect().move(850, 5)
def __init__(self): pygame.sprite.Sprite.__init__(self) self.font = pygame.font.Font(None, 20) self.color = Color('white') self.lastscore = -1 self.score = 0 self.update() self.rect = self.image.get_rect().move(10, 20)
def UpdateFromData(self, TB, data, lcolor=Color("red")): x = self.pos[0] + math.cos(data.angle) * data.distance_linear y = self.pos[1] - math.sin(data.angle) * data.distance_linear pygame.draw.line(TB.background, Color("green"), self.pos, (x, y), 5) x = self.pos[0] + math.cos(data.angle) * data.distance y = self.pos[1] - math.sin(data.angle) * data.distance pygame.draw.line(TB.background, lcolor, self.pos, (x, y), 3) TB.RenderText( 18, "DIST: %3.2f ANG: %3.2f deg" % (data.distance, math.degrees(data.angle)), (self.pos[0], self.pos[1] - self.radius - 10), Color("black")) TB.RenderText(18, "DIST (Linear): %3.2f" % (data.distance_linear), (self.pos[0], self.pos[1] + self.radius + 10), Color("black"))
def __init__(self): pygame.sprite.Sprite.__init__(self) self.font = pygame.font.Font(None, 20) self.font.set_italic(1) self.color = Color("white") self.lastscore = -1 self.update() self.rect = self.image.get_rect().move(10, 450)
def _init_(self): pygame.sprite.Sprite._init_(self) self.font = pygame.font.Font(None, 48) self.font.set_italic(1) self.color = Color("White") self.last_score = -1 self.update() self.rect = self.image.get_rect().move(20,5)
def __init__(self, x=0, y=0, speed=1): super().__init__() self.x = x self.y = y self.width = King.SPRITE_SIZE self.height = King.SPRITE_SIZE self._speed = speed path = harmonize_path( os.path.join(os.path.dirname(__file__), "../resources/sprites/characters_black.png")) self.move_right_sprites = SpriteAnimation( path, (0, King.SPRITE_SIZE, King.SPRITE_SIZE, King.SPRITE_SIZE), count=5, colorkey=Color('black'), loop=True, frames=frames) self.move_left_sprites = SpriteAnimation( path, (0, King.SPRITE_SIZE, King.SPRITE_SIZE, King.SPRITE_SIZE), count=5, colorkey=Color('black'), loop=True, frames=frames).flip() self.move_down_sprites = self.move_right_sprites # looks the same path = harmonize_path( os.path.join(os.path.dirname(__file__), "../resources/sprites/king_up_black.png")) self.move_up_sprites = SpriteAnimation( path, (0 * King.SPRITE_SIZE, 0 * King.SPRITE_SIZE, King.SPRITE_SIZE, King.SPRITE_SIZE), count=5, colorkey=Color('black'), loop=True, frames=frames) self._current_animation = None self._current_waypoint = self._create_new_waypoint() self._move_vector = self._calculate_movement_vector() self._select_movement_direction()
def update_text(self, new_text, color=Color("white")): """ updates the text of the GUI Element in a specific color :param new_text: the text that should be displayed in the GUI element :param color: color of text """ self._text = self.font.render(new_text, True, color, None) self._text_rect = self._text.get_rect()
def Draw(self, TB, ccolor=Color("orange"), tcolor=Color("black")): pygame.draw.circle(TB.background, ccolor, self.pos, self.radius, 1) TB.RenderText(18, self.caption, (self.pos[0], self.pos[1] - self.radius - 25), tcolor) # pygame.gfxdraw.pie(TB.background, # Color("blue"), # Rect(self.pos[0]-self.radius, # self.pos[1]-self.radius, # self.radius*2,self.radius*2), # math.radians(self.forward_angle_range[0]), # math.radians(self.forward_angle_range[1]) # ) gfxdraw.pie(TB.background, self.pos[0], self.pos[1], self.radius, 360 - self.forward_angle_range[1], 360 - self.forward_angle_range[0], Color("darkgreen")) gfxdraw.pie(TB.background, self.pos[0], self.pos[1], self.radius, 360 - self.backward_angle_range[1], 360 - self.backward_angle_range[0], Color("purple"))
def __init__(self, containers): pygame.sprite.Sprite.__init__(self, containers) self.font = pygame.font.Font(None, 20) self.font.set_italic(1) self.color = Color('white') self.last_score = -1 self.score = 0 self.image = None self.update() self.rect = self.image.get_rect().move(10, 450)
def collide(self): for p in self.terrain: if pg.sprite.collide_rect(self, p): if isinstance(p, FinishLine): pg.event.post(pg.event.Event(pg.QUIT)) if isinstance(p, Grass): self.speed_x = max(3, self.speed_x / 2) self.speed = self.speed_curve() p.image.fill(Color("DarkGreen")) return
def render_game(self, game_board): #print game_board self.background.fill(Color(0, 0, 0)) x0 = self.OFFSET[0] - 1 y0 = self.OFFSET[1] - 1 x1 = self.OFFSET[0] + 10 * self.SCALE y1 = self.OFFSET[1] + 20 * self.SCALE - 1 b2 = self.SCALE * (10 + self.GAP) #x offset for second board font = pygame.font.Font(None, 22) for n in [0, 1]: if (n, "score") in game_board: score = game_board[(n, "score")] score_string = "Score: %d" % (score, ) text = font.render(score_string, 1, (255, 255, 255)) textpos = (x0 + self.SCALE * 3 + b2 * n, y1 - self.SCALE - 6) self.background.blit(text, textpos) if (2, "level") in game_board: level = game_board[(2, "level")] level_string = "Level: %d" % (level, ) text = font.render(level_string, 1, (255, 255, 255)) textpos = (x0 + self.SCALE * 6, y0 - self.SCALE * 2) self.background.blit(text, textpos) if (2, "time_left") in game_board: time = game_board[(2, "time_left")] time_string = "Time left: %d" % (round(time), ) text = font.render(time_string, 1, (255, 255, 255)) textpos = (x1 + self.SCALE * 3, y0 - self.SCALE * 2) self.background.blit(text, textpos) line_endpoints = [((x0, y0), (x0, y1)), ((x0, y1), (x1, y1)), ((x1, y1), (x1, y0)), ((x1, y0), (x0, y0)), ((x0, y1 - self.SCALE * 2), (x1, y1 - self.SCALE * 2))] for p1, p2 in line_endpoints: pygame.draw.line(self.background, self.color_deref("white"), p1, p2) pygame.draw.line(self.background, self.color_deref("white"), (p1[0] + b2, p1[1]), (p2[0] + b2, p2[1])) for (x, y) in game_board: if y not in ["level", "time_left", "score"]: disp_x = x if x >= 10: disp_x += self.GAP pygame.draw.rect( self.background, self.color_deref(game_board[(x, y)]), (self.OFFSET[0] + disp_x * self.SCALE, self.OFFSET[1] + y * self.SCALE, self.SCALE - 1, self.SCALE - 1)) self.screen.blit(self.background, (0, 0)) pygame.display.flip()
def _dim(self, color, frac): c = Color(*color) c.r = int(round(c.r*frac)) c.g = int(round(c.g*frac)) c.b = int(round(c.b*frac)) return c