def run_game(): pygame.init() pygame.mixer.init() pygame.mixer.pre_init(44100, 16, 2, 4096) # frequency, size, channels, buffersize pygame.mixer.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_height, ai_settings.screen_width)) pygame.display.set_caption("ALIEN INVASION") play_button = Button(ai_settings, screen, "Play") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) arrow = Arrow(ai_settings, screen) bg_color = (100, 230, 200) num_of_arrows = Group() num_of_balloons = Group() gf.create_fleet(ai_settings, screen, arrow, num_of_balloons) pygame.mixer.music.load('sounds/bgmmusic.wav') pygame.mixer.music.play(-1) while True: gf.check_events(ai_settings, screen, stats, sb, play_button, arrow, num_of_arrows, num_of_balloons) if stats.game_active: arrow.update() num_of_arrows.update() gf.update_each_arrows(ai_settings, screen, stats, sb, play_button, arrow, num_of_balloons, num_of_arrows) gf.update_balloons(ai_settings, stats, sb, screen, arrow, num_of_balloons, num_of_arrows) gf.update_screen(ai_settings, screen, stats, sb, arrow, num_of_arrows, num_of_balloons, play_button)
def run_game(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Monster Invasion") #Make the play button play_button = Button(ai_settings, screen, "Play") #create an instance to store game stats and create a score board stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) #manke an arrow, a gorup of bullets,and a group of monsters arrow = Arrow(ai_settings, screen) #make a group to store bullets in bullets = Group() monsters = Group() gf.create_fleet(ai_settings, screen, arrow, monsters) print('here') arrow.blitme() #start the main loop for the game while True: gf.check_events(ai_settings, screen, stats, sb, play_button, arrow, monsters, bullets) if stats.game_active: arrow.update() gf.update_bullets(ai_settings, screen, stats, sb, arrow, monsters, bullets) gf.update_monsters(ai_settings, screen, stats, sb, arrow, monsters, bullets) gf.update_screen(ai_settings, screen, stats, sb, arrow, monsters, bullets, play_button)
def main(): pygame.init() clock = pygame.time.Clock() board = CreateEmptyBoard() FillBoard(board, COLORS) launchBall = False ball = getBubble(COLORS) ball.rect.centerx = STARTX nextBall = getBubble(COLORS) # board[0][15] = copy.deepcopy(ball) # setPosition(board) arrow = Arrow() while 1: # main game loop display.fill(BEIGE) vector, angle = getVector() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() if event.type == MOUSEBUTTONDOWN: if not launchBall: ball.shoot(angle) launchBall = True if event.type == MOUSEMOTION: arrow.update(angle, vector) drawBoard(board) nextBall.draw() if ball is not None: ball.update() ball.draw() #print(ball.rect.centerx, ball.rect.centery) ball, board, checkwin = stopBubble(board, ball) else: launchBall = False ball = Bubble(nextBall.color) nextBall = getBubble(COLORS) arrow.draw() if checkwin: return 1 elif checkBottom(board) == False: return 2 pygame.display.update() clock.tick(FPS)
class Slide(UserState): def __init__(self, app, hand, time=max_slide_wait, arrow=None): UserState.__init__(self, app, hand.user) self.hand = hand self.start_time = clock() self.time = time base.slide(hand.side_sign) self.arrow = arrow if not self.arrow: self.arrow = Arrow(self.app, hand.user, hand.side) self.arrow.play_trigger() self.arrow.update(base.nui.users) print 'time', time self.timer(time, self.timeout) def hand_move(self, hand): if hand.side == self.hand.side and not self.arrow.is_playing: max_extension = 0.55 pos = hand.positions[-1].x * hand.side_sign time = max(0.0, min(1.0, (pos - hand_trigger) / (max_extension - hand_trigger))) self.time = max_slide_wait - time * (max_slide_wait - min_slide_wait) self.timer(self.time - (clock()-self.start_time), self.timeout) self.arrow.set_time_at_speed(time) self.arrow.update(base.nui.users) UserState.hand_move(self, hand) def hand_in(self, hand): if hand.side != self.hand.side: self.arrow.destroy() self.next_state(Thumbnails(self.app, self.hand.user)) def hand_out(self, hand): if hand.side == self.hand.side: self.arrow.destroy() self.next_state(Start(self.app)) def lost_user(self): self.arrow.destroy() def timeout(self): self.next_state(Slide(self.app, self.hand, self.time, self.arrow))