Beispiel #1
0
class Picture:
    def __init__(self, width, height):
        self.mWidth = width
        self.mHeight = height
        self.mSky = Sky(width, height)
        self.mPlanet1 = Planet(200, 210, 215)
        self.mPlanet1.setColor(204, 204, 204)
        self.mMountain1 = Mountain(width, height)
        self.mCrater1 = Crater(40, 130, 100, 100)
        self.mCrater2 = Crater(35, 120, 50, 50)
        self.mCrater3 = Crater(90, 10, 90, 90)
        self.mCrater4 = Crater(250, 90, 100, 100)
        self.mCrack1 = Crack(290, 250)
        self.mCrack2 = Crack(285, 240)
        self.mHill1 = Hill(175, 400)
        self.mHill2 = Hill(300, 380)
        self.mHill3 = Hill(500, 450)
        self.mStar = Star(width, height)
        return

    def draw(self, surface):
        self.mSky.draw(surface)
        self.mPlanet1.draw(surface)
        self.mMountain1.draw(surface)
        self.mCrater1.draw(surface)
        self.mCrater2.draw(surface)
        self.mCrater3.draw(surface)
        self.mCrater4.draw(surface)
        self.mCrack1.draw(surface)
        self.mCrack2.draw(surface)
        self.mHill1.draw(surface)
        self.mHill2.draw(surface)
        self.mHill3.draw(surface)
        self.mStar.draw(surface)
        return
Beispiel #2
0
 def __init__(self):
     self.win = Window((Game.win_width, Game.win_height))
     self.sky = Sky(Game.win_width, Game.win_height)
     self.platform = Platform(Game.win_width, 96, Game.win_height - 96 - 30)
     self.dino = None
     self.enemy_velocity = 250
     self.score = 0
     self.create_handlers()
     self.enemies = []
Beispiel #3
0
    def __init__(self):
        base.accept('f1', self.toggleDebug)

        self.debugNode = BulletDebugNode('Debug')
        self.debugNode.showWireframe(True)
        self.debugNode.showConstraints(True)
        self.debugNode.showBoundingBoxes(False)
        self.debugNode.showNormals(False)
        self.debugNP = base.render.attachNewNode(self.debugNode)
        # self.debugNP.show()

        # World
        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Terrain
        visNP = base.loader.loadModel('models/terrain.egg')

        mesh = BulletTriangleMesh()
        for x in visNP.findAllMatches('**/+GeomNode'):
            geom = x.node().getGeom(0)
            mesh.addGeom(geom)
        shape = BulletTriangleMeshShape(mesh, dynamic=True)

        body = BulletRigidBodyNode('Bowl')
        bodyNP = base.render.attachNewNode(body)
        bodyNP.node().addShape(shape)
        bodyNP.setPos(0, 0, 1)
        bodyNP.setCollideMask(BitMask32.allOn())
        self.world.attachRigidBody(bodyNP.node())

        visNP.reparentTo(bodyNP)

        shapex = BulletBoxShape(5)
        bodyx = BulletRigidBodyNode('Egg')
        bodyNPx = base.render.attachNewNode(bodyx)
        bodyNPx.setPos(0, 0, 3)
        bodyNPx.node().setMass(100.0)
        bodyNPx.node().addShape(shapex)
        self.world.attachRigidBody(bodyNPx.node())
        # visNP.reparentTo(bodyNPx)

        # Player
        self.players = []
        self.myId = -1
        self.speed = Vec3(0, 0, 0)
        self.walk_speed = 2.5

        # Camera
        base.disableMouse()
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)

        # SkySphere
        Sky()

        self.initCam()
Beispiel #4
0
    def __init__(self):

        self.size = (800, 400)
        self.fps = 30
        self.screen = None

        self.sky = Sky(self)
        self.foreground = Foreground(self)
        self.sun = Sun(self)
Beispiel #5
0
def enter():
    global mainstage
    mainstage = title_state.stage
    global player
    player = Player()
    global sky
    if stageload.stage == 2:
        sky = Sky(stageload.stage)
    else:
        sky = Sky(mainstage)

    global map_counter
    if stageload.stage == 2:
        map_counter = Mapcounter(stageload.stage)
    else:
        map_counter = Mapcounter(mainstage)

    game_world.add_object(sky, 0)
    game_world.add_object(player, 1)
Beispiel #6
0
def create_world():
    global prince, rose, sky, grass, balls, big_balls, icon_pause, icon_planet, blood_gage, tree, tree2, trees, trees2, dirty_waters, item_barriers, item_boosters
    prince = Prince()
    rose = Rose()
    icon_pause = Icon_pause()
    icon_planet = Icon_planet()
    blood_gage = Blood_gage()
    tree = Tree()
    tree2 = Tree2()
    #    trees = [Tree() for i in range(5)]
    #    trees2 = [Tree2() for i in range(5)]
    dirty_waters = [Dirty_water() for i in range(2)]
    item_barriers = [Item_barrier() for i in range(3)]
    item_boosters = [Item_booster() for i in range(3)]

    #    big_balls = [BigBall() for i in range(10)]

    #    big_balls_for_collsion_check = big_balls, []

    #    balls = [Ball() for i in range(10)]
    #    balls = big_balls + balls
    grass = Grass()
    sky = Sky()
Beispiel #7
0
from sky import Sky
s = Sky(400)
s.read_frame_hip()
s.read_frame_tyc()
s.print_progress(1, 3)
s.read_line()
s.print_progress(2, 3)
s.read_star()
s.print_progress(3, 3)
s.print_time()
s.init_area(1, s.fs[1], s.fs[2], s.fs[3], s.fs[4], s.fs[5], s.fs[6], s.fs[7],
            6)
s.draw_alpha_lines(15)
s.draw_delta_lines(10)
s.draw_constellation_lines()
s.draw_star()
s.draw_legend()
s.draw_alpha_text(15)
s.draw_delta_text(10)
s.draw_header_link(1, 0)
for k, v in s.f1.items():
    if v[0] == 1:
        s.draw_frame_link(k, v[1], v[3], v[4], v[6], 'hip{:03}'.format(k),
                          'red')
s.draw_frame(True, False, False, False)
s.save_img()
s.init_area(2, s.fn[1], s.fn[2], s.fn[3], s.fn[4], s.fn[5], s.fn[6], s.fn[7],
            6)
s.draw_alpha_lines(15)
s.draw_delta_lines(10)
s.draw_constellation_lines()
Beispiel #8
0
def create_sky(canvas):
    sky1 = Sky(canvas, tkinter.NW)
    sky2 = Sky(canvas, tkinter.SW)
    sky1.draw_sky()
    sky2.draw_sky()
    return sky1, sky2
Beispiel #9
0
class Game(DirectObject):
    def __init__(self):      
        #the window props
        wp = WindowProperties.getDefault()                  
        wp.setUndecorated(False)          
        wp.setFullscreen(False)     
        wp.setSize(cfg['win-size'][0], cfg['win-size'][1])  
        wp.setOrigin(-2,-2)  
        wp.setFixedSize(False)  
        wp.setTitle("Grass and Gas - wezu -PyWeek 21")
        #open the window
        base.openMainWindow(props = wp)  
          
        base.setBackgroundColor(0, 0, 0, 1)
        base.disableMouse()   
        
        self.mode=DRIVING
        
        #make sure the config is ok
        cfg['hardware-skinning']=ConfigVariableBool('hardware-skinning', True).getValue()     
        cfg['srgb']=ConfigVariableBool('framebuffer-srgb', False).getValue()
        cfg['win-size']=[ConfigVariableInt('win-size', '640 480').getWord(0), ConfigVariableInt('win-size', '640 480').getWord(1)] 
        cfg['music-volume']=ConfigVariableInt('music-volume', '50').getValue()
        cfg['sound-volume']=ConfigVariableInt('sound-volume', '100').getValue()
        cfg['key-forward']=ConfigVariableString('key-forward','w').getValue()
        cfg['key-back']=ConfigVariableString('key-back','s').getValue()
        cfg['key-left']=ConfigVariableString('key-left','a').getValue()
        cfg['key-right']=ConfigVariableString('key-right','d').getValue()
        cfg['key-jump']=ConfigVariableString('key-jump','space').getValue()
        cfg['key-cut-grass']=ConfigVariableString('key-cut-grass','shift').getValue()
        cfg['key-enter-exit-car']=ConfigVariableString('key-enter-exit-car','tab').getValue()
        cfg['shadow-size']=ConfigVariableInt('shadow-size',1024).getValue()
        cfg['shadow-area']=ConfigVariableInt('shadow-area',50).getValue()
        
       
        
        self.accept('escape', self.doExit)
        self.accept('f1', self.hideHelp)
        self.accept(cfg['key-jump'], self.doFlip)
        self.accept( cfg['key-enter-exit-car'], self.changeMode)
        self.accept(cfg['key-cut-grass'], self.shear)
        self.accept( 'window-event', self.onWindowEvent)
        
        inputState.watchWithModifiers('forward', cfg['key-forward'])
        inputState.watchWithModifiers('reverse', cfg['key-back'])
        inputState.watchWithModifiers('turnLeft', cfg['key-left'])
        inputState.watchWithModifiers('turnRight', cfg['key-right'])

        # Task
        taskMgr.add(self.update, 'updateWorld') 
        taskMgr.doMethodLater(5.0, self.countGrass, 'grass_counter')
        
        # Physics
        self.setup()
        
        # _____HANDLER_____
    def hideHelp(self):        
        if self.hud.help_frame.isHidden():
            self.hud.help_frame.show()
        else:
            self.hud.help_frame.hide()
            
    def doExit(self):
        self.cleanup()
        sys.exit(1)

    def doReset(self):
        self.cleanup()
        self.setup()

    def toggleWireframe(self):
        base.toggleWireframe()

    def toggleTexture(self):
        base.toggleTexture()

    def toggleDebug(self):
        if self.debugNP.isHidden():
            self.debugNP.show()
        else:
            self.debugNP.hide()

    def doScreenshot(self):
        base.screenshot('Bullet')
        
    def onWindowEvent(self,window=None):
        if window is not None: # window is none if panda3d is not started             
            self.filters.update()            
            self.hud.updateGuiNodes() 
            

    def countGrass(self, task):
        current=self.grass.getStatus()
        if self.grass_to_cut ==0:
            self.grass_to_cut=current
        if current == 0:   
            return
        v= (float(current)/float(self.grass_to_cut))
        #print self.grass_to_cut,  current
        self.hud.counter['text']= str(int(v*100.0))+"%"
        return task.again
        
    def update(self, task):
        dt = globalClock.getDt()
        
        if self.mode==DRIVING:
            self.car.drive(dt)
            self.hud.showSpeed(self.car.getKmph())
            self.hud.showFuel(self.car.fuel)
            self.grass.setMowerPos(self.car.blade_node)
            self.hud.grradar_display['frameTexture']=self.grass.gradar['tex']
            node_to_follow=self.car.node
            speed=0.3
        elif self.mode==WALKING:    
            self.char.walk(dt)
            node_to_follow=self.char.actor_node
            speed=0.03
        self.world.doPhysics(dt, 10, 0.001)
        if self.mode!=EXITING:
            self.camera.follow(node_to_follow, dt, speed)
            
        self.sun_sky.sun_node.setPos(self.camera.cam_node.getPos(render))    
        return task.cont

    def cleanup(self):
        self.world = None
        self.worldNP.removeNode()
    
    def _setMode(self, mode):
        self.mode=mode
        #self.camera.zoomIn()
        
    def changeMode(self):
        if self.mode==DRIVING:
            if self.car.stopEngine():
                self.car.exitCar()
                self.char.exitCar(self.car.node)
                #self.char.getOutOfCar(self.car.node)
                Sequence(Wait(3.6), Func(self._setMode, WALKING)).start()
                self.mode=EXITING
                #self.camera.zoomIn()
                self.hud.hide()
                self.driving_music.stop()
                self.walking_music.play()
        elif self.mode==WALKING:
            if abs(self.char.node.getDistance(self.car.node))<2.0:
                #if self.char
                self.mode=DRIVING
                #self.camera.zoomOut()
                self.hud.show()
                self.char.enterCar()
                self.car.enterCar()
                self.driving_music.play()
                self.walking_music.stop()
                #self.car.node.node().setMass(self.car.mass)
            
    def doFlip(self):
        if self.mode==DRIVING:
            self.car.flip()
            self.grass.getStatus()
        if self.mode==WALKING:
            self.char.jump()
    
    def shear(self):
        if self.mode==DRIVING:
            if self.car.blade_spining:
                self.car.blade_spining=False
                self.grass.mower_blade.hide()
            else:    
                self.car.blade_spining=True
                self.grass.mower_blade.show()
                
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.hide()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Plane
        #shape = BulletPlaneShape(Vec3(0, 0, 1), 0)        
        #mesh = BulletTriangleMesh()
        #geomNodes = loader.loadModel('levels/test1/collision').findAllMatches('**/+GeomNode')
        #geomNode = geomNodes.getPath(0).node()
        #geom = geomNode.getGeom(0)
        #mesh.addGeom(geom)
        #shape = BulletTriangleMeshShape(mesh, dynamic=False, bvh=True )                
        #np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        #np.node().addShape(shape)
        #np.setPos(0, 0, 20.0)
        #np.setCollideMask(BitMask32.allOn())
        #self.world.attachRigidBody(np.node())

        #sky dome
        self.sun_sky=Sky()
        self.sun_sky.setTime(17.0)
        
        #terrain
        self.ground=Terrain(self.world, self.worldNP)
        self.ground.loadMesh(path+'levels/gandg2/collision')
        self.ground.setMaps(path+'levels/gandg2/')
        self.ground.setTextures((39, 1, 2, 15, 4, 5))
        
        #grass
        self.grass=Grass()
        self.grass.setMap(path+'levels/gandg2/grass.png')     
        self.grass_to_cut=self.grass.getStatus()
        # Car
        self.car=Car(self.world, self.worldNP)
        self.car.setPos(161.0,160.0,26)
        #camera
        self.camera=FlyingCamera()
        
        #car to character scale 0.0128        
        self.char=Character(self.world, self.worldNP)        
        self.char.enterCar()
        #self.char.setPos(256, 250, 80)
        
        #filter manager, post process
        self.filters=Postprocess()        
        #self.filters.setupFxaa() 
        #no time to make it work, sorry...
        self.filters.setupFilters()
        
        
        #map objects .. hardcoded because of time
        self.object_root=render.attachNewNode('object_root')
        obj=[
            (path+'models/pyweek_wall1',0.0,(303.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(301.0,405.0,25.0980434417725),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(299.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(297.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(295.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(293.0,405.0,25.0980434417725),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(291.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(289.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(287.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(285.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(283.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(281.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(281.0,385.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(283.0,385.0,25.0980453491211),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(285.0,385.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,404.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,402.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,400.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,398.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,396.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,394.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,392.0,25.237850189209),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,404.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,398.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,396.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,394.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,392.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,390.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,388.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,386.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(286.0,386.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(286.0,388.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(286.0,390.0,25.0980434417725),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(287.0,391.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(289.0,391.0,25.1190624237061),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(291.0,391.0,25.1960334777832),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(293.0,391.0,25.1596641540527),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(295.0,391.0,25.2697868347168),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(297.0,391.0,25.3282146453857),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(299.0,391.0,25.3496627807617),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(301.0,391.0,25.2688617706299),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(303.0,391.0,25.2534332275391),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,402.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_box',0.0,(279.600006103516,401.700012207031,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(279.399993896484,402.200012207031,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(279.600006103516,402.700012207031,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(279.399993896484,403.399993896484,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(278.799987792969,402.799987792969,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(278.799987792969,402.100006103516,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(279.0,401.5,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(278.5,401.600006103516,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(278.799987792969,401.899993896484,25.5980415344238),None),            
            (path+'models/pyweek_box',90.0,(279.5,402.600006103516,25.5980415344238),None),
            (path+'models/pyweek_box',90.0,(279.0,402.5,25.5980415344238),None),
            (path+'models/pyweek_box',90.0,(279.399993896484,402.0,25.5980415344238),None),
            (path+'models/pyweek_box',90.0,(278.100006103516,402.299987792969,25.0980415344238),None),
            (path+'models/pyweek_box',90.0,(277.799987792969,401.700012207031,25.0980415344238),None),
            (path+'models/pyweek_box',90.0,(278.200012207031,401.899993896484,25.5980415344238),None),
            (path+'models/pyweek_box',90.0,(279.399993896484,402.399993896484,26.0980415344238),None),
            (path+'models/pyweek_box',90.0,(279.0,401.899993896484,26.0980415344238),None),
            (path+'models/pyweek_box',90.0,(278.799987792969,402.399993896484,26.0980415344238),None)
            ]
        for i in obj:
            loadObject(model=i[0], H=i[1], pos=i[2], world=self.world, worldNP=self.worldNP, root=self.object_root, collision_solid=i[3])
        self.object_root.flattenStrong()
        
        #models/pyweek_gate,90.0,(280.0,399.0,25.0980415344238))
                
        #gui    
        self.hud=HUD()
        
        #volume
        sfxMgr = base.sfxManagerList[0]
        sfxMgr.setVolume(cfg['sound-volume']*0.01)
        musicMgr = base.musicManager
        musicMgr.setVolume(cfg['music-volume']*0.01)
        
        #music
        self.driving_music=loader.loadMusic(path+'music/driving.ogg')
        self.driving_music.setLoop(True) 
        self.driving_music.play()
        self.walking_music=loader.loadMusic(path+'music/walking.ogg')
        self.walking_music.setLoop(True) 
        
        print self.char.actor.getScale(render)    
Beispiel #10
0
from sky import Sky
s = Sky(400)
alpha = (6 + 45 / 60 + 08.917 / 3600) * 15
delta = -16 - 42 / 60 - 58.02 / 3600
s.read_frame_tyc()
fid = s.id_frame_tyc(alpha, delta)
print(fid)
cubesat = Led(brightness=1.,
              std=1.,
              sequence=header,
              frequency=30,
              x=CMOS.cols // 2,
              y=CMOS.rows // 2)
# Receiver object with a camera, that captures images at a fixed frequency (1 / fps)
# The receiver generates a random noise pattern that is applied to all the captured images. Set noise=False for no noise
print(CMOS)
print('\nGenerating background variation noise pattern, please wait... ',
      end='')
receiver = Receiver(camera=CMOS, fps=60)
print('Done!')

# Create teh sky  with random stars and 1 cubesat (Led)
sky = Sky()
sky.add_random_stars(N_STARS,
                     max_x=CMOS.cols,
                     max_y=CMOS.rows,
                     min_brightness=.02,
                     max_brightness=1.,
                     min_std=.01,
                     max_std=2.)
sky.add_cubesat(cubesat)

# Capture a video from t=0 to t=100 ms. The cubesat (Led) will be repeating its sequence starting at t=0
# Video frames will include the cubesat (Led) or not, according to it's blinking frecuency, current state in the sequence (High or Low)
# and video capturing speed (fps)
timestamps, video = receiver.capture_video(sky, millis_end=150)

# Process the frames as we want, in this case it's just a median filter
Beispiel #12
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.hide()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Plane
        #shape = BulletPlaneShape(Vec3(0, 0, 1), 0)        
        #mesh = BulletTriangleMesh()
        #geomNodes = loader.loadModel('levels/test1/collision').findAllMatches('**/+GeomNode')
        #geomNode = geomNodes.getPath(0).node()
        #geom = geomNode.getGeom(0)
        #mesh.addGeom(geom)
        #shape = BulletTriangleMeshShape(mesh, dynamic=False, bvh=True )                
        #np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        #np.node().addShape(shape)
        #np.setPos(0, 0, 20.0)
        #np.setCollideMask(BitMask32.allOn())
        #self.world.attachRigidBody(np.node())

        #sky dome
        self.sun_sky=Sky()
        self.sun_sky.setTime(17.0)
        
        #terrain
        self.ground=Terrain(self.world, self.worldNP)
        self.ground.loadMesh(path+'levels/gandg2/collision')
        self.ground.setMaps(path+'levels/gandg2/')
        self.ground.setTextures((39, 1, 2, 15, 4, 5))
        
        #grass
        self.grass=Grass()
        self.grass.setMap(path+'levels/gandg2/grass.png')     
        self.grass_to_cut=self.grass.getStatus()
        # Car
        self.car=Car(self.world, self.worldNP)
        self.car.setPos(161.0,160.0,26)
        #camera
        self.camera=FlyingCamera()
        
        #car to character scale 0.0128        
        self.char=Character(self.world, self.worldNP)        
        self.char.enterCar()
        #self.char.setPos(256, 250, 80)
        
        #filter manager, post process
        self.filters=Postprocess()        
        #self.filters.setupFxaa() 
        #no time to make it work, sorry...
        self.filters.setupFilters()
        
        
        #map objects .. hardcoded because of time
        self.object_root=render.attachNewNode('object_root')
        obj=[
            (path+'models/pyweek_wall1',0.0,(303.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(301.0,405.0,25.0980434417725),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(299.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(297.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(295.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(293.0,405.0,25.0980434417725),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(291.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(289.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(287.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(285.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(283.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(281.0,405.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(281.0,385.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(283.0,385.0,25.0980453491211),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(285.0,385.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,404.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,402.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,400.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,398.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,396.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,394.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(304.0,392.0,25.237850189209),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,404.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,398.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,396.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,394.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,392.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,390.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,388.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,386.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(286.0,386.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(286.0,388.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(286.0,390.0,25.0980434417725),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(287.0,391.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(289.0,391.0,25.1190624237061),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(291.0,391.0,25.1960334777832),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(293.0,391.0,25.1596641540527),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(295.0,391.0,25.2697868347168),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(297.0,391.0,25.3282146453857),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(299.0,391.0,25.3496627807617),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(301.0,391.0,25.2688617706299),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',0.0,(303.0,391.0,25.2534332275391),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_wall1',90.0,(280.0,402.0,25.0980415344238),path+'models/pyweek_wall1_collision'),
            (path+'models/pyweek_box',0.0,(279.600006103516,401.700012207031,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(279.399993896484,402.200012207031,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(279.600006103516,402.700012207031,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(279.399993896484,403.399993896484,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(278.799987792969,402.799987792969,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(278.799987792969,402.100006103516,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(279.0,401.5,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(278.5,401.600006103516,25.0980415344238),None),
            (path+'models/pyweek_box',0.0,(278.799987792969,401.899993896484,25.5980415344238),None),            
            (path+'models/pyweek_box',90.0,(279.5,402.600006103516,25.5980415344238),None),
            (path+'models/pyweek_box',90.0,(279.0,402.5,25.5980415344238),None),
            (path+'models/pyweek_box',90.0,(279.399993896484,402.0,25.5980415344238),None),
            (path+'models/pyweek_box',90.0,(278.100006103516,402.299987792969,25.0980415344238),None),
            (path+'models/pyweek_box',90.0,(277.799987792969,401.700012207031,25.0980415344238),None),
            (path+'models/pyweek_box',90.0,(278.200012207031,401.899993896484,25.5980415344238),None),
            (path+'models/pyweek_box',90.0,(279.399993896484,402.399993896484,26.0980415344238),None),
            (path+'models/pyweek_box',90.0,(279.0,401.899993896484,26.0980415344238),None),
            (path+'models/pyweek_box',90.0,(278.799987792969,402.399993896484,26.0980415344238),None)
            ]
        for i in obj:
            loadObject(model=i[0], H=i[1], pos=i[2], world=self.world, worldNP=self.worldNP, root=self.object_root, collision_solid=i[3])
        self.object_root.flattenStrong()
        
        #models/pyweek_gate,90.0,(280.0,399.0,25.0980415344238))
                
        #gui    
        self.hud=HUD()
        
        #volume
        sfxMgr = base.sfxManagerList[0]
        sfxMgr.setVolume(cfg['sound-volume']*0.01)
        musicMgr = base.musicManager
        musicMgr.setVolume(cfg['music-volume']*0.01)
        
        #music
        self.driving_music=loader.loadMusic(path+'music/driving.ogg')
        self.driving_music.setLoop(True) 
        self.driving_music.play()
        self.walking_music=loader.loadMusic(path+'music/walking.ogg')
        self.walking_music.setLoop(True) 
        
        print self.char.actor.getScale(render)    
Beispiel #13
0
 def run(self):
     
     while self.paused[0] == 1:
         pass
     
     sky = Sky(self.queue)
     sun = Sun(self.queue, 300, 100)
     moon = Moon(self.queue, 300, 100)
     ground = Ground(self.queue)
     
     time = 75
     self.shared[0] = time
     day = 0
     seasons = ["spring", "summer", "fall", "winter"]
     season = "spring"
     self.shared[2] = seasons.index(season)
     seasonStages = ["early", "mid", "mid", "late"]
     seasonStage = "mid"
     
     weatherOptions = ["clear", "clear", "clear", "clear", "cloudy", "cloudy", "overcast", "rain", "rain", "storm"]
     weather = choice(weatherOptions)
     self.shared[1] = weatherOptions.index(weather)
     
     self.queue.put(QueueItem("cont"))   
     self.paused[0] = 1
     self.paused[3] = 0
     while self.paused[0] == 1:
         pass
     
     while True:
         
         sky.update(time)
         sun.update(time)
         moon.update(time, day)
         ground.update(time, season, seasonStage, seasons)
         
         sun.draw()
         moon.draw()
         ground.draw()
                
         time += 3
         if time > 1600:
             time = 0
             day += 1
             if day > 15:
                 day = 0
             season = seasons[int(day/4)]
             self.shared[2] = seasons.index(season)
             seasonStage = seasonStages[day%len(seasonStages)]
             
             if season == "winter" and seasonStage == "early":
                 weather = "rain"
             else: 
                 weather = choice(weatherOptions)
         
         self.shared[0] = time
         self.shared[1] = weatherOptions.index(weather)
         self.queue.put(QueueItem("cont"))
         self.paused[0] = 1
         sleep(0.05)
         while self.paused[0] == 1:
             pass
Beispiel #14
0
class Game:

    win_width = 1450
    win_height = 800

    def __init__(self):
        self.win = Window((Game.win_width, Game.win_height))
        self.sky = Sky(Game.win_width, Game.win_height)
        self.platform = Platform(Game.win_width, 96, Game.win_height - 96 - 30)
        self.dino = None
        self.enemy_velocity = 250
        self.score = 0
        self.create_handlers()
        self.enemies = []

    def create_handlers(self):
        self.win.add_handler('w', lambda x: self.jump())
        self.win.add_handler('W', lambda x: self.jump())
        self.win.add_handler('<space>', lambda x: self.reset())

    def reset(self):
        if not self.dino.alive:
            self.dino.alive = True
            self.enemies = []
            self.score = 0
            self.enemy_velocity = 250

    def jump(self):
        if self.dino:
            self.dino.jump()

    @property
    def window_is_open(self):
        return self.win.open

    def check_collision_with_ground(self):
        if not (self.dino.y + self.dino.height >= self.platform.y):
            return
        self.dino.y = self.platform.y - self.dino.height
        self.dino.reset_force()
        self.dino.allow_jump()

    def update_dino(self, dt: float):
        if not self.dino:
            return
        self.dino.tick(dt)
        self.check_collision_with_ground()

    def remove_enemies(self):
        for enemy in self.enemies:
            if enemy.x + enemy.width < 0:
                self.enemies.remove(enemy)
            else:
                return

    def move_enemies(self, dt: float):
        delta = -dt * self.enemy_velocity
        for enemy in self.enemies:
            enemy.move(delta)

    def tick_enemies(self, dt: float):
        for enemy in self.enemies:
            enemy.tick(dt)

    def update_enemies(self, dt: float):
        self.move_enemies(dt)
        self.tick_enemies(dt)
        self.remove_enemies()

    def update_score(self, dt: float):
        self.score += dt * 10

    def update_platform(self, dt: float):
        delta = -dt * self.enemy_velocity
        self.platform.move(delta)

    def update(self, dt: float):
        self.update_dino(dt)
        self.update_enemies(dt)
        self.update_score(dt)
        self.update_platform(dt)
        self.sky.tick(dt)

    def tick(self, timedelta: float):
        if self.dino.alive:
            self.update(timedelta)
        self.draw()

    def display_score(self):
        c = self.win.canvas
        c.create_text(c.winfo_width() - 10,
                      20,
                      text=f'Score: {int(self.score)}',
                      anchor=tkinter.E,
                      font=("Purisa", 24))

    def display_game_over(self):
        c = self.win.canvas
        c.create_text(c.winfo_width() // 2,
                      c.winfo_height() // 2,
                      text='Game Over',
                      font=("Purisa", 80))
        c.create_text(c.winfo_width() // 2,
                      c.winfo_height() // 2 + 60,
                      text='Press space to play again',
                      font=("Purisa", 25))

    def draw(self):
        self.win.clear()
        self.win.draw(self.sky)
        self.win.draw(self.platform)
        for enemy in self.enemies:
            self.win.draw(enemy)
        if self.dino:
            self.win.draw(self.dino)
        if not self.dino.alive:
            self.display_game_over()
        self.display_score()
        self.win.update()

    def change_ground(self, path):
        self.platform.load_sprite(path)

    def add_player(self, dino: Dino):
        self.dino = dino

    def add_enemy(self, enemy):
        self.enemies.append(enemy)

    def increase_speed(self):
        self.enemy_velocity += 100
Beispiel #15
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.hide()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Plane
        #shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        #mesh = BulletTriangleMesh()
        #geomNodes = loader.loadModel('levels/test1/collision').findAllMatches('**/+GeomNode')
        #geomNode = geomNodes.getPath(0).node()
        #geom = geomNode.getGeom(0)
        #mesh.addGeom(geom)
        #shape = BulletTriangleMeshShape(mesh, dynamic=False, bvh=True )
        #np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        #np.node().addShape(shape)
        #np.setPos(0, 0, 20.0)
        #np.setCollideMask(BitMask32.allOn())
        #self.world.attachRigidBody(np.node())

        #sky dome
        self.sun_sky = Sky()
        self.sun_sky.setTime(17.0)

        #terrain
        self.ground = Terrain(self.world, self.worldNP)
        self.ground.loadMesh(path + 'levels/gandg2/collision')
        self.ground.setMaps(path + 'levels/gandg2/')
        self.ground.setTextures((39, 1, 2, 15, 4, 5))

        #grass
        self.grass = Grass()
        self.grass.setMap(path + 'levels/gandg2/grass.png')
        self.grass_to_cut = self.grass.getStatus()
        # Car
        self.car = Car(self.world, self.worldNP)
        self.car.setPos(161.0, 160.0, 26)
        #camera
        self.camera = FlyingCamera()

        #car to character scale 0.0128
        self.char = Character(self.world, self.worldNP)
        self.char.enterCar()
        #self.char.setPos(256, 250, 80)

        #filter manager, post process
        self.filters = Postprocess()
        #self.filters.setupFxaa()
        #no time to make it work, sorry...
        self.filters.setupFilters()

        #map objects .. hardcoded because of time
        self.object_root = render.attachNewNode('object_root')
        obj = [(path + 'models/pyweek_wall1', 0.0, (303.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (301.0, 405.0,
                                                    25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (299.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (297.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (295.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (293.0, 405.0,
                                                    25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (291.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (289.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (287.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (285.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (283.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (281.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (281.0, 385.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (283.0, 385.0,
                                                    25.0980453491211),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (285.0, 385.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 404.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 402.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 400.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 398.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 396.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 394.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 392.0,
                                                     25.237850189209),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 404.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 398.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 396.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 394.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 392.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 390.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 388.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 386.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 386.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 388.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 390.0,
                                                     25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (287.0, 391.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (289.0, 391.0,
                                                    25.1190624237061),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (291.0, 391.0,
                                                    25.1960334777832),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (293.0, 391.0,
                                                    25.1596641540527),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (295.0, 391.0,
                                                    25.2697868347168),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (297.0, 391.0,
                                                    25.3282146453857),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (299.0, 391.0,
                                                    25.3496627807617),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (301.0, 391.0,
                                                    25.2688617706299),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (303.0, 391.0,
                                                    25.2534332275391),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 402.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_box', 0.0,
                (279.600006103516, 401.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.399993896484, 402.200012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.600006103516, 402.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.399993896484, 403.399993896484, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 402.799987792969, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 402.100006103516, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0, (279.0, 401.5,
                                                  25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0, (278.5, 401.600006103516,
                                                  25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 401.899993896484, 25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.5, 402.600006103516,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.0, 402.5,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.399993896484, 402.0,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.100006103516, 402.299987792969, 25.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (277.799987792969, 401.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.200012207031, 401.899993896484, 25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (279.399993896484, 402.399993896484, 26.0980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.0, 401.899993896484,
                                                   26.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.799987792969, 402.399993896484, 26.0980415344238), None)]
        for i in obj:
            loadObject(model=i[0],
                       H=i[1],
                       pos=i[2],
                       world=self.world,
                       worldNP=self.worldNP,
                       root=self.object_root,
                       collision_solid=i[3])
        self.object_root.flattenStrong()

        #models/pyweek_gate,90.0,(280.0,399.0,25.0980415344238))

        #gui
        self.hud = HUD()

        #volume
        sfxMgr = base.sfxManagerList[0]
        sfxMgr.setVolume(cfg['sound-volume'] * 0.01)
        musicMgr = base.musicManager
        musicMgr.setVolume(cfg['music-volume'] * 0.01)

        #music
        self.driving_music = loader.loadMusic(path + 'music/driving.ogg')
        self.driving_music.setLoop(True)
        self.driving_music.play()
        self.walking_music = loader.loadMusic(path + 'music/walking.ogg')
        self.walking_music.setLoop(True)

        print self.char.actor.getScale(render)
Beispiel #16
0
class Game(DirectObject):
    def __init__(self):
        #the window props
        wp = WindowProperties.getDefault()
        wp.setUndecorated(False)
        wp.setFullscreen(False)
        wp.setSize(cfg['win-size'][0], cfg['win-size'][1])
        wp.setOrigin(-2, -2)
        wp.setFixedSize(False)
        wp.setTitle("Grass and Gas - wezu -PyWeek 21")
        #open the window
        base.openMainWindow(props=wp)

        base.setBackgroundColor(0, 0, 0, 1)
        base.disableMouse()

        self.mode = DRIVING

        #make sure the config is ok
        cfg['hardware-skinning'] = ConfigVariableBool('hardware-skinning',
                                                      True).getValue()
        cfg['srgb'] = ConfigVariableBool('framebuffer-srgb', False).getValue()
        cfg['win-size'] = [
            ConfigVariableInt('win-size', '640 480').getWord(0),
            ConfigVariableInt('win-size', '640 480').getWord(1)
        ]
        cfg['music-volume'] = ConfigVariableInt('music-volume',
                                                '50').getValue()
        cfg['sound-volume'] = ConfigVariableInt('sound-volume',
                                                '100').getValue()
        cfg['key-forward'] = ConfigVariableString('key-forward',
                                                  'w').getValue()
        cfg['key-back'] = ConfigVariableString('key-back', 's').getValue()
        cfg['key-left'] = ConfigVariableString('key-left', 'a').getValue()
        cfg['key-right'] = ConfigVariableString('key-right', 'd').getValue()
        cfg['key-jump'] = ConfigVariableString('key-jump', 'space').getValue()
        cfg['key-cut-grass'] = ConfigVariableString('key-cut-grass',
                                                    'shift').getValue()
        cfg['key-enter-exit-car'] = ConfigVariableString(
            'key-enter-exit-car', 'tab').getValue()
        cfg['shadow-size'] = ConfigVariableInt('shadow-size', 1024).getValue()
        cfg['shadow-area'] = ConfigVariableInt('shadow-area', 50).getValue()

        self.accept('escape', self.doExit)
        self.accept('f1', self.hideHelp)
        self.accept(cfg['key-jump'], self.doFlip)
        self.accept(cfg['key-enter-exit-car'], self.changeMode)
        self.accept(cfg['key-cut-grass'], self.shear)
        self.accept('window-event', self.onWindowEvent)

        inputState.watchWithModifiers('forward', cfg['key-forward'])
        inputState.watchWithModifiers('reverse', cfg['key-back'])
        inputState.watchWithModifiers('turnLeft', cfg['key-left'])
        inputState.watchWithModifiers('turnRight', cfg['key-right'])

        # Task
        taskMgr.add(self.update, 'updateWorld')
        taskMgr.doMethodLater(5.0, self.countGrass, 'grass_counter')

        # Physics
        self.setup()

        # _____HANDLER_____
    def hideHelp(self):
        if self.hud.help_frame.isHidden():
            self.hud.help_frame.show()
        else:
            self.hud.help_frame.hide()

    def doExit(self):
        self.cleanup()
        sys.exit(1)

    def doReset(self):
        self.cleanup()
        self.setup()

    def toggleWireframe(self):
        base.toggleWireframe()

    def toggleTexture(self):
        base.toggleTexture()

    def toggleDebug(self):
        if self.debugNP.isHidden():
            self.debugNP.show()
        else:
            self.debugNP.hide()

    def doScreenshot(self):
        base.screenshot('Bullet')

    def onWindowEvent(self, window=None):
        if window is not None:  # window is none if panda3d is not started
            self.filters.update()
            self.hud.updateGuiNodes()

    def countGrass(self, task):
        current = self.grass.getStatus()
        if self.grass_to_cut == 0:
            self.grass_to_cut = current
        if current == 0:
            return
        v = (float(current) / float(self.grass_to_cut))
        #print self.grass_to_cut,  current
        self.hud.counter['text'] = str(int(v * 100.0)) + "%"
        return task.again

    def update(self, task):
        dt = globalClock.getDt()

        if self.mode == DRIVING:
            self.car.drive(dt)
            self.hud.showSpeed(self.car.getKmph())
            self.hud.showFuel(self.car.fuel)
            self.grass.setMowerPos(self.car.blade_node)
            self.hud.grradar_display['frameTexture'] = self.grass.gradar['tex']
            node_to_follow = self.car.node
            speed = 0.3
        elif self.mode == WALKING:
            self.char.walk(dt)
            node_to_follow = self.char.actor_node
            speed = 0.03
        self.world.doPhysics(dt, 10, 0.001)
        if self.mode != EXITING:
            self.camera.follow(node_to_follow, dt, speed)

        self.sun_sky.sun_node.setPos(self.camera.cam_node.getPos(render))
        return task.cont

    def cleanup(self):
        self.world = None
        self.worldNP.removeNode()

    def _setMode(self, mode):
        self.mode = mode
        #self.camera.zoomIn()

    def changeMode(self):
        if self.mode == DRIVING:
            if self.car.stopEngine():
                self.car.exitCar()
                self.char.exitCar(self.car.node)
                #self.char.getOutOfCar(self.car.node)
                Sequence(Wait(3.6), Func(self._setMode, WALKING)).start()
                self.mode = EXITING
                #self.camera.zoomIn()
                self.hud.hide()
                self.driving_music.stop()
                self.walking_music.play()
        elif self.mode == WALKING:
            if abs(self.char.node.getDistance(self.car.node)) < 2.0:
                #if self.char
                self.mode = DRIVING
                #self.camera.zoomOut()
                self.hud.show()
                self.char.enterCar()
                self.car.enterCar()
                self.driving_music.play()
                self.walking_music.stop()
                #self.car.node.node().setMass(self.car.mass)

    def doFlip(self):
        if self.mode == DRIVING:
            self.car.flip()
            self.grass.getStatus()
        if self.mode == WALKING:
            self.char.jump()

    def shear(self):
        if self.mode == DRIVING:
            if self.car.blade_spining:
                self.car.blade_spining = False
                self.grass.mower_blade.hide()
            else:
                self.car.blade_spining = True
                self.grass.mower_blade.show()

    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.hide()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Plane
        #shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        #mesh = BulletTriangleMesh()
        #geomNodes = loader.loadModel('levels/test1/collision').findAllMatches('**/+GeomNode')
        #geomNode = geomNodes.getPath(0).node()
        #geom = geomNode.getGeom(0)
        #mesh.addGeom(geom)
        #shape = BulletTriangleMeshShape(mesh, dynamic=False, bvh=True )
        #np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        #np.node().addShape(shape)
        #np.setPos(0, 0, 20.0)
        #np.setCollideMask(BitMask32.allOn())
        #self.world.attachRigidBody(np.node())

        #sky dome
        self.sun_sky = Sky()
        self.sun_sky.setTime(17.0)

        #terrain
        self.ground = Terrain(self.world, self.worldNP)
        self.ground.loadMesh(path + 'levels/gandg2/collision')
        self.ground.setMaps(path + 'levels/gandg2/')
        self.ground.setTextures((39, 1, 2, 15, 4, 5))

        #grass
        self.grass = Grass()
        self.grass.setMap(path + 'levels/gandg2/grass.png')
        self.grass_to_cut = self.grass.getStatus()
        # Car
        self.car = Car(self.world, self.worldNP)
        self.car.setPos(161.0, 160.0, 26)
        #camera
        self.camera = FlyingCamera()

        #car to character scale 0.0128
        self.char = Character(self.world, self.worldNP)
        self.char.enterCar()
        #self.char.setPos(256, 250, 80)

        #filter manager, post process
        self.filters = Postprocess()
        #self.filters.setupFxaa()
        #no time to make it work, sorry...
        self.filters.setupFilters()

        #map objects .. hardcoded because of time
        self.object_root = render.attachNewNode('object_root')
        obj = [(path + 'models/pyweek_wall1', 0.0, (303.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (301.0, 405.0,
                                                    25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (299.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (297.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (295.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (293.0, 405.0,
                                                    25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (291.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (289.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (287.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (285.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (283.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (281.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (281.0, 385.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (283.0, 385.0,
                                                    25.0980453491211),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (285.0, 385.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 404.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 402.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 400.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 398.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 396.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 394.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 392.0,
                                                     25.237850189209),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 404.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 398.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 396.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 394.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 392.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 390.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 388.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 386.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 386.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 388.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 390.0,
                                                     25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (287.0, 391.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (289.0, 391.0,
                                                    25.1190624237061),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (291.0, 391.0,
                                                    25.1960334777832),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (293.0, 391.0,
                                                    25.1596641540527),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (295.0, 391.0,
                                                    25.2697868347168),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (297.0, 391.0,
                                                    25.3282146453857),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (299.0, 391.0,
                                                    25.3496627807617),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (301.0, 391.0,
                                                    25.2688617706299),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (303.0, 391.0,
                                                    25.2534332275391),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 402.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_box', 0.0,
                (279.600006103516, 401.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.399993896484, 402.200012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.600006103516, 402.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.399993896484, 403.399993896484, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 402.799987792969, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 402.100006103516, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0, (279.0, 401.5,
                                                  25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0, (278.5, 401.600006103516,
                                                  25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 401.899993896484, 25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.5, 402.600006103516,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.0, 402.5,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.399993896484, 402.0,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.100006103516, 402.299987792969, 25.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (277.799987792969, 401.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.200012207031, 401.899993896484, 25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (279.399993896484, 402.399993896484, 26.0980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.0, 401.899993896484,
                                                   26.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.799987792969, 402.399993896484, 26.0980415344238), None)]
        for i in obj:
            loadObject(model=i[0],
                       H=i[1],
                       pos=i[2],
                       world=self.world,
                       worldNP=self.worldNP,
                       root=self.object_root,
                       collision_solid=i[3])
        self.object_root.flattenStrong()

        #models/pyweek_gate,90.0,(280.0,399.0,25.0980415344238))

        #gui
        self.hud = HUD()

        #volume
        sfxMgr = base.sfxManagerList[0]
        sfxMgr.setVolume(cfg['sound-volume'] * 0.01)
        musicMgr = base.musicManager
        musicMgr.setVolume(cfg['music-volume'] * 0.01)

        #music
        self.driving_music = loader.loadMusic(path + 'music/driving.ogg')
        self.driving_music.setLoop(True)
        self.driving_music.play()
        self.walking_music = loader.loadMusic(path + 'music/walking.ogg')
        self.walking_music.setLoop(True)

        print self.char.actor.getScale(render)
Beispiel #17
0
from sky import Sky
s = Sky(400, True)
s.read_frame_tyc()
s.print_time()
s.read_star_tyc()
s.print_time()
i = 0
n = len(s.f3)
for k, v in s.f3.items():
    d = s.alpha_d(v[5])
    s.init_area(k, v[1], v[2], v[3], v[4], v[5], v[6], v[7], 16, True)
    s.draw_alpha_lines(d)
    s.draw_delta_lines(1)
    s.draw_frame(True, True, True, True)
    s.draw_star_tyc(int(k - 1))
    s.draw_legend(True)
    s.draw_alpha_text(d)
    s.draw_delta_text(1)
    s.draw_header_tyc(k)
    s.save_img()
    i = i + 1
    s.print_progress(i, n)
s.print_time()