void search(int x, int y, int d, int step) { map[x][y] = 2; ans = step > ans ? step : ans; int dx = x + dir[d][0], dy = y + dir[d][1]; if (dx < 0 || dx >= n) { move_y(x, y, step); map[x][y] = 0; return ; } if (dy < 0 || dy >= n) { move_x(x, y, step); map[x][y] = 0; return ; } if(map[dx][dy] == 1) { if (d == 0 || d == 2) move_y(x, y, step); else move_x(x, y, step); map[x][y] = 0; return ; } if (map[dx][dy] == 2) { map[x][y] = 0; return ; } search(dx, dy, d, step + 1); map[x][y] = 0; }
int main() { init_ATX_power(); init_limit_switches(); init_timer(); init_motors(); sei(); enable_ATX_power(); delay_milliseconds(100); enable_x_motor(); delay_milliseconds(200); #define CONTINUOUS_HOMING 0 #if CONTINUOUS_HOMING while (1) { home_x(); delay_milliseconds(4000); move_x(MM_to_uSTEPS(MOVE_DISTANCE)); delay_milliseconds(200); } #else home_x(); delay_milliseconds(500); disable_x_motor(); disable_ATX_power(); while (1) continue; #endif }
int rt_ptr_key(int key, t_rt *rt) { if (key == 65307) rt_exit("exit\n"); else if (key == 65363 && rt->obj != NULL) { rt->obj->y -= 30; rt_image_loop(rt); } else if (key == 65361 && rt->obj != NULL) { rt->obj->y += 30; rt_image_loop(rt); } else if (key == 65362 && rt->obj != NULL) { rt->obj->z += 30; rt_image_loop(rt); } else if (key == 65364 && rt->obj != NULL) { rt->obj->z -= 30; rt_image_loop(rt); } else if (key == 65365 || key == 65366) move_x(key, rt); return (0); }
// UPDATE void Entity::Update(float elapsed, Entity* e) { vel_x = lerp(vel_x, 0.0, elapsed * 2.0); vel_x += acc_x * elapsed; if (type == PLAYER) { if (shootCooldown > 0.0) { shootCooldown -= elapsed; } } else if (type == GRUNT) { if (distanceTo(e) <= 12.0) { moveTo_x(e->x); move_x(elapsed); willShoot = true; } if (shootCooldown > 0.0) { shootCooldown -= elapsed; } } }
static void key_cb(SDL_Keycode k, int shift, struct game_state *gs) { switch (k) { case SDLK_r: init_game_state(gs); break; case SDLK_q: if (shift) end_cb(gs); break; case SDLK_j: case SDLK_s: drop_block(gs); break; case SDLK_h: case SDLK_a: move_x(gs, -1); break; case SDLK_l: case SDLK_d: move_x(gs, 1); break; case SDLK_k: case SDLK_w: rot_block(gs); break; } draw_cb(gs); }
void Roll::update(Spirit& spirit, const stage::Zone& zone, const enemy::EnemyVec& enemies, const prop::PropVec& props) { if (spirit.orientation.h == common::Horizontal::LEFT) { spirit.force.add_x(-values[ctr.value()]); } else if (spirit.orientation.h == common::Horizontal::RIGHT) { spirit.force.add_x(values[ctr.value()]); } move_x(zone, props, spirit); move_y(zone, props, spirit); if (!check_ground(zone, props, spirit)) { if (spirit.orientation.h == common::Horizontal::LEFT) { spirit.force.set_vx(-speed); } else if (spirit.orientation.h == common::Horizontal::RIGHT) { spirit.force.set_vx(speed); } if (spirit.link != nullptr) { // Prevent stickiness when attached to a prop. spirit.mass.update_y(-1); } spirit.motion_flag.set(static_cast<int>(MotionState::FALL)); } else if(spirit.controller->is_pressed(input::Glyph::A)) { spirit.force.reset(); spirit.motion_flag.set(static_cast<int>(MotionState::JUMP)); } else if (ctr.update()) { spirit.force.reset(); if(spirit.controller->is_pressed(input::Glyph::A)) { spirit.motion_flag.set(static_cast<int>(MotionState::JUMP)); } else if (spirit.controller->is_on(input::Glyph::LEFT) || spirit.controller->is_on(input::Glyph::RIGHT)) { spirit.motion_flag.set(static_cast<int>(MotionState::WALK)); } else { spirit.motion_flag.set(static_cast<int>(MotionState::IDLE)); } } }
void move_home() { Slp_1_Write(1); Slp_2_Write(1); uint8 x = Lim_1_Read(), y = Lim_2_Read(); while(!x || !y) { if(!y){ Dir_1_Write(1); Dir_2_Write(1); Stp_1_Write(0); Stp_1_Write(1); Stp_2_Write(0); Stp_2_Write(1); CyDelay(10); } else if(!x){ Dir_1_Write(0); Dir_2_Write(1); Stp_1_Write(0); Stp_1_Write(1); Stp_2_Write(0); Stp_2_Write(1); CyDelay(10); } x = Lim_1_Read(); y = Lim_2_Read(); } Slp_1_Write(0); Slp_2_Write(0); x_pos = 0; y_pos = 0; col_square = 11; row_square = 0; move_x(35); move_y(15); }
void doRender() { image::Render(&img, move_x(), move_y()); }
static void on_handle_key(int key) { switch (key) { case 10: case 13: case 27: case KEY_CANCEL: case KEY_ENTER: case KEY_CLOSE: case KEY_EXIT: text_widget.close(); break; case KEY_DOWN: case KEY_SF: case 'J': case 'j': case 'X': case 'x': move_y(1); break; case KEY_UP: case KEY_SR: case 'K': case 'k': case 'W': case 'w': move_y(-1); break; case KEY_LEFT: case 'H': case 'h': case 'P': case 'p': move_x(-1); break; case KEY_RIGHT: case 'L': case 'l': case 'N': case 'n': move_x(1); break; case KEY_NPAGE: case ' ': move_y(text_box_y); break; case KEY_PPAGE: case KEY_BACKSPACE: case 'B': case 'b': move_y(-text_box_y); break; case KEY_HOME: case KEY_BEG: move_x(-max_scroll_x); break; case KEY_LL: case KEY_END: move_x(max_scroll_x); break; case '\t': move_x(8); break; case KEY_BTAB: move_x(-8); break; } }
void do_force(FILE *fplog,t_commrec *cr, t_inputrec *inputrec, int step,t_nrnb *nrnb,gmx_wallcycle_t wcycle, gmx_localtop_t *top, gmx_groups_t *groups, matrix box,rvec x[],history_t *hist, rvec f[],rvec buf[], tensor vir_force, t_mdatoms *mdatoms, gmx_enerdata_t *enerd,t_fcdata *fcd, real lambda,t_graph *graph, t_forcerec *fr,gmx_vsite_t *vsite,rvec mu_tot, real t,FILE *field,gmx_edsam_t ed, int flags) { static rvec box_size; int cg0,cg1,i,j; int start,homenr; static double mu[2*DIM]; rvec mu_tot_AB[2]; bool bSepDVDL,bStateChanged,bNS,bFillGrid,bCalcCGCM,bBS,bDoForces; matrix boxs; real e,v,dvdl; t_pbc pbc; float cycles_ppdpme,cycles_pme,cycles_force; start = mdatoms->start; homenr = mdatoms->homenr; bSepDVDL = (fr->bSepDVDL && do_per_step(step,inputrec->nstlog)); clear_mat(vir_force); if (PARTDECOMP(cr)) { pd_cg_range(cr,&cg0,&cg1); } else { cg0 = 0; if (DOMAINDECOMP(cr)) cg1 = cr->dd->ncg_tot; else cg1 = top->cgs.nr; if (fr->n_tpi > 0) cg1--; } bStateChanged = (flags & GMX_FORCE_STATECHANGED); bNS = (flags & GMX_FORCE_NS); bFillGrid = (bNS && bStateChanged); bCalcCGCM = (bFillGrid && !DOMAINDECOMP(cr)); bDoForces = (flags & GMX_FORCE_FORCES); if (bStateChanged) { update_forcerec(fplog,fr,box); /* Calculate total (local) dipole moment in a temporary common array. * This makes it possible to sum them over nodes faster. */ calc_mu(start,homenr, x,mdatoms->chargeA,mdatoms->chargeB,mdatoms->nChargePerturbed, mu,mu+DIM); } if (fr->ePBC != epbcNONE) { /* Compute shift vectors every step, * because of pressure coupling or box deformation! */ if (DYNAMIC_BOX(*inputrec) && bStateChanged) calc_shifts(box,fr->shift_vec); if (bCalcCGCM) { put_charge_groups_in_box(fplog,cg0,cg1,fr->ePBC,box, &(top->cgs),x,fr->cg_cm); inc_nrnb(nrnb,eNR_CGCM,homenr); inc_nrnb(nrnb,eNR_RESETX,cg1-cg0); } else if (EI_ENERGY_MINIMIZATION(inputrec->eI) && graph) { unshift_self(graph,box,x); } } else if (bCalcCGCM) { calc_cgcm(fplog,cg0,cg1,&(top->cgs),x,fr->cg_cm); inc_nrnb(nrnb,eNR_CGCM,homenr); } if (bCalcCGCM) { if (PAR(cr)) { move_cgcm(fplog,cr,fr->cg_cm); } if (gmx_debug_at) pr_rvecs(debug,0,"cgcm",fr->cg_cm,top->cgs.nr); } #ifdef GMX_MPI if (!(cr->duty & DUTY_PME)) { /* Send particle coordinates to the pme nodes. * Since this is only implemented for domain decomposition * and domain decomposition does not use the graph, * we do not need to worry about shifting. */ wallcycle_start(wcycle,ewcPP_PMESENDX); GMX_MPE_LOG(ev_send_coordinates_start); bBS = (inputrec->nwall == 2); if (bBS) { copy_mat(box,boxs); svmul(inputrec->wall_ewald_zfac,boxs[ZZ],boxs[ZZ]); } gmx_pme_send_x(cr,bBS ? boxs : box,x,mdatoms->nChargePerturbed,lambda); GMX_MPE_LOG(ev_send_coordinates_finish); wallcycle_stop(wcycle,ewcPP_PMESENDX); } #endif /* GMX_MPI */ /* Communicate coordinates and sum dipole if necessary */ if (PAR(cr)) { wallcycle_start(wcycle,ewcMOVEX); if (DOMAINDECOMP(cr)) { dd_move_x(cr->dd,box,x,buf); } else { move_x(fplog,cr,GMX_LEFT,GMX_RIGHT,x,nrnb); } /* When we don't need the total dipole we sum it in global_stat */ if (NEED_MUTOT(*inputrec)) gmx_sumd(2*DIM,mu,cr); wallcycle_stop(wcycle,ewcMOVEX); } for(i=0; i<2; i++) for(j=0;j<DIM;j++) mu_tot_AB[i][j] = mu[i*DIM + j]; if (fr->efep == efepNO) copy_rvec(mu_tot_AB[0],mu_tot); else for(j=0; j<DIM; j++) mu_tot[j] = (1.0 - lambda)*mu_tot_AB[0][j] + lambda*mu_tot_AB[1][j]; /* Reset energies */ reset_energies(&(inputrec->opts),fr,bNS,enerd,MASTER(cr)); if (bNS) { wallcycle_start(wcycle,ewcNS); if (graph && bStateChanged) /* Calculate intramolecular shift vectors to make molecules whole */ mk_mshift(fplog,graph,fr->ePBC,box,x); /* Reset long range forces if necessary */ if (fr->bTwinRange) { clear_rvecs(fr->f_twin_n,fr->f_twin); clear_rvecs(SHIFTS,fr->fshift_twin); } /* Do the actual neighbour searching and if twin range electrostatics * also do the calculation of long range forces and energies. */ dvdl = 0; ns(fplog,fr,x,f,box,groups,&(inputrec->opts),top,mdatoms, cr,nrnb,step,lambda,&dvdl,&enerd->grpp,bFillGrid,bDoForces); if (bSepDVDL) fprintf(fplog,sepdvdlformat,"LR non-bonded",0,dvdl); enerd->dvdl_lr = dvdl; enerd->term[F_DVDL] += dvdl; wallcycle_stop(wcycle,ewcNS); } if (DOMAINDECOMP(cr)) { if (!(cr->duty & DUTY_PME)) { wallcycle_start(wcycle,ewcPPDURINGPME); dd_force_flop_start(cr->dd,nrnb); } } /* Start the force cycle counter. * This counter is stopped in do_forcelow_level. * No parallel communication should occur while this counter is running, * since that will interfere with the dynamic load balancing. */ wallcycle_start(wcycle,ewcFORCE); if (bDoForces) { /* Reset PME/Ewald forces if necessary */ if (fr->bF_NoVirSum) { GMX_BARRIER(cr->mpi_comm_mygroup); if (fr->bDomDec) clear_rvecs(fr->f_novirsum_n,fr->f_novirsum); else clear_rvecs(homenr,fr->f_novirsum+start); GMX_BARRIER(cr->mpi_comm_mygroup); } /* Copy long range forces into normal buffers */ if (fr->bTwinRange) { for(i=0; i<fr->f_twin_n; i++) copy_rvec(fr->f_twin[i],f[i]); for(i=0; i<SHIFTS; i++) copy_rvec(fr->fshift_twin[i],fr->fshift[i]); } else { if (DOMAINDECOMP(cr)) clear_rvecs(cr->dd->nat_tot,f); else clear_rvecs(mdatoms->nr,f); clear_rvecs(SHIFTS,fr->fshift); } clear_rvec(fr->vir_diag_posres); GMX_BARRIER(cr->mpi_comm_mygroup); } if (inputrec->ePull == epullCONSTRAINT) clear_pull_forces(inputrec->pull); /* update QMMMrec, if necessary */ if(fr->bQMMM) update_QMMMrec(cr,fr,x,mdatoms,box,top); if ((flags & GMX_FORCE_BONDED) && top->idef.il[F_POSRES].nr > 0) { /* Position restraints always require full pbc */ set_pbc(&pbc,inputrec->ePBC,box); v = posres(top->idef.il[F_POSRES].nr,top->idef.il[F_POSRES].iatoms, top->idef.iparams_posres, (const rvec*)x,fr->f_novirsum,fr->vir_diag_posres, inputrec->ePBC==epbcNONE ? NULL : &pbc,lambda,&dvdl, fr->rc_scaling,fr->ePBC,fr->posres_com,fr->posres_comB); if (bSepDVDL) { fprintf(fplog,sepdvdlformat, interaction_function[F_POSRES].longname,v,dvdl); } enerd->term[F_POSRES] += v; enerd->term[F_DVDL] += dvdl; inc_nrnb(nrnb,eNR_POSRES,top->idef.il[F_POSRES].nr/2); } /* Compute the bonded and non-bonded forces */ do_force_lowlevel(fplog,step,fr,inputrec,&(top->idef), cr,nrnb,wcycle,mdatoms,&(inputrec->opts), x,hist,f,enerd,fcd,box,lambda,graph,&(top->excls),mu_tot_AB, flags,&cycles_force); GMX_BARRIER(cr->mpi_comm_mygroup); if (ed) { do_flood(fplog,cr,x,f,ed,box,step); } if (DOMAINDECOMP(cr)) { dd_force_flop_stop(cr->dd,nrnb); if (wcycle) dd_cycles_add(cr->dd,cycles_force,ddCyclF); } if (bDoForces) { /* Compute forces due to electric field */ calc_f_el(MASTER(cr) ? field : NULL, start,homenr,mdatoms->chargeA,x,f,inputrec->ex,inputrec->et,t); /* When using PME/Ewald we compute the long range virial there. * otherwise we do it based on long range forces from twin range * cut-off based calculation (or not at all). */ /* Communicate the forces */ if (PAR(cr)) { wallcycle_start(wcycle,ewcMOVEF); if (DOMAINDECOMP(cr)) { dd_move_f(cr->dd,f,buf,fr->fshift); /* Position restraint do not introduce inter-cg forces */ if (EEL_FULL(fr->eeltype) && cr->dd->n_intercg_excl) dd_move_f(cr->dd,fr->f_novirsum,buf,NULL); } else { move_f(fplog,cr,GMX_LEFT,GMX_RIGHT,f,buf,nrnb); } wallcycle_stop(wcycle,ewcMOVEF); } } if (bDoForces) { if (vsite) { wallcycle_start(wcycle,ewcVSITESPREAD); spread_vsite_f(fplog,vsite,x,f,fr->fshift,nrnb, &top->idef,fr->ePBC,fr->bMolPBC,graph,box,cr); wallcycle_stop(wcycle,ewcVSITESPREAD); } /* Calculation of the virial must be done after vsites! */ calc_virial(fplog,mdatoms->start,mdatoms->homenr,x,f, vir_force,graph,box,nrnb,fr,inputrec->ePBC); } if (inputrec->ePull == epullUMBRELLA || inputrec->ePull == epullCONST_F) { /* Calculate the center of mass forces, this requires communication, * which is why pull_potential is called close to other communication. * The virial contribution is calculated directly, * which is why we call pull_potential after calc_virial. */ set_pbc(&pbc,inputrec->ePBC,box); dvdl = 0; enerd->term[F_COM_PULL] = pull_potential(inputrec->ePull,inputrec->pull,mdatoms,&pbc, cr,t,lambda,x,f,vir_force,&dvdl); if (bSepDVDL) fprintf(fplog,sepdvdlformat,"Com pull",enerd->term[F_COM_PULL],dvdl); enerd->term[F_DVDL] += dvdl; } if (!(cr->duty & DUTY_PME)) { cycles_ppdpme = wallcycle_stop(wcycle,ewcPPDURINGPME); dd_cycles_add(cr->dd,cycles_ppdpme,ddCyclPPduringPME); } #ifdef GMX_MPI if (PAR(cr) && !(cr->duty & DUTY_PME)) { /* In case of node-splitting, the PP nodes receive the long-range * forces, virial and energy from the PME nodes here. */ wallcycle_start(wcycle,ewcPP_PMEWAITRECVF); dvdl = 0; gmx_pme_receive_f(cr,fr->f_novirsum,fr->vir_el_recip,&e,&dvdl, &cycles_pme); if (bSepDVDL) fprintf(fplog,sepdvdlformat,"PME mesh",e,dvdl); enerd->term[F_COUL_RECIP] += e; enerd->term[F_DVDL] += dvdl; if (wcycle) dd_cycles_add(cr->dd,cycles_pme,ddCyclPME); wallcycle_stop(wcycle,ewcPP_PMEWAITRECVF); } #endif if (bDoForces && fr->bF_NoVirSum) { if (vsite) { /* Spread the mesh force on virtual sites to the other particles... * This is parallellized. MPI communication is performed * if the constructing atoms aren't local. */ wallcycle_start(wcycle,ewcVSITESPREAD); spread_vsite_f(fplog,vsite,x,fr->f_novirsum,NULL,nrnb, &top->idef,fr->ePBC,fr->bMolPBC,graph,box,cr); wallcycle_stop(wcycle,ewcVSITESPREAD); } /* Now add the forces, this is local */ if (fr->bDomDec) { sum_forces(0,fr->f_novirsum_n,f,fr->f_novirsum); } else { sum_forces(start,start+homenr,f,fr->f_novirsum); } if (EEL_FULL(fr->eeltype)) { /* Add the mesh contribution to the virial */ m_add(vir_force,fr->vir_el_recip,vir_force); } if (debug) pr_rvecs(debug,0,"vir_force",vir_force,DIM); } /* Sum the potential energy terms from group contributions */ sum_epot(&(inputrec->opts),enerd); if (fr->print_force >= 0 && bDoForces) print_large_forces(stderr,mdatoms,cr,step,fr->print_force,x,f); }
void do_force(FILE *log,t_commrec *cr,t_commrec *mcr, t_parm *parm,t_nsborder *nsb,tensor vir_part,tensor pme_vir, int step,t_nrnb *nrnb,t_topology *top,t_groups *grps, rvec x[],rvec v[],rvec f[],rvec buf[], t_mdatoms *mdatoms,real ener[],t_fcdata *fcd,bool bVerbose, real lambda,t_graph *graph, bool bNS,bool bNBFonly,t_forcerec *fr, rvec mu_tot, bool bGatherOnly) { static rvec box_size; static real dvdl_lr = 0; int cg0,cg1,i,j; int start,homenr; static real mu_and_q[DIM+1]; real qsum; start = START(nsb); homenr = HOMENR(nsb); cg0 = CG0(nsb); cg1 = CG1(nsb); update_forcerec(log,fr,parm->box); /* Calculate total (local) dipole moment in a temporary common array. * This makes it possible to sum them over nodes faster. */ calc_mu_and_q(nsb,x,mdatoms->chargeT,mu_and_q,mu_and_q+DIM); if (fr->ePBC != epbcNONE) { /* Compute shift vectors every step, because of pressure coupling! */ if (parm->ir.epc != epcNO) calc_shifts(parm->box,box_size,fr->shift_vec); if (bNS) { put_charge_groups_in_box(log,cg0,cg1,parm->box,box_size, &(top->blocks[ebCGS]),x,fr->cg_cm); inc_nrnb(nrnb,eNR_RESETX,homenr); } else if (parm->ir.eI==eiSteep || parm->ir.eI==eiCG) unshift_self(graph,parm->box,x); } else if (bNS) calc_cgcm(log,cg0,cg1,&(top->blocks[ebCGS]),x,fr->cg_cm); if (bNS) { inc_nrnb(nrnb,eNR_CGCM,cg1-cg0); if (PAR(cr)) move_cgcm(log,cr,fr->cg_cm,nsb->workload); if (debug) pr_rvecs(debug,0,"cgcm",fr->cg_cm,nsb->cgtotal); } /* Communicate coordinates and sum dipole and net charge if necessary */ if (PAR(cr)) { move_x(log,cr->left,cr->right,x,nsb,nrnb); gmx_sum(DIM+1,mu_and_q,cr); } for(i=0;i<DIM;i++) mu_tot[i]=mu_and_q[i]; qsum=mu_and_q[DIM]; /* Reset energies */ reset_energies(&(parm->ir.opts),grps,fr,bNS,ener); if (bNS) { if (fr->ePBC != epbcNONE) /* Calculate intramolecular shift vectors to make molecules whole */ mk_mshift(log,graph,parm->box,x); /* Reset long range forces if necessary */ if (fr->bTwinRange) { clear_rvecs(nsb->natoms,fr->f_twin); clear_rvecs(SHIFTS,fr->fshift_twin); } /* Do the actual neighbour searching and if twin range electrostatics * also do the calculation of long range forces and energies. */ dvdl_lr = 0; ns(log,fr,x,f,parm->box,grps,&(parm->ir.opts),top,mdatoms, cr,nrnb,nsb,step,lambda,&dvdl_lr); } /* Reset PME/Ewald forces if necessary */ if (EEL_LR(fr->eeltype)) clear_rvecs(homenr,fr->f_pme+start); /* Copy long range forces into normal buffers */ if (fr->bTwinRange) { for(i=0; i<nsb->natoms; i++) copy_rvec(fr->f_twin[i],f[i]); for(i=0; i<SHIFTS; i++) copy_rvec(fr->fshift_twin[i],fr->fshift[i]); } else { clear_rvecs(nsb->natoms,f); clear_rvecs(SHIFTS,fr->fshift); } /* Compute the forces */ force(log,step,fr,&(parm->ir),&(top->idef),nsb,cr,mcr,nrnb,grps,mdatoms, top->atoms.grps[egcENER].nr,&(parm->ir.opts), x,f,ener,fcd,bVerbose,parm->box,lambda,graph,&(top->atoms.excl), bNBFonly,pme_vir,mu_tot,qsum,bGatherOnly); /* Take long range contribution to free energy into account */ ener[F_DVDL] += dvdl_lr; #ifdef DEBUG if (bNS) print_nrnb(log,nrnb); #endif /* The short-range virial from surrounding boxes */ clear_mat(vir_part); calc_vir(log,SHIFTS,fr->shift_vec,fr->fshift,vir_part); inc_nrnb(nrnb,eNR_VIRIAL,SHIFTS); if (debug) pr_rvecs(debug,0,"vir_shifts",vir_part,DIM); /* Compute forces due to electric field */ calc_f_el(start,homenr,mdatoms->chargeT,f,parm->ir.ex); /* When using PME/Ewald we compute the long range virial (pme_vir) there. * otherwise we do it based on long range forces from twin range * cut-off based calculation (or not at all). */ /* Communicate the forces */ if (PAR(cr)) move_f(log,cr->left,cr->right,f,buf,nsb,nrnb); }
void movepiece(struct movement move) { moveRow(row_square - move.fromRow); moveCol(col_square - move.fromCol); row_square = move.toRow; col_square = move.toCol; CyDelay(5000); Em_Write(1); int rowdis = move.fromRow - move.toRow; int coldis = move.fromCol - move.toCol; //diagnal movement if clear path if (abs(rowdis) == abs(coldis)) { int temp = 0; for(int i = 1; i <= abs(coldis); i++) { if (board[move.fromRow + i * rowdis / abs(coldis)][move.fromCol + i * coldis / abs(coldis)] != 0) temp++; } if (temp == 0) { for(int i = 0; i < abs(coldis) * 51; i++) { move_x(coldis / abs(coldis)); move_y(rowdis / abs(rowdis) * -1); } } return; } //col movement if clear path if (rowdis == 0) { int temp = 0; for(int i = 1; i <= abs(coldis); i++) { if (board[move.fromRow][move.fromCol + i * coldis / abs(coldis)] != 0) temp++; } moveCol(coldis); return; } //row movement if clear path if (coldis == 0) { int temp = 0; for(int i = 1; i <= abs(rowdis); i++) { if (board[move.fromRow + i * rowdis / abs(rowdis)][move.fromCol] != 0) temp++; } moveRow(rowdis); return; } //up or down indicator for end adjustment, where down is 1 and up -1 //left or right indicator for end adjustment, where left is -1 and right is 1 int uod = 0, lor = 0; //determines the best path between spaces for cols if (move.fromCol < move.toCol) { lor = 1; } else if (move.fromCol > move.toCol) { lor = -1; } else if (move.fromCol < 6) { lor = 1; } else { lor = -1; } moveColHalf(lor * -1); //determines the best path between spaces for rows if (move.fromRow > move.toRow) { uod = -1; } else if (move.fromRow < move.toRow) { uod = 1; } else if (move.toRow < 4) { uod = -1; } else { uod = 1; } //moves across the rows with the adjustment if (rowdis == 0) { moveRowHalf(uod); } else if (rowdis > 0) { moveRowHalf(rowdis / abs(rowdis) * (rowdis * 2 - uod * -1)); } else { moveRowHalf(rowdis / abs(rowdis) * (abs(rowdis) * 2 - uod)); } //moves across the rows if (coldis == 0) { moveColHalf(lor); } else if (coldis > 0) { moveColHalf(coldis / abs(coldis) * (coldis * 2 - lor * -1)); } else { moveColHalf(coldis / abs(coldis) * (abs(coldis) * 2 - lor)); } //moves row adjustment moveRowHalf(-1 * uod); Em_Write(0); }
void moveColHalf(int dis) { move_x(25 * dis); }
void moveCol(int dis) { move_x(50 * dis); }
QVector3D EnvRoomTemplate::ClipPlayerTrajectory(const QVector3D & pos, const QVector3D & vel) const { QVector3D new_vel; bool x_collide = false; bool z_collide = false; QPointF move(pos.x() + vel.x(), pos.z() + vel.z()); QPointF move_x(pos.x() + vel.x(), pos.z()); QPointF move_z(pos.x(), pos.z() + vel.z()); for (int i=0; i<colliders.size(); ++i) { if (colliders[i].contains(move)) { if (colliders[i].contains(move_x)) { x_collide = true; } if (colliders[i].contains(move_z)) { z_collide = true; } } } if (!x_collide && z_collide) { new_vel = QVector3D(vel.x(), 0, 0); } else if (!z_collide && x_collide) { new_vel = QVector3D(0, 0, vel.z()); } else if (x_collide && z_collide) { new_vel = QVector3D(0, 0, 0); } else { new_vel = vel; } move = QPointF(pos.x() + new_vel.x(), pos.z() + new_vel.z()); for (int i=0; i<circ_colliders.size(); ++i) { QVector3D cent_dir = QVector3D(circ_colliders[i].pos.x() - move.x(), 0, circ_colliders[i].pos.y() - move.y()); const float cent_dist = cent_dir.length(); if ((circ_colliders[i].stay_inside && cent_dist > circ_colliders[i].rad) || (!circ_colliders[i].stay_inside && cent_dist < circ_colliders[i].rad)) { new_vel += cent_dir.normalized() * (cent_dist - circ_colliders[i].rad); } } /* qDebug() << "the mountpoints:"; for (int angle=0; angle<=360; angle+=18) { if (angle % 36 == 0) { qDebug() << sinf(float(angle)* MathUtil::_PI_OVER_180) * 20.0f << "0" << cosf(float(angle)* MathUtil::_PI_OVER_180) * 20.0f << -sinf(float(angle)* MathUtil::_PI_OVER_180) << "0" << -cosf(float(angle)* MathUtil::_PI_OVER_180); } else { qDebug() << sinf(float(angle)* MathUtil::_PI_OVER_180) * 12.1f << "0" << cosf(float(angle)* MathUtil::_PI_OVER_180) * 12.1f << sinf(float(angle)* MathUtil::_PI_OVER_180) << "0" << cosf(float(angle)* MathUtil::_PI_OVER_180); } } */ return new_vel; }
void main(void) { int8 recibe[5]; //declaramos variables int8 send2[1]; LED_OFF(LED_OK); //encendemos led rojo LED_ON(LED_FAIL); usb_init(); //inicializamos el USB setup_adc_ports(AN0); //Configura canais analógico setup_adc(ADC_CLOCK_INTERNAL); //De acordo com relógio interno. /*SETUP_TIMER_1 (T1_INTERNAL|T1_DIV_BY_2); //Configurar timer1 para clock iterno/8 enable_interrupts (INT_TIMER1); //Habilitar Interrupções enable_interrupts (global);*/ usb_task(); //habilita periferico usb e interrupciones usb_wait_for_enumeration(); //esperamos hasta que el PicUSB sea configurado por el host enable_interrupts (global); LED_OFF(LED_FAIL); //desligo o LED vermelho LED_ON(LED_OK); //acendo o LED verde move_x('S'); move_y('S'); while (true) { if(usb_enumerated()) //si el PicUSB está configurado { if (usb_kbhit(1)) //si el endpoint de salida contiene datos del host { LED_ON(LED_DATA); usb_get_packet(1, recibe, 5); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe if(modo == 1) { if(dir_x == 1 && value_x == 1){ move_x('R'); } if(dir_x == 2 && value_x == 1){ move_x('L'); } if(dir_y == 1 && value_y == 1){ move_y('F'); } if(dir_y == 2 && value_y == 1){ move_y('B'); } delay_ms(20); } if (modo == 4) { status = 1; usb_put_packet(1, send2, 1, USB_DTS_TOGGLE); //enviada a informação para o PC com o status } LED_OFF(LED_DATA); } } } }