def __init__(self, screen, gameSelection=False): self.screen = screen self.gameSelection = gameSelection self.font = load.load_font("Nexa Light", 40) self.timer = pygame.time.Clock() self.selection = 0 self.bg = Surface((32, 32)) self.titleImg = load.load_image("title") self.offset = 175 self.mouse = pygame.mouse s = random.choice("01") self.snowing = int(s) if not self.snowing: r = random.choice("00000001") self.raining = int(r) else: self.raining = False self.rain = Rain() self.snow = Snow() # random trees self.numTrees = random.randint(10, 15) self.trees = pygame.sprite.Group() increment = SCREEN_WIDTH // self.numTrees for t in range(self.numTrees): # better random distribution x = random.randint(t * increment - 5, (t + 1) * increment + 5) img = int(random.choice("111223")) y = SCREEN_HEIGHT + random.randint(10, 60) tree = Tree(x, y, img) self.trees.add(tree)
def intro(): snow = Snow(velocity=(0, 0.5)) i = ika.Random(0, 7) gba = ika.Image('gfx/gba' + str(i) + '.png') ikalogo = ika.Image('gfx/ika.png') hatchlogo = ika.Image('gfx/HatchetLogo2.png') v = ika.Video d = 50 def showGba(): v.ClearScreen() v.Blit(gba, (v.xres - gba.width) / 2, (v.yres - gba.height) / 2) try: delay(lambda: v.Blit(ikalogo, 0, 0, ika.Opaque), 200, snow) delay(lambda: v.ClearScreen(), d, snow) delay(lambda: v.Blit(hatchlogo, 0, 0, ika.Opaque), 200, snow) delay(lambda: v.ClearScreen(), d, snow) delay(showGba, 200, snow) delay(lambda: v.ClearScreen(), d, snow) except _DoneException: return
def enter(): game_framework.reset_time() global map, player, house, background, avalanche, coin, snows, map_on_coins, game_over, santa, game_clear, distance, stones map = Map() player = Player() house = House() background = Background() avalanche = Avalanche() coin = Coin() game_over = Game_over() santa = Santa() game_clear = Game_clear() distance = Distance() map_on_coins = [Map_on_Coin() for i in range(200)] snows = [Snow() for i in range(20)] stones = [Stone() for i in range(10)] Player.x = 300.0 Player.y = 300.0 Player.unreal_x = 300.0 Player.unreal_y = 0 Player.jump_before_y = 0 Map.map_move_y_minor = 0 Avalanche.game_over = 0 Game_clear.game_clear = 0 Santa.game_clear = 0
def AutoExec(): system.engine.mapThings.append(Snow(velocity=(0, 0.5))) if 'unityrune' not in savedata.__dict__: system.engine.things.append(RuneListener()) if 'introanim' not in savedata.__dict__: setattr(savedata, 'introanim', 'True') system.engine.things.append(IntroAnim())
def AutoExec(): system.engine.mapThings.append(Snow(6000, velocity=(-.2, 3))) if 'waterrune' not in savedata.__dict__: system.engine.things.append(RuneListener()) if 'nearend' in savedata.__dict__: system.engine.things.append(RuneListener()) if 'icechunks1' in savedata.__dict__: breakIceRun() sound.playMusic("music/wind.ogg")
def AutoExec(): system.engine.mapThings.append(Snow(4000, velocity=(-1, 1.5))) system.engine.background = ika.Image('gfx/mountains.png') if 'bridge_broken' not in savedata.__dict__: for x in range(19, 22): ika.Map.SetTile(x, 28, 4, 152) ika.Map.SetTile(x, 29, 4, 158) ika.Map.SetTile(x, 30, 4, 164) ika.Map.entities['break_gap'].x = -100 if 'windguard' not in savedata.__dict__ and 'nearend' in savedata.__dict__: system.engine.things.append(RuneListener())
def __init__(self, master, screen, wallist, brwalls, snowlist, snowmanlist, player, base): self.screen = screen self.master = master self.gplayer = pygame.sprite.Group() self.gsm = pygame.sprite.Group() self.gs = pygame.sprite.Group() self.gw = pygame.sprite.Group() self.gb = pygame.sprite.Group() self.gbase = pygame.sprite.Group() self.other = pygame.sprite.Group() self.btnlist = [] self.base = Base(self, *base) self.run = True self.slist = [] self.blist = [] self.wlist = [] self.sc = 0 for i in wallist: self.wlist.append(Wall(self, i[1] * 50, i[0] * 50)) for i in brwalls: w = Wall(self, i[1] * 50, i[0] * 50) w.breakable = True w.sprite.image = self.load_image("wall2.png") self.wlist.append(w) for i in snowlist: Snow(self, i[1] * 50, i[0] * 50) self.sc += 1 for i in snowmanlist: self.slist.append(Snowman(self, i[1] * 50, i[0] * 50)) self.player = Player(self, *player[:-1]) self.player.time = player[-1] for i in range(30): Wall(self, i * 50, -50) Wall(self, i * 50, 750) Wall(self, -50, i * 50) Wall(self, 1050, i * 50) self.menu = Menu(self, 1050, 0)
def menu(): bg = ika.Image('gfx/title.png') cursor = ika.Image('gfx/ui/pointer.png') snow = Snow(velocity=(0, 0.5)) snow.update() result = None cursorPos = 0 FADE_TIME = 60 font = ika.Font('system.fnt') def draw(): ika.Video.Blit(bg, 0, 0, ika.Opaque) ika.Video.Blit(cursor, 68, 128 + cursorPos * 26) txt = '(c) 2003, 2021' length = font.StringWidth(txt) font.Print(ika.Video.xres - length - 10, ika.Video.yres - 10, txt) txt = 'Version 1.02' length = font.StringWidth(txt) font.Print(ika.Video.xres - length - 10, ika.Video.yres - 20, txt) if controls.useGamePad: font.Print(10, ika.Video.yres - 10, 'Gamepad controls enabled.') for i in range(FADE_TIME - 1, -1, -1): draw() ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, i * 255 / FADE_TIME), True) snow.update() snow.draw() ika.Video.ShowPage() ika.Input.Update() ika.Delay(1) u = 0 # gay unpress hack while result == None: draw() snow.update() snow.draw() ika.Video.ShowPage() ika.Input.Update() ika.Delay(1) if (controls.up() or controls.ui_up() or controls.joy_up()) and cursorPos > 0: if not u: cursorPos -= 1 u = 1 elif (controls.down() or controls.ui_down() or controls.joy_down()) and cursorPos < 2: if not u: cursorPos += 1 u = 1 elif controls.attack() or controls.ui_accept() or controls.joy_attack( ): result = cursorPos else: u = 0 # one last draw. Later on, there's a blurfade that can take advantage of this: draw() snow.draw() return result for i in range(FADE_TIME): draw() ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, i * 255 / FADE_TIME), True) snow.update() snow.draw() ika.Video.ShowPage() ika.Input.Update() ika.Delay(1)
def AutoExec(): system.engine.mapThings.append(Snow(3000, velocity=(-1, 1.5)))
def AutoExec(): system.engine.mapThings.append(Snow(5000, velocity=(-1.2, 3))) sound.playMusic("music/wind.ogg")
def AutoExec(): global spawned spawned = 0 system.engine.mapThings.append(Snow(100, velocity=(.4, 1), colour=ika.RGB(255,192,255))) system.engine.background = ika.Image('gfx/mountains.png')
def AutoExec(): system.engine.mapThings.append(Snow(5000, velocity=(-.5, 2)))
def AutoExec(): system.engine.mapThings.append(Snow(4000, velocity=(-1, 1.5))) system.engine.background = ika.Image('gfx/mountains.png')
BLUE = (150, 190, 255) # Set the screen size SCREENWIDTH = 400 SCREENHEIGHT = 400 # Open a new window # The window is defined as (width, height), measured in pixels size = (SCREENWIDTH, SCREENHEIGHT) screen = pygame.display.set_mode(size) pygame.display.set_caption("Snow Animation") #Create list all_snow = pygame.sprite.Group() snowflake = Snow(BLUE, 100, 0) all_snow.add # This loop will continue until the user exits the game carryOn = True # The clock will be used to control how fast the screen updates clock = pygame.time.Clock() # Background image - https://nl.aliexpress.com/item/10X10ft-Winter-backdrop-Vinyl-Photography-Backdrops-props-photography-Background-NDT23/32264655459.html background = pygame.image.load("snowbackground.jpg") #---------Main Program Loop---------- while carryOn: # --- Main event loop ---
# Set the screen size SCREENWIDTH = 400 SCREENHEIGHT = 400 # Open a new window # The window is defined as (width, height), measured in pixels size = (SCREENWIDTH, SCREENHEIGHT) screen = pygame.display.set_mode(size) pygame.display.set_caption("My Animation") speed = 1 all_sprites_list = pygame.sprite.Group() snowFlake1 = Snow(WHITE, 10, 10, random.randint(20, 80)) snowFlake1.rect.x = random.randint(0, 400) snowFlake1.rect.y = 1 snowFlake2 = Snow(WHITE, 10, 10, random.randint(20, 80)) snowFlake2.rect.x = random.randint(0, 400) snowFlake2.rect.y = 4 snowFlake3 = Snow(WHITE, 10, 10, random.randint(20, 80)) snowFlake3.rect.x = random.randint(0, 400) snowFlake3.rect.y = 6 snowFlake4 = Snow(WHITE, 10, 10, random.randint(20, 80)) snowFlake4.rect.x = random.randint(0, 400) snowFlake4.rect.y = 60
def __init__(self, screen, timer, custom=False): self.screen = screen self.timer = timer '''Game Mode''' if custom != False: # 0, if no platforms are drawn self.custom = True if isinstance(custom, list): self.customPlatTypes = custom self.customNumPlatforms = None else: self.customNumPlatforms = custom self.customPlatTypes = None else: self.custom = False '''Game Mechanics''' self.totalGameTime = 1000 self.gameover = False self.gameover_image = None self.gameover_rect = None self.pause = False self.done = False font = load.load_font("OpenSans-Semibold", 40) self.pause_image = font.render("Paused", True, (236, 247, 255)) self.pause_rect = self.pause_image.get_rect() self.pause_rect.center = self.screen.get_rect().center self.exit = True self.showFPS = False self.noCrashes = False '''Background''' self.bg = Surface((32, 32)) self.bgTime = 0 self.bgColor = Game.bgColor self.sundownTime = 0 self.rainStart = random.randint(0, self.totalGameTime) self.rainEnd = self.rainStart + random.randint(150, 500) self.rainEndColor = None self.darkenTime = (self.rainEnd - self.rainStart) / 3 self.lightenTime = 2 * (self.rainEnd - self.rainStart) / 3 self.raining = self.darkening = self.lightening = False self.snowing = False self.snow = Snow() '''Game entities''' self.entities = pygame.sprite.Group() self.rocks = pygame.sprite.Group() self.trees = pygame.sprite.Group() self.birds = pygame.sprite.Group() self.coins = pygame.sprite.Group() self.ice = pygame.sprite.Group() self.player = Player() self.entities.add(self.player) self.coinCount = 0 self.flyingBirds = [] self.collectedCoins = [] self.clouds = None '''Score''' self.score = Score() self.scoreSprite = pygame.sprite.Group() self.scoreSprite.add(self.score) '''Platforms''' self.platforms = [] self.numPlatforms = 30 self.generatePlatforms() self.createPlatforms() '''Camera''' self.totalWidth = 1024 * len(self.platformTypes) self.totalHeight = 800 self.camera = Camera(complex_camera, self.totalWidth, self.totalHeight) '''Generating obstacles''' self.iceCoords = makeIce(self.platforms) rockInfo = makeRock(self.platforms) self.treeDict = makeTrees(self.platforms) self.birdDict = generateBirds(self.platforms) self.coinDict = makeCoins(self.platforms) (self.rockRects, self.rockCoords, self.rockAngles) = \ (rockInfo[0], rockInfo[1], rockInfo[2]) # ROCKS offset = 1024 for item in range(1, len(self.rockRects)): currentPlatform = self.platforms[item] x = self.rockRects[currentPlatform][0] + offset y = self.rockRects[currentPlatform][1] angle = self.rockAngles[currentPlatform] obstacle = random.choice("001") rock = Rock(x, y, angle) if obstacle == "0" else Penguin( x, y, angle) self.rocks.add(rock) offset += 1024 # ICE iceOffset = 0 for item in range(self.numPlatforms): currentPlatform = self.platforms[item] x = iceOffset ice = Ice(x, 299, currentPlatform, self.iceCoords) self.ice.add(ice) iceOffset += 1024 # TREES offset = 0 for item in range(len(self.treeDict)): currentPlatform = self.platforms[item] treeCoords = self.treeDict[currentPlatform] for tree in treeCoords: x = offset + tree[0] yOffset = random.randint(5, 20) y = tree[1] + 300 + yOffset tree = Tree(x, y) self.trees.add(tree) offset += 1024 # BIRBS & COINS offset = 0 for item in range(self.numPlatforms): currentPlatform = self.platforms[item] coords = self.birdDict[currentPlatform] coinCoords = self.coinDict[currentPlatform] if coords != None: for point in coords: x = offset + point[0] y = point[1] bird = Bird(x, y, 0) self.birds.add(bird) if coinCoords != None: for coin in coinCoords: x = offset + coin[0] y = coin[1] coin = Coin(x, y) self.coins.add(coin) offset += 1024
def AutoExec(): system.engine.mapThings.append( Snow(600, velocity=(.4, 1), colour=ika.RGB(192, 192, 255))) system.engine.background = ika.Image('gfx/mountains.png')
from snow import Snow import lyrics from pygame import mixer stdscr = curses.initscr() curses.noecho() curses.cbreak() curses.curs_set(0) stdscr.nodelay(True) mixer.init() mixer.music.load("1519.mp3") mixer.music.play() lyr = lyrics.load() fires = [Fire(14, 14), Fire(stdscr.getmaxyx()[1] - 14, 14)] snow = Snow(stdscr) title = UnTypist("The Great Fire - OK GO", x="center", y="center", win=stdscr) tps = UnTypist("", x=16, y=16) tps2 = UnTypist("", x=40, y=16) t = 40 currtps = True paused = False while True: #Input k = stdscr.getch() if k == ord('q'): break if k == ord('p'):
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @desc: @author: DYL @contact: [email protected] @site: www.xxxx.com @software: PyCharm @since:python 3.5.2 on 2016/11/3.10:49 """ from snow import Snow from snow import HttpResponse #http://www.cnblogs.com/wupeiqi/articles/6536518.html def index(request): return HttpResponse('OK') routes = [ (r'/index/', index), ] app = Snow(routes) app.run(port=8012)
def credits(): m = sound.music.get('music/Existing.s3m', ika.Sound('music/Existing.s3m')) m.loop = True sound.fader.kill() sound.fader.reset(m) bg = ika.Image('gfx/mountains2.png') snow = Snow(velocity=(0.5, 0.75)) y = -ika.Video.yres font = ika.Font('system.fnt') totalitems = 27 #total collectable items - tnt, + all types of runes #currently 6 of each rune type 18 total, + 4 main runes + 5 TNT = 27 s = system.engine.player.stats collecteditems = s.totaltnt + s.powerrunes + s.strengthrunes + s.guardrunes + 4 #hack - assume that all 4 main runes are collected :P itempercent = str(round(collecteditems * 100 / totalitems, 1)) + '%' if automap.map.getMapPct() >= 100: mappercent = '100.0%' else: mappercent = str(automap.map.getMapPct()) + '%' totaltxt = _basetext + """ *** Final Stats *** Total Time Played: """ + system.engine.time + """ Item Collection Rate: """ + itempercent + """ Map Completion Rate: """ + mappercent + """ """ _text = totaltxt.split('\n') class CreditEnt(object): def __init__(self, e, name, x, y, h): self.ent = e self.name = name self.x = x self.y = y self.h = int(h / 2) #display line at midpoint of image height if self.name == 'soulreaver': self.displayname = 'Rune Guardian' #hack else: self.displayname = name.capitalize() self.num = str(system.engine.player.stats[self.name]) def draw(self, offset): self.ent.Draw(self.x, self.y - offset) font.Print(140, self.y - offset + self.h, self.displayname) font.Print(250, self.y - offset + self.h, self.num) def draw(): ika.Video.Blit(bg, 0, 0, ika.Opaque) ika.Video.DrawRect(0, 0, ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0, 128), True) firstLine = int(y) / font.height adjust = int(y) % font.height length = (ika.Video.yres / font.height) + 1 Y = -adjust while Y < ika.Video.yres and firstLine < len(_text): if firstLine >= 0: font.CenterPrint(160, Y, _text[firstLine]) Y += font.height firstLine += 1 for en in entlist: en.draw(int(y)) ika.Video.DrawTriangle((0, 0, ika.RGB(0, 0, 0)), (ika.Video.xres, 0, ika.RGB(0, 0, 0, 0)), (0, 60, ika.RGB(0, 0, 0, 0))) ika.Video.DrawTriangle( (ika.Video.xres, ika.Video.yres, ika.RGB(0, 0, 0)), (0, ika.Video.yres, ika.RGB(0, 0, 0, 0)), (ika.Video.xres, ika.Video.yres - 60, ika.RGB(0, 0, 0, 0))) snow.draw() entlist = [] startx = 80 starty = 0 for i, txt in enumerate(_text): if '*** Enemy Stats ***' in txt: starty = i * 10 + 30 break #hack because the full sprite dimensions aren't directly accessible heights = [16] * 3 + [32] * 3 + [72] * 3 + [112] halfwidths = [8] * 3 + [16] * 3 + [48] * 4 offseth = [0] * 3 + [0] * 3 + [16] * 3 + [15] #compensate for hotspot for i, entname in enumerate([ 'anklebiter', 'carnivore', 'devourer', 'razormane', 'dragonpup', 'hellhound', 'yeti', 'gorilla', 'soulreaver', 'serpent' ]): e = ika.Entity(-100, -100, 2, entname + '.ika-sprite') #put it off screen! entlist.append( CreditEnt(e, entname, startx - halfwidths[i], starty - offseth[i], heights[i])) starty += heights[i] + 10 maxy = len(_text) * 10 draw() xi.effects.fadeIn(50) now = ika.GetTime() while True: t = ika.GetTime() delta = (t - now) / 5.0 y += delta now = t snow.update() draw() ika.Video.ShowPage() ika.Input.Update() if y > maxy: break system.killmusic = False #keep music playing after returning to menu raise EndGameException
RED = (255, 0, 0) # Set the screen size SCREENWIDTH = 400 SCREENHEIGHT = 400 # Open a new window # The window is defined as (width, height), measured in pixels size = (SCREENWIDTH, SCREENHEIGHT) screen = pygame.display.set_mode(size) pygame.display.set_caption("Falling Snow") speed = 100 SNOW = pygame.sprite.Group() for i in range(80): mySnow = Snow(WHITE, 10, 10, random.randint(7, 20)) mySnow.rect.x = random.randint(0, 400) mySnow.rect.y = random.randint(0, 400) SNOW.add(mySnow) # This loop will continue until the user exits the game carryOn = True # The clock will be used to control how fast the screen updates clock = pygame.time.Clock() #---------Main Program Loop---------- while carryOn: # --- Main event loop --- for event in pygame.event.get(): # Player did something if event.type == pygame.QUIT: # Player clicked close button
def AutoExec(): system.engine.mapThings.append(Snow(velocity=(0, 0.5)))