from Tkinter import * import time from UI.Renderer import * from Vec2D import Vec2D from Core import Physics from RigidBody2D import RigidBody2D width = height = 600 root = Tk() cd = Physics() can = Canvas(root, bg="white", width=width, height=height) renderer = Renderer(can) sidewidth = 20 vert_vertices = [Vec2D(-sidewidth/2,-height/2), Vec2D(-sidewidth/2,height/2), Vec2D(sidewidth/2,height/2), Vec2D(sidewidth/2,-height/2)] hori_vertices = [Vec2D(-width/2 + 2*sidewidth, -sidewidth/2), Vec2D(-width/2+2*sidewidth, sidewidth/2), Vec2D(width/2-2*sidewidth, sidewidth/2), Vec2D(width/2-2*sidewidth, -sidewidth/2)] tri_vertices = [Vec2D(-20,10), Vec2D(20,10), Vec2D(0,-100)] sqr_vertices = [Vec2D(-10,-10), Vec2D(-10,10), Vec2D(10,10), Vec2D(10,-10)] rect_vertices = [Vec2D(-60,-5), Vec2D(-60, 5), Vec2D(60, 5), Vec2D(60, -5)] avatar_vertices = [Vec2D(-10, -20), Vec2D(-10, 20), Vec2D(40, 0)] tri = RigidBody2D(tri_vertices,pos=Vec2D(200,200),velocity=Vec2D(10,10), angularVelocity=-2, inverseMass = 500, inertia = 2, muS = .2, muK = .09) sqr1 = RigidBody2D(sqr_vertices, pos=Vec2D(400,400), velocity=Vec2D(-160,-160), angularVelocity=5, orientation = 0, inverseMass = 2500, inertia =.05,muS = .2, muK = .01) sqr2 = RigidBody2D(sqr_vertices, pos=Vec2D(350,300), velocity=Vec2D(60,-60), angularVelocity=5, orientation = 0, inverseMass = 2500, inertia =.05, muS = .2, muK = .01) rect1 = RigidBody2D(rect_vertices, pos=Vec2D(90, 200), velocity=Vec2D(20,-60), angularVelocity=1, orientation = 0, inverseMass = 600, inertia =6, muS = .25, muK = .04) leftwall = RigidBody2D(vert_vertices, pos=Vec2D(sidewidth,height/2), inverseMass = 0, inertia = 999999) rightwall = RigidBody2D(vert_vertices, pos=Vec2D(width-sidewidth,height/2), inverseMass = 0, inertia = 999999) topwall = RigidBody2D(hori_vertices, pos =Vec2D(width/2, sidewidth), inverseMass = 0, inertia = 999999) bottomwall = RigidBody2D(hori_vertices, pos=Vec2D(width/2, height-sidewidth-50), inverseMass = 0, inertia = 999999, orientation=-.2) divider1 = RigidBody2D(rect_vertices, pos=Vec2D(width- 100,height/2), inverseMass=0, orientation=.2, inertia = 999999) divider2 = RigidBody2D(tri_vertices, pos=Vec2D(width/4,height/2), inverseMass=0, orientation=1.57,inertia = 999999) avatar = RigidBody2D(avatar_vertices, pos = Vec2D(200,100), velocity=Vec2D(0,0),inverseMass=4000, inertia=.4, muS=.3, muK=.04, angularVelocity=0) entities = [ rect1, tri, sqr1, sqr2, leftwall,rightwall,topwall, bottomwall, divider1, divider2, avatar]
def reverse(self): self.speed = max(self.speed-self.fowardThrust, self.MAX_REVERSE) heading=self.heading.getRotated(self.orientation) self.velocity += heading*self.speed def update(self, deltaTime): self.angularVelocity*=.97 self.velocity*=.98 RigidBody2D.update(self, deltaTime) width = height = 800 root = Tk() cd = Physics() can = Canvas(root, bg="gray", width=width, height=height) can.pack() renderer = Renderer(can) damMult = .01 sidewidth = 20 sqr_vertices = [Vec2D(-10,-10), Vec2D(-10,10), Vec2D(10,10), Vec2D(10,-10)] class HealthBar(Entity): def __init__(self,width, height, target, offset): self.rightVerts = [Vec2D(width/2,height/2), Vec2D(width/2,-height/2)] self.leftVerts=[Vec2D(-width/2,-height/2), Vec2D(-width/2,height/2)] self.originalHealth=target.health self.vertices=self.leftVerts+self.rightVerts self.target=target self.offset=offset self.width = width