Quantcast
Channel: Сообщество PHP DevelStudio - среда разработки программ
Viewing all articles
Browse latest Browse all 6336

Скорость объекта

$
0
0
Столкновение и скорость объектов не работает.Так как на форуме и поиск не работает,это немного усложняет задачу:найти быстрее решение.Нашел я архив с файлом 'animation.php',после замены,столкновение так же не работает,а вот скорость впечатлила,но проблема в том,что объект не останавливается.Помогите пожалуйста.
Вот код в 'animation.php':
PHP код:

<?


class animate {
    
    static function 
toSpeed(){
        
        
$vspeed =& $GLOBALS['__VSPEED'];
        if (
count($vspeed))
        foreach (
$vspeed as $self=>$speed){
            if (
link_null($self)){
               
// pre($self);
                
unset($vspeed[$self]);
                continue;
            }
            
control_y($selfcontrol_y($selfnull) + $speed);
        }
        
        
$hspeed =& $GLOBALS['__HSPEED'];
        if (
count($hspeed))
        foreach (
$hspeed as $self=>$speed){
            if (
link_null($self)){
                unset(
$hspeed[$self]);
                continue;
            }
            
control_x($selfcontrol_x($selfnull) + $speed);
        }
        
        
// collisions
        
$coll =& $GLOBALS['__COLLISION'];
        if (
$coll)
        foreach (
$coll as $self=>$arr){
            
            if (
link_null($self)){
                unset(
$coll[$self]);
                continue;
            }
            
            
$arr1['x'] = control_x($selfnull);
            
$arr1['y'] = control_y($selfnull);
            
$arr1['w'] = control_w($selfnull);
            
$arr1['h'] = control_h($selfnull);
            foreach (
$arr as $toobj=>$event){
                
                if (
link_null($toobj)){
                    unset(
$coll[$self][$toobj]);
                    continue;
                }
                
                
$arr2['x'] = control_x($toobjnull);
                
$arr2['y'] = control_y($toobjnull);
                
$arr2['w'] = control_w($toobjnull);
                
$arr2['h'] = control_h($toobjnull);
                
                if (
Geometry::collision2D($arr1$arr2)){
                    
                    
//
                    
if (is_object($event)){
                        
f($event$self$toobj);
                    } elseif (
$event[0]=='%'){
                        
$event[0] = ' '$event ltrim($event);
                        
f($event$self$toobj);
                    } else {
                        
//pre("$event($self, $toobj)");
                        
$event($self$toobj);
                    }
                }
            }
        }
    }
    
    static function 
toView(){
        
        if (!isset(
$GLOBALS['__VIEW'])) return;
        
        
$f   $GLOBALS['__VIEW']['OWNER'];
        
$f_w control_w($fnull);
        
$f_h control_h($fnull);
        
$f_x control_x($fnull);
        
$f_y control_y($fnull);
        
        
$o   $GLOBALS['__VIEW']['OBJECT'];
        
$w   control_w($onull);
        
$h   control_h($onull);
        
$x   control_x($onull);
        
$y   control_y($onull);
        
        
$view_x 0;
        
$view_y 0;
        
        if (!isset(
$GLOBALS['__VIEW']['OFFSET_X'])){
            
            
$offset_x $x;
            
$offset_y $y;
            
$GLOBALS['__VIEW']['OFFSET_X'] = $x;
            
$GLOBALS['__VIEW']['OFFSET_Y'] = $y;
        } else {
            
            
$offset_x $GLOBALS['__VIEW']['OFFSET_X'];
            
$offset_y $GLOBALS['__VIEW']['OFFSET_Y'];
        }
        
        
// определим центр окна...
        //$center_x = intval($f_w / 2) - $offset_x - intval($w/2);
        //$center_y = intval($f_h / 2) - $offset_y - intval($h/2);
        
        
$center_x $offset_x intval($w/2);
        
$center_y $offset_y $h;
        
        
// определим позицию объекта по центру...
        
$center_ox $x intval($w 2);
        
$center_oy $y intval($h 2);
        
        
// -top - движение камеры вверх
        // +top - ... вниз
        
        // -left - движение камеры влево
        // +left - ... вправо
        
        
$move_x $center_x $center_ox;
        
$move_y $center_y $center_oy intval($h 2);
         
        
        
form_scrollby($f$move_x$move_y);
    }
    
    static function 
hspeed($obj$value null){
        
        if (
$obj instanceof group){
            
            foreach (
$obj->objects as $self){
                
self::hspeed($self$value);
            }
        }
        
        if (!
is_object($obj))
            
$obj toObject($obj);
            
        if (
$value === null)
            return (int)
$GLOBALS['__HSPEED'][$obj->self];
        else {
            if (
$value == 0)
                unset(
$GLOBALS['__HSPEED'][$obj->self]);
            else
                
$GLOBALS['__HSPEED'][$obj->self] = (int)$value;
        }
    }
    
    static function 
vspeed($obj$value null){
        
        if (
$obj instanceof group){
            foreach (
$obj->objects as $self)
                
self::vspeed($self$value);
        }
        
        if (!
is_object($obj))
            
$obj toObject($obj);
            
        if (
$value === null)
            return (int)
$GLOBALS['__VSPEED'][$obj->self];
        else {
            if (
$value == 0){
                
                unset(
$GLOBALS['__VSPEED'][$obj->self]);
            }
            else
                
$GLOBALS['__VSPEED'][$obj->self] = (int)$value;
        }
    }
    
    static function 
collision($obj$toobj$event){
        
        if (
$obj instanceof group){
            foreach (
$obj->objects as $self)
                
self::collision($self$toobj$event);
        }
        
        if (!
is_object($obj))
            
$obj toObject($obj);
        
        if (!
is_object($toobj))
            
$obj toObject($toobj);
        
        
$GLOBALS['__COLLISION'][$obj->self][$toobj->self] = $event;
    }
    
    static function 
delCollision($obj$toobj false){
        
        
$obj toObject($obj);
        if (
$toobj){
            
$toobj toObject($toobj);
            unset(
$GLOBALS['__COLLISION'][$obj->self][$toobj->self]);
        } else {
            unset(
$GLOBALS['__COLLISION'][$obj->self]);
        }
    }
    
    static function 
setView($obj$offsetX 0$offsetY 0){
        
        
        if (!
is_object($obj))
            
$obj toObject($obj);
        
        if (!isset(
$GLOBALS['__VIEW']))
            
setTimer(10'animate::toView()');
        
        if (!
$obj){
            unset(
$GLOBALS['__VIEW']);
        } else {
            
$GLOBALS['__VIEW']['OBJECT'] = $obj->self;
            
$GLOBALS['__VIEW']['OWNER']  = $obj->owner;
        }
    }
    
    static function 
objectFree($self){
        
        if (
$GLOBALS['__VIEW']['OBJECT'] == $self)
            unset(
$GLOBALS['__VIEW']);
        
        unset(
$GLOBALS['__VSPEED'][$self]);
        unset(
$GLOBALS['__HSPEED'][$self]);
        
        unset(
$GLOBALS['__COLLISION'][$self]);
        
        if (
$GLOBALS['__COLLISION'])
        foreach (
$GLOBALS['__COLLISION'] as $s=>$arr){
            foreach (
$arr as $toobj=>$event)
                if (
$toobj == $self)
                    unset(
$GLOBALS['__COLLISION'][$s][$toobj]);
        }
    }
}

if (!
$GLOBALS['APP_DESIGN_MODE'] && IS_THREAD!==true){
    
setTimer(30'animate::toSpeed()');
}
?>

Может что-то в нём изменить или есть какие-то более лучше способы?

Viewing all articles
Browse latest Browse all 6336

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>