def deerCtrl(): global deers for d in deers: d.yo = height - 30 - onLandY(max(min(d.x, width / 2), 0)) if noise.noise(T * 0.001, deers.index(d)) < 0.5: d.x -= d.spd d.walk() else: d.rest() if d.x < -100: deers.remove(d)
def deerCtrl(): global deers for d in deers: d.yo = height-30-onLandY(max(min(d.x,width/2),0)) if noise.noise(T*0.001,deers.index(d))<0.5: d.x -= d.spd d.walk() else: d.rest() if d.x<-100: deers.remove(d)
def drawReflection(): reflection = canvas pygame.draw.rect(screen, (180, 180, 180), [0, height, width / 2, 50]) for i in range(0, 2 * (screen.get_height() - height), 2): screen.blit( reflection, [ (math.sin(i * 0.5)) * i * 0.5 + (noise.noise(pygame.time.get_ticks() * 0.001, i * 0.2) - 0.5) * 20, height + i - 1, ], (0, height - i, width / 2, 1), )
def drawReflection(): reflection = canvas pygame.draw.rect(screen,(180,180,180),[0,height,width/2,50]) for i in range(0,2*(screen.get_height()-height),2): screen.blit(reflection,[(math.sin(i*0.5))*i*0.5+(noise.noise(pygame.time.get_ticks()*0.001,i*0.2)-0.5)*20,height+i-1],(0,height-i,width/2,1))
def makeLand(n,m=0,maxheight = 20): return max(noise.noise(n*0.1,m*0.5)*maxheight,2)-2
def main(): global x, lspds, locs, gamestart, landloc, landni, fullscreen, birds, terrain, keyseq, T gamestart = True showconsole = False while 1: canvas.fill([240,240,240]) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() man.keyupdowncontrol(event,horse) if event.type == pygame.KEYDOWN: if showconsole: k = pygame.key.name(event.key) #print k if k == "return": exe("".join(keyseq)) showconsole = False elif k == "space": keyseq.append(" ") elif k == "-": keyseq.append("-") elif len(k) == 1: keyseq.append(k) elif event.key == pygame.K_BACKSPACE : if len(keyseq) > 0: keyseq.pop() if event.key == pygame.K_SLASH: showconsole = not showconsole if showconsole: settings.msg = ["CONSOLE READY.",settings.msgt] else: settings.msg = ["",settings.msgt] keyseq = [] if event.key == pygame.K_f and not showconsole: fullscreen = not fullscreen if fullscreen: pygame.display.set_mode([width/2,height+50],pygame.FULLSCREEN) else: pygame.display.set_mode([width/2,height+50]) pygame.display.set_caption("") #print(pygame.key.get_pressed()) for i in range(0,len(Ls)): if i == 2: for c in cranes: c.draw(canvas) if i == 3:#+terrain: """ gfont.s = 10 gfont.w = 1 gfont.color = (120,120,120) gfont.drawStr(canvas,"Hermit",300-x*0.7,260) gfont.s = 5 gfont.w = 1 gfont.color = (120,120,120) gfont.drawStr(canvas,"by lingdong",450-x*0.7,280) """ for d in deers: d.draw(canvas) horse.draw(canvas) man.draw(canvas) for a in arrows: a.draw(canvas) for b in birds: b.simpDraw(canvas) pctrl.draw(canvas) if Ls[i] != None: canvas.blit(Ls[i],[locs[i]-x*lspds[i]-buff,0]) if locs[i]-x*lspds[i] < -width-buff: locs[i] += width*2 Ls[i] = None thread.start_new_thread(mt,(1, i)) if Lrs[i] != None: canvas.blit(Lrs[i],[locrs[i]-x*lspds[i]-buff,0]) if locrs[i]-x*lspds[i] < -width-buff: locrs[i] += width*2 Lrs[i] = None thread.start_new_thread(mt,(2, i)) clock.tick() T += 1 u.text(canvas,10,10,"FPS: %.1f" % clock.get_fps(),(160,160,160)) man.keyholdcontrol() if (0 or pygame.key.get_pressed()[pygame.K_RIGHT]) and not man.status[0].endswith("ing"): for a in arrows: a.x -= SPEED for b in birds: b.x -= SPEED for p in pctrl.particles: p.x -= SPEED for d in deers: d.x-=SPEED*0.5 for c in cranes: c.x-=SPEED x+=SPEED horse.walk() if random.random()<0.0005: makeBirds(random.randrange(6,12)) if random.random() < 0.0005 and terrain[3] == 0: makeDeers(1) if random.random() < 0.001 and terrain[3] == 1: makeCranes(random.randrange(1,5)) else: horse.rest() u.polygon(canvas,(130,130,130),[[0,height]]+[[landloc-x+i*landDensity,height-land[i]] for i in range(0,len(land))]+[[width/2,height]]) if -x+landloc<-landDensity: landni += 1 land.append(makeLand(landni,maxheight=20+terrain[3]*120)) land.pop(0) landloc += landDensity man.yo = height-20-onLandY(man.x) horse.yo = height-30-onLandY(horse.x) for d in deers: d.yo = height-30-onLandY(max(min(d.x,width/2),0)) if noise.noise(T*0.001,deers.index(d))<0.5: d.x -= d.spd d.walk() else: d.rest() if d.x<-100: deers.remove(d) for c in cranes: c.x -= 2*c.s c.fly() if c.x<-100: cranes.remove(c) for a in arrows: #a.fly() #print(a.x) if a.x > width/2 or a.x < -10 or height-onLandY(a.x) >= a.calcHead()[1]: a.fly() else: a.v[0] = 0 a.v[1] = 0 a.flicker = 0 if a.x > width/2: arrows.remove(a) for b in birds: if b.health > 0: if ((abs(man.x - b.x) < 100 and random.random()<0.05) or random.random()<0.0002) and b.on == 0: b.on = 1 ra = math.pi/20.0+random.random()*math.pi/6.0*2.1 rl = random.choice([3,4,5]) b.v=[rl*math.cos(ra),-rl*math.sin(ra)] if b.on == 1: b.simpFly() if abs(man.x - b.x) > 160 and random.random()<1: b.v[1] = min(b.v[1]+0.05,0.4) if b.y >= 2: b.on = 0 else: b.rest() if 0 < b.x < width/2: b.yo=height-3-onLandY(b.x) for a in arrows: #print(u.dist(a.x,a.y,b.x,b.y+b.yo)) if u.dist(a.x,a.y,b.x,b.y+b.yo) < b.s*30 and a.v[0] > 0: a.v[0]/= 2 b.arrow = a b.health = 0 b.x = a.calcFeather()[0] b.y = a.calcFeather()[1] - b.yo for i in range(0,12): pctrl.particles.append(particle.Particle(a.calcFeather()[0],a.calcFeather()[1],[8*(random.random()-0.5),8*(random.random()-0.3)])) if b.x<0 or b.x>width or b.yo<0: birds.remove(b) else: b.fall() pctrl.emit() man.animate() horse.animate() #array = [] #screen.unlock() screen.blit(canvas,[0,0]) reflection = canvas#pygame.transform.flip(canvas,False,True) pygame.draw.rect(screen,(180,180,180),[0,height,width/2,50]) for i in range(0,2*(screen.get_height()-height),2): screen.blit(reflection,[(math.sin(i*0.5))*i*0.5+(noise.noise(pygame.time.get_ticks()*0.001,i*0.2)-0.5)*20,height+i-1],(0,height-i,width/2,1)) if settings.msg[0] != "": screen.blit(box,[5,height+33-showconsole*20]) u.text(screen,10,height+35-showconsole*20,settings.msg[0],(240,240,240)) if settings.msg[1] <= 0 and not showconsole: settings.msg[0] = "" else: settings.msg[1]-=1 if showconsole: input = "".join(keyseq) u.text(screen,10,height+25,">"+input.lower(),(240,240,240)) u.text(screen,10,height+35," "+" | ".join(parse.parse(input.split("-")[0],commandlist)[:3]),(240,240,240)) array = [pygame.surfarray.pixels_red(screen),pygame.surfarray.pixels_green(screen),pygame.surfarray.pixels_blue(screen)] filter.filter(array,T) array = [] #icon.blit(screen,[0,0],[0,0,512,512]) #pygame.display.set_icon(icon) pygame.display.flip()
def main(): global x, lspds, locs, gamestart, landloc, landni, fullscreen, birds, terrain, keyseq, T gamestart = True showconsole = False while 1: canvas.fill([240, 240, 240]) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() man.keyupdowncontrol(event, horse) if event.type == pygame.KEYDOWN: if showconsole: k = pygame.key.name(event.key) #print k if k == "return": exe("".join(keyseq)) showconsole = False elif k == "space": keyseq.append(" ") elif k == "-": keyseq.append("-") elif len(k) == 1: keyseq.append(k) elif event.key == pygame.K_BACKSPACE: if len(keyseq) > 0: keyseq.pop() if event.key == pygame.K_SLASH: showconsole = not showconsole if showconsole: settings.msg = ["CONSOLE READY.", settings.msgt] else: settings.msg = ["", settings.msgt] keyseq = [] if event.key == pygame.K_f and not showconsole: fullscreen = not fullscreen if fullscreen: pygame.display.set_mode([width / 2, height + 50], pygame.FULLSCREEN) else: pygame.display.set_mode([width / 2, height + 50]) pygame.display.set_caption("") #print(pygame.key.get_pressed()) for i in range(0, len(Ls)): if i == 2: for c in cranes: c.draw(canvas) if i == 3: #+terrain: """ gfont.s = 10 gfont.w = 1 gfont.color = (120,120,120) gfont.drawStr(canvas,"Hermit",300-x*0.7,260) gfont.s = 5 gfont.w = 1 gfont.color = (120,120,120) gfont.drawStr(canvas,"by lingdong",450-x*0.7,280) """ for d in deers: d.draw(canvas) horse.draw(canvas) man.draw(canvas) for a in arrows: a.draw(canvas) for b in birds: b.simpDraw(canvas) pctrl.draw(canvas) if Ls[i] != None: canvas.blit(Ls[i], [locs[i] - x * lspds[i] - buff, 0]) if locs[i] - x * lspds[i] < -width - buff: locs[i] += width * 2 Ls[i] = None thread.start_new_thread(mt, (1, i)) if Lrs[i] != None: canvas.blit(Lrs[i], [locrs[i] - x * lspds[i] - buff, 0]) if locrs[i] - x * lspds[i] < -width - buff: locrs[i] += width * 2 Lrs[i] = None thread.start_new_thread(mt, (2, i)) clock.tick() T += 1 u.text(canvas, 10, 10, "FPS: %.1f" % clock.get_fps(), (160, 160, 160)) man.keyholdcontrol() if (0 or pygame.key.get_pressed()[pygame.K_RIGHT] ) and not man.status[0].endswith("ing"): for a in arrows: a.x -= SPEED for b in birds: b.x -= SPEED for p in pctrl.particles: p.x -= SPEED for d in deers: d.x -= SPEED * 0.5 for c in cranes: c.x -= SPEED x += SPEED horse.walk() if random.random() < 0.0005: makeBirds(random.randrange(6, 12)) if random.random() < 0.0005 and terrain[3] == 0: makeDeers(1) if random.random() < 0.001 and terrain[3] == 1: makeCranes(random.randrange(1, 5)) else: horse.rest() u.polygon(canvas, (130, 130, 130), [[0, height]] + [[landloc - x + i * landDensity, height - land[i]] for i in range(0, len(land))] + [[width / 2, height]]) if -x + landloc < -landDensity: landni += 1 land.append(makeLand(landni, maxheight=20 + terrain[3] * 120)) land.pop(0) landloc += landDensity man.yo = height - 20 - onLandY(man.x) horse.yo = height - 30 - onLandY(horse.x) for d in deers: d.yo = height - 30 - onLandY(max(min(d.x, width / 2), 0)) if noise.noise(T * 0.001, deers.index(d)) < 0.5: d.x -= d.spd d.walk() else: d.rest() if d.x < -100: deers.remove(d) for c in cranes: c.x -= 2 * c.s c.fly() if c.x < -100: cranes.remove(c) for a in arrows: #a.fly() #print(a.x) if a.x > width / 2 or a.x < -10 or height - onLandY( a.x) >= a.calcHead()[1]: a.fly() else: a.v[0] = 0 a.v[1] = 0 a.flicker = 0 if a.x > width / 2: arrows.remove(a) for b in birds: if b.health > 0: if ((abs(man.x - b.x) < 100 and random.random() < 0.05) or random.random() < 0.0002) and b.on == 0: b.on = 1 ra = math.pi / 20.0 + random.random() * math.pi / 6.0 * 2.1 rl = random.choice([3, 4, 5]) b.v = [rl * math.cos(ra), -rl * math.sin(ra)] if b.on == 1: b.simpFly() if abs(man.x - b.x) > 160 and random.random() < 1: b.v[1] = min(b.v[1] + 0.05, 0.4) if b.y >= 2: b.on = 0 else: b.rest() if 0 < b.x < width / 2: b.yo = height - 3 - onLandY(b.x) for a in arrows: #print(u.dist(a.x,a.y,b.x,b.y+b.yo)) if u.dist(a.x, a.y, b.x, b.y + b.yo) < b.s * 30 and a.v[0] > 0: a.v[0] /= 2 b.arrow = a b.health = 0 b.x = a.calcFeather()[0] b.y = a.calcFeather()[1] - b.yo for i in range(0, 12): pctrl.particles.append( particle.Particle( a.calcFeather()[0], a.calcFeather()[1], [ 8 * (random.random() - 0.5), 8 * (random.random() - 0.3) ])) if b.x < 0 or b.x > width or b.yo < 0: birds.remove(b) else: b.fall() pctrl.emit() man.animate() horse.animate() #array = [] #screen.unlock() screen.blit(canvas, [0, 0]) reflection = canvas #pygame.transform.flip(canvas,False,True) pygame.draw.rect(screen, (180, 180, 180), [0, height, width / 2, 50]) for i in range(0, 2 * (screen.get_height() - height), 2): screen.blit(reflection, [ (math.sin(i * 0.5)) * i * 0.5 + (noise.noise(pygame.time.get_ticks() * 0.001, i * 0.2) - 0.5) * 20, height + i - 1 ], (0, height - i, width / 2, 1)) if settings.msg[0] != "": screen.blit(box, [5, height + 33 - showconsole * 20]) u.text(screen, 10, height + 35 - showconsole * 20, settings.msg[0], (240, 240, 240)) if settings.msg[1] <= 0 and not showconsole: settings.msg[0] = "" else: settings.msg[1] -= 1 if showconsole: input = "".join(keyseq) u.text(screen, 10, height + 25, ">" + input.lower(), (240, 240, 240)) u.text( screen, 10, height + 35, " " + " | ".join(parse.parse(input.split("-")[0], commandlist)[:3]), (240, 240, 240)) array = [ pygame.surfarray.pixels_red(screen), pygame.surfarray.pixels_green(screen), pygame.surfarray.pixels_blue(screen) ] filter.filter(array, T) array = [] #icon.blit(screen,[0,0],[0,0,512,512]) #pygame.display.set_icon(icon) pygame.display.flip()