Example #1
0
void Player::update(int width, int height)
{
    if (m_position.getX() < 0) {
        stopX(0);
    }
    if (m_position.getX() > (width - m_width)) {
        stopX(width - m_width);
    }
    if (m_position.getY() < 0) {
        stopY(0);
    }
    if (m_position.getY() > (height - m_height)) {
        stopY(height - m_height);
    }
}
Example #2
0
void Player::update() {
    int pixelsToChangeFrame = 12;
    Vector2D v0 = m_velocity;
    if (m_velocity.getX() > 0) {
        decrementAccelerationX();
    }
    if (m_velocity.getX() < 0) {
        incrementAccelerationX();
    }
    if (m_velocity.getY() > 0) {
        decrementAccelerationY();
    }
    if (m_velocity.getY() < 0) {
        incrementAccelerationY();
    }
    m_velocity += m_acceleration;
    if (m_velocity.getX()*v0.getX() < 0 || m_velocity.getX() == 0) {
        stopX(m_position.getX());
    }
    if (m_velocity.getY()*v0.getY() < 0 || m_velocity.getY() == 0) {
        stopY(m_position.getY());
    }
    if (m_velocity.length() > m_maxVelocity) {
        m_velocity = m_velocity.normalize()*m_maxVelocity;
        m_acceleration.setX(0);
    }
    m_position += m_velocity + m_acceleration * 1 / 2;
    m_currentFrame = (abs((int) (m_position - m_lastStop).length()) / pixelsToChangeFrame) % m_spriteNum;
}
void arduinoThread::digitalPinChanged(const int & pinNum) {
    // note: this will throw tons of false positives on a bare mega, needs resistors
    if (curState == HOMING) {
        if (pinNum == X_LIMIT_PIN && ard.getDigital(X_LIMIT_PIN)) {
            stopX();
            homeY();
        }
        if (pinNum == Y_LIMIT_PIN && ard.getDigital(Y_LIMIT_PIN)) {
            stopY();
            homeZ();
        }
        if (pinNum == Z_LIMIT_PIN && ard.getDigital(Z_LIMIT_PIN)) {
            stopZ();
            curState = HOME;
        }
    }
    // if not homing or reseting and the switch is down, it's an error
    else if (curState != PREPRINT && curState != RESET && curState != HOME && curState != SHOOT_FACE) {
        if (ard.getDigital(pinNum) == ARD_HIGH){
            curState = ERROR;
        }
    }
}
void disableServosNow(){
	stopY( false );
	stopZ( false );
}
void step_servoY() {       		    // synchroniczne
	volatile ServoChannel &ser = servos[INNER_SERVOY];
	if( pcb_type == 2 ){			// servos + magicled
		if( ser.pos_changed == true ){  // mam byc gdzie indziej
		//	Serial.print("-pos= " + String(servos[index].last_pos ));
		//	Serial.print("\t tar= " + String(servos[index].target_pos) );
		//	Serial.println("\t d= " + String(delta) );
			servo_lib[INNER_SERVOY].writeMicroseconds(ser.last_pos);
			ser.pos_changed = false;
			if(ser.last_pos == ser.target_pos){		// on target pos
				ser.moving= DRIVER_DIR_STOP;
				send_servoYisReady();
			}
		}
	}else if(pcb_type == 3 ){		// actuators + magicled
		if( ser.moving != DRIVER_DIR_STOP ){
			ser.last_pos = analogRead(PIN_B3_IN_Y);
			if( ser.last_pos == y_last_val || abs(ser.last_pos - y_last_val) <= 3){
			/*
				if( y_repeat %30 == 1 ){
					Serial.print("-");
					Serial.print(ser.last_pos);
					Serial.print("-");
					Serial.println(y_repeat);
				}*/
				y_repeat++;
				if( y_repeat == 700 ){
					Serial.print("RRYSTOPS,");
					Serial.println(ser.last_pos);
					Serial.flush();
					stopY( false );
					sendYpos();
					y_repeat = 0;
				}
			}else{
			/*
				if(y_repeat>60){
					Serial.print("-reset-");
					Serial.print(ser.last_pos);
					Serial.print("-");
					Serial.println(y_repeat);
				}*/
				y_repeat	=0;
				y_last_val	= ser.last_pos;
			}
			
			if( ser.moving == DRIVER_DIR_FORWARD ){
				if( ser.last_pos >= Y_MAX_VAL ){			// stop
					stopY( false );
					sendYpos();
		//			Serial.println("-step, STOP Z max");
				}else if( ser.last_pos >= ser.target_pos ){
					stopY( false );
					sendYpos();
				}
			}else if( ser.moving == DRIVER_DIR_BACKWARD ){
				if(  ser.last_pos <= Y_MIN_VAL ){			// stop
		//			Serial.println("-step, STOP Z min");
					stopY( false );
					sendYpos();
				}else if( ser.last_pos <= ser.target_pos ){
					stopY( false );
					sendYpos();
				}
			}
		}
	}
}