示例#1
0
文件: main.py 项目: ampotos/CaH
def process(clisock):
    signal.signal(signal.SIGSEGV, handler)
    timer = multiprocessing.Process(target=timing, args=(int(os.getpid()),))
    timer.start()
    levels.level1(clisock)
    levels.level2(clisock)
    levels.level3(clisock)
示例#2
0
def stay_on_level():
    white_background = button.draw_bordered_rounded_rect(screen, (170, 200, 800, 200), (255, 255, 255), (0, 0, 0), 10, 0)
    text = passFont.render("Too slow", False, (0, 0, 128))
    screen.blit(text, (468, 280))
    retry = button.draw_bordered_rounded_rect(screen, (490, 340, 150, 50), (139, 0, 0), (0, 0, 0), 10, 0, "Retry", (255, 255, 255), (540, 355))
    wait = True
    display_wpm(wpm)
    pygame.display.flip()
    while wait:
        for event in pygame.event.get():
            pos = pygame.mouse.get_pos()
            if event.type == pygame.QUIT:
                pygame.quit()
            if retry.collidepoint(pos) and event.type == pygame.MOUSEBUTTONDOWN:
                if current_level == 1:
                    run_level(levels.level1())
                elif current_level == 2:
                    run_level(levels.level2())
                elif current_level == 3:
                    run_level(levels.level3())
                elif current_level == 4:
                    run_level(levels.level4())
                elif current_level == 5:
                    run_level(levels.level5())
                elif current_level == 6:
                    run_level(levels.level6())
                elif current_level == 7:
                    run_level(levels.level7())
                elif current_level == 8:
                    run_level(levels.level8())
                elif current_level == 9:
                    run_level(FreeTypeLevel.TypeChallenge())
                wait = False
示例#3
0
    def LoadSprites(self):
		#loads music
        pygame.mixer.music.load("music.mp3")
        pygame.mixer.music.play(-1)
		#loads level and user layout
        level = levels.level1()
        if levelDifficulty == "easy":
            layout = level.getLayoutEasy()
        elif levelDifficulty == "normal":
            layout = level.getLayoutModerate()
        elif levelDifficulty == "hard":
            layout = level.getLayoutHard()
        else:
            layout = level.getLayoutHard()
		#initialize sprite variables and etc variables
        xcoord = (BRICK/2)
        ycoord = (BRICK/2)
        icons = level.getSprites()
        self.orb_sprites = pygame.sprite.RenderUpdates()
        self.block_sprites = pygame.sprite.RenderUpdates()
        self.powerUp_sprites = pygame.sprite.RenderUpdates()
        self.beast_sprites = pygame.sprite.RenderUpdates()
        self.orbTotal = 0
		#uses the arrays from the game board to load variables
        for i in xrange (len(layout)):
            for j in xrange (len(layout[i])):
                coord = [ i*BRICK + xcoord, j*BRICK + ycoord ]
                if layout[i][j] == level.MANPAK:
                    self.manpak = Manpak(icons[level.MANPAK],coord)
                elif layout[i][j] == level.ORB:
                    orb = Sprite.Sprite(icons[level.ORB],coord)
                    self.orb_sprites.add(orb)
                    self.orbTotal += 1
                elif layout[i][j] == level.BLOCK:
                    block = Sprite.Sprite(icons[level.BLOCK],coord)
                    self.block_sprites.add(block)
                elif layout[i][j] == level.BEAST:
                    beast = Beast(coord,icons[level.BEAST],icons[level.BEASTSCARED])
                    self.beast_sprites.add(beast)
                    orb = Sprite.Sprite(icons[level.ORB],coord)
                    self.orb_sprites.add(orb)
                    self.orbTotal += 1
                elif layout[i][j] == level.POWERUP:
                    powerUp = Sprite.Sprite(icons[level.POWERUP],coord)
                    self.powerUp_sprites.add(powerUp)
        self.manpak_sprites = pygame.sprite.RenderUpdates((self.manpak))
示例#4
0
def menu():
    global current_level
    current_level = 1
    screen = pygame.display.set_mode((900, 500))
    screen.fill((0, 191, 255))
    menu_run = True
    screen.blit(menu_image, (240, 20))
    title_font = pygame.font.SysFont('Calibri', 60)
    text = title_font.render('Touch Typer', False, (149, 85, 0))
    screen.blit(text, (330, 400))
    about = button.draw_bordered_rounded_rect(screen, (180, 320, 150, 35), (177, 156, 217), (0, 0, 0), 5, 0, "About", (255, 255, 255), (225, 328))
    play = button.draw_bordered_rounded_rect(screen, (550, 320, 150, 35), (177, 156, 217), (0, 0, 0), 5, 0, "Play", (255, 255, 255), (600, 328))
    pygame.display.flip()
    while menu_run:
        for event in pygame.event.get():
            pos = pygame.mouse.get_pos()
            if event.type == pygame.QUIT:
                pygame.quit()
            elif play.collidepoint(pos) and event.type == pygame.MOUSEBUTTONDOWN:
                menu_run = False
                run_level(levels.level1())
            elif about.collidepoint(pos) and event.type == pygame.MOUSEBUTTONDOWN:
                menu_run = False
                about_menu()
示例#5
0
文件: run.py 项目: KaosJL/pyBros
 def levels(self):
     levels.level1(self.screen, self.resolution, self.loads)
示例#6
0
def tick(level):
	player = level.sprites[0]

	maybe_x = player.x
	maybe_y = player.y
	relocate_y = False
	relocate_x = False
	allow_jump = True

	if(player.left):
		player.vel_left = run_speed
	else:
		player.vel_left = 0
	if(player.right):
		player.vel_right = run_speed
	else:
		player.vel_right = 0

	player.vel_y += fall_speed
	maybe_y = player.y + player.vel_y

	maybe_x = player.x + player.vel_right - player.vel_left

	if(maybe_y + player.height > floor_y):
		player.y = floor_y - player_height
		player.vel_y = 0
		relocate_y = True
	

	if(maybe_x < 0):
		player.x = 0
		relocate_x = True

	if(maybe_x + player.width > display_width):
		player.x = display_width - player.width
		relocate_x = True


	player_rect = pygame.Rect(maybe_x, maybe_y, player.width, player.height)
	for sprite in level.sprites:
		'''
		Used for blockade collision detection
		'''
		if(isinstance(sprite, blockade)):
			sprite_rect = sprite.getRect()
			if(player_rect.colliderect(sprite_rect)):
				
				if(player.x < sprite.x and player.y + player.height > sprite.y + 1 and player.y < sprite.y + sprite.height - 1):
					#player.x = player.x + ((player.x + player.width) - sprite.x)
					player.x = sprite.x - player.width
					player.vel_right = 0
					relocate_x = True
				if(player.x > sprite.x and player.y + player.height > sprite.y + 1 and player.y < sprite.y + sprite.height - 1):
					#player.x = player.x + (player.x - (sprite.x + sprite.width))
					player.x = sprite.x + sprite.width
					player.vel_left = 0
					relocate_x = True
					
				if(player.y + player.height < sprite.y + 1):
					player.vel_y = 0
					#player.y = player.y + (sprite.y - (player.y + player.height))
					player.y = sprite.y - player.height
					relocate_y = True
				if(player.y > sprite.y + sprite.height):
					player.vel_y = 0
					allow_jump = False
					#player.y = player.y + (sprite.y - (player.y + player.height))
					player.y = sprite.y + sprite.height
					relocate_y = True

		'''
		Used for portal collision detection
		'''
		if(isinstance(sprite, portal)):
			sprite_rect = sprite.getRect()
			if(player_rect.colliderect(sprite_rect)):
				player.level_go_pos = sprite.dir

	if(player.level_go_pos != player.level_pos):
		if(player.level_go_pos == 1):
			level.sprites = level1(player).sprites
		if(player.level_go_pos == 2):
			level.sprites = level2(player).sprites
		player.level_pos = player.level_go_pos
	else:

		if(not relocate_y):
			player.y = maybe_y
		else:
			if(0 <= player.vel_y < 1 and player.jumping and allow_jump):
				player.vel_y = jump_height

		if(not relocate_x):
			player.x = maybe_x