Beispiel #1
0
int Powerup::update(){
	mvCount++;
	if (mvCount > 1000){
		mvCount = 0;
	}
	setXVel(cos(6.28*mvCount/1000));
	setYVel(sin(6.28*mvCount/1000));
	return 0;
}
    void MovableSprite::move() // (int dir) som argument?
    {
        // Faktiskt rörelse av spriten i x-led. hitboxens x-position låts påverkas av x-vel
		hitbox.x += getXVel();
        
        // Hantera väggkollision för alla MovableSprites
		if ((hitbox.x < 0) || (hitbox.x + hitbox.w > sys.SCREEN_WIDTH))
			setXVel(-this->getXVel());
        
        // Samma som ovan fast y-led
		hitbox.y += getYVel();
        
        if ((hitbox.y < 0) || (hitbox.y + hitbox.h > sys.SCREEN_HEIGHT))
			setYVel(-this->getYVel());
    }