Jump to content

  • Log In with Google      Sign In   
  • Create Account


Kain5056

Member Since 22 Dec 2012
Offline Last Active Yesterday, 06:01 PM
-----

#5170466 Hello World App won't run in emulator

Posted by Kain5056 on Yesterday, 05:30 PM

OK, I googled it (didn't know exactly what to google at the time) and found the solution.

I downgraded the API Level to 17 just to be sure (Android version 4.2.2) and it works like a charm, both in the emulator and on my physical phone. :-)

Thanks for the help. :-)

 

A question though: Do I even need the API Level 20 stuff? Or is it safe to just uninstall them and just work with Level 17? Because the whole thing takes a billion trillion (rough estimate) Gigabytes on my HDD and it's a bit annoying since it's almost full... :-/




#5158377 Homing missile problem

Posted by Kain5056 on 05 June 2014 - 07:14 AM

I'm trying to follow this Actionscript tutorial for homing missiles, translating it to C++ with SFML.

 

But I seem to have a problem with this piece of code:

 

In Actionscript:

var rotation:int = Math.atan2(targetY, targetX) * 180 / Math.PI;
        if (Math.abs(rotation - missile.rotation) > 180)
        {
            if (rotation > 0 && missile.rotation < 0)
                missile.rotation -= (360 - rotation + missile.rotation) / ease;
            else if (missile.rotation > 0 && rotation < 0)
                missile.rotation += (360 - rotation + missile.rotation) / ease;
        }
        else if (rotation < missile.rotation)
            missile.rotation -= Math.abs(missile.rotation - rotation) / ease;
        else
            missile.rotation += Math.abs(rotation - missile.rotation) / ease;

Translated in C++ with SFML:

int current = rocket_sprite.getRotation();
    if( abs( rotation - current ) > 180 )
    {
        if( rotation > 0 && current < 0 ) rotation -= ( 360 - rotation + current ) / ease;
        else if( current > 0 && rotation < 0 ) rotation += ( 360 - rotation + current ) / ease;
    }
    else if( rotation < current ) rotation -= abs( current - rotation ) / ease;
    else rotation += abs( rotation - current ) / ease;

With this code, the missile acts crazy, getting stuck in places, continually rotating in place for no reason and other stuff like that.

 

I suspect that the problem lies in the fact that .getRotation() returns absolute values, but I don't know how to even test it.

 

Here is my complete code:

#include <math.h>
#define PI 3.14159265

class rocket
{
private:
    sf::Texture rocket_texture;
    sf::Sprite rocket_sprite;
    sf::Vector2f position;
    int rotation;

public:
    rocket();
    bool rocket_load();
    void rocket_show( sf::RenderWindow * window );
    void set_position( sf::Vector2f new_position );
    void rocket_rotate( sf::RenderWindow * window );
    void rocket_move();
};

rocket::rocket()
{
    rotation = 0.f;
}

bool rocket::rocket_load()
{
    rocket_texture.loadFromFile( "rocket.png" );
    rocket_sprite.setTexture( rocket_texture );

    return true;
}

void rocket::rocket_show( sf::RenderWindow * window )
{
    rocket_sprite.setOrigin( rocket_texture.getSize().x / 2 , rocket_texture.getSize().y / 2 );
    rocket_sprite.setPosition( position );
    window->draw( rocket_sprite );
}

void rocket::set_position( sf::Vector2f new_position )
{
    position = new_position;
}

void rocket::rocket_rotate( sf::RenderWindow * window )
{
    sf::Vector2i mouse_position = sf::Mouse::getPosition( *window );
    int targetx = mouse_position.x - position.x;
    int targety = mouse_position.y - position.y;

    rotation = atan2( targety , targetx ) * 180 / PI;

    int ease = 5;
    int current = rocket_sprite.getRotation();
    if( abs( rotation - current ) > 180 )
    {
        if( rotation > 0 && current < 0 ) rotation -= ( 360 - rotation + current ) / ease;
        else if( current > 0 && rotation < 0 ) rotation += ( 360 - rotation + current ) / ease;
    }
    else if( rotation < current ) rotation -= abs( current - rotation ) / ease;
    else rotation += abs( rotation - current ) / ease;

    rocket_sprite.setRotation( rotation );
}

void rocket::rocket_move()
{
    int speed = 5;
    float speedx = 0;
    float speedy = 0;
    speedx = speed * ( 90 - abs( rotation ) ) / 90;
    if( rotation < 0 ) speedy = -speed + abs( speedx );
    else speedy = speed - abs( speedx );
    position.x += speedx;
    position.y += speedy;
}

If anyone can point me to the right direction, I would really appreciate it. :-)

Thank you in advance. :-)




#5111994 How to stick on slopes?

Posted by Kain5056 on 25 November 2013 - 07:14 PM

So, I was making my first game, and I have encountered a problem I did not expect. blink.png

 

19l43s.jpg

 

As you can see, instead of staying on the ground, my entity just flies off when it meets a downward slope. wacko.png

I want the entity to stick to the ground, but I do not want to change its moving and falling speed.

How can I do that? unsure.png

 

Thanks in advance. happy.png




#5029344 Second entity moves really slow!

Posted by Kain5056 on 06 February 2013 - 03:40 AM

It works perfectly! Thank you so much for the help! smile.png

 

Here is the new game loop:

 

while( quit == false )
    {
        Uint32 ticks = delta.get_ticks();

        scrolling_background();
        if( tileedit ) editor_show( current_tile );

        while( SDL_PollEvent( &event ) )
        {
            if( event.type == SDL_KEYDOWN )
            {
                if( event.key.keysym.sym == SDLK_t ) tileedit = !tileedit;
            }

            if( event.type == SDL_QUIT ) quit = true;

            if( tileedit == false ) player1.control();
            else if( tileedit ) editor_control( tiles );
        }

        if( tileedit == false )
        {
            player1.jump();
            scrolling_background();
            player1.move( ticks , tiles );
            enemy1.move_enemy( ticks , tiles );
            player1.player_camera();
        }
        else editor_camera();

        for( int t = 0 ; t < TOTAL_TILES ; t++ )
        {
            tiles[t]->show();
        }

        if( tileedit == false ) player1.show();

        enemy1.show();

        if( SDL_Flip( screen ) == -1 ) return 5;
    }

 

 

Thanks again. smile.png




PARTNERS