Skip to content

Instantly share code, notes, and snippets.

@HariSan1
Last active November 1, 2018 22:05
Show Gist options
  • Save HariSan1/5cc8417ba547a579754d62b8bf2bf523 to your computer and use it in GitHub Desktop.
Save HariSan1/5cc8417ba547a579754d62b8bf2bf523 to your computer and use it in GitHub Desktop.
#module that moves a point (x,y) in 4 different directions, and calculates distance from another existing point
#I called the class Rocket as it could be intended for a rocket game
#Created on Thu Nov
#@author: hsantanam
#"""
from math import sqrt
class Rocket():
def __init__(self, x=0, y=0):
#each rocket has (x,y) position; user or calling function has choice
#of passing in x and y values, or by default they are set at 0
self.x = x
self.y = y
def move_up(self):
self.y += 1
def move_down(self):
self.y -= 1
def move_right(self):
self.x += 1
def move_left(self):
self.x -= 1
#calculate distance from another point
def get_distance(self, other_rocket):
distance = sqrt((self.x-other_rocket.x)**2+(self.y-other_rocket.y)**2)
return distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment