Пример #1
0
	def DodgeShootState(self):
		dodge_list = []
		for player in self.player_list:
			px = player.rect.centerx
			py = player.rect.centery
			for s in player.shots:
				if danger_zone(s, self.rect, 80):
					angle = pos_to_theta(self.rect.centery-s.y, self.rect.centerx-s.x)

					if angle > 0: self.flag_left = True
					else: self.flag_left = False

					if self.flag_left:  
						self.rect.x += -self.MOVE_SPEED*math.cos(math.radians(angle))
						self.rect.y +=  self.MOVE_SPEED*math.sin(math.radians(angle))
					else: 
						self.rect.x +=  self.MOVE_SPEED*math.cos(math.radians(angle))
						self.rect.y += -self.MOVE_SPEED*math.sin(math.radians(angle))
					break
			else:
				self.transition = 'MOVE'
					
			angle = pos_to_theta(self.rect.centery-py, self.rect.centerx-px)
			old_center = self.rect.center
			self.image_rotate = pygame.transform.rotate(self.image, angle)
			self.rect_rotate = self.image_rotate.get_rect(center = old_center)

			if time.time() - self.shot_interval > 2:
				self.shot_interval = time.time()
				self.shots.append(Bullet(self.rect_rotate, angle, 'ENEMY'))
Пример #2
0
	def key_handler(self, pressed_key, mouse_event):
		#User Movement
		x,y = mouse_event.get_pos()
		b1, b2, b3 = mouse_event.get_pressed()
		angle = pos_to_theta(self.rect.centery-y,self.rect.centerx-x)
#		angle = -90
		old_center = self.rect.center
		self.image_rotate = pygame.transform.rotate(self.image, angle)
		self.rect_rotate = self.image_rotate.get_rect(center = old_center)

		if pressed_key[K_a]:  
			self.rect.x += -self.MOVE_SPEED*math.cos(math.radians(angle))
			self.rect.y +=  self.MOVE_SPEED*math.sin(math.radians(angle))
		if pressed_key[K_d]: 
			self.rect.x +=  self.MOVE_SPEED*math.cos(math.radians(angle))
			self.rect.y += -self.MOVE_SPEED*math.sin(math.radians(angle))
		if pressed_key[K_w]:
			self.rect.x += -self.MOVE_SPEED*math.sin(math.radians(angle))
			self.rect.y += -self.MOVE_SPEED*math.cos(math.radians(angle))
		if pressed_key[K_s]:  
			self.rect.x +=  self.MOVE_SPEED*math.sin(math.radians(angle))
			self.rect.y +=  self.MOVE_SPEED*math.cos(math.radians(angle))

		if b1:
#			if len(self.shots) < self.max_shots:
			if time.time() - self.shot_interval > self.SHOT_SPEED:
				self.shot_interval = time.time()
				self.shots.append(Bullet(self.rect_rotate, angle, 'PLAYER'))
Пример #3
0
	def IdleState(self):
		for player in self.player_list:
			px = player.rect.centerx
			py = player.rect.centery		
			angle = pos_to_theta(self.rect.centery-py, self.rect.centerx-px)
			old_center = self.rect.center
			self.image_rotate = pygame.transform.rotate(self.image, angle)
			self.rect_rotate = self.image_rotate.get_rect(center = old_center)
			if time.time() - self.shot_interval > 2:
				self.shot_interval = time.time()
				self.shots.append(Bullet(self.rect_rotate, angle, 'ENEMY'))
Пример #4
0
    def update(self, screen, player_list):
        dodge_flag = False
        for player in player_list:
            px = player.rect.centerx
            py = player.rect.centery
            #dodge
            for s in player.shots:
                if danger_zone(s, self.rect, 50) or dodge_flag:
                    dodge_flag = True
                    if self.rect.centerx > 790 or self.rect.centerx < 10:
                        pass
                    elif s.x > self.rect.centerx:
                        if player.WEAPON == 1:
                            self.rect.x -= 5
                        else:
                            self.rect.x -= 3
                    else:
                        if player.WEAPON == 1:
                            self.rect.x += 5
                        else:
                            self.rect.x += 3

                    if self.rect.centery < 10:
                        pass
                    elif s.y > self.rect.centery and math.fabs(
                            s.y - self.rect.centery) < 70:
                        self.rect.y -= 3

            #   if danger_zone(s, self.rect, 100):
                    if math.fabs(s.x - self.rect.x) > 50:
                        dodge_flag = False
                else:

                    if math.fabs(py - self.rect.centery) > 500:
                        self.rect.y += 3
                    elif math.fabs(py - self.rect.centery) < 100:
                        self.rect.y -= 3

                    if math.fabs(px - self.rect.centerx) > 20:
                        if px > self.rect.centerx:
                            self.rect.x += 3
                        else:
                            self.rect.x -= 3
                    else:
                        if time.time() - self.shot_interval > 2:
                            self.shot_interval = time.time()
                            self.shots.append(
                                Bullet(self.rect.centerx, self.rect.bottom,
                                       'ENEMY'))

        for s in self.shots:
            s.update(screen)

        screen.blit(self.image, self.rect)
Пример #5
0
 def ShootState(self):
     for player in self.player_list:
         px = player.rect.centerx
         for s in player.shots:
             if danger_zone(s, self.rect, 80) and s.y > self.rect.centery:
                 self.transition = 'DODGE'
         else:
             if math.fabs(px - self.rect.centerx) < 30:
                 if time.time() - self.shot_interval > 2:
                     self.shot_interval = time.time()
                     self.shots.append(
                         Bullet(self.rect.centerx, self.rect.bottom,
                                'ENEMY'))
             else:
                 self.transition = 'APPROACH'
Пример #6
0
 def key_handler(self, pressed_key):
     if pressed_key[K_LEFT]: self.rect.move_ip(-self.MOVE_SPEED, 0)
     if pressed_key[K_RIGHT]: self.rect.move_ip(self.MOVE_SPEED, 0)
     if pressed_key[K_UP]: self.rect.move_ip(0, -self.MOVE_SPEED)
     if pressed_key[K_DOWN]: self.rect.move_ip(0, self.MOVE_SPEED)
     if pressed_key[K_SPACE]:
         if self.WEAPON == 0:
             #       if len(self.shots) < self.max_shots:
             if time.time() - self.shot_interval > self.SHOT_SPEED:
                 self.shot_interval = time.time()
                 self.shots.append(
                     Bullet(self.rect.centerx, self.rect.top, 'PLAYER'))
         if self.WEAPON == 1:
             if time.time() - self.shot_interval < self.LASER_SPEED:
                 self.shots.append(
                     Laser(self.rect.centerx, self.rect.top, 'PLAYER'))
             elif time.time() - self.shot_interval > self.LASER_SPEED * 5:
                 self.shot_interval = time.time()
Пример #7
0
	def MoveState(self):
		for player in self.player_list:
			for s in player.shots:
				if danger_zone(s, self.rect, 80):
					self.transition = 'DODGESHOOT'
			px = player.rect.centerx
			py = player.rect.centery
			angle = pos_to_theta(self.rect.centery-py, self.rect.centerx-px)			

			old_center = self.rect.center
			self.image_rotate = pygame.transform.rotate(self.image,angle)
			self.rect_rotate = self.image_rotate.get_rect(center = old_center)

			if self.flag_left:  
				self.rect.x += -self.MOVE_SPEED*math.cos(math.radians(angle))
				self.rect.y +=  self.MOVE_SPEED*math.sin(math.radians(angle))
			else: 
				self.rect.x +=  self.MOVE_SPEED*math.cos(math.radians(angle))
				self.rect.y += -self.MOVE_SPEED*math.sin(math.radians(angle))


#			if self.flag_approach == 1:
#				self.rect.x += -self.MOVE_SPEED*math.sin(math.radians(angle))
#				self.rect.y += -self.MOVE_SPEED*math.cos(math.radians(angle))
#			elif self.flag_approach == 2:  
#				self.rect.x +=  self.MOVE_SPEED*math.sin(math.radians(angle))
#				self.rect.y +=  self.MOVE_SPEED*math.cos(math.radians(angle))

			if time.time() - self.current_time > self.RANDOM:
				self.flag_left = False if self.flag_left else True
				self.current_time = time.time()
				self.RANDOM = random.randint(1,3)				

			if time.time() - self.shot_interval > 2:
				self.shot_interval = time.time()
				self.shots.append(Bullet(self.rect_rotate, angle, 'ENEMY'))