Anonymous avatar Anonymous committed 49f37bd

Two-colored laser; license must be GPL since I use GPL; moved Bomb to source dir; delete junk

Comments (0)

Files changed (11)

Bomb.py

-# coding=UTF8
-# Copyright © 2010 Rob Leachman
-# Please see the file COPYING in this distribution for license information
-import pygame
-import random
-from pygame.color import THECOLORS
-import sys # for testing
-
-import enviro # my global game environment
-from FloatingSprite import FloatingSprite
-from Fighter import Fighter
-
-     
-class Bomb(FloatingSprite):
-    def __init__(self, image_file, x, y, destX, destY, fromFighter):
-        self.image = image_file
-        FloatingSprite.__init__(self, self.image)
-        
-        self.fromFighter = fromFighter
-        self.state = "blam"
-        self.death = 0
-        
-        self.trueLeft = x
-        self.trueTop = y
-        
-        self.destX = destX
-        self.destY = destY
-        self.calcSpeed(200.0) # 200 steps is good, define this as float!
-        
-        self.detonate = 0
-        self.detonation = 0
-        self.nuked = False
-        
-    def test(self, shieldSprite, nextState):
-        # given a bomb and the shield object, see if we hit the shield
-        
-        if self.rect.top == 430:
-            return False 
-
-        tester = pygame.sprite.Group()
-        tester.add(shieldSprite)
-        if pygame.sprite.spritecollideany(self, tester):
-            #print "CAUGHT!"
-            self.state = nextState
-            return True
-        return False
- 
-# this is provided by floating sprite, duh!   
-##    def paint(self):
-##        enviro.screen.blit(self.image, self.rect)
-    
-    def nuke(self):
-        self.detonate = self.detonate + 2
-        if self.detonate % 5 == 0:
-            self.detonation = self.detonation + 5
-        for i in range (10,self.detonate,10):
-             self.circleIt(i)         
-        if self.detonate > 150:
-            self.nuked = True
-    
-    def circleIt(self, radius):
-        #pygame.draw.circle(enviro.screen, [255,255,255], [self.rect.left,self.rect.top], 20, 3)
-        
-        #drawcircle(image, colour, origin, radius, width=0)
-        enviro.drawcircle(enviro.screen, [255,255,255], [self.rect.left+4,self.rect.top+5], radius, 3)
-            
-    def explode(self):
-        self.speed = [0,0]
-        #print "death=",self.death
-        
-        if self.death == 0:
-            self.oldCenter = self.rect.center
-
-        self.death = self.death + 5
-        
-        
-        if self.death > 30:
-            self.theImage = "deadBomb4.png"
-        elif self.death > 20:
-            self.theImage = "deadBomb3.png"
-        elif self.death > 10:
-            self.theImage = "deadBomb2.png"
-        else:
-            self.theImage = "deadBomb1.png"
-            
-        self.image = pygame.image.load(self.theImage)
-        self.rect = self.image.get_rect()
-        self.rect.center = self.oldCenter
-                
-        if self.death > 40:
-           self.state = "dead"
-            
-    def __str__(self):
-        msg = FloatingSprite.__str__(self)
-        msg +=  "  Bomb state:" + str(self.state)
-        return msg  
-    
-if __name__ == '__main__':
-    
-    pygame.init()
-    enviro.screen = pygame.display.set_mode([800,600])
-    myClock = pygame.time.Clock()
-    
-    delay=100
-    interval=50
-    pygame.key.set_repeat(delay,interval)
-    
-# stuff needed for init:
-
-        
-    dramaBackground = pygame.image.load("dramaBackground.png") 
- 
-    b = Bomb("bomb.png",600,200,600,430, 0)
-    
-    while True:
-        enviro.screen.blit(dramaBackground, [400,0,330,449])          
-    
-        for event in pygame.event.get():
-            if event.type == pygame.QUIT:
-                sys.exit()
-            if event.type == pygame.KEYDOWN:
-                if (pygame.key.get_mods() == 1024): # command key
-                    if (event.key == 113):   # q
-                        sys.exit()
-                    
-            if event.type == pygame.KEYDOWN: 
-                if (pygame.key.get_mods() == 1024): # command key
-                    if (event.key == 113):   # q
-                        sys.exit()                
-                if event.key == pygame.K_h:
-                    print "hit"
-
-        b.paint()
-        if not b.nuked:
-           b.nuke()
-   
-        
-        myClock.tick(30)
-        pygame.display.flip()    
 Copyright © 2010 Rob Leachman
 ALL RIGHTS RESERVED
 
-[This program is licensed under the "MIT License"]
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated
-documentation files (the "Software"), to deal in the
-Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute,
-sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall
-be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
-KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
-OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#       Copyright 2010 Rob Leachman
+#
+#       This program is free software; you can redistribute it and/or modify
+#       it under the terms of the GNU General Public License as published by
+#       the Free Software Foundation; either version 3 of the License, or
+#       (at your option) any later version.
+#
+#       This program is distributed in the hope that it will be useful,
+#       but WITHOUT ANY WARRANTY; without even the implied warranty of
+#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#       GNU General Public License for more details.
+#
+#       You should have received a copy of the GNU General Public License
+#       along with this program; if not, write to the Free Software
+#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+#       MA 02110-1301, USA or see <http://www.gnu.org/licenses/>.
     def shoot(self, bombList, cursor, mouseButtonUp, autoTargeting):
         stillShooting = False
         laserHitCenter = [0,0]
+        shootingBomb = False
         
         # This could be better?
         if mouseButtonUp:
         
         # target a bomb
         if miss:
+            shootingBomb = True
             targetHit = False
             if len(bombList) > 0:
                 for bomb in bombList:
             #enviro.soundEffect[Noise.LASER_MISS].play()
             laserHitCenter = cursor
         
-        #print "Laser shot to", laserHitCenter    
-        pygame.draw.lines(enviro.screen, [0,255,0], False, [[683,448],laserHitCenter], 3)
+        #print "Laser shot to", laserHitCenter
+        if shootingBomb:
+            pygame.draw.lines(enviro.screen, [255,0,0], False, [[683,448],laserHitCenter], 1)
+        else:
+            pygame.draw.lines(enviro.screen, [0,255,0], False, [[683,448],laserHitCenter], 3)
         return stillShooting  
     
 if __name__ == '__main__':
 import Noise
 from FloatingSprite import FloatingSprite
 from AttackerStuff import *
-from Bomb import Bomb
+from Source import Bomb
 from DeadFighter import DeadFighter
 from Third_Party_Sources import gradients
 

ProduceDefendWin.py

 from GasFactory import GasFactory
 from Laser import Laser
 from Shields import Shields
-from Bomb import Bomb
+from Source import Bomb
 from DeadMother import DeadMother
 from Generator import Generator
 
+# coding=UTF8
+# Copyright © 2010 Rob Leachman
+# Please see the file COPYING in this distribution for license information
+import pygame
+import random
+from pygame.color import THECOLORS
+import sys # for testing
+
+import enviro # my global game environment
+from FloatingSprite import FloatingSprite
+from Fighter import Fighter
+
+     
+class Bomb(FloatingSprite):
+    def __init__(self, image_file, x, y, destX, destY, fromFighter):
+        self.image = image_file
+        FloatingSprite.__init__(self, self.image)
+        
+        self.fromFighter = fromFighter
+        self.state = "blam"
+        self.death = 0
+        
+        self.trueLeft = x
+        self.trueTop = y
+        
+        self.destX = destX
+        self.destY = destY
+        self.calcSpeed(200.0) # 200 steps is good, define this as float!
+        
+        self.detonate = 0
+        self.detonation = 0
+        self.nuked = False
+        
+    def test(self, shieldSprite, nextState):
+        # given a bomb and the shield object, see if we hit the shield
+        
+        if self.rect.top == 430:
+            return False 
+
+        tester = pygame.sprite.Group()
+        tester.add(shieldSprite)
+        if pygame.sprite.spritecollideany(self, tester):
+            #print "CAUGHT!"
+            self.state = nextState
+            return True
+        return False
+ 
+# this is provided by floating sprite, duh!   
+##    def paint(self):
+##        enviro.screen.blit(self.image, self.rect)
+    
+    def nuke(self):
+        self.detonate = self.detonate + 2
+        if self.detonate % 5 == 0:
+            self.detonation = self.detonation + 5
+        for i in range (10,self.detonate,10):
+             self.circleIt(i)         
+        if self.detonate > 150:
+            self.nuked = True
+    
+    def circleIt(self, radius):
+        #pygame.draw.circle(enviro.screen, [255,255,255], [self.rect.left,self.rect.top], 20, 3)
+        
+        #drawcircle(image, colour, origin, radius, width=0)
+        enviro.drawcircle(enviro.screen, [255,255,255], [self.rect.left+4,self.rect.top+5], radius, 3)
+            
+    def explode(self):
+        self.speed = [0,0]
+        #print "death=",self.death
+        
+        if self.death == 0:
+            self.oldCenter = self.rect.center
+
+        self.death = self.death + 5
+        
+        
+        if self.death > 30:
+            self.theImage = "deadBomb4.png"
+        elif self.death > 20:
+            self.theImage = "deadBomb3.png"
+        elif self.death > 10:
+            self.theImage = "deadBomb2.png"
+        else:
+            self.theImage = "deadBomb1.png"
+            
+        self.image = pygame.image.load(self.theImage)
+        self.rect = self.image.get_rect()
+        self.rect.center = self.oldCenter
+                
+        if self.death > 40:
+           self.state = "dead"
+            
+    def __str__(self):
+        msg = FloatingSprite.__str__(self)
+        msg +=  "  Bomb state:" + str(self.state)
+        return msg  
+    
+if __name__ == '__main__':
+    
+    pygame.init()
+    enviro.screen = pygame.display.set_mode([800,600])
+    myClock = pygame.time.Clock()
+    
+    delay=100
+    interval=50
+    pygame.key.set_repeat(delay,interval)
+    
+# stuff needed for init:
+
+        
+    dramaBackground = pygame.image.load("dramaBackground.png") 
+ 
+    b = Bomb("bomb.png",600,200,600,430, 0)
+    
+    while True:
+        enviro.screen.blit(dramaBackground, [400,0,330,449])          
+    
+        for event in pygame.event.get():
+            if event.type == pygame.QUIT:
+                sys.exit()
+            if event.type == pygame.KEYDOWN:
+                if (pygame.key.get_mods() == 1024): # command key
+                    if (event.key == 113):   # q
+                        sys.exit()
+                    
+            if event.type == pygame.KEYDOWN: 
+                if (pygame.key.get_mods() == 1024): # command key
+                    if (event.key == 113):   # q
+                        sys.exit()                
+                if event.key == pygame.K_h:
+                    print "hit"
+
+        b.paint()
+        if not b.nuked:
+           b.nuke()
+   
+        
+        myClock.tick(30)
+        pygame.display.flip()    
Add a comment to this file

Source/Tile.pyc

Binary file removed.

Source/__init__.py

 # (I learned too late for this project about the need for this key file)
 
 from Tile import *
+from Bomb import *

produce1.py

-# coding=UTF8
-# Copyright © 2010 Rob Leachman
-# Please see the file COPYING in this distribution for license information
-
-## (Including for posterity, I started learning Python and did this project
-## to get some experience. I wrote this test on November 2 so came a long way
-## in a month!)
-##
-##Object of the game is to collect 10 things
-##
-##A generator produces a thing after 10 cycles
-##A harvester will find a thing and put it to the collection; 5 cycles to get to the thing and 5 to return to the collection
-##Can sell a thing and to get coins, to buy more generators and harvesters
-##
-##Start with 300 coins
-##
-##option 0 (just hit enter):
-##	run another cycle
-##
-##option 1:
-##	build a generator for 200 coins
-##
-##option 2:
-##	build a harvester for 100 coins
-##
-##option 3: 
-##	sell a thing from the collection and get 100 coins
-##
-##
-##Each cycle:
-##
-##A.	Increment cycle count
-##
-##B.	Process input options:
-##if option=1
-##	check coin count, if greater than 199
-##		deduct 200 coins
-##		add 1 generator
-##			thing-ready = false
-##			targeted = false
-##			processor count=0			
-##if option=2
-##	check coin count, if greater than 99
-##		deduct 100 coins
-##		add 1 harvester
-##if option=3
-##	check collection count, if greater than 0
-##		deduct 1 thing from collection
-##		add 100 coins to coin count
-##
-##C.	Process cycle:
-##For each generator
-##	If not thing-ready:
-##		Increment processor count
-##		If processor count == 10
-##			processor count = 0
-##			set thing-ready = true
-##
-##For each harvester:
-##	If state = idle
-##		For each generator
-##			If thing-ready = true and targeted=false
-##				State = harvesting
-##				Target = generator
-##				Target targeted = true
-##				Progress = 0
-##	If state = harvesting
-##		Increment progress
-##		If progress > 4
-##			state = carrying
-##			progress = 0
-##			target thing-ready = false
-##			target targeted = false
-##	If state = carrying
-##		increment return
-##		if return > 4
-##			state = idle
-##			return = 0
-##			increment collection count	
-##
-##D. Check win condition
-##
-##E. Display status
-
-won=0
-coins=300
-cycle=0
-collection=0
-generators = []
-harvesters = []
-
-
-while won == 0:
-    cycle += 1
-    
-    option = raw_input('1=buy generator, 2=buy harvester, 3=sell, 0=go:')
-
-    if (option == '1'):
-##	check coin count, if greater than 199
-##		deduct 200 coins
-##		add 1 generator
-##			thing-ready = false
-##			targeted = false
-##			processor count=0			
-       if (coins > 199):
-            print "You bought a generator!"
-            coins = coins - 200
-            generator = [False, False, 0]
-            generators.append(generator)
-       else:
-            print "Cannot afford a generator!"
-
-##if option=2
-##	check coin count, if greater than 99
-##		deduct 100 coins
-##		add 1 harvester
-##          state = idle
-##          target = -1 (nobody)
-##          progress = 0  
-    if (option == '2'):
-        if (coins > 99):
-            print "You bought a harvester!"
-            coins = coins - 100
-            harvester = ['Idle', -1, 0]
-            harvesters.append(harvester)
-        else:
-            print "Cannot afford a harvester!"
-
-##if option=3
-##	check collection count, if greater than 0
-##		deduct 1 thing from collection
-##		add 100 coins to coin count
-    
-    if (option == '3'):
-        if (collection > 0):
-            print "You're selling a thing!"
-            collection -= 1
-            coins += 100
-        else:
-            print "No thing to sell!"
-    
-
-##For each generator
-##	If not thing-ready:
-##		Increment processor count
-##		If processor count == 10
-##			processor count = 0
-##			set thing-ready = true
-    for generator in generators:
-        if (generator[0] == False): # not already ready
-            generator[2] += 1
-            if (generator[2] == 10):
-                generator[0] = True
-                generator[2] = 0
-
-##For each harvester:
-##	If state = idle
-##		For each generator
-##			If thing-ready = true and targeted=false
-##				State = harvesting
-##				Target = generator
-##				Target targeted = true
-##				Progress = 0
-##	If state = harvesting
-##		Increment progress
-##		If progress > 4
-##			state = carrying
-##			progress = 0
-##			target thing-ready = false
-##			target targeted = false
-##	If state = carrying
-##		increment return
-##		if return > 4
-##			state = idle
-##			return = 0
-##			increment collection count	
-    for harvester in harvesters:
-            state = harvester[0]
-            if (state == "Idle"):
-                for generator in generators:
-                    if (generator[0] == True) and (generator[1] == False):
-
-                        state = "Harvesting"
-                        harvester[0] = state
-                        harvester[1] = generators.index(generator)
-                        generator[1] = True
-                        harvester[2] = 0
-            if (state == "Harvesting"):
-                harvester[2] += 1
-                if (harvester[2] > 4):
-                    state = "Carrying"
-                    harvester[0] = state
-                    harvester[2] = 0
-                    generator = generators[harvester[1]]
-                    generator[0] = False  
-                    generator[1] = False
-            if (state == "Carrying"):
-                harvester[2] += 1
-                if (harvester[2] > 4):
-                    state = "Idle"
-                    harvester[0] = state
-                    harvester[2] = 0
-                    collection += 1
-
-
-
-##D. Check win condition
-    print "Cycle", cycle
-    print "     Coins =", coins
-    print "     Collection =", collection
-
-    if (collection == 10):
-        print "You win at cycle #", cycle
-        won = 1
-
-
-##E. Display status
-   
-    for generator in generators:
-        print "Generator is ready:", generator[0]
-        print "Generator is targeted:", generator[1]
-        print "Generator process count:", generator[2]
-    
-    for harvester in harvesters:
-        print "Harvester state:", harvester[0]
-        print "Harvester target:", harvester[1]
-        print "Harvester progress:", harvester[2]
-    
-    print
-    

produce2.py

-# coding=UTF8
-# Copyright © 2010 Rob Leachman
-# Please see the file COPYING in this distribution for license information
-# Added a shortcut to /applications/SPE.app/Contents/Resources/_spe/shortcuts
-# Now it ends with:
-#   'Run in terminal without arguments  exit'    : 'Ctrl+X',
-# SWEET!
-
-TIMER = 20 #20 is good for prod
-SPEED = 5
-YOURSPEED = 2
-
-import pygame, sys
-from pygame.color import THECOLORS
-pygame.init()
-
-from pygame.locals import *
-
-#pygame.mouse.set_visible(0)  # interesting? hides mouse in window
-#print pygame.key.name(120)   # prints the name of a key code
-#screen.fill([255,255,255])   # white background
-
-
-class You:
-    def __init__(self):
-        self.goalX = 3
-        self.goalY = 1
-        self.locationX = getMapX(self.goalX,self.goalY)
-        self.locationY = getMapY(self.goalX,self.goalY)
-        
-        pygame.draw.rect(screen, THECOLORS["orange1"], [self.locationX,self.locationY,40,40], 0)
-        
-    def aimLeft(self):
-        if (self.goalX > 0):
-            self.goalX = self.goalX - 1
-        
-    def aimRight(self):
-        testX = getMapX(self.goalX + 1, self.goalY)
-        if testX <> -1:
-            self.goalX = self.goalX + 1
-            
-    def aimUp(self):
-        if (self.goalY == 0):
-            print "edge"
-            return
-        self.goalY = self.goalY - 1
-    
-    def aimDown(self):
-        testY = getMapY(self.goalX, self.goalY + 1)
-        if testY <> -1:
-            self.goalY = self.goalY + 1
-        
-    def move(self):
-        goalX = getMapX(self.goalX,self.goalY)
-        goalY = getMapY(self.goalX,self.goalY)
-        
-        newX = self.locationX
-        newY = self.locationY
-        
-        if self.locationX < goalX:
-            newX = newX + YOURSPEED
-            if newX > goalX:
-                newX = goalX
-        if self.locationX > goalX:
-            newX = newX - YOURSPEED
-            if newX < goalX:
-                newX = goalX
-        if self.locationY < goalY:
-            newY = newY + YOURSPEED
-            if newY > goalY:
-                newY = goalY
-        if self.locationY > goalY:
-            newY = newY - YOURSPEED
-            if newY < goalY:
-                newY = goalY
-
-            
-        #print ("GoalX",goalX,"GoalY",goalY,"CurX",self.locationX,"CurY",self.locationY)
-        
-        pygame.draw.rect(screen, THECOLORS["black"], [self.locationX,self.locationY,40,40], 0)
-        self.locationX = newX
-        self.locationY = newY
-        pygame.draw.rect(screen, THECOLORS["orange1"], [self.locationX,self.locationY,40,40], 0)
-            
-            
-class Harvester:
-    def __init__(self, count):
-        self.state = "Idle"
-        self.target = -1
-        self.progress = 0
-        self.fleetPosition = count
-
-        screenX = getLocationX(4)
-        screenY = getLocationY(4)
-    
-        pygame.draw.rect(screen, [255,0,0], 
-            [(screenX + 5) + (self.fleetPosition+1) * 7,(screenY + 70),5,5],0)
-            
-    def spawn(self):
-        # home location
-        self.locationX = 165
-        self.locationY = 230
-        
-        screenX = getLocationX(4)
-        screenY = getLocationY(4)
-    
-        pygame.draw.rect(screen, [255,255,255], 
-            [(screenX + 5) + (self.fleetPosition+1) * 7,(screenY + 70),5,5],0)
-        #pygame.draw.rect(screen, [200,0,0], [35,100,40,40], 0) #harvester
-        pygame.draw.rect(screen, [200,0,0], [self.locationX,self.locationY,40,40], 0)
-
-    def move(self, goalX, goalY, pathDirection):
-        # erase where we're at now
-        pygame.draw.rect(screen, [0,0,0], [self.locationX,self.locationY,40,40], 0)
-        
-        # then move, like add 1 to y
-        if self.locationY < goalY:
-            self.locationY = self.locationY + SPEED
-            if self.locationY > goalY:
-                self.locationY = goalY
-        if self.locationY > goalY:
-            self.locationY = self.locationY - SPEED
-            if self.locationY < goalY:
-                self.locationY = goalY
-        if self.locationX < goalX:
-            self.locationX = self.locationX + SPEED
-            if self.locationX > goalX:
-                self.locationX = goalX
-        if self.locationX > goalX:
-            self.locationX = self.locationX - SPEED
-            if self.locationX < goalX:
-                self.locationX = goalX
-        
-        # draw new
-        pygame.draw.rect(screen, [200,0,0], [self.locationX,self.locationY,40,40], 0)
-        if self.state == "Carrying":
-           self.harvest()
-        
-        if self.locationX == goalX and self.locationY == goalY:
-            if pathDirection == 1:
-                self.progress = self.progress + 1
-            else:
-                self.progress = self.progress - 1
-        return self.progress
-    
-    def harvest(self):
-        pygame.draw.rect(screen, [0,255,0], 
-               [(self.locationX + 5), (self.locationY + 5),30,30],0)
-            
-    def home(self):
-        # erase from playfield
-        pygame.draw.rect(screen, [0,0,0], [self.locationX,self.locationY,40,40], 0)
-        # add back to home list
-        screenX = getLocationX(4)
-        screenY = getLocationY(4)
-    
-        pygame.draw.rect(screen, [255,0,0], 
-            [(screenX + 5) + (self.fleetPosition+1) * 7,(screenY + 70),5,5],0)
-
-        
-    
-class Generator:
-
-    def __init__(self, location):
-        
-        self.location = location # hardcoded for now
-        self.isReady = False
-        self.isTargeted = False
-        self.processCount = 0
-        self.cycleCount = 0
-        
-        screenX = getLocationX(location)
-        screenY = getLocationY(location)
-#        pygame.draw.rect(screen, [0,0,200], [15,15,80,80],0) # generator
-#        pygame.draw.rect(screen, [100,100,0], [35,20,40,40],0) # result box
-        
-        pygame.draw.rect(screen, [0,0,200], [screenX+5,screenY+5,80,80],0) # generator
-        pygame.draw.rect(screen, [100,100,0], [screenX+25,screenY+10,40,40],0) # result box
-        
-    def __str__(self):
-        msg = "GENERATOR DEBUGGER:" + "\n"
-        msg += " Location: " + str(self.location) + "\n"
-        msg += " Ready: " + str(self.isReady) + "\n"
-        msg += " Targeted: " + str(self.isTargeted) + "\n"
-        msg += " Process count: "  + str(self.processCount) + "\n"
-        return msg
-                
-    def produce(self):
-
-        screenX = getLocationX(self.location)
-        screenY = getLocationY(self.location)
-                
-        if (self.processCount == 10):
-            self.isReady = True
-
-            pygame.draw.rect(screen, [0,255,0], 
-               [(screenX + 30), (screenY + 15),30,30],0)
-        if (self.isReady == False):
-            self.cycleCount = self.cycleCount + 1
-            if self.cycleCount > TIMER:
-                self.cycleCount = 0
-                self.processCount = self.processCount + 1
-                pygame.draw.rect(screen, [255,255,0], 
-                    [(screenX + 4) + self.processCount * 7,(screenY + 70),5,5],0)
-                    
-    def harvest(self):
-        self.isReady = False
-        self.isTargeted = False
-        self.processCount = 0
-        self.cycleCount = 0
-        screenX = getLocationX( self.location )
-        screenY = getLocationY( self.location )
-        pygame.draw.rect(screen, [100,100,0], [screenX+25,screenY+10,40,40],0) # result box
-        pygame.draw.rect(screen, [0,0,200], 
-                    [ screenX + 5, screenY + 70,80,5],0)
-                    
-
-
-def getLocationX(location):
-    screenX = 0
-    if (location == 0 or location == 3 or location == 6):
-        screenX = 10 
-    if (location == 1 or location == 4 or location == 7):
-        screenX = 140
-    if (location == 2 or location == 5 or location == 8):
-        screenX = 270
-    return screenX
-
-def getLocationY(location):
-    screenY = 0
-    
-    if (location == 0 or location == 1 or location == 2):
-        screenY = 10 
-    if (location == 3 or location == 4 or location == 5):
-        screenY = 140
-    if (location == 6 or location == 7 or location == 8):
-        screenY = 270
-    return screenY
-         
-def displayNewHarvester():
-    screenX = getLocationX(4)
-    screenY = getLocationY(4)
-    
-    harvCount = len(harvesters)
-    pygame.draw.rect(screen, [255,0,0], 
-        [(screenX + 5) + harvCount * 7,(screenY + 70),5,5],0)
-        
-def getMapX(mapLocX, mapLocY):
-    if mapLocX > len(map[mapLocY]) - 1:
-        return -1
-    return map[mapLocY][mapLocX][0]
-
-def getMapY(mapLocX, mapLocY):
-    if mapLocY > len(map) - 1:
-        return -1
-    return map[mapLocY][mapLocX][1]
-
-
-## INIT
-generators = []
-harvesters = []
-
-genKeys = [ pygame.K_KP7, pygame.K_KP8, pygame.K_KP9, 
-            pygame.K_KP4, pygame.K_KP5, pygame.K_KP6,
-            pygame.K_KP1, pygame.K_KP2, pygame.K_KP3]
-            
-path = [ [[165,230], [100, 230], [100, 100], [35, 100],  [-1,-1]],
-         [[165,230], [100, 230], [100, 100], [165, 100], [-1,-1]],
-         [[165,230], [230, 230], [230, 100], [295, 100], [-1,-1]],
-         
-         [[165,230], [100, 230], [35,  230], [-1,-1]],
-         [[165,230]],
-         [[165,230], [230, 230], [295, 230], [-1,-1]],
-         
-         [[165,230], [100, 230], [100, 360], [35, 360], [-1,-1]],
-         [[165,230], [100, 230], [100, 360], [165,360], [-1,-1]],
-         [[165,230], [230, 230], [230, 360], [295,360], [-1,-1]]
-        ]
-        
-map =   [ [[0,100], [35,100], [100,100], [165,100], [230,100], [295,100], [350,100]],
-          [[0,230], [35,230], [100,230], [165,230], [230,230], [295,230], [350,230]],
-          [[0,360], [35,360], [100,360], [165,360], [230,360], [295,360], [350,360]],
-        ]
-        
-myClock = pygame.time.Clock()
-
-screen = pygame.display.set_mode([800,600])
-
-##pygame.draw.rect(screen, [100,100,100], [10,10,90,90],0)
-##pygame.draw.rect(screen, [100,100,100], [140,10,90,90],0)
-##pygame.draw.rect(screen, [100,100,100], [280,10,90,90],0)
-###pygame.draw.rect(screen, [200,0,0], [35,100,40,40], 0) #harvester
-##pygame.draw.rect(screen, [100,100,100], [10,140,90,90],0)
-##pygame.draw.rect(screen, [255,255,255], [140,140,90,90],0)
-##pygame.draw.rect(screen, [100,100,100], [280,140,90,90],0)
-##pygame.draw.rect(screen, [100,100,100], [10,280,90,90],0)
-##pygame.draw.rect(screen, [100,100,100], [140,280,90,90],0)
-##pygame.draw.rect(screen, [100,100,100], [280,280,90,90],0)
-
-
-# Draw the pads
-for loc in range (0,9):
-    if loc == 4:
-        pygame.draw.rect(screen, [255,255,255], [getLocationX(loc),getLocationY(loc),90,90],0)
-    else:
-        pygame.draw.rect(screen, [100,100,100], [getLocationX(loc),getLocationY(loc),90,90],0)
-        
-you = You()
-
-while True:
-
-    for event in pygame.event.get():
-        if event.type == pygame.QUIT:
-            sys.exit()
-        #print pygame.key.get_mods()  # show modifier keys
-        #if (event.type == KEYUP) or (event.type == KEYDOWN): # show key
-        #    print event
-
-        if event.type == pygame.KEYDOWN:          # check for key presses
-            if event.key == pygame.K_LEFT:        # left arrow turns left    
-                you.aimLeft()
-            if event.key == pygame.K_RIGHT:
-                you.aimRight()
-            if event.key == pygame.K_UP:
-                you.aimUp()
-            if event.key == pygame.K_DOWN:
-                you.aimDown()
-                
-            if event.key in genKeys:
-                genLocation = genKeys.index(event.key)
-                
-                if (genLocation == 4): # the base, add a harvester
-                    harvCount = len(harvesters)
-                    if (harvCount < 10):
-                        print "You bought a harvester!"
-                        newHarv = Harvester(len(harvesters))
-                        harvesters.append(newHarv)
-                        harvCount = len(harvesters)
-                        print "Now have", harvCount, "harvesters"
-                        #displayNewHarvester()
-                    else:
-                        print "Max 10 harvesters!"
-                else: # a producing location, add a generator
-                    foundGen = False
-                    for generator in generators:
-                        if generator.location == genLocation:
-                            foundGen = True
-                    if (foundGen == False):
-                        print "You bought a generator!"
-                        newGen = Generator(genLocation)
-                        generators.append(newGen)
-                
-##            if event.key == pygame.K_p:
-##                print "X!"
-##                gen = Generator(0)                
-##                generators.append(gen)
-          #  if event.key == pygame.K_z:
-
-            if event.key == pygame.K_p:
-                for generator in generators:
-                    print generator
-        if (event.type == pygame.KEYDOWN):
-            if (pygame.key.get_mods() == 1024): # command key
-                if (event.key == 113):   # q
-                    sys.exit()
-             
-    you.move()
-    for generator in generators:
-        generator.produce()
-        
-    for harvester in harvesters:
-        state = harvester.state
-        if state == "Idle":
-            for generator in generators:
-                # need to check idle here again because two generators could be ready at the same time...
-                if state == "Idle" and generator.isReady == True and generator.isTargeted == False:
-                    print "Found target to harvest"
-                    state = "Harvesting"
-                    harvester.state = state
-                    harvester.target = generator.location
-                    generator.isTargeted = True
-                    harvester.progress = 0
-                    harvester.spawn()
-        if state == "Harvesting":
-            
-            goalX = path[harvester.target][harvester.progress][0]
-            goalY = path[harvester.target][harvester.progress][1]
-            
-            if goalX <> -1:
-                newProgress = harvester.move(goalX, goalY, 1)
-            else:
-                print "GOAL MET"
-                state = "Carrying"
-                harvester.state = state
-                harvester.harvest()
-                harvester.progress = harvester.progress - 1;
-                for generator in generators:
-                    if harvester.target == generator.location:
-                        generator.harvest()
-        if state == "Carrying":
-            goalX = path[harvester.target][harvester.progress][0]
-            goalY = path[harvester.target][harvester.progress][1]
-            newProgress = harvester.move(goalX, goalY, -1) 
-            if newProgress == -1:
-                state = "Idle"
-                harvester.state = state
-                print "Home!"
-                harvester.home()
-                
-    
-                
-    myClock.tick(40)
-    fps = myClock.get_fps()
-    pygame.display.flip()
-                        
-##            if (state == "Harvesting"):
-##                harvester[2] += 1
-##                if (harvester[2] > 4):
-##                    state = "Carrying"
-##                    harvester[0] = state
-##                    harvester[2] = 0
-##                    generator = generators[harvester[1]]
-##                    generator[0] = False  
-##                    generator[1] = False
-##            if (state == "Carrying"):
-##                harvester[2] += 1
-##                if (harvester[2] > 4):
-##                    state = "Idle"
-##                    harvester[0] = state
-##                    harvester[2] = 0
-##                    collection += 1

produce3.py

-# coding=UTF8
-# Copyright © 2010 Rob Leachman
-# Please see the file COPYING in this distribution for license information
-## #! /usr/bin/env python
-
-# Added a shortcut to /applications/SPE.app/Contents/Resources/_spe/shortcuts
-# Now it ends with:
-#   'Run in terminal without arguments  exit'    : 'Ctrl+X',
-# Fast interative development, SWEET!
-
-# Produce stuff with generators
-# Can buy generators for cash
-# Can sell stuff to get cash at market
-
-# Need gas to produce stuff
-# Can convert stuff to gas for coin
-
-# Need stuff to power shield
-# Need progressively better shields
-
-# Need stuff to power laser
-# Laser reduces need for shields
-
-# With enough shields and lasers the attack ends - WIN
-
-# Robots will harvest stuff
-# Robots can be upgraded to refuel generators
-
-# Start with a bunch of stuff
-# Shields being depleted so restock with stuff
-# Eventually realize you need to sell some stuff to get cash
-# Buy a generator with some cash
-# Now generator is producing stuff
-# Keep restocking shields with stuff
-# Attack increases so need more shields, stuff
-# Have to sell stuff to get cash to buy generators
-#
-#
-# Laser sound from http://www.freesound.org/samplesViewSingle.php?id=18387
-# Music from http://www.jmickle.co.uk/
-#
-# -- Instruction mode
-# -- No dead-ends
-# -- Paint the instruction screen on pause
-# -- Make the docking under the places more obvious
-# -- Take out the money altogether
-
-
-#pygame.mouse.set_visible(0)  # interesting? hides mouse in window
-
-
-import pygame, sys, random
-import os.path
-from pygame.mixer import *
-from pygame.color import THECOLORS
-from pygame.locals import *
-
-import pyconsole
-from test_syntax import *
-from test_functions import *
-
-import enviro # my global game environment
-import Noise # the noise module, all the music and effects stuff go here
-
-from YourStuff import *
-from AttackerStuff import *
-from Fighter import Fighter
-from FloatingSprite import FloatingSprite
-from Harvester import Harvester
-from MotherShip import MotherShip
-from GasFactory import GasFactory
-from Laser import Laser
-from Shields import Shields
-from Bomb import Bomb
-
-import Title
-import Menu
-
-fullscreen = 1
-
-def main(continuing, firstRun):
-    # Init the screen and sound and everything... 
-    pygame.init()
-    Noise.initMixer()
-    myClock = pygame.time.Clock()
-    enviro.screen = pygame.display.set_mode([800,600])
-
-    # Full-screen mojo from Arcade Tonk Tanks!
-    if fullscreen == 1:
-        screenrect = Rect(0, 0, 800, 600) 
-        bestdepth = pygame.display.mode_ok(screenrect.size, pygame.FULLSCREEN, 32)
-        enviro.screen = pygame.display.set_mode(screenrect.size, pygame.FULLSCREEN, bestdepth)
-    #
-    #enviro.screen.fill([255,255,255])   # white background... but we like black
-    
-    console = pyconsole.Console(
-        enviro.screen, #The surface you want the console to draw on
-        (401,0,328,449), #A rectangle defining the size and position of the console
-        functions={"f":f,"prime":seive, "type":type, "line":line, "polygon":polygon, "circle":circle}, # Functions for the console
-        key_calls={"d":sys.exit}, # Defines what function Control+char will call, in this case ctrl+d calls sys.exit()
-        syntax={re_add:console_add, re_function:console_func}
-        )
-        
-    pygame.display.set_caption('Produce, Defend, Win!')
-    
-    if firstRun:
-        Title.run("myTitle.png", False)
-        Title.run("instructions.png", True)
-    
-    if not continuing:
-        
-        enviro.credits = 0
-        enviro.shieldUpgrades = 1
-        enviro.laserUpgrades = 1
-        enviro.gasFactoryIsBuilt = False
-        enviro.botFactoryIsBuilt = False
-        enviro.BOMB_POWER = 500
-        
-    if enviro.test == 1:
-        enviro.gasFactoryIsBuilt = True
-        enviro.botFactoryIsBuilt = True
-##        enviro.credits = 20000        
-
-    # Draw the pads, the base, get me a you, create some gas, all that stuff...
-    enviro.start()
-
-    if enviro.gasFactoryIsBuilt:
-        enviro.gasFactory.build()
-    if enviro.botFactoryIsBuilt:
-        enviro.factory.build()
-
-    instruction = "Arrow keys or WASD to move"
-    font = pygame.font.Font(None, 20)
-    instruction_text = font.render(instruction, 1, (255,255,255))
-    instruction_pos = [10, 500]
-    enviro.screen.blit(instruction_text, instruction_pos)
-    instruction_text = font.render("Your goal is to make $50000", 1, (255,255,255))
-    enviro.screen.blit(instruction_text, [10,520])
-    
-    enviro.writeCredits(enviro.credits)
-
-    motherBecameActive = False
-
-    fightersActive = 1
-    frustration = 0
-
-    shieldPower = enviro.START_SHIELD_POWER
-
-    # The first one's free...
-    newGen = Generator(5,enviro.gasGauges)
-    newGen.refill(enviro.gasGauges)
-    enviro.generators.append(newGen)
-
-    bombList = pygame.sprite.Group()
-
-    dramaBackground = pygame.image.load("dramaBackground.png")
-
-    # Ready to play, bring up the music!
-    Noise.playMusic('Concrete Water.ogg')
-    pygame.mixer.music.set_volume(enviro.musicLevel[enviro.musicVolume])
-
-    shooter = False
-    paused = False
-
-    shooting = False
-    
-    theKillerBomb = None
-
-    alive = 1
-    while alive == 1:
-        
-        releasedButton = False
-
-        if not paused:
-           enviro.screen.blit(dramaBackground, [400,0,330,449])
-
-        console.process_input()
-        for event in pygame.event.get():
-            if event.type == pygame.KEYDOWN:          # check for key presses
-                if event.key == K_w and pygame.key.get_mods() & KMOD_CTRL:
-                    print "Console active!"
-                    console.set_active()
-                elif event.key == K_q and pygame.key.get_mods() & KMOD_CTRL: 
-                    # Just a little hack so you can play with both pyconsole and python
-                    # Hit ctrl w to hide pyconsole, then ctrl q to switch modes, then ctrl w again to show the console
-                    # I don't expect anyone to actually use both modes in one app, if you really need to, you can be more creative than this.
-                    console.setvar("python_mode", not console.getvar("python_mode"))
-                    console.set_interpreter()   
-                    
-            if event.type == pygame.QUIT:
-                sys.exit()
-            elif event.type == pygame.MOUSEMOTION:
-                newCursor = event.pos
-                if (newCursor[0] > 400 and newCursor[0] < 730 and newCursor[1]<430):
-                    pygame.mouse.set_cursor(*enviro.LASER_POINTER)
-                    shooter = True
-                else:
-                    pygame.mouse.set_cursor(*pygame.cursors.arrow)
-                    shooter = False
-                    shooting = False
-            elif event.type == pygame.MOUSEBUTTONDOWN:
-                if shooter and not paused:
-                    shooting = True
-                    #print "shoot!"
-##                else:
-##                    print "no shot, either not in fight window or we are paused"
-            elif event.type == pygame.MOUSEBUTTONUP:
-                releasedButton = True
-                
-                #cursor.update(event.pos)
-
-            #print pygame.key.get_mods()  # show modifier keys
-            #if (event.type == KEYUP) or (event.type == KEYDOWN): # show key
-            #    print "DEBUG KEY:", event
-
-            if event.type == pygame.KEYDOWN:
-                if (pygame.key.get_mods() == 1024): # command key
-                    if (event.key == 113):   # q
-                        sys.exit()
-
-             
-                if event.key == pygame.K_h and pygame.key.get_mods() & KMOD_CTRL:
-                    print "HARVESTER DEBUG"
-                    for harvester in enviro.harvesters:
-                        print harvester
-                
-                if event.key == pygame.K_ESCAPE or event.key == pygame.K_p:
-                    if paused:
-                        enviro.writePaused(False)
-                        paused = False
-                    else:
-                        enviro.writePaused(True)
-                        paused = True
-                        
-                if event.key == pygame.K_m: # hit m for music mute
-                    enviro.musicVolume += 1
-                    if enviro.musicVolume > len(enviro.musicLevel) - 1:
-                        enviro.musicVolume = 0
-                    pygame.mixer.music.set_volume(enviro.musicLevel[enviro.musicVolume])
-                if event.key == pygame.K_x: # hit s for effects mute
-                    enviro.effectsVolume += 1
-                    if enviro.effectsVolume > len(enviro.soundEffectsLevel) - 1:
-                        enviro.effectsVolume = 0
-                    for effect in enviro.soundEffect:
-                        effect.set_volume(enviro.soundEffectsLevel[enviro.effectsVolume])
-                        
-                if event.key == pygame.K_t:
-                    print "REFUEL"
-                    enviro.laser.stashStuff()
-                if event.key == pygame.K_n:
-                    print "NUKE"
-                    alive = 0
-                    
-                
-                if paused:
-                    #print pygame.key.name(109)   # prints the name of a key code
-                    break # no other commands will be processed until unpause
-                if event.key == pygame.K_LEFT or event.key == pygame.K_a:        
-                    enviro.you.aimLeft(enviro.pads)
-                if event.key == pygame.K_RIGHT or event.key == pygame.K_d:
-                    enviro.you.aimRight(enviro.pads)
-                if event.key == pygame.K_UP or event.key == pygame.K_w:
-                    enviro.you.aimUp(enviro.pads)
-                if event.key == pygame.K_DOWN or event.key == pygame.K_s:
-                    enviro.you.aimDown(enviro.pads)
-                if event.key == pygame.K_SPACE:
-                    action = enviro.you.interact(enviro.generators, enviro.shields, enviro.theBase, enviro.laser)
-                    #print "key ACTION at ", action[0], "act=", action[1]
-                    if action[0] > -1 and action[1] == 1:
-                        enviro.doAction(enviro.you, action, enviro.gasGauges) # build a generator               
-                    
-                if event.key in enviro.genKeys:
-                    genLocation = enviro.genKeys.index(event.key)
-                    
-                    if (genLocation == 4): # the base, add a harvester
-                        harvCount = len(enviro.harvesters)
-                        if (harvCount < 10):
-                            print "You bought a harvester!"
-                            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
-                        foundGen = False
-                        for generator in enviro.generators:
-                            if generator.location == genLocation:
-                                foundGen = True
-                        if (foundGen == False):
-                            print "You bought a generator!"
-                            newGen = Generator(genLocation,enviro.gasGauges)
-                            enviro.generators.append(newGen)
-                            
-        """ now do all the stuff that happens each frame: """
-        
-        if not paused:
-            for generator in enviro.generators:
-                generator.produce(enviro.gasGauges)
-            shieldPower = enviro.shields.powerUp(shieldPower, enviro.fuelPile)
-            shieldSprite = enviro.shields.paintShield(shieldPower)
-
-            frustration += 1
-            if frustration > enviro.MOTHER_FLEET_INCREASE_WAITTIME:
-                frustration = 0
-                fightersActive += 1
-                if fightersActive > enviro.mother.getFleetSize():
-                   fightersActive = enviro.mother.getFleetSize()            
-
-            # paint her progress, and get any emitted bombs
-            theMother = enviro.mother.paint(bombList, fightersActive) 
-            bombList = theMother[0]
-            drama = theMother[1]
-            herState = theMother[2]
-            
-            if not herState == "Waiting":
-                if not motherBecameActive:
-                    motherBecameActive = True
-                    if pygame.mixer:
-                        Noise.playMusic('Grinder-1.ogg')
-##                        music = os.path.join('Sound', 'Grinder-1.ogg')
-##                        pygame.mixer.music.load(music)
-##                        pygame.mixer.music.play(-1)
-                
-            if drama == 1:
-                shieldPower = shieldPower - enviro.BOMB_POWER
-                if shieldPower < 0:
-                    shieldPower = 0
-                enviro.shields.hitShield(shieldPower)
-                enviro.shields.paintShield(shieldPower)
-                enviro.soundEffect[Noise.SHIELD_HIT].play()
-                
-            if len(bombList) > 0:
-                for bomb in bombList:
-                    if bomb.move() == 0 and bomb.rect.top == 430:
-                        if theKillerBomb == None:
-                            theKillerBomb = bomb
-                            channel = pygame.mixer.find_channel(True)
-                            if channel:
-                                #print "got channel"
-                                channel.play(enviro.soundEffect[Noise.MOTHER_HIT])
-                            else:
-                                print "no channel for mother kill sound, will try to use main"
-                                enviro.soundEffect[Noise.MOTHER_HIT].play()                            
-                            
-                    if shieldPower > 0:
-                        bomb.test(shieldSprite, "caught")                            
-                            
-                if not theKillerBomb == None:
-                    if not theKillerBomb.nuked:
-                        theKillerBomb.paint()
-                        theKillerBomb.nuke()
-                    else:
-                        alive = 0
-                    
-
-
-        if not paused:
-            for harvester in enviro.harvesters:
-                harvester.getNextState(enviro.shields, 
-                   enviro.theBase, enviro.generators, enviro.laser)
-                
-            for pad in enviro.padArray:
-                pad.clearNeeds()
-
-##        if not paused:
-            next = enviro.you.moveYou(enviro.pads)
-            if next <> "moving":
-                if next == "up":
-                    enviro.you.aimUp(enviro.pads)
-                if next == "down":
-                    enviro.you.aimDown(enviro.pads)
-                if next == "right":
-                    enviro.you.aimRight(enviro.pads)
-                if next == "left":
-                    enviro.you.aimLeft(enviro.pads)
-                if next == "act":
-                    action = enviro.you.interact(enviro.generators, 
-                               enviro.shields, enviro.theBase, enviro.laser)
-                    if action[0] > -1 and action[1] == 1:
-                        enviro.doAction(enviro.you, action, enviro.gasGauges)
-
-            autoTarget = False
-            if not shooting:
-                target = enviro.laser.autoTarget(bombList)            
-                if target[0] > 0:
-                    newCursor = target
-                    shooting = True
-                    autoTarget = True
-            if shooting:
-                shooting = enviro.laser.shoot(bombList, newCursor, 
-                                             releasedButton, autoTarget)
-                if enviro.mother.state == "Hit":
-                    if pygame.mixer:
-                        Noise.playMusic('Concrete Water.ogg')
-                        motherBecameActive = False
-                            
-        if enviro.credits > 49999:
-            alive=0
-                    
-        myClock.tick(30)
-        fps = myClock.get_fps()
-        #print fps
-        console.draw()
-        if not paused:
-            pygame.display.flip()
-    
-    pygame.mixer.music.fadeout(1000)    
-    if enviro.credits > 49999:
-        enviro.winner()
-    else:
-        enviro.loser()
-        
-        
-        
-if __name__ == '__main__':
-    main(False, True)
-    
-    while True:
-        for event in pygame.event.get():
-            if event.type == pygame.QUIT:
-                sys.exit()            
-
-            if event.type == pygame.KEYDOWN:
-                if event.key == pygame.K_c:
-                    main(True, False)
-                if event.key == pygame.K_r:
-                    main(False, False)
-                if event.key == pygame.K_q:
-                    sys.exit()
-                    
-            if event.type == pygame.KEYDOWN:
-                if (pygame.key.get_mods() == 1024): # command key
-                    if (event.key == 113):   # q
-                        sys.exit()                    
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.