.comment-link {margin-left:.6em;}

Wednesday, April 08, 2009

 

button class for the pycap game eninge

This is a button class example for the pycap game engine written in python (of course)..










# Template pycap game v1.0

# Written by Farbs



appIni = {      "mCompanyName"          : "CompanyNameGoesHere",

                "mFullCompanyName"      : "CompanyNameGoesHere",

                "mProdName"             : "Pycap Template Game",

                "mProductVersion"       : "1.0",

                "mTitle"                        : "piano_roll",

                "mRegKey"                       : "piano_roll",

                "mWidth"                        : 800,

                "mHeight"                       : 600,

                "mAutoEnable3D" : 1,

                "mVSyncUpdates" : 1 }



res = None

PC = None

PCR = None

squaret = None



class square:

  #test = squaret.hittest( x, y)        define in mousedown

  #..................................

  #define in init like the following example

  #global squaret

  #squaret = square(20, 20)

  #..............................

  #define in draw

  #squaret.draw()



  image = None

#       

  def __init__( self, x, y ):

          self.state = 0 #intitial state

          self.x = x

          self.y = y

          self.maxx = x + 20

          self.maxy = y + 20

  def update( self, delta ):

     pass

  def draw( self ):

      pass

      if self.state == 0:

        PC.setColour(0,0,0, 105)               

        PC.fillRect(self.x, self.y, 20, 20)

        PC.setColour(0,90,90,190)

        PC.fillRect(self.x + 3, self.y + 3, 14, 14)

      else:

         PC.setColour(50,50,50,135)

         PC.fillRect(self.x + 1, self.y + 1, 19, 19)

         

  def hittest( self, x, y ):

          pass

          hit = 0       

          if x > self.x:

              if x < self.maxx:

                 if y > self.y:

                   if y < self.maxy:

                      PC.markDirty()

                      hit = 1

          if hit == 1:

                  oldstate = self.state

                  if oldstate == 0:

                     self.state = 1

                  if oldstate == 1:

                     self.state = 0

          #return hit

 

def loadBase():

        import PycapRes

        global PCR

        PCR = PycapRes

        square.image = None



def init():

        import Pycap

        global PC

        PC = Pycap

        global squaret

        squaret = square(20, 20)

       

        pass

       

def mouseDown( x, y, i ):

        global mousex, mousey

        mousex = x

        mousey = y

        test = squaret.hittest( x, y)

        #if test == 1:

        #       if square

        #this indicates the mouse is pressed

        pass

       

def mouseMove( x, y ):

        pass

#    global mousex, mousey

#    mousex = x

#    mousey = y



def update( delta ):

        PC.markDirty()



def draw():

        PC.setColour( 255, 255, 255, 255 )

        PC.fillRect( 0, 0, 800, 600 )

        squaret.draw()

Labels:


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?