示例#1
0
    def updatedaytime(self):
        """Update daytime cycle should be called in each sec"""
        self.daytime+=1

        #time tu sunrise or sunset
        dd=(self.daylength*0.1)

        #sunrise
        if self.daytime<=dd:
            self.lightlevel=255-self.daydelta*self.daytime
            self.daystate="Sunrise"
        #day
        if self.daytime>=dd and self.daytime<self.daylength/2:
            self.lightlevel=0
            self.daystate="Day"
        #sunset
        if self.daytime>=self.daylength/2:
            lightdelta=self.daytime-self.daylength/2
            self.lightlevel=self.daydelta*lightdelta
            self.daystate="Sunset"
        #night
        if self.daytime>=self.daylength/2+dd:
            self.lightlevel=255
            self.daystate="Night"

        #limit
        if self.daytime>self.daylength:self.daytime=0
        if self.daytime<0:self.daytime=self.daylength

        #Emit change daystate event
        if self.lastdaystate!=self.daystate:
            self.lastdaystate=self.daystate[:]
            basePluginSystem.emit_event("daytimechange",
                daytime=self.daystate[:])
示例#2
0
    def move(self, direction, speed, collisions=True):
        """Move player to a given direction"""
        #north east west south
        mv={"n":(0, speed),
            "s":(0, -speed),
            "e":(-speed, 0),
            "w":(speed, 0)}
        if direction not in mv.keys():return

        #can't go through a blocked block
        if self.currmap:
            xx=int(self.position[0]+0.2+mv[direction][0])
            yy=int(self.position[1]+0.2+mv[direction][1])
            if collisions and self.currmap.isblocked((xx, yy)):
                #self.position=[int(self.position[0]),int(self.position[1])]
                return
        #Emit event
        frompos=tuple(self.position)
        topos=[0,0]
        topos[0]=self.position[0]+mv[direction][0]
        topos[1]=self.position[1]+mv[direction][1]
        basePluginSystem.emit_event("playermove",
            player=self,
            frompos=frompos,topos=topos)
        #update position
        self.position=topos[:]
示例#3
0
 def putblock(self, mousepos):
     """Put block on the ground"""
     if self.actioninrange(mousepos):
         #Emit mineblock event
         basePluginSystem.emit_event("placeblock",
             pos=mousepos,
             block=self.currenttile,
             player=self.player)
示例#4
0
 def mineblock(self, mousepos):
     """Collect block"""
     plpos=self.player.getposition()
     if self.actioninrange(mousepos, 2):
         if not self.minetimer.timepassed(self.minedelay):return
         #Emit mineblock event
         basePluginSystem.emit_event("mineblock",
             pos=mousepos,
             player=self.player)
         #
         self.hidechest()
         #TODO:Sound plugin
         self.playsound(self.minesound)
示例#5
0
 def update(self):
     """Update game"""
     #update daytime
     if self.daytimetimer.timepassed(1000):
         basePluginSystem.emit_event("daytimeupdate")
     #Grow
     if self.growtimer.timepassed(2000):
         Engine.map.randomgrow(self.player.currmap)
     #Unload sectors
     if self.unloadtimer.timepassed(15000):
         #print "Unloading all sectors on the fly"
         Engine.map.mapstack.unloadall()
     #update pages
     self.invscreen.update()
     if self.chestinventory:self.chestinventory.update()
     self.actionbar.update()
     #set current tile
     self.currenttile=self.actionbar.getselected()
示例#6
0
 def addtext(self, text):
     if len(self.tbuffer)>1024:self.clear()
     self.tbuffer.append(text)
     basePluginSystem.emit_event("messageadded",
         message=text)