Package icaro-bloques :: Module componente
[hide private]
[frames] | no frames]

Source Code for Module icaro-bloques.componente

  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 sys, pygame 
 14  from os import system 
 15  from componente_datos import * 
 16   
 17   
 18   
19 -class componente(pygame.sprite.Sprite):
20 pulsado=0 21 conector_h_dato=pygame.Rect(0,0,30,20)#conector hembra dato 22 ide=0 23 color=(110,20,90) 24 texto="" 25
26 - def __init__( 27 self, 28 x,y, 29 identidad, 30 argumentos, 31 color, 32 texto, 33 fondo, 34 ventana, 35 textorender 36 ):
37 pygame.sprite.Sprite.__init__(self) 38 #esto es para poder mandar los datos a guardar 39 self.imagenintermedia=texto.strip(" ") 40 self.imagen=pygame.image.load ( 41 sys.path[0] + 42 43 "/imagenes/componentes/"+ 44 texto.strip(" ")+ 45 ".png" 46 ) 47 self.arg=argumentos 48 self.ide=identidad 49 self.posicion=(x,y) 50 self.color=color 51 self.fondo=fondo 52 self.ventana=ventana 53 self.textorender=textorender 54 self.texto=texto 55 self.color_texto=self.fondo.color_texto 56 #rectangulo que representa toda el area del componente 57 self.rectan=pygame.Rect( 58 self.posicion[0], 59 self.posicion[1], 60 60, 61 60 62 ) 63 self.conector_m=pygame.Rect(0,0,40,10)#conector macho 64 self.conector_h=pygame.Rect(0,0,40,10)#conector hembra 65 self.fondo.lista_ordenada.append(0) 66 self.lista_conector_h_datos=[] 67 self.lista_valores=[] 68 self.pegado=0 69 self.pegado_a=0 70 self.vivo=True 71 for a in range(self.arg): 72 # creo dos lista con los valores del rect 73 # de cada conector que creo 74 # y sus valores. 75 # estas listas son las que parsean los componentes_datos 76 self.lista_conector_h_datos.append((0,0,0,0)) 77 self.lista_valores.append("") 78 self.dibujar()
79 - def dibujar(self):
80 81 self.conector_h[0]=self.rectan[0]+10 82 self.conector_h[1]=self.rectan[1] 83 # estos son los cuadrados que forman el vacio 84 # que representa el conector hembra 85 pygame.draw.rect( 86 self.fondo.screen, 87 self.color, 88 (self.posicion[0],self.posicion[1]-10, 10,10), 89 0 90 ) 91 pygame.draw.rect( 92 self.fondo.screen, 93 self.color, 94 (self.posicion[0]+10,self.posicion[1]-7, 4,4), 95 0 96 ) 97 pygame.draw.rect( 98 self.fondo.screen, 99 self.color, 100 (self.posicion[0]+50,self.posicion[1]-10,10,10), 101 0 102 ) 103 pygame.draw.rect( 104 self.fondo.screen, 105 self.color, 106 (self.posicion[0]+46,self.posicion[1]-7,4,4), 107 0 108 ) 109 factor=0 110 if self.arg==0: 111 # el cuerpo del componente 112 pygame.draw.rect( 113 self.fondo.screen, 114 self.color, 115 ( 116 self.posicion[0], 117 self.posicion[1]+factor, 60,40 118 ), 119 0 120 ) 121 factor +=40 122 factory=(len(self.texto)*7) 123 for a in range(self.arg): 124 # el cuerpo del componente 125 pygame.draw.rect( 126 self.fondo.screen, 127 self.color, 128 ( 129 self.posicion[0], 130 self.posicion[1]+factor, 25+factory,40 131 ), 132 0 133 ) 134 # conector hembra datos 135 136 pygame.draw.rect( 137 self.fondo.screen, 138 self.color, 139 ( 140 (self.posicion[0]+25+factory), 141 (self.posicion[1]+factor 142 ), 143 10,10 144 ), 145 0 146 ) 147 pygame.draw.rect( 148 self.fondo.screen, 149 self.color, 150 ( 151 (self.posicion[0]+25+factory+3), 152 (self.posicion[1]+factor+10 153 ), 154 4,4 155 ), 156 0 157 ) 158 pygame.draw.rect( 159 self.fondo.screen, 160 self.color, 161 ( 162 (self.posicion[0]+25+factory), 163 (self.posicion[1]+30+factor), 164 10, 165 10 166 ), 167 0 168 ) 169 pygame.draw.rect( 170 self.fondo.screen, 171 self.color, 172 ( 173 (self.posicion[0]+25+factory+3), 174 (self.posicion[1]+30+factor-4), 175 4, 176 4 177 ), 178 0 179 ) 180 self.conector_h_dato[0]=self.rectan[0]+25+factory 181 self.conector_h_dato[1]=self.rectan[1]+20+factor 182 self.lista_conector_h_datos[a]= ( 183 self.conector_h_dato[0], 184 self.conector_h_dato[1], 185 self.conector_h_dato[2], 186 self.conector_h_dato[3] 187 ) 188 factor +=40 189 self.rectan[3]=factor 190 self.conector_m[0]=self.rectan[0]+10 191 self.conector_m[1]=self.rectan[1]+factor+10 192 pygame.draw.rect( 193 self.fondo.screen, 194 self.color, 195 ( 196 self.posicion[0]+14, 197 (self.posicion[1]+factor), 198 32, 199 10 200 ), 201 0 202 ) 203 #=============================================================================== 204 # 205 #=============================================================================== 206 pygame.draw.rect( 207 self.fondo.screen, 208 self.color, 209 ( 210 self.posicion[0]+10, 211 (self.posicion[1]+factor), 212 40, 213 3 214 ), 215 0 216 ) 217 pygame.draw.rect( 218 self.fondo.screen, 219 self.color, 220 ( 221 self.posicion[0]+10, 222 (self.posicion[1]+factor+7), 223 40, 224 3 225 ), 226 0 227 ) 228 #=============================================================================== 229 # 230 #=============================================================================== 231 self.fondo.screen.blit( 232 self.imagen, 233 (self.posicion[0]+(self.rectan[2]/2)-15, 234 self.posicion[1]+(self.rectan[3]/2)-5) 235 ) 236 self.textorender.render( 237 self.texto, 238 self.color_texto, 239 ( 240 ( 241 self.posicion[0]+10), 242 (self.posicion[1]+(self.rectan[3]/2)-20) 243 ) 244 )
245
246 - def update(self):
247 ban_a=0 248 posic_mouse= self.ventana.mousexy 249 botones_mouse = self.ventana.boton_mouse 250 self.rectan[0]=self.posicion[0] 251 self.rectan[1]=self.posicion[1]-10 252 if self.vivo==True: 253 if self.pegado==0: 254 self.fondo.lista_ordenada[self.ide]=0 255 for a in range(len(self.fondo.objetos)): 256 if (self.conector_h.colliderect 257 ( 258 self.fondo.objetos[a].conector_m 259 ) 260 and 261 self.fondo.objetos[a].vivo)==True: 262 263 self.pegado=1 264 self.pegado_a=a 265 break 266 else: 267 self.pegado=0 268 self.pegado_a=0 269 if self.pegado==1: 270 x,y,aa,bb=self.fondo.objetos[self.pegado_a].conector_m 271 xx=x-10 272 yy=y+10 273 self.posicion=(xx,yy) 274 iden=self.fondo.objetos[self.pegado_a].ide 275 self.fondo.lista_ordenada[self.ide]=iden 276 if (botones_mouse[1]==1 and 277 self.rectan.collidepoint(self.ventana.mousexy) and 278 self.pulsado==0 and 279 self.ventana.seleccionado==0): 280 posic_mouse= self.ventana.mousexy 281 self.ventana.seleccionado=self.ide 282 self.posic_rel_x=abs(self.posicion[0]-posic_mouse[0]) 283 self.posic_rel_y=abs(self.posicion[1]-posic_mouse[1]) 284 self.pulsado=1 285 if (self.ventana.seleccionado== self.ide): 286 self.posicion= ( 287 posic_mouse[0]-self.posic_rel_x, 288 posic_mouse[1]-self.posic_rel_y 289 ) 290 self.pulsado==1 291 self.pegado=0 292 self.pegado_a=0 293 if botones_mouse[1]==0: 294 self.pulsado=0 295 self.ventana.seleccionado=0 296 if (botones_mouse[1]==1 297 and self.rectan.collidepoint(self.ventana.mousexy) 298 and self.ventana.seleccion_menu==3): 299 for i in range(1,len(self.fondo.objetos_datos)): 300 self.fondo.objetos_datos[i].conectado=0 301 self.fondo.objetos_datos[i].pegado=0 302 self.fondo.objetos_datos[i].pegado_a=0 303 self.fondo.objetos_datos[i].pegado_b=0 304 self.fondo.objetos_datos[i].pegado2=0 305 self.fondo.objetos_datos[i].pegado_a2=0 306 a=self.fondo.objetos.index(self) 307 ident=self.fondo.objetos[a].ide 308 for i in range(len(self.fondo.objetos)): 309 self.fondo.objetos[i].pegado_a=0 310 self.fondo.objetos[i].pegado=0 311 self.fondo.objetos[a].vivo=False 312 del self.fondo.tipo_obj[a] 313 self.kill() 314 self.fondo.objetos.remove(self) 315 self.fondo.lista_ordenada[self.ide]=0 316 self.dibujar() 317 for a in range(self.arg): 318 319 self.lista_valores[a]=""
320 321
322 -class componente_bloque_dos(pygame.sprite.Sprite):
323 pulsado=0 324 #rectangulo que representa toda el area del componente 325 rectan=pygame.Rect(0,0,60,60) 326 ide=0 327 color=(110,20,90) 328 texto=""
329 - def __init__(self,x,y,identidad,color,texto,fondo,ventana,textorender):
330 pygame.sprite.Sprite.__init__(self) 331 #esto es para poder mandar los datos a guardar 332 self.imagenintermedia=texto.strip(" ") 333 self.arg=0 334 self.ide=identidad 335 self.posicion=(x,y) 336 self.color=color 337 self.fondo=fondo 338 self.ventana=ventana 339 self.textorender=textorender 340 self.texto=texto 341 self.color_texto=self.fondo.color_texto 342 #rectangulo que representa toda el area del componente 343 self.rectan=pygame.Rect(self.posicion[0],self.posicion[1],60,60) 344 #conector macho 345 self.conector_m=pygame.Rect(0,0,40,10) 346 #conector hembra 347 self.conector_h=pygame.Rect(0,0,40,10) 348 self.fondo.lista_ordenada.append(0) 349 self.lista_conector_h_datos=[] 350 self.lista_valores=[] 351 self.pegado=0 352 self.pegado_a=0 353 self.lista_conector_h_datos.append((0,0,0,0)) 354 self.lista_valores.append("") 355 self.vivo=True 356 self.dibujar()
357 - def dibujar(self):
358 # estos son los cuadrados que forman el vacio que representa el conector hembra 359 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+60,self.posicion[1]-10, 10,10),0) 360 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+70,self.posicion[1]-7, 4,4),0) 361 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+110,self.posicion[1]-10, 10,10),0) 362 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+106,self.posicion[1]-7, 4,4),0) 363 364 # el cuerpo del componente 365 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0],self.posicion[1], 120,40),0) 366 # el conector macho 367 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+14,self.posicion[1]+40, 32,10),0) 368 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+10,self.posicion[1]+40, 40,3),0) 369 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+10,self.posicion[1]+47, 40,3),0) 370 371 self.textorender.render(self.texto,self.color_texto,((self.posicion[0]+10),(self.posicion[1]+10))) 372 self.conector_m[0]=self.rectan[0]+10 373 self.conector_m[1]=self.rectan[1]+50 374 self.conector_h[0]=self.rectan[0]+70 375 self.conector_h[1]=self.rectan[1]
376 - def update(self):
377 ban_a=0 378 posic_mouse= self.ventana.mousexy 379 botones_mouse = self.ventana.boton_mouse 380 self.rectan[0]=self.posicion[0] 381 self.rectan[1]=self.posicion[1]-10 382 if self.vivo==True: 383 if self.pegado==0: 384 self.fondo.lista_ordenada[self.ide]=0 385 for a in range(len(self.fondo.objetos)): 386 if self.conector_h.colliderect(self.fondo.objetos[a].conector_m): 387 self.pegado=1 388 self.pegado_a=a 389 break 390 else: 391 self.pegado=0 392 self.pegado_a=0 393 if self.pegado==1: 394 x,y,aa,bb=self.fondo.objetos[self.pegado_a].conector_m 395 xx=x-70 396 yy=y+10 397 self.posicion=(xx,yy) 398 self.fondo.lista_ordenada[self.ide]=self.fondo.objetos[self.pegado_a].ide 399 if (botones_mouse[1]==1 and 400 self.rectan.collidepoint(self.ventana.mousexy) and 401 self.pulsado==0 and 402 self.ventana.seleccionado==0): 403 posic_mouse= self.ventana.mousexy 404 self.ventana.seleccionado=self.ide 405 self.posic_rel_x=abs(self.posicion[0]-posic_mouse[0]) 406 self.posic_rel_y=abs(self.posicion[1]-posic_mouse[1]) 407 self.pulsado=1 408 if (self.ventana.seleccionado== self.ide): 409 self.posicion=(posic_mouse[0]-self.posic_rel_x,posic_mouse[1]-self.posic_rel_y) 410 self.pulsado==1 411 self.pegado=0 412 self.pegado_a=0 413 if botones_mouse[1]==0: 414 self.pulsado=0 415 self.ventana.seleccionado=0 416 417 if (botones_mouse[1]==1 418 and self.rectan.collidepoint(self.ventana.mousexy) 419 and self.ventana.seleccion_menu==3): 420 for i in range(1,len(self.fondo.objetos_datos)): 421 self.fondo.objetos_datos[i].conectado=0 422 self.fondo.objetos_datos[i].pegado=0 423 self.fondo.objetos_datos[i].pegado_a=0 424 self.fondo.objetos_datos[i].pegado_b=0 425 self.fondo.objetos_datos[i].pegado2=0 426 self.fondo.objetos_datos[i].pegado_a2=0 427 a=self.fondo.objetos.index(self) 428 ident=self.fondo.objetos[a].ide 429 for i in range(len(self.fondo.objetos)): 430 self.fondo.objetos[i].pegado_a=0 431 self.fondo.objetos[i].pegado=0 432 self.fondo.objetos[a].vivo=False 433 del self.fondo.tipo_obj[a] 434 self.kill() 435 self.fondo.objetos.remove(self) 436 self.fondo.lista_ordenada[self.ide]=0 437 self.dibujar()
438 439
440 -class componente_bloque_uno(pygame.sprite.Sprite):
441 pulsado=0 442 rectan=pygame.Rect(0,0,60,60)#rectangulo que representa toda el area del componente 443 conector_h_dato=pygame.Rect(0,0,30,20)#conector hembra dato 444 ide=0 445 color=(110,20,90) 446 texto=""
447 - def __init__(self,x,y,identidad,color,texto,fondo,ventana,textorender):
448 pygame.sprite.Sprite.__init__(self) 449 self.imagenintermedia=texto.strip(" ") #esto es para poder mandar los datos a guardar 450 self.imagen=pygame.image.load( 451 sys.path[0] + 452 "/imagenes/componentes/"+ 453 texto.strip(" ")+ 454 ".png" 455 ) 456 self.arg=1 457 self.ide=identidad 458 self.posicion=(x,y) 459 self.color=color 460 self.fondo=fondo 461 self.ventana=ventana 462 self.textorender=textorender 463 self.texto=texto 464 self.color_texto=self.fondo.color_texto 465 self.rectan=pygame.Rect(self.posicion[0],self.posicion[1],60,60)#rectangulo que representa toda el area del componente 466 self.conector_m=pygame.Rect(0,0,40,10)#conector macho 467 self.conector_h=pygame.Rect(0,0,40,10)#conector hembra 468 self.fondo.lista_ordenada.append(0) 469 self.lista_conector_h_datos=[] 470 self.lista_valores=[] 471 self.pegado=0 472 self.pegado_a=0 473 self.lista_conector_h_datos.append((0,0,0,0)) 474 self.lista_valores.append("") 475 self.vivo=True 476 self.dibujar()
477 - def dibujar(self):
478 self.conector_h[0]=self.rectan[0]+10 479 self.conector_h[1]=self.rectan[1] 480 #~ pygame.draw.line(self.fondo.screen,(0,0,0),(self.posicion[0]-3,self.posicion[1]-10),(self.posicion[0]-3,self.posicion[1]+40),5) 481 482 # estos son los cuadrados que forman el vacio que representa el conector hembra 483 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0],self.posicion[1]-10, 10,10),0) 484 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+10,self.posicion[1]-7, 4,4),0) 485 486 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+50,self.posicion[1]-10, 10,10),0) 487 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+46,self.posicion[1]-7, 4,4),0) 488 489 # el cuerpo del componente 490 #~ pygame.draw.line(self.fondo.screen,(0,0,0),(self.posicion[0]+60,self.posicion[1]-2),(self.posicion[0]+129,self.posicion[1]-2),5) 491 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0],self.posicion[1], 120,40),0) 492 # el conector macho 493 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+74,self.posicion[1]+40, 32,10),0) 494 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+70,self.posicion[1]+40, 40,3),0) 495 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+70,self.posicion[1]+47, 40,3),0) 496 # conector hembra datos 497 self.conector_h_dato[0]=self.rectan[0]+120 498 self.conector_h_dato[1]=self.rectan[1]+20 499 self.lista_conector_h_datos[0]=(self.conector_h_dato[0],self.conector_h_dato[1],self.conector_h_dato[2],self.conector_h_dato[3]) 500 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+120,self.posicion[1], 10,10),0) 501 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+123,self.posicion[1]+10, 4,4),0) 502 503 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+120,self.posicion[1]+30, 10,10),0) 504 pygame.draw.rect(self.fondo.screen,self.color,(self.posicion[0]+123,self.posicion[1]+26, 4,4),0) 505 506 # texto.render(str(self.ide),self.color_texto,((self.posicion[0]+10),(self.posicion[1]+10))) 507 #self.fondo.screen.blit(self.imagen,(self.posicion[0],self.posicion[1]-11)) 508 self.textorender.render(self.texto,self.color_texto,((self.posicion[0]+10),(self.posicion[1]+10))) 509 self.conector_m[0]=self.rectan[0]+70 510 self.conector_m[1]=self.rectan[1]+50
511 - def update(self):
512 ban_a=0 513 posic_mouse= self.ventana.mousexy 514 botones_mouse = self.ventana.boton_mouse 515 self.rectan[0]=self.posicion[0] 516 self.rectan[1]=self.posicion[1]-10 517 if self.vivo==True: 518 if self.pegado==0: 519 self.fondo.lista_ordenada[self.ide]=0 520 for a in range(len(self.fondo.objetos)): 521 if self.conector_h.colliderect(self.fondo.objetos[a].conector_m): 522 self.pegado=1 523 self.pegado_a=a 524 break 525 else: 526 self.pegado=0 527 self.pegado_a=0 528 if self.pegado==1: 529 x,y,aa,bb=self.fondo.objetos[self.pegado_a].conector_m 530 xx=x-10 531 yy=y+10 532 self.posicion=(xx,yy) 533 self.fondo.lista_ordenada[self.ide]=self.fondo.objetos[self.pegado_a].ide 534 if (botones_mouse[1]==1 and 535 self.rectan.collidepoint(self.ventana.mousexy) and 536 self.pulsado==0 and 537 self.ventana.seleccionado==0): 538 posic_mouse= self.ventana.mousexy 539 self.ventana.seleccionado=self.ide 540 self.posic_rel_x=abs(self.posicion[0]-posic_mouse[0]) 541 self.posic_rel_y=abs(self.posicion[1]-posic_mouse[1]) 542 self.pulsado=1 543 if (self.ventana.seleccionado== self.ide): 544 self.posicion=(posic_mouse[0]-self.posic_rel_x,posic_mouse[1]-self.posic_rel_y) 545 self.pulsado==1 546 self.pegado=0 547 self.pegado_a=0 548 if botones_mouse[1]==0: 549 self.pulsado=0 550 self.ventana.seleccionado=0 551 if (botones_mouse[1]==1 552 and self.rectan.collidepoint(self.ventana.mousexy) 553 and self.ventana.seleccion_menu==3): 554 for i in range(1,len(self.fondo.objetos_datos)): 555 self.fondo.objetos_datos[i].conectado=0 556 self.fondo.objetos_datos[i].pegado=0 557 self.fondo.objetos_datos[i].pegado_a=0 558 self.fondo.objetos_datos[i].pegado_b=0 559 self.fondo.objetos_datos[i].pegado2=0 560 self.fondo.objetos_datos[i].pegado_a2=0 561 a=self.fondo.objetos.index(self) 562 ident=self.fondo.objetos[a].ide 563 for i in range(len(self.fondo.objetos)): 564 self.fondo.objetos[i].pegado_a=0 565 self.fondo.objetos[i].pegado=0 566 self.fondo.objetos[a].vivo=False 567 del self.fondo.tipo_obj[a] 568 self.kill() 569 self.fondo.objetos.remove(self) 570 self.fondo.lista_ordenada[self.ide]=0 571 self.dibujar()
572 573 574 # hay problema cuando borras un componente de cero argumentos 575 # revizar 576
577 -class componente_cero_arg(pygame.sprite.Sprite):
578 # el componente cuadrado es el bloque minimo que puede tener un 579 # icaro-block 580 pulsado=0 581 582 583 #conector_h_dato=pygame.Rect(0,0,10,20)#conector hembra dato 584 ide=0 585 color=(110,20,90) 586 texto=""
587 - def __init__(self,x,y,identidad,color,texto,fondo,ventana,textorender):
588 pygame.sprite.Sprite.__init__(self) 589 self.ide=identidad 590 self.posicion=(x,y) 591 self.posicion2=(x,y+60) 592 self.arg=0 593 self.fondo=fondo 594 #rectangulo que representa toda el area del componente 595 self.rectan=pygame.Rect(self.posicion[0],self.posicion[1],60,60) 596 self.rectan2=pygame.Rect(self.posicion2[0],self.posicion2[1],60,60) 597 self.conector_h=pygame.Rect(0,0,40,10)#conector hembra 598 self.conector_m=pygame.Rect(0,0,40,10)#conector macho 599 self.vivo=True 600 self.fondo.lista_ordenada.append(0) 601 self.lista_conector_h_datos=[] 602 self.lista_valores=[] 603 self.pegado=0 604 self.pegado_a=0 605 self.color=color 606 self.texto=texto 607 self.fondo=fondo 608 self.ventana=ventana 609 self.textorender=textorender 610 self.color_texto=self.fondo.color_texto 611 self.dibujar()
612
613 - def dibujar(self):
614 #conector hembra 615 pygame.draw.rect( 616 self.fondo.screen, 617 self.color, 618 (self.posicion[0],self.posicion[1]-10, 10,10), 619 0 620 ) 621 pygame.draw.rect( 622 self.fondo.screen, 623 self.color, 624 (self.posicion[0]+10,self.posicion[1]-7, 4,4), 625 0 626 ) 627 pygame.draw.rect( 628 self.fondo.screen, 629 self.color, 630 (self.posicion[0]+50,self.posicion[1]-10, 10,10), 631 0 632 ) 633 pygame.draw.rect( 634 self.fondo.screen, 635 self.color, 636 (self.posicion[0]+46,self.posicion[1]-7, 4,4), 637 0 638 ) 639 #cuerpo del componente 640 pygame.draw.rect( 641 self.fondo.screen, 642 self.color, 643 (self.posicion[0],self.posicion[1], 60,40), 644 0 645 ) 646 self.textorender.render( 647 str(self.ide), 648 self.color_texto, 649 ((self.posicion[0]+10),(self.posicion[1]+10)) 650 ) 651 652 pygame.draw.rect( 653 self.fondo.screen, 654 self.color, 655 (self.posicion2[0],self.posicion2[1], 60,40), 656 0 657 ) 658 self.textorender.render( 659 str(self.ide), 660 self.color_texto, 661 ((self.posicion2[0]+10),(self.posicion2[1]+10)) 662 ) 663 pygame.draw.rect( 664 self.fondo.screen, 665 self.color, 666 (self.posicion2[0]+14,(self.posicion2[1]+40), 32,10), 667 0 668 ) 669 pygame.draw.rect( 670 self.fondo.screen, 671 self.color, 672 (self.posicion2[0]+10,(self.posicion2[1]+40), 40,3), 673 0 674 ) 675 pygame.draw.rect( 676 self.fondo.screen, 677 self.color, 678 (self.posicion2[0]+10,(self.posicion2[1]+47), 40,3), 679 0 680 ) 681 # self.conector_h es la ficha "hembra" 682 self.conector_h[0]=self.rectan[0]+10 683 self.conector_h[1]=self.rectan[1] 684 self.conector_m[0]=self.rectan2[0]+10 685 self.conector_m[1]=self.rectan2[1]+50
686 - def update(self):
687 ban_a=0 688 posic_mouse= self.ventana.mousexy 689 botones_mouse = self.ventana.boton_mouse 690 self.rectan[0]=self.posicion[0] 691 self.rectan[1]=self.posicion[1]-10 692 self.rectan2[0]=self.posicion2[0] 693 self.rectan2[1]=self.posicion2[1]-10 694 if self.vivo==True: 695 if self.pegado==0: 696 self.fondo.lista_ordenada[self.ide]=0 697 for a in range(len(self.fondo.objetos)): 698 if self.conector_h.colliderect(self.fondo.objetos[a].conector_m): 699 self.pegado=1 700 self.pegado_a=a 701 break 702 else: 703 self.pegado=0 704 self.pegado_a=0 705 if self.pegado==1: 706 x,y,aa,bb=self.fondo.objetos[self.pegado_a].conector_m 707 xx=x-10 708 yy=y+10 709 self.posicion=(xx,yy) 710 self.fondo.lista_ordenada[self.ide]=self.fondo.objetos[self.pegado_a].ide 711 if (botones_mouse[1]==1 and 712 self.rectan.collidepoint(self.ventana.mousexy) and 713 self.pulsado==0 and 714 self.ventana.seleccionado==0): 715 posic_mouse= self.ventana.mousexy 716 self.ventana.seleccionado=self.ide 717 self.posic_rel_x=abs(self.posicion[0]-posic_mouse[0]) 718 self.posic_rel_y=abs(self.posicion[1]-posic_mouse[1]) 719 self.pulsado=1 720 if (self.ventana.seleccionado== self.ide and self.pulsado==1): 721 self.posicion=(posic_mouse[0]-self.posic_rel_x,posic_mouse[1]-self.posic_rel_y) 722 self.pulsado==1 723 self.pegado=0 724 self.pegado_a=0 725 ############################################################################### 726 if (botones_mouse[1]==1 and 727 self.rectan2.collidepoint(self.ventana.mousexy) and 728 self.pulsado==0 and 729 self.ventana.seleccionado==0): 730 posic_mouse2= self.ventana.mousexy 731 self.ventana.seleccionado=self.ide 732 self.posic_rel_x2=abs(self.posicion2[0]-posic_mouse2[0]) 733 self.posic_rel_y2=abs(self.posicion2[1]-posic_mouse2[1]) 734 self.pulsado=2 735 if (self.ventana.seleccionado== self.ide) and self.pulsado==2: 736 self.posicion2=(posic_mouse[0]-self.posic_rel_x2,posic_mouse[1]-self.posic_rel_y2) 737 self.pulsado==2 738 self.pegado=0 739 self.pegado_a=0 740 ############################################################################### 741 742 if botones_mouse[1]==0: 743 self.pulsado=0 744 self.ventana.seleccionado=0 745 if (botones_mouse[1]==1 746 and self.rectan.collidepoint(self.ventana.mousexy) 747 and self.ventana.seleccion_menu==3): 748 for i in range(1,len(self.fondo.objetos_datos)): 749 self.fondo.objetos_datos[i].conectado=0 750 self.fondo.objetos_datos[i].pegado=0 751 self.fondo.objetos_datos[i].pegado_a=0 752 self.fondo.objetos_datos[i].pegado_b=0 753 self.fondo.objetos_datos[i].pegado2=0 754 self.fondo.objetos_datos[i].pegado_a2=0 755 a=self.fondo.objetos.index(self) 756 ident=self.fondo.objetos[a].ide 757 for i in range(len(self.fondo.objetos)): 758 self.fondo.objetos[i].pegado_a=0 759 self.fondo.objetos[i].pegado=0 760 self.fondo.objetos[a].vivo=False 761 del self.fondo.tipo_obj[a] 762 self.kill() 763 self.fondo.objetos.remove(self) 764 self.fondo.lista_ordenada[self.ide]=0 765 self.dibujar()
766