Exemplo n.º 1
0
 def __init__(self):
     super().__init__()
     #-----------------------------
     #         Collisions
     #-----------------------------
     self.__rigid_body = False #Boolean if it's a rigid body
     self.__collide = False #Boolean if it's a collide body
     self.__collide_hit_box = Hitbox(Rect(0,0,0,0)) #Collide hit box (see Hit Box)
     self.__rigid_hit_box = Hitbox(Rect(0,0,0,0)) #Rigid hit box
     self.rigid_size_factor = 0.999 #Scale factor for rigid body hit box
def platform(x, y, xmax):
    """
        Crée une plateforme de longueur length et de hauteur 12 ayant son coin
        supérieur gauche aux coordonnées x,y
        Renvoie un SolidPlatform
    """
    plat = SolidPlatform(Hitbox(Rect(0, 0, xmax - x, 12)))
    plat.translate(Vector(x, y))
    return plat
def add_coins(objects, x0, y0, width, height, number):
    for i in range(number):
        if (number > 1):
            coeff = i / (number - 1)
        else:
            coeff = 0.5
        #objects.append(Coin(Hitbox(Rect(x0,y0,10,10))))
        objects.append(
            Coin(Hitbox(Rect(x0 + coeff * width, y0 + coeff * height, 10,
                             10))))
Exemplo n.º 4
0
    def __init__(self):
        super().__init__()
        self.damages = 1
        hb = Hitbox(Rect(0, 0, 4, 4))
        self.set_hit_box(hb)
        self.set_collide(True)

        self.lifecollide = True
        self.projcollide = True
        self.solidcollide = True
Exemplo n.º 5
0
 def __init__(self):
     hb = Hitbox(Rect(0, 0, 7, 7))
     super().__init__(hb)
     self.set_rigid_body(True)
     self.max_pv = 1
     self.pv = 1
     self.small = True
     self.create_sps("Rhombus")
     self.animation_speed = 0.2
     self.controller = LaserTurretBotController(self)
Exemplo n.º 6
0
    def __init__(self):
        hb = Hitbox(Rect(0, 0, 9, 12))
        self.mult_offset = 1.5
        super().__init__(hb)
        self.max_pv = 3
        self.pv = 3
        self.small = True
        self.create_sps("skeleton")
        self.sps_right = self.sps
        self.create_sps("skeleton_inverse")
        self.sps_left = self.sps
        self.animation_speed = 0.2
        self.set_state("r")
        self.controller = ZombieController(self)

        self.collide_plat = None
Exemplo n.º 7
0
    def __init__(self):
        super().__init__()
        self.set_hit_box(Hitbox(Rect(-1, -2, 12, 16)))  #Specific Hit box
        self.set_rigid_body(True)  #it's a rigid body

        self.create_sps("player")  #Set sprite
        self.animation_speed = 0.05
        self.set_state("r")  #First state : runing ('r')
        self.controller = PlayerController(
            self)  #Controller for the player (see below)
        self.score = 0  #Score of the player

        self.small = False  #Life bar

        self.inventory = defaultdict(
            int)  #Ref to inventory to give items to Campaign mod

        self.score_to_add = 0  #Score to add for animations
def generate_level(filename, name_of_level='', para=True, limgpar=[]):
    """
            Génère un niveau associé à la musique du fichier filename
            Renvoie un GameLevel
        """
    (first_beat, tempos, nb_beats) = bpm_info(filename)
    platforms = []

    jump_points = [0]
    tempo_index = 0

    for tmp in tempos:
        speed = get_speed(tmp)
        jump_points.append(jump_points[-1] + speed * 60 / tmp)
    print("generated level length = ", jump_points[-1] / speed, " seconds")

    y = 0  #initially the height is at 500 #It's at 0 now ^^
    jump_points[0] = -1000  # Beginning platform

    for i in range(nb_beats):
        #pourquoi +50 et +24 ? #La taille des plateformes non ?
        platforms.append(
            platform(jump_points[i] + 50, y, jump_points[i + 1] + 24))

        dy = random.randint(-24, 24)
        y += dy  #at each point the y coordinate changes

    def player_pos(t):
        return t * speed

    objects = []

    objects.append(
        Flag(Hitbox(Rect(jump_points[-1] + 24 - 10, y - 20 - dy, 10,
                         20))))  # Add flag

    for i in range(len(platforms)):
        rd = random.random()
        if (rd < 0.25):
            (x, y, w,
             h) = platforms[i].get_hit_box().get_world_rect().get_coord()
            w -= 10
            nb = 3
            if (rd < 0.10):
                nb = 5
            add_coins(objects, x + w / 3, y - h, w / 3, 0, nb)

    for i in range(len(platforms) - 1):
        rd = random.random()
        if (rd < 0.33):
            (x1, y1, w1,
             h1) = platforms[i].get_hit_box().get_world_rect().get_coord()
            (x2, y2, w2,
             h2) = platforms[i + 1].get_hit_box().get_world_rect().get_coord()
            w1 -= 10
            w2 -= 10
            start_x = x1 + w1
            end_x = x2
            start_y = y1 - 45
            end_y = y2 - 45
            add_coins(objects, start_x, start_y, end_x - start_x,
                      end_y - start_y, random.randint(2, 3))

    return GameLevel(platforms + objects,
                     player_pos,
                     name=name_of_level,
                     parallax=para,
                     limgpar=limgpar,
                     music=filename)
Exemplo n.º 9
0
 def __init__(self,shield,name='spike'):
     hb = Hitbox(Rect(0,0,10,10))
     PickableNode.__init__(self,hb,name)
     self.create_sps("spike")
     self.shield = shield
Exemplo n.º 10
0
 def copy(self):
     """ Returns the copy of this """
     sd = SolidPlatform(Hitbox(Rect(0, 0, 0, 0)))
     self.paste_in(sd)
     return sd
Exemplo n.º 11
0
 def __init__(self):
     self.rect = Rect()
     self.fen = None  #Undefined yet
     self.angle = 0
     self.rotation_effect = False  #Timed effect of rotation
     self.remove_rotation_effect = True  #Possibility to remove it