Ejemplo n.º 1
0
    def snap_to_point(self):
        disx = (self.drag_module.rect.centerx + 30)%60
        if disx > 30:
            relx = 60 - disx
        else:
            relx = disx

        disy = (self.drag_module.rect.centery + 30)%60
        if disy > 30:
            rely = 60 - disy
        else:
            rely = disy
            
        dis = get_dis_nsqrt((relx,rely),(0,0))
        
        if dis <= 100:
            if disx > 30:
                self.drag_module.rect.centerx += relx
            else:
                self.drag_module.rect.centerx -= relx

            if disy > 30:
                self.drag_module.rect.centery += rely
            else:
                self.drag_module.rect.centery -= rely
Ejemplo n.º 2
0
    def graphic_logic(self):
        if self.new_wire != None and self.event == 1:
            self.new_wire.update(True)
            
        if self.delete_timer > 0:
            self.delete_timer -= 1
            self.delete_rect.center = self.delete_module.port_pos(self.delete_port)
            if self.delete_port == 1:
                self.delete_rect.centery -= 20
            else:
                self.delete_rect.centery += 20
            self.delete_rect.centerx -= 5
            self.delete_draw = True
            
        if self.event == 2 or self.event == 3:
            mouse_pos = pygame.mouse.get_pos()
            if get_dis_nsqrt(self.drag_module.rect.center,(900,600)) < 10000:
                self.draw_delc_p = 1
            else:
                self.draw_delc_p = 0

            if self.drag_module.rect.left < 140 and self.event == 2:
                self.draw_delc2 = True

            if self.drag_module.rect.centery <= 0:
                self.draw_delc_p = 1
                self.draw_delc = True
                self.draw_delc2 = True
                self.draw_dels = True
            elif self.drag_module.rect.centery >= 600:
                self.draw_delc_p = 1
                self.draw_delc = True
                self.draw_delc2 = True
                self.draw_dels = True
            elif self.drag_module.rect.centerx >= 900:
                self.draw_delc_p = 1
                self.draw_delc = True
                self.draw_delc2 = True
                self.draw_dels = True
                
            relx = mouse_pos[0] - self.drag_mPos[0]
            rely = mouse_pos[1] - self.drag_mPos[1]
            self.drag_mPos = mouse_pos
            self.drag_module.rect.x += relx
            self.drag_module.rect.y += rely
            self.drag_module.move_update()
            if self.draw_delc_delay <= 0:
                self.draw_delc = True
            else:
                self.draw_delc_delay -= 1
Ejemplo n.º 3
0
    def mouse_up(self,pos):
        if self.delete_timer > 0:
            dis = get_dis_nsqrt(self.delete_rect.center,pos)
            if dis <= 110:
                self.click_on_delete()
                self.deleting = False

        if self.event == 1:
            if self.double_click:
                self.double_click = False
                self.event = 0
                if self.deleting == False:
                    snap_to_port(self.gates_group,self.new_wire,pos)
                    self.new_wire = None
                    self.delete_timer = 0
                
                    self.delete_module = None
                    self.delete_port = None
            else:
                self.double_click = True
                
        elif self.event == 2:
            self.snap_to_side()
            self.snap_to_point()
            if self.drag_module.rect.centery <= 0:
                self.drag_module.kill()
            elif self.drag_module.rect.centery >= 600:
                self.drag_module.kill()
            elif self.drag_module.rect.centerx >= 900:
                self.drag_module.kill()
            elif get_dis_nsqrt(self.drag_module.rect.center,(900,600)) < 10000:
                self.drag_module.kill()
            elif self.drag_module.rect.left <= 140:
                self.drag_module.kill()
            self.drag_module.move_update()
            self.event = 0
            self.drag_module.image = self.drag_module_original_image
            self.drag_module = None
            self.drag_mPos = (0,0)
        elif self.event == 3:
            self.snap_to_side()
            self.snap_to_point()
            if self.drag_module.rect.centery <= 0:
                self.drag_module.kill()
            elif self.drag_module.rect.centery >= 600:
                self.drag_module.kill()
            elif self.drag_module.rect.centerx >= 900:
                self.drag_module.kill()
            elif get_dis_nsqrt(self.drag_module.rect.center,(900,600)) < 10000:
                self.drag_module.kill()
            elif self.drag_module.rect.left <= 140:
                self.drag_module.kill()
            self.drag_module.move_update()
            self.side_bar.new_module_stop(self.new_type)
            self.event = 0
            self.drag_module.image = self.drag_module_original_image
            self.drag_module = None
            self.drag_mPos = (0,0)

        select_sprites = self.gates_group.get_sprites_at(pos)
        if len(select_sprites) > 0:
            if select_sprites[-1].__class__.__name__ == 'Button':
                select_sprites[-1].mouse_up()