예제 #1
0
	def __init__(self, x, y, speedX, speedY, imageName=None, colorkey=None, clipRect=None):
		Weapon.__init__(self, imageName, colorkey, clipRect)
		self.rect = Rect(x, y, 0, 0)
		self.speedX = speedX
		self.speedY = speedY
		self.atk = 5

		# Important if you want pinpoint accuracy
		self.floatX = float(self.rect.x)
		self.floatY = float(self.rect.y)

		self.angle = math.degrees(math.atan2(speedY, speedX))
		self.flipH = True
예제 #2
0
class Test_Weapon(unittest.TestCase):

    def setUp(self):
        self.w = Weapon(name="The Axe of Destiny", damage=20)

    def test_init(self):
        self.assertEqual(self.w.get_name(), "The Axe of Destiny")
        self.assertEqual(self.w.get_damage(), 20)

    def test_save(self):
        self.assertEqual(self.w.prepare_json(), {
            "name": "The Axe of Destiny",
            "damage": 20
        })
class TestWeapon(unittest.TestCase):
    def setUp(self):
        self.weapon = Weapon('Sword', 150, 0.5)

    def test_initialisation(self):
        self.assertEqual(self.weapon.w_type, 'Sword')
        self.assertEqual(self.weapon.damage, 150)
        self.assertEqual(self.weapon.crit, 0.5)

    def test_value_error(self):
        with self.assertRaises(ValueError):
            self.weapon = Weapon('Sword', 150, 2.5)

    def test_critical_hit(self):
        crit_hits = []
        for i in range(20):
            crit_hits.append(self.weapon.critical_hit())

        flag = [False, False]
        for i in crit_hits:
            if i:
                flag[0] = True
            if not i:
                flag[1] = True

        self.assertEqual(flag, [True, True])
    def get_treasure(hero):

        rand = random.randint(1, 4)
        if rand == 1:
            # hero.get_starting_mana()
            mana_points = random.randint(10, 200)
            hero.take_mana(mana_points)

            if hero.get_mana() == hero.starting_mana:
                print('Found mana. Hero mana is max.')
            else:
                print('Found mana. Hero mana is {}').format(hero.get_mana())

        elif rand == 2:
            health_points = random.randint(10, 20)
            hero.take_healing(health_points)

            if hero.get_health() == hero.starting_health:
                print('Found health. Hero health is max.')
            else:
                print('Found health. Hero health is {}').format(
                    hero.get_health())

        elif rand == 3:
            w = Weapon.load_weapon_from_file('weapons.json')
            print('Hero took:')
            print(w)
            hero.equip(w)

        else:
            s = Spell.load_spell_from_file('spells.json')
            print('Hero learnt')
            print(s)
            hero.learn(s)
예제 #5
0
    def __init__(self, **kwargs):
        self.name = kwargs['name']
        self.title = kwargs['title']
        self.health = kwargs['health']
        self.mana = kwargs['mana']
        self.mana_regeneration_rate = kwargs['mana_regeneration_rate']

        self.starting_health = kwargs['health']
        self.starting_mana = kwargs['mana']

        self.current_spell = None
        self.current_weapon = Weapon(name="Hands", damage=20)
예제 #6
0
class Hero(Creature):
    def __init__(self, **kwargs):
        self.name = kwargs['name']
        self.title = kwargs['title']
        self.health = kwargs['health']
        self.mana = kwargs['mana']
        self.mana_regeneration_rate = kwargs['mana_regeneration_rate']

        self.starting_health = kwargs['health']
        self.starting_mana = kwargs['mana']

        self.current_spell = None
        self.current_weapon = Weapon(name="Hands", damage=20)

    def known_as(self):
        return "{} known as the {}".format(self.name, self.title)

    def take_healing(self, healing_points):
        self.health = min(self.starting_health, self.health + healing_points)

    def take_mana(self, *args):
        if len(args) == 0:
            mana_value = self.mana + self.mana_regeneration_rate
            self.mana = min(self.starting_mana, mana_value)
        else:
            mana_value = self.mana + args[0]
            self.mana = min(self.starting_mana, mana_value)

    def attack(self, **kwargs):
        if kwargs['by'] == "weapon":
            if self.current_weapon is None:
                return 0
            else:
                return self.current_weapon.get_damage()

        if kwargs['by'] == "magic":
            if self.current_spell is None:
                return 0
            else:
                return self.current_spell.get_damage()
예제 #7
0
    def draw(self, screen):

        gun_img = Weapon.get_weapon_image( self.current_weapon )

        if self.direction == Direction.WEST:
            screen.blit(gun_img, (self.centerx - gun_img.get_rect().width, self.centery))

        elif self.direction == Direction.EAST:
            gun_img = pygame.transform.flip(gun_img, True, False)
            screen.blit(gun_img, (self.centerx, self.centery))

        elif self.direction == Direction.SOUTH:
            gun_img = pygame.transform.rotate(gun_img, 90)  # CCW
            screen.blit(gun_img, (self.centerx, self.centery))
        
        # weapon drawn below survivor
        elif self.direction == Direction.NORTH:
            south = pygame.transform.rotate(gun_img, 90)
            gun_img = pygame.transform.flip(south, False, True)
            screen.blit(gun_img, (self.centerx, self.centery - gun_img.get_rect().height))

        screen.blit(self.img, (self.x, self.y))
예제 #8
0
파일: WpnBlade.py 프로젝트: hmourit/Aleph
 def __init__(self, imageName=None, colorkey=None, clipRect=None, sound=None, soundVolume=1):
     Weapon.__init__(self, imageName, colorkey, clipRect, sound, soundVolume)
     self.attackAngle = 0
     self.hip = math.sqrt(self.rect.w * self.rect.w + self.rect.h * self.rect.h)
     self.melee = True
예제 #9
0
파일: WpnBite.py 프로젝트: hmourit/Aleph
 def __init__(self, imageName=None, colorkey=None, clipRect=None, *args):
     Weapon.__init__(self, sound="wolf_bite.wav", soundVolume=0.5)
     self.melee = True
 def test_value_error(self):
     with self.assertRaises(ValueError):
         self.weapon = Weapon('Sword', 150, 2.5)
예제 #11
0
 def make_enemy():
     enemy = Fights.load_rand_enemy()
     enemy.equip(Weapon.load_weapon_from_file('weapons.json'))
     enemy.learn(Spell.load_spell_from_file('spells.json'))
     return enemy
예제 #12
0
	def __init__(self):
		Weapon.__init__(self, "items-1small.png", None, Rect(110, 120, 9, 11))
		self.cooldown = 0
예제 #13
0
 def test_has_weapon(self):
     something = Enity("Ivo", 100)
     something.equip_weapon(Weapon("axe", 35, 0.5))
     self.assertTrue(something.has_weapon())
예제 #14
0
 def test_equip_weapon(self):
     something = Enity("Ivo", 100)
     a = Weapon("axe", 35, 0.5)
     something.equip_weapon(a)
     self.assertEqual(something.weapon, a)
예제 #15
0
	def __init__(self, imageName=None, colorkey=None, clipRect=None):
		Weapon.__init__(self, imageName, colorkey, clipRect, "bow_shot.wav")
		self.cooldown = 0
예제 #16
0
    def __init__(self):
        dinosaur_one = Dinosaur()
        dinosaur_one.type = 'T-Rex'
        dinosaur_one.energy = 100
        dinosaur_one.attack_power = 20
        dinosaur_one.health = 190
        dinosaur_one.attack_type = ''

        dinosaur_two = Dinosaur()
        dinosaur_two.type = 'Brontosaurus'
        dinosaur_two.energy = 90
        dinosaur_two.attack_power = 30
        dinosaur_two.health = 200
        dinosaur_two.attack_type = ''

        dinosaur_three = Dinosaur()
        dinosaur_three.type = 'Pterodactyl'
        dinosaur_three.energy = 80
        dinosaur_three.attack_power = 40
        dinosaur_three.health = 170
        dinosaur_three.attack_type = ''

        dino_attack_one = Weapon()
        dino_attack_one.type = 'Tail Whip'
        dino_attack_one.attack_power = 15

        # dino attacks
        dino_attack_two = Weapon()
        dino_attack_two.type = 'Bite'
        dino_attack_two.attack_power = 20

        dino_attack_three = Weapon()
        dino_attack_three.type = 'Roar'
        dino_attack_three.attack_power = 25

        none = Weapon()
        none.type = 'none'
        none.attack_power = 0

        self.dinosaur_list = [dinosaur_one, dinosaur_two, dinosaur_three]
        self.dino_attack_type_list = (dino_attack_one, dino_attack_two,
                                      dino_attack_three, none)
예제 #17
0
    def create_weapon(self):
        name = input("What is the weapon name?")
        max_damage = input("What is the max damage of the weapon?")

        return Weapon(name, max_damage)
예제 #18
0
파일: WpnBite.py 프로젝트: hmourit/Aleph
 def __init__(self, imageName=None, colorkey=None, clipRect=None, *args):
     Weapon.__init__(self, sound="wolf_bite.wav", soundVolume=0.5)
     self.melee = True
if __name__ == "__main__":
	main_fishers = {}
#	global totalspells
	first = create_context_map()
	mainmap,totalspells = first[0]
	fishers_on_game = first[1]
#	global locks_islands 
	locks_islands = []
	### One lock for each island###
#	for i in range(len(mainmap)):
#		locks_islands.append(threading.Lock())
	###-------------------------###	
#	m = thread_player(1)
#	m.start()	
	simple12 = Weapon("simpl1",10,10)
	simpl22 = Defense("simpl1",10,10)
	fish1  = Fisher("Brave fisher",100,simple12,simpl22,mainmap["island 0"],'0')
	fishers_on_game["Brave fisher"] = fish1
	
	simple1 = Weapon("simpl1",1,1)
	simpl2 = Defense("simpl1",1,1)
	fish11 = Fisher("Looser 1",1,simple1,simpl2,mainmap["island 0"],'0')
	fishers_on_game["Looser 1"] = fish11
	
	a = count_number_fishers_alive(fishers_on_game,1)
	if(a == 0):
		print("The game is running, no winners")
	else:
		print(a)	
	exit()
예제 #20
0
 def __init__(self):
     Weapon.__init__(self, "wpns-modern2.png", -1, Rect(48, 28, 24, 17),
                     "bullet_shot.ogg", 0.5)
     self.sheetCoord[0].append(pygame.Rect(82, 25, 26, 20))
     self.cooldown = 0
예제 #21
0
 def test_attack_with_weapopn(self):
     something = Enity("Ivo", 100)
     something.equip_weapon(Weapon("axe", 35, 0.5))
     self.assertEqual(something.attack(), 35)
예제 #22
0
    def __init__(self):

        robot_one = Robot()
        robot_one.name = 'George'
        robot_one.power_level = 100
        robot_one.weapon = ''
        robot_one.attack_power = 30
        robot_one.health = 200

        robot_two = Robot()
        robot_two.name = 'Jimmy'
        robot_two.power_level = 90
        robot_two.weapon = ''
        robot_two.attack_power = 40
        robot_two.health = 180

        robot_three = Robot()
        robot_three.name = 'Jill'
        robot_three.power_level = 80
        robot_three.weapon = ''
        robot_three.attack_power = 50
        robot_three.health = 160

        self.robots_list = [robot_one, robot_two, robot_three]

        weapon_one = Weapon()
        weapon_one.type = 'revolver'
        weapon_one.attack_power = 10

        weapon_two = Weapon()
        weapon_two.type = 'Light Saber'
        weapon_two.attack_power = 15

        weapon_three = Weapon()
        weapon_three.type = 'Sword'
        weapon_three.attack_power = 20

        none = Weapon()
        none.type = 'none'
        none.attack_power = 0

        self.weapon_list = [weapon_one, weapon_two, weapon_three, none]
예제 #23
0
class Player(PS.DirtySprite):
    IMAGES = None
    IMAGES_RIGHT = None
    IMAGES_LEFT = None
    IMAGES_FRONT = None
    IMAGES_BACK = None
    IMAGES_RIGHT_DMG = None
    IMAGES_LEFT_DMG = None
    IMAGES_FRONT_DMG = None
    IMAGES_BACK_DMG = None
    # attack images
    IMG_ATTACK_D = None  # 100 x 150 dimensions
    IMG_ATTACK_U = None
    IMG_ATTACK_R = None
    IMG_ATTACK_L = None
    # Animation cycle variables
    CYCLE = 0.5
    ADCYCLE = .05
    WIDTH = 100
    HEIGHT = 100

    def __init__(self, fps=1):
        # Call the parent class (Sprite) constructor
        PS.DirtySprite.__init__(self)
        self.image = PI.load("FPGraphics/MC/MCwalk/MCFront.png") \
            .convert_alpha()
        self.rect = self.image.get_rect()
        self.rect_copy = self.rect
        self.rect.x = 100
        self.rect.y = 100
        self.face = 'd'
        self.load_images()
        # self.speed both determines the speed of the player &
        # ensures the the player moves at an integer distance
        # during play (arbitrary value)
        self.speed = 1
        self.time = 0.0
        self.frame = 0
        self.got_key = False
        # will turn to True once you've run into the yellow block
        # collision conditions, if true, we will not move in that direction
        self.health = 20
        self.dmg_count = 0
        self.invincibility_frame = PI.load("FPGraphics/emptyImg.png") \
            .convert_alpha()
        self.weapon = Weapon()
        self.moved = False
        self.interval = 0
        self.modified_map = False
        self.banner = -1 #holds the ID of the sign that the player just read
        self.pill = False
        self.at_door_num = -1  # allows player to open door if player has key
        self.at_sign_num = -1  # if player is at a sign, allow sign msg to appear on space
        self.attack_pose = False

        #eating sound
#        self.eatEffect = PM.Sound("music/soundeffects/eating.mod")
#        self.eated = False
        self.EatR = PI.load("FPGraphics/MC/MCwalk/MCRightEat.png")\
                .convert_alpha()
        self.EatL = PI.load("FPGraphics/MC/MCwalk/MCLeftEat.png")\
            .convert_alpha()
        self.EatF = PI.load("FPGraphics/MC/MCwalk/MCFrontEat.png")\
            .convert_alpha()
        self.EatB = PI.load("FPGraphics/MC/MCwalk/MCBackEat.png")\
            .convert_alpha()

        self.items_of_killed = []
        # Item Variables
        self.grab_item = False
        self.item = False
        self.item_img = None
        self.item_use_count = 0
        self.item_type = 0
        self.item_health = 0
        #projectile movement
        self.pdx = 0
        self.pdy = 0
        self.player_items = []
        self.player_traps = []
        self.player_projectiles = []
        self.can_eat = True
        self.eat_item = False
        #consider changing this for MC general img poses...?
        self.eat_time = 50
        self.eat_timer = 0

        self.effect_time = -1
        self.change_invincibility = False
        # self.burger_capacity = random.randint(1, 15)
        self.burger_capacity = 1
        self.enemy_ID = -1

        self.can_attack = True

        ##joystick##
        self.joy = Joystick()
        self.joyOn = False
#        self.mvJoy = (0, 0)
        self.mvD = False
        self.mvR = False
        self.mvL = False
        self.mvU = False

    def set_attacking_rect(self):
        self.attacking_rect = self.rect
        self.rect = self.rect_copy

    def reset_attacking_rect(self):
        self.rect = self.attacking_rect

    def update_camera(self):
        if self.attack_pose:
            return False
        return True

        self.enemy_ID = -1

    def has_item(self):
        return self.item

    def get_item_img(self):
        return self.item_img

    def remove_player_item(self, item):
        self.player_items.remove(item)

    def remove_player_trap(self, item):
        self.player_traps.remove(item)

    def get_player_items(self):
        return self.player_items

    def drop_item(self, surface):
        if self.item_type == 1:
            self.player_items.append(Item.IceCreamScoop(self.rect.x,
                                                        self.rect.y, surface))

    def chng_invincibility(self):
        ret = self.change_invincibility
        self.change_invincibility = False
        return ret


    def get_invincibility(self):
        return self.new_invincibility

    def get_item(self):
        # if ice cream scoop
        if self.item_type == 1:
            self.item_img = PI.load("FPGraphics/drops/DropIceCream.png").convert_alpha()
        # if bread drop = faster
        elif self.item_type == 2:
            self.item_img = PI.load("FPGraphics/drops/breadDrop.png").convert_alpha()
            self.speed = 2
        # if lettuce drop = trap
        elif self.item_type == 3:
            self.item_img = PI.load("FPGraphics/drops/lettuceDrop.png").convert_alpha()
        # if meat drop = longer invincibility
        elif self.item_type == 4:
            self.item_img = PI.load("FPGraphics/drops/meatDrop.png").convert_alpha()
            self.change_invincibility = True
            self.new_invincibility = Globals.DEFAULT_INVINCIBILITY*2
        # if burger drop
        elif self.item_type == 5:
            self.burger_capacity -= 1
            if self.burger_capacity == 0:
                self.health = 0
            self.item_img = PI.load("FPGraphics/drops/burgerDrop.png").convert_alpha()
        # if lettuce drop = trap
        elif self.item_type == 6:
            self.item_img = PI.load("FPGraphics/drops/creamDrop.png").convert_alpha()

    def is_item_usable(self):
        if self.item:
            if self.item_type == 1 or self.item_type == 3 or self.item_type == 5 or self.item_type == 6:
                return True
            else: 
                return False

    def restore_normal(self):
        self.speed = 1
        self.item = False
        self.change_invincibility = True
        self.new_invincibility = Globals.DEFAULT_INVINCIBILITY

    def drop_trap(self, surface):
        rect = self.item_img.get_rect()
        rect.x = self.rect.x
        rect.y = self.rect.y
        self.player_traps.append(Trap(surface,         # surface to be drawn in
                                     rect,             # rect of the image 
                                     self.item_img,   # the type of trap
                                     'P',              # Player is the user 
                                     1600,             # lifetime 
                                     self.item_img,            # image 
                                     False))           # if the trap will be animated

    def get_player_traps(self):
        return self.player_traps

    def throw_LC(self):
        self.player_projectiles.append(LettuceCutter(self));

    def throw_CC(self):
        self.player_projectiles.append(CreamCutter(self));

    def get_player_projectiles(self):
        return self.player_projectiles

    def get_items_of_killed(self):
        return self.items_of_killed

    def get_modified_map(self):
        returned = self.modified_map
        self.modified_map = False
        return returned

    def get_rect_if_moved(self):
        if self.moved:
            return self.rect
        else:
            return None

    def get_health(self):
        return self.health

    def set_health(self, new_health, check_start=False):
        self.health = new_health
        if check_start:
            self.check_starting_health()

    def check_starting_health(self):
        if self.health >= 20:
            self.health = 20

    def decrement_health(self, enemy_ID):
        if self.health > 0:
            self.health -= 1
        self.dmg_count = 3

    def invincibility_frames(self):
        self.image = self.invincibility_frame

    def get_face(self):
        return self.face

    def player_got_key(self):
        return self.got_key

    def get_coordinates(self):
        coordinates = [self.rect.x, self.rect.y]
        return coordinates

    def open_door(self, bg):  # pass the enire block group.
#        self.eated = False
        self.eat_timer = self.eat_time
        for block in bg:
            if block.get_type() == self.at_door_num:
                block.kill()
#                if self.eated is False:
#                    self.eatEffect.play(50)
#                    self.eated = True
        self.modified_map = True
        self.at_door_num = -1

    def read_sign(self):  # pass the enire block group.
        self.banner = self.at_sign_num

    def handle_collision(self, bg):
        collisions = PS.spritecollide(self, bg, False)

        if len(collisions) == 0:
            self.at_sign_num = -1
            self.at_door_num = -1
            pass

        for collision in collisions:
            # check if collided with an item
            if type(collision.get_type()) is int:
                if self.grab_item:
                    self.item = True
                    self.item_use_count = -1
                    self.effect_time = -1
                    # self.modified_map = True
                    self.item_type = collision.get_type()
                    self.item_health = collision.get_health()
                    # if item is to attack the enemy
                    if self.item_type == 1 or self.item_type == 3 or self.item_type == 5 or self.item_type == 6:
                        self.item_use_count = collision.get_use_count()
                    # if item is for player effects
                    else: 
                        self.effect_time = collision.get_use_count()
                    self.get_item()
                    collision.disappear()
                elif self.eat_item:
                    self.eat_item = False
                    self.eat_timer = self.eat_time
                    self.health += collision.get_health()
                    if self.health > 25:
                        self.health = 25
                    collision.disappear()
            elif collision.get_type() == "K":  # found key
                collision.kill()
                self.pill = True
                # self.open_door(bg)
                self.got_key = True
                self.modified_map = True
            
            elif self.face == 'r' or self.face == 'ra' or self.face == 'rs':
                if(self.rect.x + self.rect.width
                   ) >= collision.rect.left:
                    self.rect.x = collision.rect.left \
                        - self.rect.width
            elif self.face == 'l' or self.face == 'ls':
                if(self.rect.x) <= (collision.rect.left +
                                    collision.rect.width):
                    self.rect.x = (collision.rect.left +
                                   collision.rect.width)
            elif self.face == 'd' or self.face == 'ds':
                if(self.rect.y + self.rect.height
                   ) >= collision.rect.top:
                        self.rect.y = collision.rect.top -\
                            self.rect.height
            elif self.face == 'u' or self.face == 'us':
                if(self.rect.y <= (collision.rect.top +
                                   collision.rect.height)):
                        self.rect.y = collision.rect.top +\
                            collision.rect.height

            if collision.get_type() == '!':  # at a sign
                self.at_sign_num = collision.get_id()
            else:
                self.at_sign_num = -1
            #door
            if isinstance(collision.get_type(), str) and collision.get_type().isdigit():  # at a door
                if self.pill:  # unlockable door
                    self.at_door_num = collision.get_type()
                else:
                    self.at_door_num = -1
            else:
                self.at_door_num = -1

    def eat_frames(self):
        if self.face == 'ds':
            self.image = self.EatF
        if self.face == 'us':
            self.image = self.EatB
        if self.face == 'rs':
            self.image = self.EatR
        if self.face == 'ls':
            self.image = self.EatL

    ###Used when joystick is plugged in. Handled slightly different.
    ##Will try to merge, but considering that calling handle_keys inside handle_joy
    ##throws off the cycle / animation, I want to avoid that :/
    def handle_joy(self, bg, enemy_bg, item_group, screen, interval=0.0065):
        try:
            self.items_of_killed = []
            self.attack_pose = False
            standing = True
            self.grab_item = False
            self.interval = interval
            temp = self.rect.x
            self.rect = self.rect_copy
            hat_dir = (0, 0)
            hat_move = False
            axis_move = False
            axis_dir0 = 0.0
            axis_dir1 = 0.0

            for event in PE.get():
                if event.type in Joystick.JOYSTICK:
                    if event.type == PG.JOYBUTTONUP:
                        self.joy.buttons[event.button] = False
                    elif event.type == PG.JOYBUTTONDOWN:
                        self.joy.buttons[event.button] = True
                    if event.type == PG.JOYHATMOTION:
                        if self.joy.joystick.get_hat(0) == (0, 0):
                            hat_move = False
#                            self.mvJoy = (0, 0)
                            self.mvD = False
                            self.mvU = False
                            self.mvR = False
                            self.mvL = False
                        else:
                            hat_move = True
                            if hat_dir == (0, 0):
                                hat_dir = self.joy.joystick.get_hat(0)
                    if event.type == PG.JOYAXISMOTION:
                        if math.fabs(self.joy.joystick.get_axis(0)) < 0.5 and math.fabs(self.joy.joystick.get_axis(1)) < 0.5:
                            axis_move = False
                        else:
                            axis_move = True
                            if math.fabs(axis_dir0) < 0.5:
                                axis_dir0 = self.joy.joystick.get_axis(0)
                            if math.fabs(axis_dir1) < 0.5:
                                axis_dir1 = self.joy.joystick.get_axis(1)

                    ####Exit
                    if self.joy.buttons[6] is True:  # back button (L7 on peter's joystick)
                        if Globals.SCORE > 0:
                            Globals.PLAYERNAME = str(inbx.ask(Globals.SCREEN, 'Name'))
                        Globals.STATE = 'Menu'

                    #attack
                    elif self.joy.buttons[0] is True:  # A button (1 button)
                        if 'r' in self.face:
                            self.image = self.IMG_ATTACK_R
                            self.attack_rect = self.image.get_rect()
                            self.attack_rect.x = self.rect.x
                            self.attack_rect.y = self.rect.y
                        if 'l' in self.face:
                            self.image = self.IMG_ATTACK_L
                            self.attack_rect = self.image.get_rect()
                            self.attack_rect.x = self.rect.x - 50
                            self.attack_rect.y = self.rect.y
                        if 'd' in self.face:
                            self.image = self.IMG_ATTACK_D
                            self.attack_rect = self.image.get_rect()
                            self.attack_rect.x = self.rect.x
                            self.attack_rect.y = self.rect.y
                        if 'u' in self.face:
                            self.image = self.IMG_ATTACK_U
                            self.attack_rect = self.image.get_rect()
                            self.attack_rect.x = self.rect.x
                            self.attack_rect.y = self.rect.y - 50
                        self.rect = self.attack_rect

                        collisions = PS.spritecollide(self, enemy_bg, False)

                        if self.can_attack:
                            self.can_attack = False
                            killed_enemies = self.weapon.attack(self, self.rect.x, self.rect.y,
                                                                self.face, screen, enemy_bg)
                            for killed in killed_enemies:
                                self.items_of_killed.append(killed.drop_item(screen))
                                killed.decrement_health(1)
                                killed.move_back(self.face, bg)
                                killed.last_hit = 80
                        self.attack_pose = True
                        standing = True

                        #handle signs
                        if self.at_sign_num != -1:
                            self.read_sign()
                        #handle locked doors
                        if self.at_door_num != -1:
                            self.open_door(bg)
                            self.pill = False
                    #pickup
                    elif self.joy.buttons[1] is True:  # B button (2 button)
                        if not self.item:
                            self.grab_item = True
                            self.handle_collision(item_group)
                    #make trap
                    elif self.joy.buttons[2] is True:  # X button (3 button)
                        if self.item and self.can_drop: #can_drop is used to prevent inaccurate key detection
                            if self.item_type == 1 or self.item_type == 5:
                                self.drop_trap(screen)
                            if self.item_type == 3:
                                self.throw_LC()
                            if self.item_type == 6:
                                self.throw_CC()
                            self.can_drop = False
                            self.item_use_count -= 1
                            if self.item_use_count == 0:
                                self.item = False
                    #drop (get rid of held item)
                    elif self.joy.buttons[3] is True:  # Y button (4 button)
                        if self.item and self.can_drop:
                            self.item = False
                    #eat
                    elif self.joy.buttons[4] is True:  # LB button / Left shoulder 1 button (L5)
                        if not self.item and self.can_eat:
                            self.can_eat = False
                            self.eat_item = True
                            self.handle_collision(item_group)

                    ##if event is the
                    ####Event 9-JoyHatMotion (joy = 0 hat = 0)
                    ##move.
#                    elif event.type == PG.JOYHATMOTION:  # arrow pad
                    elif hat_move is True:
                        standing = False
                        if hat_dir == (-1, 0):  # store these into local variables?
                            self.mvL = True
#                            self.rect.x -= self.speed  # move left
#                            self.face = 'l'
#                            self.pdx = -1
#                            self.pdy = 0
#                            self.handle_collision(bg)
#                            self.rect_copy = self.rect
                        elif hat_dir == (0, -1):
                            self.mvD = True
#                            self.rect.y += self.speed  # move down
#                            self.face = 'd'
#                            self.pdx = 0
#                            self.pdy = 1
#                            self.handle_collision(bg)
#                            self.rect_copy = self.rect
                        elif hat_dir == (1, 0):
                            self.mvR = (1, 0)
#                            self.rect.x += self.speed  # move right
#                            self.face = 'r'
#                            self.pdx = 1
#                            self.pdy = 0
#                            self.handle_collision(bg)
                            self.rect_copy = self.rect
                        elif hat_dir == (0, 1):
                            self.mvU = (0, 1)
#                            self.rect.y -= self.speed  # move up
#                            self.face = 'u'
#                            self.pdx = 0
#                            self.pdy = -1
#                            self.handle_collision(bg)
#                            self.rect_copy = self.rect
                        else:
                            #STANDING
                            standing = True

                        if standing:
#                            self.joy.axishats = [False, False, False]  # not moving at all
                            if self.face == 'd':
                                    self.face = 'ds'
                            if self.face == 'u':
                                    self.face = 'us'
                            if self.face == 'r':
                                    self.face = 'rs'
                            if self.face == 'l':
                                    self.face = 'ls'


                    ####Event 7-JoyAxisMotion (joy = 0 axis 0 for LR, 1 for UD)
#                    elif event.type == PG.JOYAXISMOTION:  # these are for left ball
                    elif axis_move is True:
                        standing = False
                        if axis_dir0 < -0.5 : # left
                            self.rect.x -= self.speed  # move left
                            self.face = 'l'
                            self.pdx = -1
                            self.pdy = 0
                            self.handle_collision(bg)
                            self.rect_copy = self.rect
                        elif axis_dir0 > 0.5: # right
                            self.rect.x += self.speed  # move right
                            self.face = 'r'
                            self.pdx = 1
                            self.pdy = 0
                            self.handle_collision(bg)
                            self.rect_copy = self.rect
                        elif axis_dir1 > 0.5:  # down
                            self.rect.y += self.speed  # move down
                            self.face = 'd'
                            self.pdx = 0
                            self.pdy = 1
                            self.handle_collision(bg)
                            self.rect_copy = self.rect
                        elif axis_dir1 < -0.5:  # up
                            self.rect.y -= self.speed  # move up
                            self.face = 'u'
                            self.pdx = 0
                            self.pdy = -1
                            self.handle_collision(bg)
                            self.rect_copy = self.rect

#                        #STANDING
                        else:
                            #STANDING
                            standing = True

                        if standing:
#                            self.joy.axishats = [False, False, False]  # not moving at all
                            if self.face == 'd':
                                    self.face = 'ds'
                            if self.face == 'u':
                                    self.face = 'us'
                            if self.face == 'r':
                                    self.face = 'rs'
                            if self.face == 'l':
                                    self.face = 'ls'

                    ##Not using Right axis ball
                    if standing:
#                        self.joy.axishats = [False, False, False]  # not moving at all
                        if self.face == 'd':
                                self.face = 'ds'
                        if self.face == 'u':
                                self.face = 'us'
                        if self.face == 'r':
                                self.face = 'rs'
                        if self.face == 'l':
                                self.face = 'ls'
                    if self.joy.buttons[2] is False:
                        self.can_drop = True
                    if self.joy.buttons[4] is False:
                        self.can_eat = True
                    if self.joy.buttons[0] is False:
                        self.can_attack = True

        except IndexError, err:  # if no joystick
            pass
예제 #24
0
	def __init__(self):
		Weapon.__init__(self, "wpns-modern2.png", -1, Rect(48, 28, 24, 17), "bullet_shot.ogg", 0.5)
		self.sheetCoord[0].append(pygame.Rect(82, 25, 26, 20))
		self.cooldown = 0
 def setUp(self):
     self.weapon = Weapon('Sword', 150, 0.5)
예제 #26
0
 def __init__(self, canvas):
     Weapon.__init__(self, BOMB_DMG, BOMB_STAM, BOMB_IMG, 
                     BOMB_IMG_EXPL, BOMB_FIRE, BOMB_EXPL, BOMB_SPEED, BOMB_COOLDOWN, TYPE_B, canvas)
예제 #27
0
 def setUp(self):
     self.w = Weapon(name="The Axe of Destiny", damage=20)
예제 #28
0
 def __init__(self, canvas):
     Weapon.__init__(self, MISSILE_DMG, MISSILE_STAM, MISSILE_IMG, 
                     MISSILE_IMG_EXPL, MISSILE_FIRE, MISSILE_EXPL, MISSILE_SPEED, MISSILE_COOLDOWN, TYPE_M, canvas)
예제 #29
0
    def __init__(self):
        # sprite initialisation
        self.sprites = (
            arcade.Sprite("sprites/player/all_player_mv.png",
                          scale=CONST.SPRITE_SCALING_PLAYER,
                          image_x=0,
                          image_y=0,
                          image_width=66,
                          image_height=66),
            arcade.Sprite("sprites/player/all_player_mv.png",
                          scale=CONST.SPRITE_SCALING_PLAYER,
                          image_x=66,
                          image_y=0,
                          image_width=66,
                          image_height=66),
            arcade.Sprite("sprites/player/all_player_mv.png",
                          scale=CONST.SPRITE_SCALING_PLAYER,
                          image_x=122,
                          image_y=0,
                          image_width=66,
                          image_height=66),
            arcade.Sprite("sprites/player/all_player_mv.png",
                          scale=CONST.SPRITE_SCALING_PLAYER,
                          image_x=188,
                          image_y=0,
                          image_width=66,
                          image_height=66),
            arcade.Sprite("sprites/player/all_player_mv.png",
                          scale=CONST.SPRITE_SCALING_PLAYER,
                          image_x=254,
                          image_y=0,
                          image_width=66,
                          image_height=66),
            arcade.Sprite("sprites/player/all_player_mv.png",
                          scale=CONST.SPRITE_SCALING_PLAYER,
                          image_x=375,
                          image_y=0,
                          image_width=66,
                          image_height=66),
        )
        self.sprite = self.sprites[0]

        self.up_pressed = 0
        self.down_pressed = 0
        self.left_pressed = 0
        self.right_pressed = 0
        self.auto_fire = 0
        self.stun = 0
        self.count = 0
        self.sound = arcade.Sound("audios/gun-1.mp3")

        self._sprite_count = 0
        self._tempo_sprite = 0

        # position at begining
        self.sprite.center_x = CONST.PLAYER_X
        self.sprite.center_y = CONST.PLAYER_Y
        self.vel = CONST.PLAYER_INIT_VEL

        # weapon
        self.weapon = Weapon()
예제 #30
0
    def __init__(self, fps=1):
        # Call the parent class (Sprite) constructor
        PS.DirtySprite.__init__(self)
        self.image = PI.load("FPGraphics/MC/MCwalk/MCFront.png") \
            .convert_alpha()
        self.rect = self.image.get_rect()
        self.rect_copy = self.rect
        self.rect.x = 100
        self.rect.y = 100
        self.face = 'd'
        self.load_images()
        # self.speed both determines the speed of the player &
        # ensures the the player moves at an integer distance
        # during play (arbitrary value)
        self.speed = 1
        self.time = 0.0
        self.frame = 0
        self.got_key = False
        # will turn to True once you've run into the yellow block
        # collision conditions, if true, we will not move in that direction
        self.health = 20
        self.dmg_count = 0
        self.invincibility_frame = PI.load("FPGraphics/emptyImg.png") \
            .convert_alpha()
        self.weapon = Weapon()
        self.moved = False
        self.interval = 0
        self.modified_map = False
        self.banner = -1 #holds the ID of the sign that the player just read
        self.pill = False
        self.at_door_num = -1  # allows player to open door if player has key
        self.at_sign_num = -1  # if player is at a sign, allow sign msg to appear on space
        self.attack_pose = False

        #eating sound
#        self.eatEffect = PM.Sound("music/soundeffects/eating.mod")
#        self.eated = False
        self.EatR = PI.load("FPGraphics/MC/MCwalk/MCRightEat.png")\
                .convert_alpha()
        self.EatL = PI.load("FPGraphics/MC/MCwalk/MCLeftEat.png")\
            .convert_alpha()
        self.EatF = PI.load("FPGraphics/MC/MCwalk/MCFrontEat.png")\
            .convert_alpha()
        self.EatB = PI.load("FPGraphics/MC/MCwalk/MCBackEat.png")\
            .convert_alpha()

        self.items_of_killed = []
        # Item Variables
        self.grab_item = False
        self.item = False
        self.item_img = None
        self.item_use_count = 0
        self.item_type = 0
        self.item_health = 0
        #projectile movement
        self.pdx = 0
        self.pdy = 0
        self.player_items = []
        self.player_traps = []
        self.player_projectiles = []
        self.can_eat = True
        self.eat_item = False
        #consider changing this for MC general img poses...?
        self.eat_time = 50
        self.eat_timer = 0

        self.effect_time = -1
        self.change_invincibility = False
        # self.burger_capacity = random.randint(1, 15)
        self.burger_capacity = 1
        self.enemy_ID = -1

        self.can_attack = True

        ##joystick##
        self.joy = Joystick()
        self.joyOn = False
#        self.mvJoy = (0, 0)
        self.mvD = False
        self.mvR = False
        self.mvL = False
        self.mvU = False
pathfile = "/".join(newpath)
sys.path.append(pathfile)

from Fisher import Fisher
from Weapon import Weapon
from Defense import Defense
from Island import Island
from Medkit import Medkit
from Spell import Spell
from Individual import Individual
from libGamePiratesAndFishers import genRandomName


@pytest.mark.parametrize("standartinput,expected", [([
    Defense("Defense1", 10, 10),
    Weapon("Weapon 1", 10, 10),
    Island("Island 1")
], None)])
def test_init_fisher(standartinput, expected):
    #first test, name is correct
    namegen = genRandomName(10)
    idgen = genRandomName(64)
    genericnumb = 100
    genFisher = Fisher(namegen, genericnumb, standartinput[1],
                       standartinput[0], standartinput[2], idgen)
    assert genFisher.getName() == namegen
    assert genFisher.getWeapon() == standartinput[1]
    assert genFisher.getDefense() == standartinput[0]
    assert genFisher.getactualIsland() == standartinput[2]
    #second test, name is incorrect, check if is standard
    namegen = genRandomName(100)
예제 #32
0
 def __init__(self, canvas):
     Weapon.__init__(self, MAINGUN_DMG, MAINGUN_STAM, LASER_GREEN, 
                     LASER_BLUE, LASER_FIRE, LASER_EXPL, MAINGUN_SPEED, MAINGUN_COOLDOWN, TYPE_L, canvas)
 def test_critical_hit(self):
     my_weapon = Weapon("axe", 30, 0.5)
     flags = set()
     for i in range(1000):
         flags.add(my_weapon.critical_hit())
     self.assertEqual(2, len(flags))
예제 #34
0
	def __init__(self):
		Weapon.__init__(self, "sw_weapons.png", -1, Rect(78, 24, 15, 18), "laser_shot.wav", 0.5)
		self.sheetCoord[0].append(Rect(132, 21, 16, 20))
		self.cooldown = 0
예제 #35
0
from AK47 import AK47
from Knife import Knife
from Weapon import Weapon

if __name__ == '__main__':
    weapon = Weapon()

    weapon.set_weapon(Knife())
    weapon.to_apply_weapon()

    weapon.set_weapon(AK47())
    weapon.to_apply_weapon()