Commits

Anonymous committed 29fcf90

Fixed a flicker bug! and some cleanup and stuff... need more of that :)

  • Participants
  • Parent commits b0d3a84

Comments (0)

Files changed (5)

 
     def move(self, goalX, goalY, pathDirection):
         #print "Target=", self.target, "progress=", self.progress
-        # erase where we're at now
+        
+        # erase where we're at now -- or not, since in the end I decided to paint the road every frame
         #pygame.draw.rect(enviro.screen, [0,0,0], [self.locationX,self.locationY,40,40], 0)
-        self.rect.top = self.locationY
-        self.rect.left = self.locationX
+        #self.rect.top = self.locationY
+        #self.rect.left = self.locationX
         #enviro.screen.blit(enviro.roadImage,self.rect,self.rect)
         
         # then move, like add 1 to y
             if self.locationX < goalX:
                 self.locationX = goalX
         
-        # draw new -- this should be reworked, we paint empty then paint with stuff... but I'm busy
+        # draw new
         if self.state == "GotGas" or self.state == "DeliverGas":
            enviro.screen.blit(self.imageGas, [self.locationX,self.locationY])            
-        else:
-           enviro.screen.blit(self.imageEmpty, [self.locationX,self.locationY])
-        if (self.state == "Carrying" or
+        elif (self.state == "Carrying" or
             self.state == "Selling" or 
             self.state == "Fueling" or 
             self.state == "Stuck" or 
             self.state == "Reenergizing" or
             self.state == "GetGas"):
            self.paintHarvesterWithStuff()
+        else:
+           enviro.screen.blit(self.imageEmpty, [self.locationX,self.locationY])
         
         if self.locationX == goalX and self.locationY == goalY:
             if pathDirection == 1:
             [(coordX + 5) + (self.fleetPosition+1) * 7,(coordY + 70),5,5],0)
 
     def getNextState(self, shields, base, generators, laser):
-        #print "handle state " , self.state
+        #print "state ", self.state, "progress", self.progress, "x", self.locationX
         
         if self.state == "Cooling":
             self.cooldown = self.cooldown - 1
             goalX = enviro.path[self.target][self.progress][0]
             goalY = enviro.path[self.target][self.progress][1]
             if goalX <> -1:
-                newProgress = self.move(goalX, goalY, 1)
+                self.move(goalX, goalY, 1)
             else:
                 if self.state == "Fueling":
                     if shields.loadFuel():
             goalX = enviro.path[self.target][self.progress][0]
             goalY = enviro.path[self.target][self.progress][1]
             if goalX <> -1:
-                newProgress = self.move(goalX, goalY, 1)
+                self.move(goalX, goalY, 1)
             else:
                 if laser.stashStuff():
                     self.state = "Returning"
             goalX = enviro.path[self.target][self.progress][0]
             goalY = enviro.path[self.target][self.progress][1]
             if goalX <> -1:
-                newProgress = self.move(goalX, goalY, 1)
+                self.move(goalX, goalY, 1)
             else:
                 if self.state == "GetGas":
                     self.state = "GotGas"
             goalY = enviro.path[self.target][self.progress][1]
             
             if goalX <> -1:
-                newProgress = self.move(goalX, goalY, 1)
+                self.move(goalX, goalY, 1)
             else:
-                #print "GOAL MET"
                 for generator in generators:
                     if self.target == generator.location:
                         if generator.harvestStuff():
                     self.progress = 0
                             
             if shields.needFuel():
-                #print "Need to refuel the shield generator!"
-
-                #print "stuck with stuff, and shields need so refueling..."
                 self.state = "Fueling"
                 self.target = 9 # the shield generator
                 self.progress = 0
                 self.progress = 0
                 
             else:
-                # see if we can make gas out of this stuff
+                # see if the stuff should be made into gas
                 genNeedsGas = False
                 for generator in generators:
                     genIsEmpty = generator.checkTankEmpty()
                     if genIsEmpty:
-                        #print "Stuck, found empty tank"
                         genNeedsGas = True
                         generator.gasPromised = True                    
                         self.state = "GetGas"
                         break
                         
                 if not genNeedsGas:
-                    # we're just stuck, pick a spot and go
+                    # we're just stuck, pace awhile and try again in a bit
                     goalX = enviro.path[self.target][self.progress][0]
                     goalY = enviro.path[self.target][self.progress][1]
-                    
                     if goalX <> -1:
-                        newProgress = self.move(goalX, goalY, 1)
+                        self.move(goalX, goalY, 1)
                     else:
                         self.state = "Carrying"
-                        self.progress = self.progress - 1;
+                        self.progress = self.progress - 1
+                        # Huh, I needed to move here to avoid some mean flicker
+                        # Not sure why just here though, odd?
+                        goalX = enviro.path[self.target][self.progress][0]
+                        goalY = enviro.path[self.target][self.progress][1]                        
+                        self.move(goalX, goalY, -1) 
 
 
 if __name__ == '__main__':
+Produce, Defend, WIN!
+
+There's a lot I could say, the big thing on my mind at the moment,
+I learned game programming in Python this last month by reading
+Hello World! Computer Programming for Kids and Other Beginners
+by Warren D. Sande and Carter Sande. Highly recommended, we got
+the book for Steven but I had fun working through it myself and
+this seemed a fun way to add Python to my resume.
+
+I hope you enjoy the game! See COPYING for license terms.
+
+Robert Leachman
+December 2010
+callmerob at gmail dot com
                     #print "at base and not carrying"                    
                     if base.getStuff():
                         self.carrying = 1
-                    #else:
-                        #print "cannot get!"
-                else:
-                    print "gas at home? HMM"
+                #else:
+                    #print "gas at home? HMM"
         if self.goalX == 5 and self.goalY == 1:
             action[0] = 5
         if self.goalX == 1 and self.goalY == 2:
                 enviro.credits = enviro.credits + 1000
                 #print "now you have ", enviro.credits
                 enviro.writeCredits(enviro.credits)
-            else:
-                if self.carrying == 2:
-                    print "gas at market, hmm"
+##            else:
+##                if self.carrying == 2:
+##                    print "gas at market, hmm"
                     
         return action
     
          [[165,230], [230, 230], [230, 360], [360,360], [360,540], [425,540], [660,540], [-1,-1]], # to the laser        
          [[165,230], [100,230], [-1,-1]], # stuck path 1
          [[165,230], [230,230], [-1,-1]], # stuck path 2
-         [[165,230], [230, 230], [230, 360], [360,360], [360,540], [425,540], [450,540], [-1,-1]] # to the market        
+         [[165,230], [230, 230], [230, 360], [360,360], [360,540], [425,540], [435,540], [-1,-1]] # to the market        
         ]
         
 
         if (harvCount < 10):
             newHarv = Harvester(len(enviro.harvesters))
             enviro.harvesters.append(newHarv)
-            harvCount = len(enviro.harvesters)
-            print "Now have", harvCount, "harvesters"
-            #displayNewHarvester()
         else:
             print "Max 10 harvesters!"
     else: # a producing location, add a generator
 def varInfo(object, spacing=10, collapse=1):
     methodList = [method for method in dir(object) if not callable(getattr(object, method))]
     processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
-##    print "\n".join(["%s %s" %
-##                      (method.ljust(spacing),
-##                       processFunc(str(getattr(object, method))))
-##                     for method in methodList])
     result = ""
     for method in methodList:
         if method <> "__builtins__" and method <> "THECOLORS":
 ##            enviro.screen = pygame.display.set_mode([800,600])
             state = 0
          else:
-            print 'Exit!'
+            print 'never-never land'
             pygame.quit()
             sys.exit()