def build(settings): pygame.init() fullscreen = True if fullscreen: depth = 0 flags = FULLSCREEN | HWSURFACE | DOUBLEBUF else: depth = 16 flags = SWSURFACE | DOUBLEBUF modes = display.list_modes(depth, flags) if fullscreen: if modes == -1: # Welcome to exceptionlessland raise SystemExit("Failed to initialize display") else: mode = max(modes) else: mode = (settings.screen_width,settings.screen_height) display.set_mode(mode, flags) #print(modes) #print(mode[0]) #print(mode[1]) return (display.get_surface(),mode[0],mode[1])
def main(): display.init() maxX, maxY = display.list_modes()[0] screen = display.set_mode((maxX / 3, maxY / 3)) display.flip() pgw = PygameWidget() p = Player(pgw, pipe_desc=Player.test_pipe_desc) p.play() clock = pygame.time.Clock() running = True while running: clock.tick(60) for evt in [pygame.event.wait()] + pygame.event.get(): if evt.type == pygame.KEYDOWN: if p._playing: p.pause() else: p.play() elif evt.type == pygame.QUIT: p.stop() running = False
def main(): display.init() maxX, maxY = display.list_modes()[0] screen = display.set_mode((maxX / 2, maxY / 2)) background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((255, 255, 255)) screen.blit(background, (0, 0)) display.flip() clock = pygame.time.Clock() font = PangoFont(size=30, family='monospace') text1 = font.render('red', color=(255, 0, 0), background=(255, 255, 255, 0)) text2 = font.render('green', color=(0, 255, 0)) text3 = font.render('blue', color=(0, 0, 255)) text4 = font.render('blue-trans', color=(0, 0, 255, 128)) text5 = font.render('cyan-trans', color=(0, 255, 255, 128)) while 1: clock.tick(60) for event in pygame.event.get(): log.debug('event: %s', event) if event.type == pygame.QUIT: return True screen.blit(text1, (20, 20)) screen.blit(text2, (20, 80)) screen.blit(text3, (20, 140)) screen.blit(text4, (200, 20)) screen.blit(text5, (200, 80)) display.flip()
def start_menu(): from pygame.display import set_mode, list_modes, set_caption from pygame import init, quit from pygame.constants import FULLSCREEN from bin.Controller import process from obj.Field import Field init() screen = set_mode(list_modes()[0], FULLSCREEN) set_caption("Hero Misadventures") menu = Menu(("Previous Field", "New Field", "Load Field", "Quit"), screen, surface=color("Lawn Green"), selection_color=color("Lime Green"), text_color=color("Medium Blue")) while True: choose = menu.update() if choose == 0: field = Field(screen) process(screen, field) elif choose == 1: from ctypes import cdll cdll.LoadLibrary("Generator.so").main_generator( "res/GENERATOR.HMinf", "res/FIELD.HMmap") field = Field(screen) process(screen, field) elif choose == 2: from pickle import load field = load(open("res/SAVE.HMsave", "rb")) field.screen = screen process(screen, field) elif choose == 3: quit() return
def admin_menu(): from pygame.display import set_mode, list_modes, set_caption from pygame import init, quit init() screen = set_mode(list_modes()[0]) set_caption("Hero Misadventures") menu = Menu(("Debug", "Release"), screen, text_color=color("White"), surface=color("Black"), selection_color=color("Slate Gray")) while True: choose = menu.update() if choose == -1: continue else: if choose == 0: from cProfile import runctx from pstats import Stats runctx( "from bin.Interaction import debug_menu; debug_menu(screen)", {"screen": screen}, {}, "test/profiling.prof") file = open("test/profiling.txt", "w") info = Stats("test/profiling.prof", stream=file) info.strip_dirs().sort_stats("cumulative").print_stats() elif choose == 1: quit() start_menu() return
from pygame import draw, display, mouse from pygame.locals import * from numpy import * pygame.init() #n_samples = 22050 * 4 #sa = zeros((n_samples, 2)) #sound = sndarray.make_sound(sa) #sa = sndarray.samples(sound) #sound.play(-1) devs = init_multitouch(touch_callback) flags = FULLSCREEN | HWSURFACE | DOUBLEBUF mode = max(display.list_modes(0, flags)) display.set_mode(mode, flags) #display.set_mode((640, 480)) screen = display.get_surface() width, height = screen.get_size() txtfont = pygame.font.SysFont(None, 40) mouse.set_visible(False) fingers = [] start = None prevtime = None df = 0 curpos = (0, 0) curvel = (0, 0)
#!/usr/bin/env python # from psychopy import * import game import pygame import avalgame import text_input from pygaze.eyetracker import EyeTracker from pygaze.libscreen import Screen, Display from pygame.display import list_modes print list_modes() pygame.init() disp = Display() clock = pygame.time.Clock() ### Definitions ###### Resolution #win_size = pygame.display.Info() #windowSize = pygame.display.set_mode((win_size.current_w, win_size.current_h), pygame.FULLSCREEN) # Change as you want (MUST RESPECT DISPLAY DIMENSIONS) windowSize = pygame.display.set_mode((1024, 768), pygame.FULLSCREEN) running = True version = "v1.00" avalgame = avalgame.Avalgame() class GameSettings(pygame.font.Font): def __init__(self, screen, display, bg_color=(0, 0, 0), font='media/fonts/arial.ttf',
import pygame from pygame import draw, display, image, key, font, transform, mouse pygame.init() #mouse.set_visible(False) key.set_repeat(10, 75) try: import android except ImportError: android = None import particles if RELEASE: modes = display.list_modes() VWIDTH, VHEIGHT = modes[0] else: VWIDTH, VHEIGHT = 1080, 960 FPS = 60 TURNS = 10 color_schemes = ["blue", "red", "green", "yellow"] COLOR_SPARKS = map(pygame.Color, ["#E6E6AC", "#777278", "#A9A990"]) color_keymap = { pygame.K_a: "blue", pygame.K_s: "red", pygame.K_d: "green", pygame.K_f: "yellow" }
import pygame from pygame import draw, display, rect from pygame.locals import SWSURFACE, FULLSCREEN, HWSURFACE, DOUBLEBUF pygame.init() fullscreen = False if fullscreen: depth = 0 flags = FULLSCREEN | HWSURFACE | DOUBLEBUF else: depth = 16 flags = SWSURFACE | DOUBLEBUF modes = display.list_modes(depth, flags) if fullscreen: if modes == -1: # Welcome to exceptionlessland raise SystemExit("Failed to initialize display") else: mode = max(modes) else: mode = (640, 480) display.set_mode(mode, flags) screen = display.get_surface() width, height = screen.get_size() # }}} fg = (0x30, 0x30, 0x30)
from pygame import display from pygame import event from pygame import locals _Colors = [ locals.Color(255, 0, 0), locals.Color(0, 255, 0), locals.Color(0, 0, 255), locals.Color(255, 255, 255), locals.Color(0, 0, 0) ] if __name__ == "__main__": pygame.init() clock = time.Clock() screen = display.set_mode(display.list_modes()[0], locals.FULLSCREEN) counter = itertools.count() color_index = 0 color = _Colors[color_index] running = True while running: clock.tick(30) for evt in event.get(): if evt.type == locals.QUIT: running = False elif evt.type == locals.KEYDOWN: if evt.key == locals.K_ESCAPE: running = False else: color_index += 1 color = _Colors[color_index % len(_Colors)]
def main(): pygame.init() gutil.initializeDisplay(swidth, sheight) from pygame import display print display.list_modes() live_dj = Dj() player = Player() # On your own here, but it needs x and y fields. boss = Boss() muzzle_flash = MuzzleFlash() flame = Flame() enemy_bullets = BulletSet() player_bullets = BulletSet() space = [Texture("bg/space_%s" % n, z=-100) for n in range(1, 32)] start_screens = [ Texture("start_screen_%s" % n, z=-100) for n in range(1, 3) ] class Background(object): def __init__(self): self.x = swidth // 2 self.y = sheight // 2 self.z = 0 @property def texture(self): return space[(steps // 15) % len(space)] bg = Background() class StartScreen(object): def __init__(self): self.x = swidth // 2 self.y = sheight // 2 self.z = 0 self.current_texture_index = 0 @property def texture(self): return start_screens[(steps // 30) % len(start_screens)] start_screen = StartScreen() boss_weapons = [ 'easy_attack_1.xml', 'spread_attack.xml', 'laser_attack.xml', 'gravity_attack.xml', 'homing_laser.xml', 'sweep_attack.xml', 'flower_attack.xml', ] global steps start = time.time() joy = JoystickServer() joy.daemon = True joy.start() done = False gun = Debounce(15) laser = Debounce(60 * 5) last_time = time.time() game_tick = 1.0 / 60.0 time_left = 0.0 # Start twilio polling twilio = MessagePoll() twilio.start() last_twilio_msg = None last_twilio_msg_step = 0 last_shot_step = None last_game_over = -GAME_OVER_FRAMES - 1 last_boss_break_step = None def start_screen_visible(): return last_game_over is not None and steps - last_game_over > GAME_OVER_FRAMES while not done: keys = pygame.key.get_pressed() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(1, 1, 1) glPointSize(10) glLoadIdentity() rp = RenderPass() if not start_screen_visible() and ( joy.state.buttons and joy.state.buttons[0]) or keys[pygame.K_z]: #if steps % 3: muzzle_flash.x = player.x + 85 muzzle_flash.y = player.y + 6 if steps % 2 == 0: muzzle_flash.current_texture_index += 1 if muzzle_flash.current_texture_index >= len( muzzle_flash.textures): muzzle_flash.current_texture_index = 0 muzzle_flash.texture = muzzle_flash.textures[ muzzle_flash.current_texture_index] if not start_screen_visible() and player.health > 0: rp.mark_for_draw(muzzle_flash) else: last_shot_step = None # Flame. flame.x = player.x - 8 flame.y = player.y if steps % 4 == 0: flame.current_texture_index += 1 if flame.current_texture_index >= len(flame.textures): flame.current_texture_index = 0 flame.texture = flame.textures[flame.current_texture_index] if start_screen_visible(): rp.mark_for_draw(start_screen) else: if boss.health > 0: map(rp.mark_for_draw, enemy_bullets) rp.mark_for_draw(boss) if player.health > 0: map(rp.mark_for_draw, player_bullets) rp.mark_for_draw(player) rp.mark_for_draw(flame) rp.mark_for_draw(bg) glLoadIdentity() rp.render() if start_screen_visible(): enemy_bullets.clear() player_bullets.clear() elif boss.health <= 0: draw_label('YOU KILLED THE DJ', swidth / 2 - 150, sheight / 2, 300, 40) if last_game_over is None: last_game_over = steps elif player.health <= 0: draw_label('GAME OVER', swidth / 2 - 100, sheight / 2, 200, 50) if last_game_over is None: last_game_over = steps else: # Health bars. draw_health_bar(player.health / 100., sheight - 30, (0., 0.8, 0.)) draw_health_bar(boss.health / 100., 10, (0.8, 0., 0.)) draw_label("PLAYER", 15, sheight - 29, 52, 16) draw_label("BOSS", 15, 11, 35, 16) # Twilio. if not start_screen_visible(): TWILIO_WIDTH = ( 210, 260, ) draw_label("Tired of this DJ? Shoot him.", swidth - TWILIO_WIDTH[0] - 10, 60, TWILIO_WIDTH[0], 16) draw_label("TEXT (503) 8-CANVAS", swidth - TWILIO_WIDTH[1] - 10, 34, TWILIO_WIDTH[1], 23) if ((steps - last_twilio_msg_step) % (TWILIO_MSG_DURATION * 60) and last_twilio_msg is not None): #parts = msg[] offset = 0 line_len = 40 char_w = 12 #for m in msg[offset:offset + line_len]: while True: if offset > len(msg): break end = min(len(msg), offset + line_len) m = msg[offset:offset + line_len] w = len(m) * char_w h = 26 rot = math.sin(steps / 6.) * (50 / len(m)) x = swidth - ((line_len * char_w) + (150 - ((steps * 1.07) - last_twilio_msg_step))) y = (sheight / 2) + 30 y -= (h + 3) * (offset / line_len) draw_label(m, x, y, w, 23, rotation=rot) offset += line_len else: if last_twilio_msg is not None: boss.health -= TWILIO_ATTACK last_twilio_msg_step = 0 last_twilio_msg = None if steps % 60 == 0 and twilio.messages: msg = twilio.messages.pop() last_twilio_msg_step = steps last_twilio_msg = msg # Boss movement. #print live_dj.activity_level() #print 75. / (live_dj.activity_level() + 1) activity_level = live_dj.activity_level() if activity_level > 3 or abs(boss.x - boss.starting_x) > 3: if last_boss_break_step is None: last_boss_break_step = steps boss.x = int( math.cos((steps - last_boss_break_step + (2 * 3.1416 * 30)) / 30.) * 50 + (boss.starting_x - 50)) else: last_boss_break_step = None boss.y = math.sin(steps / 75.) * 110 + (sheight / 2) pygame.display.flip() curtime = time.time() time_left += curtime - last_time last_time = curtime while time_left >= game_tick: time_left -= game_tick for hitbox in hitboxes['player_ship'].values(): hitbox = HitBox(player, hitbox) if boss.health > 0 and enemy_bullets.collides(hitbox): player.health -= BOSS_ATTACK player.last_hit_step = steps for hitbox in hitboxes['boss_ship'].values(): hitbox = HitBox(boss, hitbox) if player.health > 0 and player_bullets.collides(hitbox): boss.health -= PLAYER_ATTACK boss.last_hit_step = steps enemy_bullets.step(swidth, sheight, 100) player_bullets.step(swidth, sheight, 100) eventlist = pygame.event.get() for event in eventlist: if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE: done = True if player.health > 0 and ( joy.state.buttons and joy.state.buttons[0] or joy.state.buttons[8] or joy.state.buttons[9]) or keys[pygame.K_z]: if gun.fire(): player_bullets.load("player_shot.xml", source=player, target=boss) last_shot_step = steps if player.health > 0 and ( joy.state.buttons and joy.state.buttons[1] or joy.state.buttons[2] or joy.state.buttons[3]) or keys[pygame.K_x]: if laser.fire(): player_bullets.load("player_laser.xml", source=player, target=boss) player_bullets.update_roots(player.x + 30, player.y + 2) gun.step() laser.step() dx, dy = 0, 0 if joy.state.hats: dx, dy = joy.state.hats[0] if keys[pygame.K_RIGHT]: dx = 1 elif keys[pygame.K_LEFT]: dx = -1 if keys[pygame.K_UP]: dy = 1 elif keys[pygame.K_DOWN]: dy = -1 player.move(dx, dy) if start_screen_visible() and ( keys[pygame.K_RETURN] or joy.state.buttons and (joy.state.buttons[7] or joy.state.buttons[6] or joy.state.buttons[4] or joy.state.buttons[5]) and (player.health <= 0 or boss.health <= 0)): enemy_bullets.clear() player.health = 100. boss.health = 100. last_game_over = None if keys[pygame.K_q]: time.sleep(1) steps += 1 if not start_screen_visible() and steps % 15 == 0: activity_level = live_dj.activity_level() _rand = random.random() if activity_level: enemy_bullets.load(boss_weapons[activity_level], source=boss, target=player) elif _rand > 0.7: enemy_bullets.load(boss_weapons[1], source=boss, target=player) print "FPS:", steps / (time.time() - start)