Last active
April 10, 2018 22:48
-
-
Save Auer11/4f5265236f2227651011c3be60e26c39 to your computer and use it in GitHub Desktop.
Game3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scene import * | |
import random | |
from math import atan2 | |
import ui | |
import scene_drawing | |
A = Action | |
from sympy.geometry import Point | |
class MyScene (Scene): | |
def setup(self): | |
self.unit=40 | |
self.speed=.1 | |
self.m_blue=None | |
self.m_red=None | |
self.min_dist=50 | |
self.max_dist=100 | |
self.red=SpriteNode('emj:Red_Circle') | |
self.red.size=self.unit,self.unit | |
self.red.position=self.size.x/2-self.min_dist,self.size.y/2 | |
self.add_child(self.red) | |
self.blue=SpriteNode('emj:Blue_Circle') | |
self.blue.size=self.unit,self.unit | |
self.blue.position=self.size.x/2+self.min_dist,self.size.y/2 | |
self.add_child(self.blue) | |
self.connector=SpriteNode('pzl:Green4') | |
self.connector.size=20,20 | |
self.connector.z_position=-1 | |
self.add_child(self.connector) | |
self.paths=[self.blue.position.x,self.blue.position.y,self.red.position.x,self.red.position.y] | |
scene_drawing.line(self.blue.position.x,self.blue.position.y,self.red.position.x,self.red.position.y) | |
#self.c_img=ShapeNode(self.connector,'#00ffff') | |
#self.add_child(c_img) | |
def did_change_size(self): | |
pass | |
def connector_update(self): | |
bx=self.blue.position.x | |
by=self.blue.position.y | |
rx=self.red.position.x | |
ry=self.red.position.y | |
p1, p2 = Point(bx, by), Point(rx, ry) | |
p3=p1.midpoint(p2) | |
p3length=p1.distance(p2) | |
#print(p3length) | |
self.connector.position=(p3.x,p3.y) | |
deltax=bx-rx | |
deltay=by-ry | |
self.connector.rotation=atan2(deltay,deltax)-4.7 | |
sx,sy=self.connector.size | |
self.connector.size=sx,p3length | |
def nodes_update(self,n0de,touch): | |
#n0de.position=touch.location | |
if n0de.position.x>touch.location.x: | |
n0de.position.x-=self.speed | |
elif n0de.position.x <touch.location.x: | |
n0de.position.x+=self.speed | |
if n0de.position.y >touch.location.y: | |
n0de.position.y-=self.speed | |
elif n0de.position.y<touch.location.y: | |
n0de.position.y+=self.speed | |
def update(self): | |
self.connector_update() | |
def touch_began(self, touch): | |
if touch.location in self.blue.frame: | |
#self.blue.position=touch.location | |
self.m_blue=touch.touch_id | |
elif touch.location in self.red.frame: | |
#self.red.position=touch.location | |
self.m_red=touch.touch_id | |
def touch_moved(self, touch): | |
if self.m_blue==touch.touch_id: | |
#self.blue.position=touch.location | |
self.nodes_update(self.blue,touch) | |
if self.m_red==touch.touch_id: | |
#self.red.position=touch.location | |
self.nodes_update(self.red,touch) | |
def touch_ended(self, touch): | |
pass | |
if self.m_red==touch.touch_id: | |
self.m_red=None | |
if self.m_blue==touch.touch_id: | |
self.m_blue=None | |
if __name__ == '__main__': | |
run(MyScene(), show_fps=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment