-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflying_object.py
More file actions
31 lines (25 loc) · 1.13 KB
/
Copy pathflying_object.py
File metadata and controls
31 lines (25 loc) · 1.13 KB
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
X_COORD = 0
Y_COORD = 1
class FlyingObject():
def __init__(self, location, speed):
"""Creates a new object of the FlyingObject Class"""
self._speed = speed
self._location = location
def move(self, min_screen_size, max_screen_size):
"""Moves the object one tick"""
# We calculate the new location according to the object movement vector
x_change = max_screen_size[X_COORD] - min_screen_size[X_COORD]
new_x_coords = (self._speed[X_COORD] + self._location[X_COORD] -
min_screen_size[X_COORD]) % x_change + \
min_screen_size[X_COORD]
y_change = max_screen_size[Y_COORD] - min_screen_size[Y_COORD]
new_y_coords = (self._speed[Y_COORD] + self._location[Y_COORD] -
min_screen_size[Y_COORD]) % y_change + \
min_screen_size[Y_COORD]
self._location = (new_x_coords, new_y_coords)
def get_location(self):
"""Returns the object's location"""
return self._location
def get_speed(self):
"""Returns the object's speed"""
return self._speed