source: nagslang/screens/area.py@ 21:1b048d2a8411

Last change on this file since 21:1b048d2a8411 was 21:1b048d2a8411, checked in by Simon Cross <hodgestar@…>, 8 years ago

Fake area.

File size: 1.2 KB
Line 
1"""Display a game area."""
2
3import pygame
4import pymunk
5import pymunk.pygame_util
6
7from nagslang.screens.base import Screen
8from nagslang.events import ScreenChange
9
10
11class AreaScreen(Screen):
12
13 def setup(self, world):
14 self.add_walls(world)
15 self.add_protagonist(world)
16
17 def add_walls(self, world):
18 self.walls = []
19 body = pymunk.Body()
20 body.position = (400, 300)
21 corners = [(-200, -150), (-200, 150), (200, 150), (200, -150)]
22 corner = corners[-1]
23 for next_corner in corners:
24 self.walls.append(pymunk.Segment(body, corner, next_corner, 5))
25 corner = next_corner
26 self.space.add(*self.walls)
27
28 def add_protagonist(self, world):
29 body = pymunk.Body(100, 1000)
30 body.position = (400, 300)
31 self.protagonist = pymunk.Circle(body, 30)
32 self.space.add(self.protagonist)
33
34 def handle_event(self, ev):
35 if ev.type == pygame.locals.KEYDOWN:
36 if ev.key == pygame.locals.K_ESCAPE:
37 ScreenChange.post('menu')
38
39 def render(self, surface):
40 surface.fill(pygame.color.Color(0, 0, 0))
41 pymunk.pygame_util.draw(surface, *self.walls)
42 pymunk.pygame_util.draw(surface, self.protagonist)
Note: See TracBrowser for help on using the repository browser.