Trees | Indices | Help |
---|
|
1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 4 # This program is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 3 of the License, or 7 # (at your option) any later version. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 import os 14 import pygame 1517 """ 18 el componente inicial no tiene conector hembra porque SIEMPRE va a 19 a tener el ide=0 20 """ 21 pulsado=0 22 posicion=(0,0) 23 #rectangulo que representa toda el area del componente 24 rectan=pygame.Rect(0,0,60,60) 25 conector_m=pygame.Rect(0,0,40,10)#conector macho 26 ide=0 27 color=(80,00,80) 28 pegado_a=0 #es solo por compatibilidad con los demas componentes 29 vivo=True 30 posic_rel_x=0 31 posic_rel_y=012433 pygame.sprite.Sprite.__init__(self) 34 self.ide=identidad 35 self.posicion=(x,y) 36 self.fondo=fondo 37 self.ventana=ventana 38 self.texto=texto 39 self.fondo.lista_ordenada.append(0) 40 self.color_texto=self.fondo.color_texto42 # el cuerpo del componente 43 pygame.draw.rect( 44 self.fondo.screen, 45 self.color, 46 (self.posicion[0],self.posicion[1], 60,40), 47 0 48 ) 49 # el conector macho 50 pygame.draw.rect( 51 self.fondo.screen, 52 self.color, 53 ( 54 self.posicion[0]+14, 55 self.posicion[1]+40, 32,10 56 ), 57 0 58 ) 59 pygame.draw.rect( 60 self.fondo.screen, 61 self.color, 62 ( 63 self.posicion[0]+10, 64 self.posicion[1]+40, 40,3 65 ), 66 0 67 ) 68 pygame.draw.rect( 69 self.fondo.screen, 70 self.color, 71 ( 72 self.posicion[0]+10, 73 self.posicion[1]+47, 40,3 74 ), 75 0 76 ) 77 self.texto.render( 78 "inicio", 79 self.color_texto, 80 ( 81 (self.posicion[0]+10), 82 (self.posicion[1]+10) 83 ) 84 )8587 posic_mouse= self.ventana.mousexy 88 botones_mouse = self.ventana.boton_mouse 89 # self.rectan es el rect que representa 90 # la totalidad de la figura 91 if self.posicion[0]<0: 92 self.posicion=(0,self.posicion[1]) 93 if self.posicion[1]<0: 94 self.posicion=(self.posicion[0],0) 95 self.rectan[0]=self.posicion[0] 96 self.rectan[1]=self.posicion[1]-10 97 # self.conector_m es la ficha "macho" 98 self.conector_m[0]=self.rectan[0]+10 99 self.conector_m[1]=self.rectan[1]+50 100 #cargo la lista de los dos conectores hembra y macho 101 if (botones_mouse[1]==1 and 102 self.rectan.collidepoint(self.ventana.mousexy) and 103 self.pulsado==0 and 104 self.ventana.seleccionado==0): 105 106 posic_mouse= self.ventana.mousexy 107 self.ventana.seleccionado=self.ide 108 self.posic_rel_x=abs(self.posicion[0]-posic_mouse[0]) 109 self.posic_rel_y=abs(self.posicion[1]-posic_mouse[1]) 110 self.pulsado=1 111 112 if (self.ventana.seleccionado== self.ide): 113 114 self.posicion= ( 115 posic_mouse[0]-self.posic_rel_x, 116 posic_mouse[1]-self.posic_rel_y 117 ) 118 self.pulsado==1 119 if botones_mouse[1]==0: 120 self.pulsado=0 121 self.ventana.seleccionado=0 122 self.dibujar() 123 pygame.display.update
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Sun Sep 16 23:29:31 2012 | http://epydoc.sourceforge.net |