Commits

Dan Ross committed 40e1e54

earwig.py is sans pymunk now

Comments (0)

Files changed (1)

 from pygame.locals import *
 from pygame.color import *
 import sys
-import pymunk
-from pymunk import Vec2d
 import random
 
-def to_pygame(p):
-    """Small hack to convert pymunk to pygame coordinates"""
-    return int(p.x), int(-p.y+600)
 
 class Earwig(pygame.sprite.Sprite):
     """Our earwig sprite"""
 
 def main():
 
-    ##### Pymunk
-    pymunk.init_pymunk()
-    space = pymunk.Space()
-    space.gravity = Vec2d(0, -900)
-    
-    ###### Pygame
     pygame.init()
+    screen = pygame.display.set_mode([640, 480])
     clock = pygame.time.Clock()
     earwig = pygame.image.load('earwig.png')
-    screen = pygame.display.set_mode([640, 480])
-    
-    line_body = pymunk.Body(pymunk.inf, pymunk.inf)
-    line = pymunk.Segment(line_body, (0, 200), (400, 200), 0)
-    space.add_static(line)
-    line.elasticity = .95
-    circles = []
-    running = True
-    ticks_to_circles = 10
     earwig_group = pygame.sprite.Group()
+    running = True
+    ticks_to_earwig = 10
+
     while running:
-        ticks_to_circles -= 1         
-        #pg_circle = pygame.draw.circle(screen, THECOLORS['red'], 
-        #        to_pygame(circle_body.position), int(circle_shape.radius), 2) 
-        
+        clock.tick(50)
+        ticks_to_earwig -= 1         
         
-        #print(len(circles) 
         for event in pygame.event.get():
             if event.type == QUIT:
                running = False 
             elif event.type == KEYDOWN and event.key == K_ESCAPE:
                running = False 
          
-        if ticks_to_circles <= 0:
-            ticks_to_circles = 100
-            mass = 50 
-            radius = 25
-            inertia = pymunk.moment_for_circle(mass, 0, radius, (0,0))
-            c_body = pymunk.Body(mass, inertia)
-            c_shape = pymunk.Circle(c_body, radius, (0,0))
-            c_shape.elasticity = .95
-            c_body.position = (random.randint(50, 150), 400)
-            space.add(c_body, c_shape)
-            circles.append(c_shape)
-            earwig_group.add(Earwig(to_pygame(c_body.position)))
+        if ticks_to_earwig <= 0:
+            ticks_to_earwig = 100
+            earwig_group.add(Earwig([random.randint(20, 320), random.randint(20, 460)] ))
 
-        dt= 1.0/60.0
-        for x in range(1):
-            space.step(dt)
-                                        
+        ### Draw stuff                                
         screen.fill(THECOLORS['white'])
-
-        for circle in circles:
-            pos = to_pygame(circle.body.position)
-            radius = circle.radius
-            pygame.draw.circle(screen, THECOLORS['red'], pos, int(circle.radius), 2) 
-            #for earwig in earwig_group:
-            #    earwig.pos = pos
-            #screen.blit(earwig, [pos[0] - 75, pos[1] - 60]) 
-            #wiggy = Earwig(to_pygame(circle.body.position))
-            #earwig_group.add(Earwig(to_pygame(circle.body.position)))
-            #earwig_group.draw(screen)
-        earwig_group.update()
         earwig_group.draw(screen)
-        #print(len(earwig_group))
-        pg_line = pygame.draw.lines(screen, THECOLORS['lightgray'], False, [to_pygame(line.a), to_pygame(line.b)], 5)
-        
+        ### Update stuff
+        earwig_group.update()
         pygame.display.flip()
-        clock.tick(50)
 
 if __name__ == '__main__':
    main() 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.