void Simulator::UpdateRobot(SimRobot &r, double dt) { if(r.conf==0.0) { return; } /* do an acceleration check */ AccelerationLimit(r, maxRobotAccel * dt); /* Speed Limit */ SpeedLimit(r, maxRobotSpeed); /* store off old velocities and positions */ r.oldpos = r.pos; /* transform to world coords */ r.vel.v = r.vcmd.v; r.vel.v = r.vel.v.rotate(r.pos.dir); r.pos.p += r.vel.v * dt; r.pos.dir = anglemod(r.pos.dir + r.vcmd.va * dt); /* look for wall collisions */ r.collision = CheckWallCollision(r, field_minX, field_maxX, field_minY, field_maxY); }
void BreakoutLevel::HandleFrame(unsigned char frame) { // Move ball _screen->fillRect(_ball_x, _ball_y, BLOCK_HEIGHT, BLOCK_HEIGHT, COLOR_BG); _ball_x += _ball_inc_x; _ball_y += _ball_inc_y; CheckWallCollision(); CheckPadCollision(); CheckBlockCollision(); _screen->fillRect(_ball_x, _ball_y, BLOCK_HEIGHT, BLOCK_HEIGHT, COLOR_RED); // Move pad if(_last_pad_position != _pad_position) { if(_last_pad_position < _pad_position) // Moving right _screen->fillRect(_last_pad_position, PAD_Y, _pad_position - _last_pad_position, BLOCK_HEIGHT, COLOR_BG); else _screen->fillRect(_pad_position + BLOCK_WIDTH, PAD_Y, _last_pad_position - _pad_position, BLOCK_HEIGHT, COLOR_BG); _last_pad_position = _pad_position; _screen->fillRect(_last_pad_position, PAD_Y, BLOCK_WIDTH, BLOCK_HEIGHT, COLOR_TEXT); } }