Beispiel #1
0
    def doCraftWeapon(self, game_map, wepToCraft):
        itemsUsed = self.weaponInfo.totalItemsToCraft(wepToCraft)
        for needed in itemsUsed:
            for supply in self.craftPouch:
                if needed == supply:
                    self.craftPouch.remove(supply)
        chance = random.randint(1,10)
        if chance <= self.attributes['crafting_skill']:
            crafted = True
            self.weapon = weapon(wepToCraft)
        else:
            crafted = False

        self.wepCanCraft = None
        self.has_weapon = crafted
        return crafted
Beispiel #2
0
    def __init__(self, goals, actions, x=0, y=0, district='d12', gender='male', do_not_load=False):
        Particle.__init__(self, (x, y), 1, 1)
        self.id = Tribute.ID_COUNTER
        Tribute.ID_COUNTER += 1
        self.goals = goals
        self.actions = actions

        # remove the fight action. we don't want them fighting unless someone is in range
        self.fight_action = actions[5]
        self.explore_action = actions[12]
        self.actions = self.actions[:5] + self.actions[6:12]

        self.district = district
        self.has_weapon = False
        self.weapon = weapon('')
        self.has_ally = False
        self.allies = []
        self.craftPouch = []
        self.fighting_state = FIGHT_STATE['not_fighting']
        self.opponent = None
        self.last_opponent = None
        self.sighted = None
        self.last_sighted_location = None
        self.last_action = None
        self.printy_action = 'none'
        self.old_state = self.state
        self.visited_set = set()
        self.explore_point_index = 0
        self.explore_point = NAVIGATION_POINTS[self.explore_point_index]

        self.hidden = False

        self.weaponInfo = weaponInfo()
        self.wepCanCraft = ''
        self.bestScavChoice = ''
        self.bestScavPoints = 0

        if do_not_load:
            self.attributes = None
            self.gender = gender
            self.stats = None
            self.last_name = None
            self.first_name = None
            self.killed = None
        else:
            d = json.load(open('./distributions/stats.json'))

            self.attributes = {
                'size': U(d['size']['mean'], d['size']['spread']),
                'strength': U(d['strength']['mean'], d['strength']['spread']),
                'speed': U(d['speed']['mean'], d['speed']['spread']),
                'hunting_skill': U(d['hunting_skill'][self.district]['mean'], d['hunting_skill'][self.district]['spread']),
                'fighting_skill': U(d['fighting_skill'][self.district]['mean'], d['fighting_skill'][self.district]['spread']),
                'weapon_skill': U(d['weapon_skill'][self.district]['mean'], d['weapon_skill'][self.district]['spread']),
                'camouflage_skill': U(d['camouflage_skill'][self.district]['mean'], d['camouflage_skill'][self.district]['spread']),
                'friendliness': U(d['friendliness']['mean'], d['friendliness']['spread']),
                'district_prejudices': dict(d['district_prejudices'][self.district]),
                'stamina': U(d['stamina']['mean'], d['stamina']['spread']),
                'endurance': U(d['endurance']['mean'], d['endurance']['spread']),
                'crafting_skill': U(d['crafting_skill'][self.district]['mean'], d['crafting_skill'][self.district]['spread']),
                'bloodlust': U(d['bloodlust']['mean'], d['bloodlust']['spread']),
                'max_health': U(d['max_health']['mean'], d['max_health']['spread'])
            }
            self.gender = gender
            self.stats = {
                'health': self.attributes['max_health'],
                'energy': self.attributes['stamina'],
                'hunger_energy': 100
            }

            self.last_name = random.choice(d['last_names'])
            if self.gender == 'male':
                self.first_name = random.choice(d['first_names_male'])
            else:
                self.first_name = random.choice(d['first_names_female'])

            self.killed = False
            pass
Beispiel #3
0
 def getWeapon(self):
     self.has_weapon = True
     weaponType = random.randint(1, 10)
     self.weapon = weapon(self.weaponInfo.weaponType(weaponType))
     print str(self), ' has picked up a ', str(self.weapon)
Beispiel #4
0
from spaceMarine import spacemarine
from weapon import weapon
from to_wound import to_wound
import random
import numpy

tactical_marine = spacemarine(3, 3, 4, 4, 4, 3, 8, 3)
bolter = weapon("Bolter", 24, "Rapid Fire 1", 4, 0, 1, "")


def to_hit_ranged(bs):
    bs_dice = [6, 5, 4, 3, 2, 1]  #Dice required to hit
    toHit = bs_dice[bs - 1]
    diceRoll = random.randrange(1, 7)
    if diceRoll >= toHit:
        return True
    else:
        return False


def toWound(toughness, strength):
    diceRoll = random.randint(1, 7)
    strengt_toughness_chart = to_wound(toughness, strength)
    if diceRoll >= strengt_toughness_chart.wound():
        return True
    else:
        return False


def main():
    if to_hit_ranged(3):
Beispiel #5
0
def load_pg_from_file(filename,uid=0):
    config = load_yaml_file(filename)
    a=weapon(config['weapon'][0],config['weapon'][1],config['weapon'][2],config['weapon'][3])
    f=pg().buildFromAttribute(str(uid)+' - '+config['name'],config['primary'],config['secondary'],a,config['armor'],config['faction'],config['skill'])
    return f
Beispiel #6
0
 def setUp(self):
     self.new_weapon=weapon.weapon("mimi",100, 0.5)
Beispiel #7
0
p_proj_art_arr = [] #order is player proj
e_proj_art_arr = [] #order is eproj, eproj2
p_proj_art_arr.append(pygame.image.load("Assets/Art/projectile.png"))#.convert())
e_proj_art_arr.append(pygame.image.load("Assets/Art/Eprojectile_2.png"))#.convert())
e_proj_art_arr.append(pygame.image.load("Assets/Art/Eprojectile.png"))#.convert())
print("Art loaded!")

# spawn a proj every other frame, returning 1.5 * pi ("up") when returning an angle
def mvmtPtrn1(x):
    if x % 16 == 0: # fire proj
        return (1.5 * math.pi)
    else:
        return None
        
proj1    = projectile2.Projectile(0, 0, 35, 1.5 * math.pi, 10, p_proj_art_arr[0])
weap1    = weapon.weapon((0,0), proj1, mvmtPtrn1, screen, size)

# object initialization

menu               = menu.menu_object(menu_art,size,screen)
player             = player.player_object(player_ship,size,screen,weap1)
starfield          = background.starfield_object(size)
enemy_hldr         = enemy_holder.enemy_holder(enemy_ship_arr,e_proj_art_arr,size,screen)

#tracks if the player is alive
player_alive = True

#tracks frames for timers
frame_counter = 0

#value to determine if the player is shooting or not
    pygame.image.load("Assets/Art/Eprojectile_2.png"))  #.convert())
e_proj_art_arr.append(
    pygame.image.load("Assets/Art/Eprojectile.png"))  #.convert())
print("Art loaded!")


# spawn a proj every other frame, returning 1.5 * pi ("up") when returning an angle
def mvmtPtrn1(x):
    if x % 16 == 0:  # fire proj
        return (1.5 * math.pi)
    else:
        return None


proj1 = projectile2.Projectile(0, 0, 35, 1.5 * math.pi, 10, p_proj_art_arr[0])
weap1 = weapon.weapon((0, 0), proj1, mvmtPtrn1, screen, size)

# object initialization

menu = menu.menu_object(menu_art, size, screen)
player = player.player_object(player_ship, size, screen, weap1)
starfield = background.starfield_object(size)
enemy_hldr = enemy_holder.enemy_holder(enemy_ship_arr, e_proj_art_arr, size,
                                       screen)

#tracks if the player is alive
player_alive = True

#tracks frames for timers
frame_counter = 0
Beispiel #9
0
def main():
    # tiempo de retraso en milisegundos en la primera repetición
    delay = 101
    # intervalo de tiempo en milisegundos entre repeticiones
    interval = 100
    # habilita la repetición de teclas
    pygame.key.set_repeat(delay, interval)

    projectile_model = parabolic.projectile(20, 400, 10, window)
    projectile_view = parabolic.projectile_view()
    projectile_controller = parabolic.projectile_controller(
        projectile_model, projectile_view)

    world_model = world.world(WIDTH, HEIGHT, window)
    world_view = world.world_view()
    world_controller = world.world_controller(world_model, world_view)

    referee_model = world.rules(projectile_controller, world_controller, WIDTH,
                                HEIGHT)
    referee_view = world.rules_view()
    referee_controller = world.rules_controller(referee_model, referee_view)

    weapon_model = weapon.weapon(50, 400, window)
    weapon_view = weapon.weapon_view()
    weapon_controller = weapon.weapon_controller(weapon_model, weapon_view)

    weapon_bar = weapon.weapon_bar(10, HEIGHT + 10, window)
    weapon_bar_view = weapon.weapon_bar_view()
    weapon_bar_controller = weapon.weapon_bar_controller(
        weapon_bar, weapon_bar_view)

    target_model = world.target(500, HEIGHT - 35, 10, window)
    target_view = world.target_view()
    target_controller = world.target_controller(target_model, target_view)

    player_model = ia_player.player()
    player_view = ia_player.player_view()
    player_controller = ia_player.player_controller(player_model, player_view)

    trainer = ia_player.trainer(TRAIN_POPULATION)
    projectile_matrix = Make_population_of_projectils()

    actual_state = AIMING_TRAIN_STATE
    IA_mode = True if (actual_state == AIMING_IA_STATE) else False

    if (actual_state == AIMING_TRAIN_STATE):
        target_controller.Disable_bar()

    shoot_x = 0
    shoot_y = 0
    degree = 0

    global change_state_flag
    global holding_up_ball_flag

    status_bar = False
    actual_time = 0

    explosion_delay = 1000
    magnitude = 0
    shoot_x = 0
    shoot_Y = 0

    # son valores necesarios para la posición del proyectil, como no cambian literalmente nunca
    # los he movido aqui.
    weapon_w, weapon_h = weapon_controller.Get_size()
    target_max_x = target_controller.Get_x_range()

    while (True):

        background()

        target_controller.Update_view()

        #Update_projectile(projectile_controller)

        world_controller.Update_view()

        referee_controller.Check_edges()

        weapon_bar_controller.Update_view()

        weapon_bar_controller.Update_bar(status_bar)

        fps = np.floor(fpsClock.get_fps())

        text("FPS: {}".format(fps), 400, HEIGHT + 10)

        text("Wind: no", 10, HEIGHT + 40)

        shoot_angle = np.floor(degree)

        text("angle: {}".format(shoot_angle), 400, HEIGHT + 25)

        weapon_controller.Update_view(degree)

        # son necesarios mas adelante en la maquina de estados y como su valor
        # no cambia, hasta que el juego se reseta, decidi ponerlo aqui.
        target_x, target_y = target_controller.Get_pos()

        #state machine
        if (actual_state == AIMING_TRAIN_STATE):

            for i in range(TRAIN_POPULATION):
                projectile = projectile_matrix[i]
                player = trainer.Get_single(i)
                projectile_apply_force(target_x, target_max_x, player, \
                  weapon_controller, projectile)

            holding_up_ball_flag = False

            actual_state = EXPLOSION_TRAIN_STATE
        elif (actual_state == EXPLOSION_TRAIN_STATE):
            actual_time += get_time_ms()

            for i in range(TRAIN_POPULATION):
                projectile = projectile_matrix[i]
                projectile.Set_time(actual_time)
                if (actual_time > explosion_delay):
                    source_x, soruce_y = projectile.Get_position()
                    trainer.Set_population_fitness(target_x, target_y,
                                                   source_x, soruce_y, i)
                    projectile.Set_explosion()

            if (actual_time > explosion_delay):
                actual_time = 0
                actual_state = POST_EXPLOSION_TRAIN_STATE
                print(trainer.Get_population_fitness())
                trainer.Make_new_generation()

        elif (actual_state == POST_EXPLOSION_TRAIN_STATE):
            for i in range(TRAIN_POPULATION):
                projectile = projectile_matrix[i]
                projectile.Reset()

            target_controller.Reset()
            holding_up_ball_flag = True
            actual_state = AIMING_TRAIN_STATE
        elif (actual_state == AIMING_IA_STATE):

            projectile_apply_force(target_x, target_max_x, player_controller,
                                   weapon_controller, projectile_controller)

            holding_up_ball_flag = False

            actual_state = EXPLOSION_STATE

        elif (actual_state == AIMING_STATE):
            #set new position of the weapon
            degree = get_degrees(weapon_w, weapon_h)
            degree = limit_degrees(degree)
            weapon_and_projectile_update(degree, weapon_controller,
                                         projectile_controller)

            if (change_state_flag):
                change_state_flag = False
                shoot_x, shoot_y = get_shoot_components(degree)
                actual_state = SHOOT_STATE
                status_bar = True
                print("change state")

        elif (actual_state == SHOOT_STATE):

            if (change_state_flag):
                magnitude = weapon_bar_controller.Get_magnitude()
                #negativo porque la y crece hacia abajo, y el angulo
                #esta hacia arriba
                force = shoot_force(shoot_x, -shoot_y, magnitude)
                projectile_controller.Apply_force(force)
                change_state_flag = False
                actual_state = EXPLOSION_STATE
                status_bar = False
                holding_up_ball_flag = False
                #print("componenetes de la fuerza: {}, {}".format(force.x, force.y))
                #print(magnitude)
                print("change state")

        elif (actual_state == EXPLOSION_STATE):
            actual_time += get_time_ms()

            projectile_controller.Set_time(actual_time)

            if (actual_time > explosion_delay):
                #obtenemos el daño si es que hay
                damage = projectile_controller.Get_damage(target_x, target_y)
                target_controller.Update_HP(damage)
                projectile_controller.Set_explosion()
                actual_state = POST_EXPLOSION_STATE

        elif (actual_state == POST_EXPLOSION_STATE):

            if (change_state_flag or IA_mode):
                change_state_flag = False
                projectile_controller.Reset()
                weapon_bar_controller.Reset()
                target_controller.Reset()
                actual_state = AIMING_IA_STATE if (IA_mode) else AIMING_STATE
                holding_up_ball_flag = True
                actual_time = 0
                print("change state")

        #p_x, p_y = pygame.mouse.get_pos()
        #print(projectile_controller.Get_damage(p_x, p_y))

        for i in range(TRAIN_POPULATION):
            projectile = projectile_matrix[i]
            projectile.Update_model()
            projectile.Update_view()

        events()

        update_surface_task()
Beispiel #10
0
    def arsenal(self):
        weaponslist = []
        for x in range(random.randint(0, 9)):
            weaponslist.append(weapon.weapon())

        return weaponslist