def run(g): g.quit = 0 t = timer.Timer(FPS) g.paint(g.screen) pygame.display.flip() while not g.quit: for e in pygame.event.get(): if e.type == QUIT: g.quit = 1 if e.type == KEYDOWN and e.key == K_ESCAPE: g.quit = 1 g.view.x += SPEED g.run_codes(cdata, (g.view.right // TW, 0, 1, 17)) g.loop() ##In run(), I have changed the update function to paint, so that ##I can display the player's score on the screen at all times. ##:: g.paint(g.screen) img = g.font.render('%05d' % g.player.score, 1, (0, 0, 0)) g.screen.blit(img, (0 + 1, SH - img.get_height() + 1)) img = g.font.render('%05d' % g.player.score, 1, (255, 255, 255)) g.screen.blit(img, (0, SH - img.get_height())) pygame.display.flip() ## t.tick()
def run(g): g.quit = 0 ##In run(), I add a Timer so that I can keep a constant framerate of FPS fps. ##:: t = timer.Timer(FPS) ## g.paint(g.screen) pygame.display.flip() while not g.quit: for e in pygame.event.get(): if e.type == QUIT: g.quit = 1 if e.type == KEYDOWN and e.key == K_ESCAPE: g.quit = 1 ##In run(), each frame I move the view to the right by SPEED pixels. ##:: g.view.x += SPEED ## g.loop() updates = g.update(g.screen) pygame.display.update(updates) ##In run(), at the end of each frame, I give the timer a tick. The timer will delay the ##appropriate length. ##:: t.tick()
def run(g): g.quit = 0 t = timer.Timer(FPS) g.paint(g.screen) pygame.display.flip() while not g.quit: for e in pygame.event.get(): if e.type == QUIT: g.quit = 1 if e.type == KEYDOWN and e.key == K_ESCAPE: g.quit = 1 g.view.x += SPEED ##In run(), each frame I make sure to run the codes that are on the far ##right of the screen. ##:: g.run_codes(cdata, (g.view.right // TW, 0, 1, 17)) ## g.loop() updates = g.update(g.screen) pygame.display.update(updates) t.tick()
def main(): screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), SWSURFACE) my_timer = timer.Timer(FPS) pygame.font.init() pygame.mixer.init(44100, -16, 2, 1024) # Big buffer for Windows. next_vid = SplashScreenTilevid(screen, my_timer) while True: next_vid = next_vid.run() pygame.mixer.stop() # Kill any music left running. if next_vid is None: break
def init(self): self.random = 0 self.init_play() self.lcur = 0 self.scale2x = SCALE2X if '-scale2x' in sys.argv: self.scale2x = not self.scale2x self.lowres = LOWRES if '-lowres' in sys.argv: self.lowres = not self.lowres self.vsync = VSYNC if '-vsync' in sys.argv: self.vsync = not self.vsync sw, sh = SW, SH if not self.lowres: sw, sh = sw * 2, sh * 2 mode = 0 if FULL: mode |= FULLSCREEN if '-full' in sys.argv: mode ^= FULLSCREEN if mode & FULLSCREEN: mode |= HWSURFACE | DOUBLEBUF self.screen = pygame.display.set_mode((sw, sh), mode) if mode & FULLSCREEN: pygame.mouse.set_visible(False) pygame.display.set_caption(TITLE) self.timer = timer.Timer(FPS) # self.timer = timer.Speedometer() pygame.joystick.init() joy_count = pygame.joystick.get_count() for joynum in range(joy_count): joystick = pygame.joystick.Joystick(joynum) joystick.init() self.input = Input() if not self.lowres: self._screen = self.screen self.screen = self._screen.convert().subsurface(0, 0, SW, SH) pygame.font.init() f_main = data.filepath(os.path.join('fonts', '04B_20__.TTF')) f_scale = 0.35 # f_main = data.filepath(os.path.join('fonts','04B_25__.TTF')) # f_scale = 0.75 # f_main = data.filepath(os.path.join('fonts','04B_11__.TTF')) # f_scale = 0.67 self.fonts = {} self.fonts['intro'] = pygame.font.Font(f_main, int(36 * f_scale)) # self.fonts['intro2'] = pygame.font.Font(data.filepath(os.path.join('fonts','vectroid.ttf')),72) # self.fonts['title'] = pygame.font.Font(data.filepath(os.path.join('fonts','vectroid.ttf')),32) self.fonts['help'] = pygame.font.Font(f_main, int(24 * f_scale)) self.font = self.fonts['menu'] = pygame.font.Font( f_main, int(24 * f_scale)) self.fonts['level'] = pygame.font.Font(f_main, int(24 * f_scale)) self.fonts['pause'] = pygame.font.Font(f_main, int(36 * f_scale)) import level level.pre_load() try: if '-nosound' in sys.argv: 1 / 0 # stop crackling sound on some windows XP machines. if os.name == 'posix' or 1: try: pygame.mixer.pre_init(44100, -16, 2, 1024 * 3) except: pygame.mixer.pre_init() else: pygame.mixer.pre_init() pygame.mixer.init() except: print 'mixer not initialized' self._music_name = None self.sfx = {} for name in [ 'bubble', 'capsule', 'coin', 'hit', 'item', 'powerup', 'pop', 'jump', 'explode', 'door', 'fally', 'boss_explode' ]: self.sfx[name] = Sound( data.filepath(os.path.join('sfx', '%s.wav' % name)))
def run(g): g.quit = 0 ##In run(), adding a pause variable to the game. ##:: g.pause = 0 ## t = timer.Timer(FPS) ##In run(), initializing the stars. ##:: stars = [] NS = 256 for n in range(0, NS): stars.append([ random.randrange(0, SW), random.randrange(0, SH), random.randrange(2, 8) ]) ## while not g.quit: for e in pygame.event.get(): if e.type is QUIT: g.quit = 1 if e.type is KEYDOWN and e.key == K_ESCAPE: g.quit = 1 ##In run(), in the event loop, checking for F10 for full screen, RETURN for pause. ##:: if e.type is KEYDOWN and e.key == K_F10: #g.screen = pygame.display.set_mode((SW,SH),FULLSCREEN|HWSURFACE|DOUBLEBUF) pygame.display.toggle_fullscreen() if e.type is KEYDOWN and e.key == K_RETURN: g.pause ^= 1 ## ##In run(), handles pause, and also renders the star field before the ##foreground is painted. ##:: if not g.pause: g.view.x += SPEED g.run_codes(cdata, (g.view.right / TW, 0, 1, 17)) g.loop() g.screen.fill((0, 0, 0)) n = 0 for n in range(0, NS): x, y, s = stars[n] if ((g.frame * s) % 8) < s: x -= 1 if x < 0: x += SW stars[n][0] = x g.screen.set_at((x, y), (255, 255, 255)) g.paint(g.screen) img = g.font.render('%05d' % g.player.score, 1, (0, 0, 0)) g.screen.blit(img, (0 + 1, SH - img.get_height() + 1)) img = g.font.render('%05d' % g.player.score, 1, (255, 255, 255)) g.screen.blit(img, (0, SH - img.get_height())) pygame.display.flip() g.frame += 1 ## t.tick()
def run(self): time = timer.Timer(base.FPS) self.loadLevel() self.start() #global app maingui = gui.App() self.guiCont = gui.Container(align=0, valign=-1) self.levelSelDlg = SelectLevelDialog(self) # toggling dialog's visibility at certain position seems to be quite tricky # we need to first add the dialog in to the container ... self.guiCont.add(self.levelSelDlg, 0, 0) maingui.init(self.guiCont) # ... then we can remove it (so that it's invisible until we want to show it) self.guiCont.remove(self.levelSelDlg) self.levelSelDlg.isVisible = False #MAYO added the eztext txtbx = eztext.Input( maxlength=45, x=100, y=570, color=(255, 0, 0), prompt="Type in the missing word to repair the Bible: ") while 1: #MAYO now check to see if the word is correct. ev = pygame.event.get() if self.inputing: txtbx.update(ev) txtbx.draw(self.screen) pygame.display.flip() for e in ev: if (e.type is QUIT): self.nextState = base.QUITGAME elif (e.type is KEYDOWN): #MAYO now add int the code to check for the bible being correct. if ((e.key == K_RETURN) and self.inputing): if txtbx.value == self.retval[2]: self.num_bibles += 1 base.num_bibles = self.num_bibles self.hud.show_dialog(_("You fixed the Bible!")) txtbx.value = "" else: self.hud.show_dialog( _("You couldn't fix the Bible!")) txtbx.value = "" txtbx.update(ev) txtbx.draw(self.screen) pygame.display.flip() self.inputing = False self.handleKeys(e.key) elif (e.type is JOYBUTTONDOWN): self.handleButton(e) else: maingui.event(e) if (self.nextState != base.GAMECONTINUES): break ## Paint the background. self.bg.view.x = self.view.x / 2 self.bg.view.y = self.view.y / 2 self.bg.paint(self.screen) ## Paint the foreground (player and such) self.paint(self.screen) ## Paint the HUD if self.player != None: self.hud.paint(self.screen) self.player.hudHeight = self.hud.height maingui.paint(self.screen) #if not (self.paused): # if (self.exit): # break ## exit while if self.player != None and ( (self.player.rect.y + self.player.rect.height) > ((len(self.tlayer) - 1) * TILE_SIZE)): print("Whoops! Fell off the level -- try again!") self.daveInTrouble(-1) if not self.paused: self.frame += 1 self.animate_background() # todo, the list index goes out of range in vid.py at line 427 # when the bottom of dave's sprite rect goes out of the screen # edit: this bug should be fixed but leaving this here for now until #try: self.OnLoop() self.loop() # todo should we catch the "undeclared variable" errors from level scripts? #except NameError, e: # print e, "" #except IndexError, e: # print e , "This is known bug which should have been fixed, plese report this" if (self.quake): self.focus_rect.x += random.randrange(-5, 5) self.focus_rect.y += random.randrange(-5, 5) if (self.quake > 0): self.quake -= 1 self.view.clamp_ip(self.focus_rect) time.tick() pygame.display.flip() return self.nextState
_p.x,_p.y = p.x,p.y p.x += dx p.y += dy if __name__ == '__main__': screen = pygame.display.set_mode((640,480)) #ss = [((rr(160,640),rr(160,480)),Effect(256,64)) for n in xrange(0,1)] ss = [] t = timer.Timer(40) f = 0 _quit = False while not _quit: for e in pygame.event.get(): if e.type is QUIT: _quit = True if e.type is KEYDOWN and e.key == K_ESCAPE: _quit = True screen.fill((0,0,0)) for pos,s in ss: s.loop(pos) s.paint(screen,(0,0)) pygame.display.flip()
def init(self): pygame.init() #if '-t' in sys.argv: base.Testing = True #MAYO: set this to always be on !!! #else: # base.Testing = False #Just until I find time to fix bugs caused by this being off. self.timer = timer.Timer(base.FPS) #Set the max FPS self.screenChanged = False self.settings = base.loadGameSettings( ) #Load the default game settings if not os.path.exists(base.path): base.saveGameSettings(self.settings) self.gameVariables = {} base.DATA = base.loadGame() self.playingMusic = {"jungle": False, "menu": False} self.screenMode = base.getFullScreenFlag(self.settings) self.screen = pygame.display.set_mode( (base.SCREEN_WIDTH, base.SCREEN_HEIGHT), self.screenMode) ## pygame.font.init() #try: #pygame.mixer.init() #base.SOUND = True #self.sound = True #except: #base.SOUND = False #self.sound = False base.SOUND = True self.sound = base.SOUND #print base.SOUND, base.MUSIC_LOADED pygame.display.set_caption("Speckpater %s" % base.VERSION) pygame.display.set_icon( pygame.image.load(os.path.join("images", "bible.png"))) self.music = 1 base.sound = DaveSound() base.initLocalization( self.settings ) #Get all settings for game that are saved to the settings file base.setScreenMode( self.screenMode, int(self.settings['bpp']) ) #Get bits per pixel (colour depth) mode from settings file and set it base.enableSounds(int(self.settings['sounds']) ) #Get sounds from the settings file and enable them gamma = float( self.settings['gamma']) #Get gama settings from settings file pygame.display.set_gamma(gamma, gamma, gamma) #Set gamma #MAYO #Joystick initialization if (pygame.joystick.get_count() > 0): #Seems like there is a virtual joystick in some computer print "Detected Joystick" base.has_joy = True base.joy = pygame.joystick.Joystick(0) base.joy.init() print self.settings print base.DATA
def init(self): self.timer = timer.Timer(FPS)
def init(self): self.random = 0 self.init_play() self.lcur = 0 self.scale2x = SCALE2X if '-scale2x' in sys.argv: self.scale2x = not self.scale2x sw,sh = SW,SH if self.scale2x: sw,sh = sw*2,sh*2 mode = FULLSCREEN if '-full' in sys.argv: mode ^= FULLSCREEN self.screen = pygame.display.set_mode((sw,sh),mode) pygame.display.set_caption(TITLE) #self.timer = timer.Timer(FPS) self.timer = timer.Timer(FPS) #self.timer = timer.Speedometer() pygame.joystick.init() joy_count = pygame.joystick.get_count() for joynum in range(joy_count): joystick = pygame.joystick.Joystick(joynum) joystick.init() self.input = Input() if self.scale2x: self._screen = self.screen self.screen = self._screen.convert().subsurface(0,0,SW,SH) pygame.font.init() self.fonts = {} self.fonts['intro'] = pygame.font.Font(data.filepath(os.path.join('fonts','LESSERCO.ttf')),36) self.fonts['intro2'] = pygame.font.Font(data.filepath(os.path.join('fonts','vectroid.ttf')),72) self.fonts['title'] = pygame.font.Font(data.filepath(os.path.join('fonts','vectroid.ttf')),32) self.fonts['help'] = pygame.font.Font(data.filepath(os.path.join('fonts','LESSERCO.ttf')),24) self.font = self.fonts['menu'] = pygame.font.Font(data.filepath(os.path.join('fonts','LESSERCO.ttf')),24) self.fonts['level'] = pygame.font.Font(data.filepath(os.path.join('fonts','LESSERCO.ttf')),24) self.fonts['pause'] = pygame.font.Font(data.filepath(os.path.join('fonts','LESSERCO.ttf')),36) import level level.pre_load() try: if '-nosound' in sys.argv: 1/0 # stop crackling sound on some windows XP machines. if os.name == 'posix' or 1: try: pygame.mixer.pre_init(44100,-16,2, 1024*3) except: pygame.mixer.pre_init() else: pygame.mixer.pre_init() pygame.mixer.init() except: print 'mixer not initialized' self._music_name = None self.sfx = {} for name in ['bubble','capsule','coin','hit','item','powerup', 'pop','jump','explode','door','fally','boss_explode']: self.sfx[name] = Sound(data.filepath(os.path.join('sfx','%s.wav'%name)))