Beispiel #1
0
    def _update_state(self):
        if collision_screen_left(self.ball):
            self.paddle1.lives -= 1
            self.ball.reset()
            self.background.flash()

        if collision_screen_right(self.ball):
            self.paddle2.lives -= 1
            self.ball.reset()
            self.background.flash()

        if collision_screen_top(self.ball) or collision_screen_bottom(
                self.ball):
            self.ball.acceleration = np.multiply(self.ball.acceleration,
                                                 np.array([1, -1]))

        self.ball.position += self.ball.acceleration
        self.ball.acceleration_multiply(
            np.array([1 + self.timer / 100000000, 1]))

        if collision(self.paddle1, self.ball):
            self.ball.accelerate(acc_factor(self.paddle1, self.ball))
            self.background.flash((0, 255, 0), 100)

        if collision(self.paddle2, self.ball):
            self.ball.accelerate(acc_factor(self.paddle2, self.ball))
            self.background.flash((0, 255, 0), 100)

        self.background.update()
Beispiel #2
0
 def update(self, keystate):
     collision(self, self.owner.game_items, self.rect)
     if self.rotation >= 360:
         self.rotation = 0
     self.rotation = self.rotation + self.move_speed
     x = self.gap * sin(self.rotation * pi / 180)
     y = self.gap * cos(self.rotation * pi / 180)
     self.rect.center = (self.owner.rect.center[0] + x,
                         self.owner.rect.center[1] + y)
Beispiel #3
0
    def update(self, keystate):
        if self.imageindex >= 3:
            self.rect.move_ip(self.movevector.x, self.movevector.y)
            collision(self, self.owner.game_items, rect=self.rect)
        if self.nowkeeptime == 0:
            self.nowkeeptime = self.keeptime
            if self.imageindex < len(self.images) - 1:
                self.imageindex = self.imageindex + 1
                self.image = self.images[self.imageindex]

            else:
                self.killself()
        else:
            self.nowkeeptime = self.nowkeeptime - 1
Beispiel #4
0
    def update(self, keystate):
        if self.nowkeeptime == 0:
            self.nowkeeptime = self.keeptime
            if self.imageindex < len(self.images) - 1:
                if self.imageindex >= 2 and self.imageindex <= 6:
                    self.rect.move_ip((0, self.speed))
                    collision(self, self.owner.game_items, rect=self.rect)
                self.imageindex = self.imageindex + 1
                self.image = self.images[self.imageindex]

            else:
                self.killself()
        else:
            self.nowkeeptime = self.nowkeeptime - 1
Beispiel #5
0
def colli2(foes, bossFoe, ownBullets):
    for foe in foes:
        for bullet in ownBullets:
            if collision(foe.foe, bullet):
                replace = foe.coll(bullet.atr, drops, foes)
                if replace:
                    foe = foe.replaceMove()
                bullet.die(ownBullets)
    for foe in bossFoe:
        for bullet in ownBullets:
            if collision(foe.foe, bullet):
                replace = foe.coll(bullet.atr, drops, bossFoe)
                if replace:
                    foe = foe.replaceMove()
                bullet.die(ownBullets)
Beispiel #6
0
    def move(self, keystate):
        direction = None
        if keystate[K_w]:
            direction = (0, -1)
        elif keystate[K_d]:
            direction = (1, 0)
        elif keystate[K_s]:
            direction = (0, 1)
        elif keystate[K_a]:
            direction = (-1, 0)
        if direction:

            if self.direct == direction:
                self.new_rect = self.rect.move(direction[0] * self.speed[0],
                                               direction[1] * self.speed[1])
                # print "#", self.new_rect.right
                if collision(self) and self.bgmap.map_passive(self.new_rect):
                    self.rect = self.new_rect
                    self.rect = self.rect.clamp(SCREENRECT)
                if self.contrlmap and direction == (
                        0, -1) and self.rect.top <= SCREEN_HEIGHT / 2:
                    self.bgmap.move_by_player(self.speed[1])
            else:
                self.direct = direction
                self.image = self.images[self.direct]
Beispiel #7
0
 def check_conditions(self):
     if not collision(self.mold, rect=self.mold.rect
                      ) or not self.mold.bgmap.map_passive(self.mold.rect):
         self.mold.both = False
         print self.mold.name + "both no pass"
     else:
         self.mold.both = True
         return 'move'
Beispiel #8
0
    def update(self, keystate):
        if self.nowkeeptime == 0:
            if self.imageindex <= len(self.images) - 1:
                if self.grow:
                    self.imageindex = self.imageindex + 1
                    if self.imageindex == len(self.images) - 1:
                        self.grow = False
                        collision(self, self.owner.game_items, rect=self.rect)
                else:
                    if self.imageindex == 0:
                        self.killself()
                        return
                    self.imageindex = self.imageindex - 1
                self.image = self.images[self.imageindex]

                self.nowkeeptime = self.keeptime[self.imageindex]
        else:
            self.nowkeeptime = self.nowkeeptime - 1
def update():

    global game_state
    global game_state_old
    key_pressed = pygame.key.get_pressed()

    if game_state is PAUSED:
        if key_pressed[K_y]:
            game_state = MENU
        if key_pressed[K_n]:
            game_state = game_state_old
        return
    if game_state is MENU:
        if menu.update() is True:
            game_state_old = game_state
            game_state = PLAYING
        return

    if CAMERA.x >= LEVEL_END:
        game_state_old = game_state
        game_state = COMPLETED

    if key_pressed[K_ESCAPE]:
        game_state_old = game_state
        game_state = PAUSED

    if key_pressed[K_r]:
        game_state = PLAYING
        initialize()

    if key_pressed[K_e]:
        player.lives += 1

    if player.lives < 1:
        return

    if game_state is COMPLETED:
        return
    update_movement()

    collision()

    update_states()
Beispiel #10
0
def colli1(own, foes, bossFoe, bullets, drops):
    global ownDie
    global dieTime
    for foe in foes:
        if collision(own, foe.foe, -10):
            foe.coll(own.atr, drops, foes)
            own.die()
    for foe in bossFoe:
        if collision(own, foe.foe, -10):
            foe.coll(0, drops, bossFoe)
            own.die()
    for bullet in bullets:
        if collision(own, bullet, -10):
            bullets.remove(bullet)
            own.die()
    for drop in drops:
        if collision(own, drop, 30):
            #drops.remove(drop)
            #own.barrage.barUp()
            drop.coll(drops, own)
Beispiel #11
0
    def check_conditions(self):
        if not SCREENRECT.contains(self.mold.new_rect)\
                            or not self.mold.bgmap.map_passive(self.mold.new_rect):
            return "thinkdirect"
        elif self.mold.conf.get(
                "turn_rate") and random.random() < self.mold.conf["turn_rate"]:
            return "thinkdirect"

        passive = collision(self.mold)
        if passive:
            self.mold.rect = self.mold.new_rect
        if self.mold.conf.get("target"):
            return "thinkdirect"
        return
Beispiel #12
0
	def __init__ (self, arg):
		sf.Sprite.__init__(self, arg)
		self._w, self._h = 0, 0

		#States
		self.clip_enabled = False

		#General sub-classes.
		self.resize = resize(self)
		self.clip = clip(self)
		self.box = box(self)
		self.children = []; self.children_class = children_class(self)
		self.animation = animation(self)

		#Collision sub-classes.
		self.overlap = overlap(self)
		self.collision = collision(self)
		self.slope_collision = slope_collision(self)
Beispiel #13
0
def main():


    open_canvas()
    global mainback
    mainback = Mainback()
    global start
    start = False

    while(start == False):
        handle_events()
        clear_canvas()
        mainback.draw()
        update_canvas()
        delay(0.08)

    #클래스 선언
    global hero
    hero = Hero()
    rabbit = Rabbit()
    rabbit_group = [Rabbit() for i in range(600)]
    land = Land()
    wood = Wood()
    global torch
    torch = Torch()
    global fire
    fire = Fire()
    eskimo = Eskimo()
    attack_fire = Attack_fire()
    attack_fire_group = [Attack_fire() for i in range(100)]
    background = BackGround()
    global ui
    ui = Ui()
    firewood = Firewood()
    firewood_group = [Firewood() for i in range(600)]

    #변수 선언
    rabbit_group_counter = 0
    rabbit_group_collision_counter = 0
    attack_group_counter = 0
    attack_group_update_counter = 0
    attack_group_collision_counter = 0
    rabbit_alive_counter = 0
    attack_group_alive_check = False
    attack_group_alive_counter = 0
    attack_group_limit = 20
    rabbit_group_draw_counter = 0
    firewood_num_counter = 0
    firewood_num_update_counter = 0
    firewood_collide_counter = 0
    rabbit_group_counter2 = 0
    rabbit_jump = False
    rabbit_num = 10
    firewood_num = 10
    rack_block = 0
    eskimo_counter = 0


    global running
    running = True



    while running:
        #핸들 이벤트
        handle_events()

        #업데이트
        hero.update()
        background.update()
        land.update()
        wood.update()
        fire.update()
        torch.update()
        eskimo.update()
        ui.update(hero.x, hero.y, hero.ability)
        for rabbit in rabbit_group: # 토끼 업데이트
            if(rabbit_group_counter == rabbit_num):
                rabbit_group_counter = 0
                break
            if(rabbit.alive):
                rabbit.update()
            rabbit_group_counter += 1

        # for rabbit in rabbit_group: # 토끼 업데이트
        #     if(rabbit_group_counter2 == 1):
        #         print("%d" % rabbit.x)
        #         break
        #     rabbit_group_counter2 += 1

        for attack_fire in attack_fire_group: # 공격불 업데이트
            if(attack_group_update_counter == hero.attack_num):
                attack_fire.init_direction()
                attack_fire.alive = True # 공격불이 활성화 됨
                attack_fire.init_fire()
                attack_group_update_counter = 0
                break
            if(attack_fire.alive):
                attack_fire.update()
            attack_group_update_counter += 1

        for firewood in firewood_group: # 장작 업데이트
            if(firewood_num_update_counter == firewood_num):
                firewood_num_update_counter = 0
                break
            firewood.update()
            firewood_num_update_counter += 1

        #함수
        for rabbit in rabbit_group: #토끼와 히어로의 충돌체크
            if(rabbit_group_collision_counter == rabbit_num):
                rabbit_group_collision_counter = 0
                break
            if(collision(rabbit, hero)):
                rabbit.y += 50
                mainback.hero_die = True
                mainback.die_sound()
                running = False
            rabbit_group_collision_counter += 1

        for rabbit in rabbit_group: # 토끼와 공격불의 충돌체크
            if(rack_block == rabbit_num):
                rack_block = 0
                break
            for attack_fire in attack_fire_group:
                if(attack_group_collision_counter == hero.attack_num):
                    attack_group_collision_counter = 0
                    break
                if(collision(rabbit, attack_fire) and rabbit.alive and attack_fire.alive):
                    attack_fire.alive = False
                    rabbit.alive = False
                    rabbit.die = True
                    hero.kill += 1
                attack_fire.die = False
                attack_group_collision_counter += 1
            rack_block += 1

        for attack_fire in attack_fire_group:
            if(eskimo_counter == hero.attack_num):
                eskimo_counter = 0
                break
            if(collision(eskimo, attack_fire)):
                 attack_fire.alive = False
                 eskimo.x -= 10
                 eskimo.hp -= 1
                 if(eskimo.hp == 0):
                    mainback.eskimo_die = True
                    running = False
                    mainback.win_sound()
            attack_fire.die = False
            eskimo_counter += 1
        if(collision(wood, hero)): # 나무와 주인공 충돌체크
            fire.collide = True
            if(ui.firewood_num != 0):
                fire.life += ui.firewood_num*250
                ui.firewood_num = 0
        else:
            fire.collide = False


        if(collision(eskimo, hero)): # 주인공과 에스키모 충돌체크
            mainback.hero_die = True
            running = False
            mainback.die_sound()

        for firewood in firewood_group: # 장작과 주인공 충돌체크
            if(firewood_collide_counter == firewood_num):
                firewood_collide_counter = 0
                break
            if(collision(firewood, hero) and firewood.die == False):
                ui.firewood_num += 1
                firewood.die = True
            firewood_collide_counter += 1

        for rabbit in rabbit_group: # 토끼 출현!
            if(rabbit_alive_counter == rabbit_num):
                break
            if(rabbit.die == False):
                rabbit.alive = True
                rabbit_alive_counter += 1

        if(fire.die): # 불이 꺼지면 토끼들이 마구마구 몰려온다.
            rabbit_num = 500

        for attack_fire in attack_fire_group: # 불 스킬 존재 유무
            if(attack_fire.alive):
                attack_group_alive_counter = 0
                break
            attack_group_alive_counter += 1
            if(attack_group_alive_counter == hero.attack_num):
                hero.attack_num = 0


        for attack_fire in attack_fire_group: # 화면 밖을 벗어나면 불 스킬 사망 판정
            if(attack_fire.x >= 900 or attack_fire.x <= -100):
                attack_fire.alive = False
        print("stage = %d" % background.stage)
        #스테이지
        if(hero.kill == 10 and background.stage == 1):
            print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
            rabbit_num += 20
            hero.ability += 10
            firewood_num += 5
            background.stage = 2
        if(hero.kill == 30 and background.stage == 2):
            rabbit_num += 30
            firewood_num += 10
            hero.ability += 10
            background.stage = 3
            background.stage3_music()
        if(hero.kill == 60 and background.stage == 3):
            rabbit_num += 40
            firewood_num += 15
            hero.ability += 10
            background.stage = 4
        if(hero.kill == 80 and background.stage == 4):
            rabbit_num += 50
            firewood_num += 20
            hero.ability += 10
            background.stage = 5
            eskimo.alive = True
            background.stage5_music()
        if(background.stage == 5):
            rabbit_jump = True

        if(rabbit_jump):
             for rabbit in rabbit_group:
                 rabbit.y += 5

        # print("%d" % hero.attack_num)
        print("킬 수 : %d num : %d" % (hero.kill, rabbit_num))
        clear_canvas()


        #그리기
        background.draw()
        fire.draw()
        wood.draw()
        torch.draw()
        hero.draw()
        eskimo.draw()
        # eskimo.draw_bb()
        # hero.draw_bb()
        for rabbit in rabbit_group: # 적토끼 출력
            if(rabbit_group_draw_counter == rabbit_num):
                rabbit_group_draw_counter = 0
                break
            if(rabbit.alive):
                rabbit.draw()
            rabbit_group_draw_counter += 1
            # rabbit.draw_bb()
        for attack_fire in attack_fire_group: # 공격 불 출력
            if(attack_group_counter == hero.attack_num):
                attack_group_counter = 0
                break
            if(attack_fire.alive):
                attack_fire.draw()
            # attack_fire.draw_bb()
            attack_group_counter += 1
        for firewood in firewood_group: # 장작 출력
            if(firewood_num_counter == firewood_num):
                firewood_num_counter = 0
                break
            firewood.draw()
            firewood_num_counter += 1
        land.draw()
        ui.draw()



        update_canvas()

        delay(0.06)

    while(mainback.hero_die or mainback.eskimo_die):
        handle_events()
        clear_canvas()
        mainback.draw()
        update_canvas()
        delay(0.08)



    close_canvas()
Beispiel #14
0
 def update(self, keystate):
     collision(self, self.owner.game_items, rect=self.rect)
     self.rect.move_ip(
         (self.speed * self.direct.x, self.speed * self.direct.y))
     if not SCREENRECT.colliderect(self.rect):
         self.killself()
Beispiel #15
0
                    missile2(Ship.x + 8, Ship.y - 40, 'data2/missile2.jpg'))

    for m in Missile:
        if m.y >= 0:
            m.render()
            m.y -= m.mov
    for m in Missile2:
        if m.y >= 0:
            m.render()
            m.y -= m.mov

    Score(score)

    for m in Missile:
        if m.y > 0:
            if d == 0 and collision(m.x, m.y, enemy.x, enemy.y) == 1:
                del enemy
                del m
                d = 1
                score += 1
            if d2 == 1 and collision(m.x, m.y, enemy2.x, enemy2.y) == 1:
                del enemy2
                del m
                d2 = 0
                score += 1

    for m in Missile2:
        if m.y > 0 and d == 0:
            if collision(m.x, m.y, enemy.x, enemy.y) == 1:
                del enemy
                enemy2 = alien2(50 * row, 50 * col, 'data2/alien2.png')
Beispiel #16
0
        if event.type == MOUSEBUTTONDOWN:            
            firebullet = True
            mbdx,mbdy = pygame.mouse.get_pos()
            posy = mbdy
            posx = mbdx
            bullet_x = x            
        
    screen.blit(background, (0,0))

    if existball == True:
        x,y = pygame.mouse.get_pos() 
        x = x - mouse_c.get_width()/2
        y = y - mouse_c.get_height()/2
        screen.blit(mouse_c,(x,y))
        pygame.mouse.set_visible(False)
        existball = collision(listbball,x,y)        
    if existball == False:
        screen.blit(balldefeated,(x,y))
        
        
        
    if existbball == True:
        if existball == True:
            bball_x,bball_y = badball_1.move(bball_x, bball_y, x, y)
            listbball[0] = [bball_x,bball_y]
            screen.blit(bball,(bball_x, bball_y))
            if firebullet == True:
                if abs(bullet_x - bball_x)<30 and abs(bullet_y-bball_y)<30:
                    existbball = False
                    firebullet = False                    
    if existbball == False: