-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrajectorymovingobject.py
29 lines (23 loc) · 1.08 KB
/
trajectorymovingobject.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
from moveableobject import MoveableObject
from constants import SCREENW
import math
import random
class TrajectoryMovingObject(MoveableObject):
"""
A gameobject that moves on a trajectory
"""
def __init__(self, x, y, speed, img):
MoveableObject.__init__(self, x, y, speed, img)
# angle randomly ranges from 100 degrees to 260, 0 degrees is vertical axis
self.degreeangle = random.randrange(100, 260)
def move(self):
# screen edge checking
if (self.x > SCREENW - self.width and self.degreeangle > 180) or random.randrange(0, 2000) == 1467:
self.degreeangle = random.randrange(100, 160)
elif (self.x < 0 and self.degreeangle < 180) or random.randrange(0, 2000) == 200:
self.degreeangle = random.randrange(200, 260)
self.x -= (((math.degrees(math.sin(math.radians(self.degreeangle))) * self.speed) / 40) * self.frame_tick)
self.y -= (((math.degrees(math.cos(math.radians(self.degreeangle))) * self.speed) / 40) * self.frame_tick)
def update(self):
super().update()
self.move()