Exemplo n.º 1
0
 def create_bullet(self,tower,badguy):
 	bul = objects.bullet(self,tower,badguy)
     bul.speed = badguy.speed * 2
     bul.power = tower.power
     bul.visual_coord = tower.visual_coord[:]
     self.tick_listeners.append(bul)
     return bul
Exemplo n.º 2
0
 def create_bullet(self,tower,badguy):
 	bul = objects.bullet(self,tower,badguy,self.towersprites)
     bul.speed = badguy.speed * 2
     bul.power = tower.power
     bul.visual_coord = tower.visual_coord[:]
     self.need_update = True
     return bul
Exemplo n.º 3
0
    def handle(self, event, screen):
        State.handle(self, event)

        # Pressing
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                if self.hero.isAlive:
                    self.hero.dv = -c.velocity
                    self.hero.moving_l = True

            if event.key == K_RIGHT:
                if self.hero.isAlive:
                    self.hero.dv = c.velocity
                    self.hero.moving_r = True

            if event.key == K_SPACE and not self.waiting:
                if not self.hero.hold and self.hero.isAlive:
                    avail, n_avail = where_ammo(self.hero.ammo)
                    if n_avail > 0:
                        self.hero.ammo[avail[0]] = objects.bullet(self.hero.x[4], self.hero.y[4])
                        self.hero.hold = True
                        self.hero.ammo_holded = avail[0]

            if event.key == K_x and not self.waiting:
                if self.hero.isAlive:
                    for j in range(c.n_bombs):
                        if self.hero.special[0][j].isAlive and self.hero.special[0][j].status == 1:
                            self.hero.special[0][j].changeStatus(2)

            if event.key == K_c and not self.waiting:
                if self.hero.isAlive:
                    b = False
                    for t in [2, 1]:
                        for j in range(c.n_bombs):
                            if self.hero.special[1][j].isAlive and self.hero.special[1][j].status == t:
                                if b:
                                    break
                                self.hero.special[1][j].changeStatus(self.hero.special[1][j].status + 1)
                                b = True
            if event.key == K_RETURN:
                print "save!"
                pygame.image.save(screen, "screencap.png")
        # Releasing
        if event.type == KEYUP:
            if event.key == K_LEFT:
                if self.hero.isAlive:
                    self.hero.dv = c.velocity if self.hero.moving_r else 0
                    self.hero.moving_l = False

            if event.key == K_RIGHT:
                if self.hero.isAlive:
                    self.hero.dv = -c.velocity if self.hero.moving_l else 0
                    self.hero.moving_r = False

            if event.key == K_SPACE:
                if self.hero.hold:
                    self.hero.hold = False
                    self.hero.ammo[self.hero.ammo_holded].hooked = False

            if event.key == K_x:
                pass
            if event.key == K_c:
                pass
Exemplo n.º 4
0
def movehero(cnt):
    global count
    global obj
    global bull_boss
    global enableshieldtime
    global userdragon
    global flagdragon
    bull_boss += 1

    def alarmhandler(signum, frame):
        ''' input method '''
        raise AlarmException

    def user_input(timeout=0.1):
        ''' input method '''
        signal.signal(signal.SIGALRM, alarmhandler)
        signal.setitimer(signal.ITIMER_REAL, timeout)

        try:
            text = getChar()()
            signal.alarm(0)
            return text
        except AlarmException:
            pass
        signal.signal(signal.SIGALRM, signal.SIG_IGN)
        return ''

    char = user_input()

    if char == 'd':
        hero.move_fwd(cnt)
        # hero.move_down()

    elif char == 'a':
        hero.move_bwd()

    elif char == 'w':
        hero.move_up(cnt)

    # elif char=='b':
    # 	hero.enable_boost()

    elif char == ' ':
        # enableshieldtime+=time.time()-y
        # y=time.time()
        if time.time() - enableshieldtime > 60 and hero.userdragon == 0:
            hero.enable_shield()
            enableshieldtime = time.time()
        # 	enableshieldtime=0

    elif char == 'b':
        count += 1
        obj = bullet(hero.xpos, hero.ypos + 1)
        # obj.hide_obs()
        # obj.move_bullets(cnt)
        # obj.check_bullet_collision()
        # obj.show_obs()

    elif char == 'q':
        quit()

    elif char == 'j':
        # hero.show_dragon(cnt)
        if flagdragon == 0:
            if hero.xpos > 30:
                hero.xpos = 30
            hero.userdragon = 1
            flagdragon = 1

    else:
        hero.move_down()

    if hero.userdragon == 1:
        count += 1

    if hero.userdragon == 1 and count % 2 == 0:
        # count+=1
        # if count%3==0:
        obj = bullet(hero.xpos + 2, hero.ypos + 45)
        obj.hide_obs()
        obj.move_bullets(cnt)
        obj.check_bullet_collision()
        obj.show_obs()

    if count >= 1 and hero.userdragon == 0:
        obj.hide_obs()
        obj.move_bullets(cnt)
        obj.check_bullet_collision()
        obj.show_obs()

    if bull_boss % 5 == 0:
        bull = boss_bullet(boss.xpos + 2, boss.ypos - 4)
        bull.hide_obs()
        bull.move_boss_bullets(cnt)
        bull.show_obs()
Exemplo n.º 5
0
    def handle(self, event, screen):
        State.handle(self, event)

        # Pressing
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                if self.hero.isAlive:
                    self.hero.dv = -c.velocity
                    self.hero.moving_l = True

            if event.key == K_RIGHT:
                if self.hero.isAlive:
                    self.hero.dv = c.velocity
                    self.hero.moving_r = True

            if event.key == K_SPACE and not self.waiting:
                if not self.hero.hold and self.hero.isAlive:
                    avail, n_avail = where_ammo(self.hero.ammo)
                    if n_avail > 0:
                        self.hero.ammo[avail[0]] = objects.bullet(
                            self.hero.x[4], self.hero.y[4])
                        self.hero.hold = True
                        self.hero.ammo_holded = avail[0]

            if event.key == K_x and not self.waiting:
                if self.hero.isAlive:
                    for j in range(c.n_bombs):
                        if (self.hero.special[0][j].isAlive
                                and self.hero.special[0][j].status == 1):
                            self.hero.special[0][j].changeStatus(2)

            if (event.key == K_c and not self.waiting):
                if self.hero.isAlive:
                    b = False
                    for t in [2, 1]:
                        for j in range(c.n_bombs):
                            if (self.hero.special[1][j].isAlive
                                    and self.hero.special[1][j].status == t):
                                if b:
                                    break
                                self.hero.special[1][j].changeStatus(
                                    self.hero.special[1][j].status + 1)
                                b = True
            if event.key == K_RETURN:
                print 'save!'
                pygame.image.save(screen, 'screencap.png')
        # Releasing
        if event.type == KEYUP:
            if event.key == K_LEFT:
                if self.hero.isAlive:
                    self.hero.dv = c.velocity if self.hero.moving_r else 0
                    self.hero.moving_l = False

            if event.key == K_RIGHT:
                if self.hero.isAlive:
                    self.hero.dv = -c.velocity if self.hero.moving_l else 0
                    self.hero.moving_r = False

            if event.key == K_SPACE:
                if (self.hero.hold):
                    self.hero.hold = False
                    self.hero.ammo[self.hero.ammo_holded].hooked = False

            if event.key == K_x:
                pass
            if event.key == K_c:
                pass
Exemplo n.º 6
0
                        pygame.time.set_timer(pygame.USEREVENT+3, 1500)

                    if keys[pygame.K_SPACE]:
                        msg = "switching ships..."
                        pygame.time.set_timer(pygame.USEREVENT+3, 3000)
        if event.type == pygame.MOUSEMOTION:
            mouse = [event.pos[0], event.pos[1]]
            aimer = mouse
        if event.type == pygame.MOUSEBUTTONDOWN:
            if pygame.mouse.get_pressed()[0]:
                if screen == "game" and spaceship.loaded > 0 and spaceship.type == "gun":
                    aimer = [event.pos[0], event.pos[1]]
                    mouse = aimer
                    aimer = checkAimer()
                    spaceship.loaded -= 1
                    bullets.add(objects.bullet([400, 300], aimer))
                elif screen == "game" and spaceship.loaded <= 0 and spaceship.type == "gun":
                    msg = "out of ammo!"
                    pygame.time.set_timer(pygame.USEREVENT+3, 2000)
                if screen == "menu":
                    if start.check(mouse):
                        screen = "game"
                        spaceship.xvelocity = 0
                    if settings.check(mouse):
                        screen = "settings"
                        prev = "menu"
                    if how.check(mouse):
                        screen = "how"
                        prev = "menu"
                        page = 0
                    if quit.check(mouse):