Jump to content

  • Log In with Google      Sign In   
  • Create Account

Kain5056

Member Since 22 Dec 2012
Offline Last Active May 17 2015 05:16 AM

#5227740 Quick question about handling 2d levels

Posted by on 07 May 2015 - 07:51 AM

 

Should I create a state for every level, or a single level state that reads from a level manager?

There should be a single state for gameplay, another for overworld, etc.
Data is what changes from stage-to-stage.  A “level manager” is ambiguous and likely not what you want.  The game engine should simply be able to take any stage data and have your character be able to walk through it, etc.

 

 

L. Spiro

 

Thanks for your answer. :-)

So, as I see it, I'll have a level (gameplay) state and an overworld state, and have the overworld determine what level file should be loaded, kind of like a glorified menu.

Seems simple enough. :-)

Thanks again. :-)




#5227705 Quick question about handling 2d levels

Posted by on 07 May 2015 - 05:01 AM

After a long time doing other things I decided to pick up and finish my first game. It's a 2D Platformer with tile-based levels. However, due to not having coded at all in a long time, I'm a bit rusty and need some advice on how to handle levels.

 

The last thing I did was create a state engine. I want my game to be level based with an overworld where new levels are gradually unlocked, like Super Mario World for example.

 

My question is: Should I create a state for every level, or a single level state that reads from a level manager? Is any of these options better than the other, more common, or outright bad practice? Or it does not really matter as long as it works for me?

 

Thank you very much in advance. :-)




#5170466 Hello World App won't run in emulator

Posted by on 30 July 2014 - 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 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 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 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