-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.py
63 lines (49 loc) · 1.21 KB
/
agent.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
58
59
60
61
62
import pygame.draw
from pygame import Rect
from vector2d import Vec2d
import math
import random
class Agent(object):
def __init__(self, pos=Vec2d(0,0), facing=0, speed=0, rot_speed=0):
self.pos = pos
self.facing = facing
self.speed = speed
self.rot_speed = rot_speed
self.r, self.g, self.b = 255, 0, 0
self.colliding = False
@property
def x(self):
return self.pos.x
@property
def y(self):
return self.pos.y
@property
def width(self):
return 20
@property
def height(self):
return 20
@property
def right(self):
return self.x + self.width
@property
def bottom(self):
return self.y + self.height
def update(self, delta_time):
self.colliding = False
def draw(self, surface):
surface.set_line_width(1.5)
surface.set_source_rgb(self.r, self.g, self.b)
surface.translate(self.pos.x, self.pos.y)
if self.colliding:
surface.move_to(-10, -10)
surface.line_to(10, -10)
surface.line_to(10, 10)
surface.line_to(-10, 10)
surface.line_to(-10, -10)
surface.rotate(self.facing)
surface.move_to(10,0)
surface.line_to(-10,5)
surface.line_to(-10,-5)
surface.line_to(10,0)
surface.stroke()