Giter Club home page Giter Club logo

arche's Introduction

arche

state management for pygame

# coding: utf-8

from arche import (
    draw, trans, pygame,
    State, ContextBuilder)

class PausedState(State):
    def handle_keydown_event(self, event):
        if event.key in [pygame.K_p, pygame.K_ESCAPE]:
            return trans.POP()

    def draw(self, ctx, interpolation):
        draw.clear(ctx, (255, 255, 255))
        draw.rect(ctx, (0, 0, 0), self.ctx.rect)

class MainState(State):
    def on_start(self):
        self.ctx.pos  = [0, 0]
        self.ctx.rect = pygame.Rect(0, 0, 10, 10)

    def handle_keydown_event(self, event):
        return {
            pygame.K_p     : trans.PUSH(PausedState),
            pygame.K_s     : trans.SET(PausedState),
            pygame.K_ESCAPE: trans.POP()
        }.get(event.key, None)

    def update(self, ctx, dt):
        if ctx.rect.x > ctx.config['size'][0]:
            ctx.pos = [0, 0]

        ctx.pos[0] += 100 * dt
        ctx.pos[1] += 100 * dt
        ctx.rect.update(ctx.pos, (10, 10))

    def draw(self, ctx, interpolation):
        draw.clear(ctx, (0, 0, 0))
        draw.rect(ctx, (255, 255, 255), ctx.rect)

if __name__ == '__main__':
    ContextBuilder('?', 400, 400) \
        .grab_mouse(False) \
        .resizable(True) \
        .step(120) \
        .fps(75) \
        .build() \
        .run(MainState)

arche's People

Contributors

brkp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.