예제 #1
0
파일: image.py 프로젝트: EliasFarhan/Kudu
    def loop(self, screen, screen_pos):
        if self.anim:
            self.anim.update_animation()
            self.img = self.anim.img
        pos = Vector2()
        if self.pos:
            pos = self.pos
        
        if self.screen_relative_pos is not None:
            pos = pos + self.screen_relative_pos * engine.get_screen_size()

        if self.screen_relative:
            pos = self.pos
        else:
            pos = pos - screen_pos
        
        center_image = False
        try:
            center_image = self.center_image
        except AttributeError:
            pass
            
        img_manager.show_image(self.img,
                   screen,
                   pos,
                   new_size=self.size,
                   center_image=center_image,
                   angle=self.angle,
                   flip=self.flip)

        GameObject.loop(self, screen, screen_pos)
예제 #2
0
 def __init__(self,
              pos,
              nmb_size):
     GameObject.__init__(self)
     self.pos = pos
     self.nmb_size = nmb_size #nmb_size for 47x27
     self.diff = 10
     self.init_image()
예제 #3
0
파일: trunk.py 프로젝트: EliasFarhan/GBJam
 def __init__(self,
              pos,
              nmb_size):
     GameObject.__init__(self)
     self.pos = pos
     self.nmb_size = nmb_size #nmb_size for 32x12
     self.size = Vector2(24+16*nmb_size,36)
     self.init_image()
예제 #4
0
파일: stump.py 프로젝트: EliasFarhan/GBJam
 def __init__(self,
              pos,
              nmb_size):
     GameObject.__init__(self)
     self.pos = pos
     self.nmb_size = nmb_size #nmb_size for 32x12
     self.size = Vector2(49,4+14*nmb_size+12)
     self.init_image()
     self.body = physics_manager.add_body(pos=self.pos+Vector2(7,3)+Vector2(31, self.size.y)/2,body_type=BodyType.static)
     physics_manager.add_box(body=self.body, pos=Vector2(),size=Vector2(31, self.size.y)/2,data=12)
예제 #5
0
 def __init__(self,pos,size,button_img='',button_text='',font='',show=False,margin=10):
     GameObject.__init__(self)
     self.pos = pos
     self.size = size
     self.update_rect(self)
     self.button_image = None
     self.show = show
     if button_img != '':
         self.button_image = Image(button_img, pos, size=size)
     self.text = Text(pos, size[1]-margin, font, text=button_text)
예제 #6
0
파일: ground.py 프로젝트: EliasFarhan/GBJam
 def __init__(self,
              pos,
              nmb_size,
              show_bottom=True):
     GameObject.__init__(self)
     self.pos = pos
     self.nmb_size = nmb_size #nmb_size for 32x12
     self.size = nmb_size*Vector2(32,12)+Vector2(24,24)
     self.show_bottom = show_bottom
     self.init_image()
예제 #7
0
파일: text.py 프로젝트: EliasFarhan/GBJam
 def __init__(self,pos,size,font,text,angle=0,color=(0,0,0),gradient=0,center=False,relative=False):
     GameObject.__init__(self)
     self.pos = pos
     self.center = center
     self.character_size = size
     self.color = color
     self.font = load_font(font,self.character_size)
     self.set_text(text)
     self.gradient = gradient
     self.time = 1
     self.screen_relative = relative
예제 #8
0
파일: bullet.py 프로젝트: EliasFarhan/GBJam
 def __init__(self,pos,size,userData=0,speed=Vector2(-5,0)):
     GameObject.__init__(self)
     self.pos = pos
     self.parallax_factor = 1.0
     self.size = size
     self.show = True
     self.flip = False
     self.body = physics_manager.add_body(self.pos+self.size/2,BodyType.dynamic)
     physics_manager.add_box(self.body,Vector2(),Vector2(self.size.x/2,2),data=userData,sensor=True)
     physics_manager.move(self.body,vx=-5)
     self.anim = BulletAnimation(self)
예제 #9
0
파일: image.py 프로젝트: EliasFarhan/GBJam
    def loop(self, screen):
        if self.anim:
            self.anim.update_animation()
            self.img = self.anim.img
            try:
                self.show = (self.anim.invincibility % (self.anim.show_frequency * 2)) < self.anim.show_frequency
            except AttributeError:
                pass
        pos = Vector2()
        if self.pos:
            pos = self.pos

        if self.screen_relative_pos is not None:
            pos = pos + self.screen_relative_pos * engine.get_screen_size()

        if self.screen_relative:
            pos = self.pos
        else:
            from engine import level_manager

            pos -= level_manager.level.screen_pos * Vector2(self.parallax_factor, 1.0)
            if pos.x > 160 or pos.x + self.size.x < 0:
                return

        center_image = False
        try:
            center_image = self.center_image
        except AttributeError:
            pass

        if self.show:
            img_manager.show_image(
                self.img, screen, pos, new_size=self.size, center_image=center_image, angle=self.angle, flip=self.flip
            )

        try:
            img_manager.show_image(
                self.anim.deal_with_it,
                screen,
                pos + self.anim.deal_pos + self.anim.deal_delta,
                new_size=Vector2(32, 32),
            )
        except AttributeError:
            pass
        GameObject.loop(self, screen)
예제 #10
0
파일: image.py 프로젝트: EliasFarhan/GBJam
    def __init__(self, pos, size=None, angle=0, relative=False, path="", parallax_factor=1.0):
        GameObject.__init__(self)
        self.anim = None
        self.flip = False
        self.img = None
        self.angle = angle
        if not isinstance(pos, Vector2) and (isinstance(pos[0], list) or isinstance(pos[0], tuple)):
            self.pos = Vector2(pos[0])
            self.screen_relative_pos = Vector2(pos[1])
        else:
            self.pos = Vector2(pos)
        self.path = path
        if size is not None:
            self.size = Vector2(size)
        self.screen_relative = relative

        self.center_image = False
        self.tmp = False
        self.show = True
        self.parallax_factor = parallax_factor
        self.update_rect()
예제 #11
0
파일: image.py 프로젝트: EliasFarhan/Kudu
 def __init__(self,
              pos,
              size=None,
              angle=0,
              relative=False,
              path=""):
     GameObject.__init__(self)
     self.anim = None
     self.flip = False
     self.img = None
     self.angle = angle
     if isinstance(pos[0], list) or isinstance(pos[0], tuple):
         self.pos = Vector2(pos[0])
         self.screen_relative_pos = Vector2(pos[1])
     else:
         self.pos = Vector2(pos)
     self.path = path
     self.size = Vector2(size)
     self.screen_relative = relative
     
     self.center_image = False
     self.update_rect()
예제 #12
0
def load_image_from_json(image_data, level, image_type=None):
    global global_object_id
    image = None
    if image_type is None:
        try:
            image_type = image_data["type"]
        except KeyError:
            log("Error: No image_type for:" + str(image_data),1)
            return 
    pos = get_element(image_data, "pos")
    size = get_element(image_data, "size")
    layer = get_element(image_data, "layer")
    angle = get_element(image_data, "angle")
    object_id = get_element(image_data, "id")
    if object_id is None:
        object_id = global_object_id
    if angle is None:
        angle = 0
    if image_type == "GameObject":
        image = GameObject()
        image.pos = Vector2(pos)
        image.size = Vector2(size)
        image.update_rect()
        image.angle = angle
        image.id = object_id
    elif image_type == "Image":
        image = Image.parse_image(image_data, pos, size, angle)
        if image is not None:
            image.id = object_id
    elif image_type == "Text":
        font = get_element(image_data, "font")
        text = get_element(image_data, "text")
        color = get_element(image_data, "color")
        if font and text:
            font = CONST.path_prefix+font
        else:
            log("Invalid arg font and text not defined for Text",1)
            return
        if not color:
            color = [0,0,0]
        image = Text(pos, size, font, text, angle,color)
        image.id = object_id
    else:
        if not isinstance(image_type,CONST.string_type):
            log("image_type not a string",1)
            return
        for c in image_type:
            if c != '.' and c != '_' and not c.isalpha():
                return
        dir_list = image_type.split(".")
        try:
            exec('''from %s import %s'''%(".".join(dir_list[0:len(dir_list)-1]), dir_list[len(dir_list)-1]))
        except ImportError:
            log("Error: ImportError with: "+str(image_type),1)
            return
        try:
            d = locals()
            exec('''image = %s.parse_image(image_data, pos, size, angle)'''%(dir_list[len(dir_list)-1]),globals(),d)
            image = d['image']
        except Exception as e:
            import traceback
            log('Error with loading image_type: %s'%(image_type)+" "+str(e),1)
            traceback.print_exc()
            return
    physic_objects = get_element(image_data, "physic_objects")
    if physic_objects:
        load_physic_objects(physic_objects, image)
    
    event_path = get_element(image_data, "event")
    if image and event_path:
        image.event = load_event(event_path)
    if not layer or layer < 0:
        layer = 1
    elif layer > len(level.objects)-1:
        layer = len(level.objects)-1
    if image:
        level.objects[layer-1].append(image)
    global_object_id += 1
    return image
예제 #13
0
파일: editor.py 프로젝트: EliasFarhan/Kudu
    def loop(self, screen,screen_pos):
        if not (self.editor_click or not get_button('editor')):
            self.editor = not self.editor
            self.lock = self.editor
            self.editor_click = True
            if self.editor:
                log("Editor mode activate")
            else:
                self.current_selected = None
        if not get_button('editor'):
            self.editor_click = False
        if self.editor:
            show_mouse()

        mouse_pos, pressed = get_mouse()
        if not self.editor:
            return

        self.gui_editor_mode.loop(screen,screen_pos)

        '''Save Level'''
        if self.save_clicked:
            self.gui_saved.loop(screen,screen_pos)
        if get_button('save') and not self.save_clicked:
            save_level(self)
            self.save_clicked = True
        elif not get_button('save'):
            self.save_clicked = False

        '''Left click,
        select a object and move it'''
        if not get_button('box'):
            self.new_obj = None
            if pressed[0] and not self.mouse_clicked[0]:
                '''Set current_selected'''
                self.current_selected = None
                for layer in self.objects:
                    for image in layer:
                        if not image.screen_relative and image.check_click(mouse_pos, self.screen_pos):
                            log("Current_object is: " + str(image))
                            self.current_selected = image
                            self.obj_init_pos = self.current_selected.pos
                            self.mouse_init_pos = mouse_pos + self.screen_pos
                self.mouse_clicked = (1, self.mouse_clicked[1], self.mouse_clicked[2])
            elif pressed[0] and self.mouse_clicked[0]:
                '''Move the current object'''
                if self.current_selected is not None:
                    self.current_selected.set_pos(self.obj_init_pos, mouse_pos + self.screen_pos - self.mouse_init_pos)
        else:
            """Create a static physic with CTRL-left mouse"""
            if pressed[0] and not self.mouse_clicked[0]:
                self.mouse_clicked = (1, self.mouse_clicked[1], self.mouse_clicked[2])
                self.new_obj = GameObject()
                self.new_obj.pos = mouse_pos + self.screen_pos
                self.objects[4].append(self.new_obj)
            elif self.mouse_clicked[0]:
                self.new_obj.size = mouse_pos + self.screen_pos - self.new_obj.pos
                if not pressed[0]:
                    """Create a static physics body"""
                    self.new_obj.body = add_static_object(self.new_obj, self.new_obj.pos+self.new_obj.size/2)
                    add_static_box(self.new_obj.body, Vector2(), self.new_obj.size/2, data=11)
                self.new_obj.update_rect()


        if not pressed[0] and self.mouse_clicked[0]:
            self.mouse_clicked = (0, self.mouse_clicked[1], self.mouse_clicked[2])

        if self.current_selected:
            self.gui_current_selected.change_text(str(self.current_selected.__class__)+" "+str(self.current_selected.id)
                                                  +" "+str(self.current_selected.angle))
            self.gui_current_selected.loop(screen, screen_pos)

        '''Size scale'''
        scale_x = get_button("scale_x_up")-get_button("scale_x_down")
        scale_y = get_button("scale_y_up")-get_button("scale_y_down")

        if self.current_selected:
            self.current_selected.scale(scale_x,scale_y)
        '''Angle'''
        angle = get_button("angle_up")-get_button("angle_down")
        if self.current_selected:
            self.current_selected.set_angle(self.current_selected.angle+angle)
예제 #14
0
파일: editor.py 프로젝트: EliasFarhan/Kudu
class Editor():
    def __init__(self):

        add_button('editor', 'LCTRL+e')
        self.editor_click = False

        self.editor = False
        self.text_size = 50

        self.mouse_clicked = (0, 0, 0)
        self.current_selected = None


        self.scale_clicked = (0, 0)  #red, enlarg

        self.save_clicked = False

        add_button('scale_y_down', ['DOWN'])
        add_button('scale_y_up', ['UP'])
        add_button('scale_x_down', ['LEFT'])
        add_button('scale_x_up', ['RIGHT'])

        add_button('angle_up',['a'])
        add_button('angle_down',['d'])

        add_button('save', ['LCTRL+s'])

        add_button('box',['LCTRL'])

        self.new_obj = None
        self.new_obj_pos = Vector2()


        self.obj_init_pos = Vector2()
        self.mouse_init_pos = Vector2()

        '''GUI'''
        self.gui_editor_mode = Text(Vector2(0, engine.get_screen_size().y-2*self.text_size), self.text_size, "data/font/pixel_arial.ttf", "Editor mode", relative=True)
        self.gui_current_selected = Text(Vector2(0, engine.get_screen_size().y-self.text_size), self.text_size, "data/font/pixel_arial.ttf", "",relative=True)
        self.gui_saved = Text(Vector2(0,0), self.text_size, "data/font/pixel_arial.ttf", "Saved",relative=True)

    def loop(self, screen,screen_pos):
        if not (self.editor_click or not get_button('editor')):
            self.editor = not self.editor
            self.lock = self.editor
            self.editor_click = True
            if self.editor:
                log("Editor mode activate")
            else:
                self.current_selected = None
        if not get_button('editor'):
            self.editor_click = False
        if self.editor:
            show_mouse()

        mouse_pos, pressed = get_mouse()
        if not self.editor:
            return

        self.gui_editor_mode.loop(screen,screen_pos)

        '''Save Level'''
        if self.save_clicked:
            self.gui_saved.loop(screen,screen_pos)
        if get_button('save') and not self.save_clicked:
            save_level(self)
            self.save_clicked = True
        elif not get_button('save'):
            self.save_clicked = False

        '''Left click,
        select a object and move it'''
        if not get_button('box'):
            self.new_obj = None
            if pressed[0] and not self.mouse_clicked[0]:
                '''Set current_selected'''
                self.current_selected = None
                for layer in self.objects:
                    for image in layer:
                        if not image.screen_relative and image.check_click(mouse_pos, self.screen_pos):
                            log("Current_object is: " + str(image))
                            self.current_selected = image
                            self.obj_init_pos = self.current_selected.pos
                            self.mouse_init_pos = mouse_pos + self.screen_pos
                self.mouse_clicked = (1, self.mouse_clicked[1], self.mouse_clicked[2])
            elif pressed[0] and self.mouse_clicked[0]:
                '''Move the current object'''
                if self.current_selected is not None:
                    self.current_selected.set_pos(self.obj_init_pos, mouse_pos + self.screen_pos - self.mouse_init_pos)
        else:
            """Create a static physic with CTRL-left mouse"""
            if pressed[0] and not self.mouse_clicked[0]:
                self.mouse_clicked = (1, self.mouse_clicked[1], self.mouse_clicked[2])
                self.new_obj = GameObject()
                self.new_obj.pos = mouse_pos + self.screen_pos
                self.objects[4].append(self.new_obj)
            elif self.mouse_clicked[0]:
                self.new_obj.size = mouse_pos + self.screen_pos - self.new_obj.pos
                if not pressed[0]:
                    """Create a static physics body"""
                    self.new_obj.body = add_static_object(self.new_obj, self.new_obj.pos+self.new_obj.size/2)
                    add_static_box(self.new_obj.body, Vector2(), self.new_obj.size/2, data=11)
                self.new_obj.update_rect()


        if not pressed[0] and self.mouse_clicked[0]:
            self.mouse_clicked = (0, self.mouse_clicked[1], self.mouse_clicked[2])

        if self.current_selected:
            self.gui_current_selected.change_text(str(self.current_selected.__class__)+" "+str(self.current_selected.id)
                                                  +" "+str(self.current_selected.angle))
            self.gui_current_selected.loop(screen, screen_pos)

        '''Size scale'''
        scale_x = get_button("scale_x_up")-get_button("scale_x_down")
        scale_y = get_button("scale_y_up")-get_button("scale_y_down")

        if self.current_selected:
            self.current_selected.scale(scale_x,scale_y)
        '''Angle'''
        angle = get_button("angle_up")-get_button("angle_down")
        if self.current_selected:
            self.current_selected.set_angle(self.current_selected.angle+angle)
예제 #15
0
 def execute_event(self):
     GameObject.execute_event(self)