def draw(): screen.fill( (255, 255, 255)) ## clear screen to background color (white) topbar.draw() for ii in range(0, len(rectangles)): pygame.draw.rect(rectangles[ii]) pygame.update()
def update( self ): l = self.projectilelist for p in self.projectilelist: p.update( ) if p.dead: l.remove( p ) self.projectilelist = l
def update(self): l = self.projectilelist for p in self.projectilelist: p.update() if p.dead: l.remove(p) self.projectilelist = l
def pause(): pause = True while pause: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_p: paused = False elif event.key == pygame.K_q: pygame.quit() quit() screen.fill(WHITE) draw_text(screen, "PAUSED", 15, WIDTH/2, HEIGHT/2) draw_text(screen, "Press P to continue or Q to quit", 15, WIDTH/2, 200) pygame.update() clock.tick(5)
def monitorObs(): obs_msg_info = { "op": "subscribe", "topic": "/obspoint", "type": "edge_info/vhc_geo" } WINSIZE = [200, 200] pygame.init() screen = pygame.display.set_mode(WINSIZE) pygame.display.set_caption('visualization') yellow = 255, 240, 200 black = 20, 20, 40 screen.fill((100, 100, 100)) zerolat = 59.33659 zerolon = 18.06748 try: obsws = websocket.create_connection(WEBSOCKET_URL) print("The connection is successful!") except: print("The connection fails!") obs_info_json = json.dumps(obs_msg_info) obsws.send(obs_info_json) while (1): obs_json = obsws.recv() type_msg = json.loads(obs_json)['op'] if type_msg == 'publish': dictionary = json.loads(obs_json)['msg']['geo']['latitude'] lat = (json.loads(obs_json)['msg']['geo']['latitude'] - zerolat) * 1000000 lon = (json.loads(obs_json)['msg']['geo']['longitude'] - zerolon) * 1000000 print(lat) print(lon) pygame.draw.circle(screen, green, [int(lat), int(lon)], 5) pygame.update()
def run_game(): game_over = False game_close = False x = width / 2 y = height / 2 x_speed = 0 y_speed = 0 snake_pixels = [] snake_length = 1 target_x = round(random.randrange(0,width-snake_size/10.0)*10) target_y = round(random.randrange(0,height-snake_size/10.0)*10) while not game_over: while game_close: game_display.fill(black) game_over_message = message_font.render("Game Over! ", True, red) game_display.blit(game_over_message, [width/3, height/3]) printscore(snake_length -1) pygame.update() for event in pygame.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: game_over = True game_close = False if event.key == pygame.K_2: run_game() if event.type == pygame.quit: game_over = True game_close = False for event in pygame.event.get(): if event.type == pygame.QUIT: game_over == True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: x_speed = -snake_size y_speed = 0 if event.key == pygame.K_RIGHT: x_speed = snake_size y_speed = 0 if event.key == pygame.K_UP: x_speed = 0 y_speed = -snake_size if event.key == pygame.K_DOWN: x_speed = 0 y_speed = snake_size if x >= width or x < 0 or y >= height or y < 0: game_close = True x += x_speed y += y_speed game_display.fill(black) pygame.draw.rect(game_display, orange, [target_x, target_y, snake_size, snake_size]) snake_pixels.append([x,y]) if len(snake_pixels) > snake_length: del snake_pixels[0] for pixel in snake_pixels[:-1]: if pixel == [x,y]: game_close = True draw_snake(snake_size, snake_pixels) printscore(snake_length -1) pygame.display.update() if x == target_x and y == target_y: target_x = round(random.randrange(0,width-snake_size/10.0)*10) target_y = round(random.randrange(0,height-snake_size/10.0)*10) snake_length += 1 clock.tick(snake_speed) pygame.quit() quit
height = 500 px = width / 2 py = height / 2 ps = 50 scr = pygame.display.set_mode((width, height)) player1 = [50, 50] player1cor = [width / 2, height / 2] img = pygame.image.load( os.path.join(r"C:\Users\henry\Desktop\Games made by me", "kappaRAINBOW.png")) lose = False keys = pygame.key.get_pressed() while not lose: if keys[K_w]: py -= ps for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() scr.blit(img, (0, 0)) pygame.update()
width = 800 height = 600 image = pygame.image.load("picture.jpg") image_scaled = pygame.transform.scale(image, (width, height)) original = image.convert() blank_surface = pygame.Surface((width, height)) blank_surface.fill([0,0,0]) chop_width = width/num_of_squares_x chop_height = width/num_of_squares_y sprite_group = pygame.sprite.Group() new_sprite = None for top_left_x in range(0, width, chop_width): for top_left_y in range(0, width, chop_height): # Create a Surface with appropriate size to use the chop background. chop_surface = pygame.surface.Surface((chop_width, chop_height)) # Blit a sub-section of original background with border area # of top_left_x, top_left_y, chop_width and chop_height chop_border = (top_left_x, top_left_y, chop_width, chop_height) chop_surface.blit(original,(0,0), chop_border) new_sprite = pygame.sprite.Sprite(chop_surface,(800,600),chop_surface.get_rect()) sprite_group.add((new_sprite)) while True: pygame.update()