Exemplo n.º 1
0
    def onLoad(self):
        # Starting position and speed
        self.position = Vector2(0,300)
        self.speed = Vector2(0,1)

        # Fix speed
        if Input.isset(K_LEFT):
            self.speed.x -= self.movespeed
        if Input.isset(K_RIGHT):
            self.speed.x += self.movespeed

        self.jumpspeed = self.startJumpspeed
        if Game.currentScene:
            GameOver.currentScene = Game.currentScene.name
Exemplo n.º 2
0
    def update(self):
        """Called every frame. Handles
        movement and other state updates."""

        if Input.down(K_LEFT):
            self.speed.x -= self.movespeed
        if Input.up(K_LEFT):
            self.speed.x += self.movespeed
        if Input.down(K_RIGHT):
            self.speed.x += self.movespeed
        if Input.up(K_RIGHT):
            self.speed.x -= self.movespeed

        self.jumpspeed = lerp(self.jumpspeed,self.startJumpspeed,0.02)

        self.translate(self.speed)
        self.collider.center = self.position
        self.speed.y += 0.5

        if self.position.y >= 1000:
            Game.loadSceneByName("GameOver")
Exemplo n.º 3
0
    def Button(text,rect,color=(0,0,0)):
        screen = pygame.display.get_surface()
        fontname = pygame.font.get_default_font()
        font = pygame.font.SysFont(fontname,30)
        surfacef = font.render(text,True,color)

        textRect = pygame.Rect((rect.width  - surfacef.get_width())/2
                              ,(rect.height - surfacef.get_height())/2
                              ,surfacef.get_width()
                              ,surfacef.get_height())

        surface = pygame.Surface(rect.size)
        surface.fill((200,200,200))
        surface.blit(surfacef,textRect)

        screen.blit(surface,rect)

        return Input.up("MB1") and rect.collidepoint(Input.mouse_pos)
Exemplo n.º 4
0
    def __init__(self):
        ShowBase.__init__(self)
        pman.shim.init(self)
        basic = core.Filename.expand_from(
            '$MAIN_DIR/assets/textures/basic_1.exr')
        basic = self.loader.load_texture(basic)
        pipeline = simplematcap.init(basic,
                                     render_node=self.render,
                                     light_dir=core.Vec3(-1, -1,
                                                         0.5).normalized())

        fog = core.Fog("Fog Name")
        fog.set_color(0, 0, 0)
        fog.set_exp_density(0.04)
        self.render.set_fog(fog)
        self.disable_mouse()
        self.input = Input()
        self.accept('escape', sys.exit)
        self.accept('f1', self.toggle_wireframe)
        self.world = World(pipeline)
        self.set_background_color(util.srgb_color(0x000000))

        self.manager = FilterManager(self.win, self.cam)
        tex = core.Texture()
        depth = core.Texture()
        quad = self.manager.render_scene_into(colortex=tex, depthtex=depth)
        post_vert_str = load_shader_str('post.vert')
        post_frag_str = load_shader_str('post.frag')
        postshader = core.Shader.make(
            core.Shader.SL_GLSL,
            vertex=post_vert_str,
            fragment=post_frag_str,
        )
        quad.set_shader(postshader)
        quad.set_shader_input('tex', tex)
        quad.set_shader_input('blur', 2.5)
        quad.set_shader_input('depth', depth)
Exemplo n.º 5
0
 def update(self):
     if Input.down(K_SPACE):
         Game.loadSceneByName("StartScene")
Exemplo n.º 6
0
    def update(self):
        # Change mode
        if Input.down(K_q):
            self.mode = "Select"
        elif Input.down(K_w):
            self.mode = "Move"
        elif Input.down(K_e):
            self.mode = "Scale"
        elif Input.down(K_r):
            self.mode = "Rotate"
        elif Input.down(K_d):
            try:
                self.objects.remove(self.selected)
                self.scene.objects.remove(self.selected)
                self.selected = None
            except:
                pass

        elif Input.isset(K_LEFT):
            self.camera.translate(Vector2(-5,0))
        elif Input.isset(K_RIGHT):
            self.camera.translate(Vector2(5,0))
        elif Input.isset(K_UP):
            self.camera.translate(Vector2(0,-5))
        elif Input.isset(K_DOWN):
            self.camera.translate(Vector2(0,5))

        # On click: Selection of objects and updating mouse position.
        if Input.down("MB1"):
            self.mpos = Vector2(Input.mouse_pos[0],Input.mouse_pos[1])
            if not Input.isset(K_LALT):
                sel = False
                for o in self.objects:
                    p = self.camera.screenToWorld(Vector2(*Input.mouse_pos))
                    if o.rect.collidepoint(p.x,p.y):
                        self.selected = o
                        sel = True
                        break
                if not sel:
                    self.selected = None

        # On drag: Moving screen or object
        if Input.motion("MB1"):
            newPos = Vector2(Input.mouse_pos[0],Input.mouse_pos[1])
            move = self.mpos - newPos
            self.mpos = newPos
            if Input.isset(K_LALT):
                self.camera.translate(move)
            elif self.selected is not None:
                if self.modes[self.mode] is not None:
                    self.modes[self.mode](-move)
Exemplo n.º 7
0
 def update(self):
     if Input.down(K_SPACE):
         Game.loadSceneByName(self.firstScene)
Exemplo n.º 8
0
 def update(self):
     if Input.down(K_SPACE):
         Game.loadSceneByName("StartScene")
Exemplo n.º 9
0
 def update(self):
     if Input.down(K_SPACE):
         Game.loadSceneByName(GameOver.currentScene)
Exemplo n.º 10
0
 def update(self):
     if Input.down(K_SPACE):
         Game.loadSceneByName(self.firstScene)
Exemplo n.º 11
0
 def update(self):
     if Input.down(K_SPACE):
         Game.loadSceneByName(GameOver.currentScene)