/*-------------------------------------------------------------------*/ void random_walk(){ switch( current_motion_type ) { case TURN_LEFT: case TURN_RIGHT: if( kilo_ticks > last_motion_ticks + turning_ticks ) { /* start moving forward */ last_motion_ticks = kilo_ticks; set_motion(FORWARD); } break; case FORWARD: if( kilo_ticks > last_motion_ticks + max_straight_ticks ) { /* perform a radnom turn */ last_motion_ticks = kilo_ticks; if( rand_soft()%2 ) { set_motion(TURN_LEFT); } else { set_motion(TURN_RIGHT); } turning_ticks = rand_soft()%max_turning_ticks + 1; } break; case STOP: default: set_motion(STOP); } }
/*-------------------------------------------------------------------*/ void setup() { /* Initialise LED and motors */ set_color(RGB(0,0,0)); set_motors(0,0); /* Initialise random seed */ uint8_t seed = rand_hard(); rand_seed(seed); /* Initialise the list of words ready for message sending. The word index is contained in the first payload byte, while the follwoing three bytes contain the randomly-chosen word */ int i; for( i = 0; i < num_words; i++ ) { words[i].data[0] = i; words[i].type = NORMAL; words[i].crc = message_crc(&words[i]); } /* Initialise motion variables */ set_motion( FORWARD ); last_motion_ticks = rand_soft() % max_straight_ticks + 1; /* Initialise mng variables */ last_broadcast_ticks = rand_soft() % max_broadcast_ticks + 1; }
void net_motion_test::OnMouseMove(UINT nFlags, CPoint point) { //TRACE("on mouse move\n"); if(m_bmouse_down) { int orix,oriy; getxy(m_ori,&orix,&oriy); int dstx,dsty; getxy(point,&dstx,&dsty); int minx = min(orix,dstx); int maxx = max(orix,dstx); int miny = min(oriy,dsty); int maxy = max(oriy,dsty); for(int i = minx; i <= maxx; i++) { for(int j = miny; j <= maxy; j++) { if(m_ori_is_set) { set_motion(i,j); }else{ clear_motion(i,j); } } } } CEdit::OnMouseMove(nFlags,point); }
void net_motion_test::set_motion(POINT pt) { int x,y; getxy(pt,&x,&y); set_motion(x,y); }
void loop() { if (msg_rcvd){ if (curr_dist < TOOCLOSE){ nxt_motion = RIGHT; set_motion(RIGHT); } else{ if (curr_dist < DIST){ nxt_motion = FORWARD; set_motion(FORWARD); } else { nxt_motion = LEFT; set_motion(LEFT); } } msg_rcvd = 0; } }
void net_motion_test::OnLButtonDown(UINT nFlags, CPoint point) { if(!is_show_motion()) { return; } if(is_motion_set(point)) { clear_motion(point); m_ori_is_set = FALSE; }else{ set_motion(point); m_ori_is_set = TRUE; } m_ori = point; m_bmouse_down = TRUE; //CEdit::OnLButtonDown(nFlags,point); }
type_motion* type_motion::setup( IKinematicsAnimated* k, CInifile* ini, LPCSTR section, LPCSTR type ) { anims.resize( dirs_number, 0 ); if( ini->line_exist( section ,type ) ) { LPCSTR line = ini->r_string( section, type ); if( !line ) { #ifdef DEBUG if( death_anim_debug ) Msg("death anims: load: no setings in section %s for %s", section, type ); #endif return this; } R_ASSERT( xr_strlen( line ) < 1023 ); const int num = _GetItemCount( line, '/' ); #ifdef DEBUG if( death_anim_debug && num == 0 ) Msg("death anims: load: no setings in section %s for %s", section, type ); #endif for( int i = 0; num > i; ++i) { string1024 sdir_anim; set_motion( k, u16(i), _GetItem( line, i, sdir_anim, '/' ) ); #ifdef DEBUG if( death_anim_debug ) Msg("death anims: load: loaded %s from section %s for %s", sdir_anim, section, type ); #endif } } #ifdef DEBUG else if( death_anim_debug ) Msg("death anims: load: no setings in section %s for %s", section, type ); #endif return this; }