Jump to content

roving-robots

  • entries
    2
  • comments
    3
  • views
    14,917

Bam! An Update On Roving Robots


admalledd

758 views

 Share

even though I fell off the face of the Internet over here due to graduating from high school, going to college and finding a job (ps: need a python/assembly programmer?) I have actually been actively working on THIS, my github of roving-robots. I had decided that I would stop really talking much about it until the hardest parts for me were done or structured in a way that I could do it.

so; lets crack down on what I got:

the main block class:


class block(object):

    #non interface stuff

    def __init__(self,img,lable=None,num=None):

        '''example init:::

        block(os.path.join(~~~~~),pygame.font.render(~~~~~),1)


        we draw img's onto fake smaller surface so that we can use IT for an absilute topleft'''

        ##TODO::: make "active" setting for textbox, and other settings???


        if type(img) == str:

            self.img = lib.common.load_img(img)

        else:

            self.img=img

        self.lable = lable

        self.lable_pos = 7,11

        self.surf = pygame.Surface((80,80))

        self.surf = self.surf.convert_alpha()

        if num is not None:

            if isinstance(num,input.Input):

                self.tbox = num

            else:

                self.tbox = input.Input(y=y,maxlength=3, color=(255,0,0), prompt=' ', restricted='0123456789')

        else:

            #used to let us know NOT to try and render this section

            self.tbox = None


        #nothing can link by default to a default block, use a subclass!

        self.link_down  = False

        self.link_up    = False

        self.link_left  = False

        self.link_right = False

        #block-linkers:

        self._dblock=None

        self._ublock=None

        self._rblock=None

        self._lblock=None


    def draw(self,screen,rect):

        if self.lable:

            self.surf.blit(self.lable,self.lable_pos)

        if self.tbox:

            self.tbox.draw(self.surf)

        self.surf.blit(self.img,(0,0))

        screen.blit(self.surf,rect)

    def event_engine(self,events):

        for event in events:

            if event.type == MOUSEBUTTONDOWN:

                print 'happy days!'



    ##link block decorators:::

    ##if "set", tey set themselves to other, and also set other.xblock to self(or none if unlinking)

    @lib.decorators.propget

    def dblock(self):

        return self._dblock

    @lib.decorators.propset

    def dblock(self,other):

        if other is None:

            #set the other block's corrisponing to None as well...

            #use name in self because other is None right now...

            self._dblock._ublock = None

        else:

            other._ublock = self

        self._dblock = other


    @lib.decorators.propget

    def ublock(self):

        return self._ublock

    @lib.decorators.propset

    def ublock(self,other):

        if other is None:

            #set the other block's corrisponing to None as well...

            self._ublock._dblock = None

        else:

            other._dblock = self

        self._ublock = other


    @lib.decorators.propget

    def lblock(self):

        return self._lblock

    @lib.decorators.propset

    def lblock(self,other):

        if other is None:

            #set the other block's corrisponing to None as well...

            self._lblock._rblock = None

        else:

            other._rblock = self

        self._lblock = other


    @lib.decorators.propget

    def rblock(self):

        return self._rblock

    @lib.decorators.propset

    def rblock(self,other):

        if other is None:

            #set the other block's corrisponing to None as well...

            self._rblock._lblock = None

        else:

            other._lblock = self

        self._rblock = other



    ##location properties

    @lib.decorators.propget

    def loc(self):

        return self.__loc

    @lib.decorators.propset

    def loc(self,value):

        self.__loc = value


    #action stuff

    def action(self,robot):

        '''robotic action to take (turn, go fwd, scan/make desision)'''

        pass

    def next(self,robot):

        '''what is the next block? (give (x,y) or instance?)'''

        pass



    def drag(self):

        '''cleans up object for a 'drop' '''

        pass

    def able_drop(self,pos,pmap):

        '''find any problems with the drop and return False if obstructed.

        else return True'''

        pass

    def drop(self,pos,pmap):

        '''finalize a drop. actually places block on grid'''

        pass

    def save(self):

        '''return a string which will allow recreation of this block (type,lable,num,pos,binding)'''

        pass

    def load(self,s):

        '''places block and recreates block based on "s" '''

        pass

note: a HECK a lot o' stuff!

but here, most of it is, quick and simple, or a place holder for future updates.

lets look at the key functions of our block:

  • __init__
    here we just set things up. load the image into the object, set lable text, try to use text_box system(if given), and set up our fake render surface.

  • draw
    simply draw what is needed to fake surface, making it simpler to align everything, then draw to screen

  • event_engine
    simple place holder for when i start working on handling the whole text_box thing. might change.

  • Xblock(set and get)
    magical system that took me so long to figure out. simply put: tries to inject this block into corresponding other block, AND clear link if set to None. example: if block X is trying to link upwards with the block above it: Y; X calls Y.dblock = X (Y's Downblock equals X)

  • loc(ation)
    place holder for when the block need to be able to be saved to a file (pickle FTW!)

  • action
    place holder that a subclass over-rides to dictate what the robot does in this "code block" (call corresponding robot function/play animation?)

  • next
    returns the next block in the sequence of code. the point of it being a whole function is for when we have a conditional block, and needs to respond differently than others.

  • drop
    subclass place holder

  • able_drop
    subclass place holder

  • drag
    subclass place holder

  • save
    to be worked on when saving gets started. I know I am going to have to change a lot of how things load right now, but that is OK. I want it working first.

  • load
    ditto for load as for save.

there, now I hope understanding some of this spaghetti wasn't so bad?

well, this was just an update to show that I am no longer dead, and once again working.

next time will be going over the sub classing system for creating new blocks!

 Share

2 Comments


Recommended Comments

PS: anyone know how to get the [ code ] block to understand that this is python?

Link to comment

Cirevam knows MIPS and of course mouse knows Python, so you could try to get in touch with them.

As for the code block, either

 or it doesn't do that.
Link to comment

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.