Beispiel #1
0
    def __init__(self,
                 width=1280,
                 height=720,
                 color=(255, 255, 255),
                 fullScreen=False):
        self.width = width
        self.height = height

        #full screen
        if (fullScreen):
            self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        else:
            self.screen = pygame.display.set_mode((width, height))

        self.color = color
        self.screen.fill((self.color))

        self.Objects = []
        self.Lights = []
        self.camera = Camera(Vector(0, 0, 0), width / 2, height / 2)
        self.Lights.append(Light(Vector(0, 0, 0)))

        #seznam prave se vykreslujicich trojuhelniku
        #face je (vertex, vertex, vertex)
        self.faces = []
Beispiel #2
0
 def __init__(self, screen, clock):
     super(Game, self).__init__(screen, clock, lifetime=float('inf'))
     self.FPS = 0
     self.scene = TestLevel(Game)
     self.camera = Camera(self.screen, distance=16)
     self.camera.start()
     self.DEVMODE = DEVMODE
     if DEVMODE:
         dev_message()
Beispiel #3
0
class Game(MicroApp):
    def __init__(self, screen, clock):
        super(Game, self).__init__(screen, clock, lifetime=float('inf'))
        self.FPS = 0
        self.scene = TestLevel(Game)
        self.camera = Camera(self.screen, distance=16)
        self.camera.start()
        self.DEVMODE = DEVMODE
        if DEVMODE:
            dev_message()

    def draw(self):
        self.camera.view(self.scene)

        if self.DEVMODE:
            self.camera.devview(self.scene)

        self.camera.show(self.DEVMODE)
        pygame.display.update()

    def step(self, dt):
        self.scene.player.keyboard_handler(
            pressed_keys=pygame.key.get_pressed())
        self.scene.step(dt)

    def on_iteration(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

            if event.type == pygame.MOUSEMOTION and pygame.mouse.get_pressed(
                    3)[0]:
                self.camera.position += np.array(
                    event.rel) * [-1, 1] / self.camera.scale_factor
            if event.type == pygame.MOUSEWHEEL:
                self.camera.distance -= event.y
            if event.type == pygame.KEYDOWN:
                if pygame.key.get_pressed()[pygame.K_r]:
                    self.camera.position = 0, 0
                    self.camera.distance = 14
                if pygame.key.get_pressed()[pygame.K_F3]:
                    self.DEVMODE = not self.DEVMODE

        self.run_tasks()
        self.step(self.clock.get_time() / 1000)
        self.draw()
        self.clock.tick(self.FPS)
        pygame.display.set_caption('{:.1f}'.format(
            self.clock.get_fps()))  # Вывод фпс в заголовок окна
Beispiel #4
0
#full screen
#screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

width = 1280
height = 720
screen = pygame.display.set_mode((width, height))

white = (255, 255, 255)
screen.fill((white))
running = True

sc = Screen(width, height)

clock = pygame.time.Clock()

camera = Camera(None, 0, 0, -100, width / 2, height / 2)

engine = Engine(sc, camera, Light(1, 1, 1))
camera.engine = engine

engine.addComponent(Axis(engine, 1000))

#nastavenim hodnoty promenne col se zviditelni hranicni kostky
col = (145, 20, 200)
#engine.addComponent(Cube(engine, -50,0,0,30,col))
#engine.addComponent(Cube(engine, 50,0,0,30,col))
engine.addComponent(Cube(engine, 0, -50, 0, 30, col))
#engine.addComponent(Cube(engine, 0,50,0,30,col))

engine.addComponent(Pyramid(engine, 0, 20, 0, 1, 1, "rainbow", True))
for i in range(0, 10):
Beispiel #5
0
class GameScreen:
    def __init__(self,
                 width=1280,
                 height=720,
                 color=(255, 255, 255),
                 fullScreen=False):
        self.width = width
        self.height = height

        #full screen
        if (fullScreen):
            self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        else:
            self.screen = pygame.display.set_mode((width, height))

        self.color = color
        self.screen.fill((self.color))

        self.Objects = []
        self.Lights = []
        self.camera = Camera(Vector(0, 0, 0), width / 2, height / 2)
        self.Lights.append(Light(Vector(0, 0, 0)))

        #seznam prave se vykreslujicich trojuhelniku
        #face je (vertex, vertex, vertex)
        self.faces = []

    def update(self):
        self.camera.update()
        for o in self.Objects:
            o.update()

        self.bubbleSort()

    def draw(self):
        self.screen.fill((self.color))

        for o in self.Objects:
            o.draw(self)

        #for f in self.faces:

        self.drawCursor()

        pygame.display.flip()

    def addObject(self, obj):
        self.Objects.append(obj)

    def removeObject(self, obj):
        self.Objects.remove(obj)

    def bubbleSort(self):
        for i in range(len(self.Objects) - 1):
            for j in range(len(self.Objects) - i - 1):
                if (self.Objects[j].Position.distance(self.camera.Position) <
                        self.Objects[j + 1].Position.distance(
                            self.camera.Position)):
                    tmp = self.Objects[j]
                    self.Objects[j] = self.Objects[j + 1]
                    self.Objects[j + 1] = tmp

    def drawCursor(self):
        pygame.draw.line(self.screen, (0, 0, 0),
                         (self.width / 2 - 5, self.height / 2),
                         (self.width / 2 + 5, self.height / 2))
        pygame.draw.line(self.screen, (0, 0, 0),
                         (self.width / 2, self.height / 2 - 5),
                         (self.width / 2, self.height / 2 + 5))