-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwall.py
57 lines (45 loc) · 1.93 KB
/
wall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pygame
import pymunk
import pymunk.pygame_util
class Wall:
def __init__(self, world, game, group, pos1=(10, 100), pos2=(100,100)):
self.world = world
self.game = game
self.pos1 = pos1
self.pos2 = pos2
self.segment = None
self.group = 5
def set_pos(self, pos1, pos2):
""" Change the position (onscreen?) of this actor """
self.pos1 = pos1
self.pos2 = pos2
def destroy(self, space):
space.remove(self.segment)
def init_physics(self, space):
segment = pymunk.Segment(space.static_body, self.pos1, self.pos2, 3)
segment.friction = .4
segment.elasticity = .9
segment.collision_type = 2
segment.group = self.group
self.segment = segment
space.add(self.segment)
def render(self, screen):
""" All drawing logic for displaying this actor onscreen """
pymunk.pygame_util.positive_y_is_up = False
position1 = pymunk.pygame_util.to_pygame(self.segment.a, screen)
position2 = pymunk.pygame_util.to_pygame(self.segment.b, screen)
local_pos1 = position1
local_pos1 = (local_pos1[0] - self.game.display.x_offset, local_pos1[1] - self.game.display.y_offset)
#local_pos1 = (local_pos1[0] - self.game.display.x_offset, self.game.display.y_offset - local_pos1[1])
self.pos1 = position1
local_pos2 = position2
local_pos2 = (local_pos2[0] - self.game.display.x_offset, local_pos2[1] - self.game.display.y_offset)
#local_pos2 = (local_pos2[0] - self.game.display.x_offset, self.game.display.y_offset - local_pos2[1])
self.pos2 = position2
pygame.draw.line(screen, (0, 128, 255), local_pos1, local_pos2)
def sync(self):
# TODO: not sure what this is supposed to do?
pass
def pull_updates(self):
# TODO: not sure what this is supposed to do?
pass