Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Space Invaders Clone - Game finished  (Read 19859 times)

0 Members and 1 Guest are viewing this topic.

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone
« Reply #15 on: September 02, 2015, 09:30:59 pm »
yeah, i test the ts=1 with my IDE for functions, it looks nice especially when it has description comments. i'm going to use this style in next game  ;)

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone
« Reply #16 on: September 20, 2015, 07:41:41 pm »
update

after reading an old post http://en.sfml-dev.org/forums/index.php?topic=7427.0 about Sprite Masking by using sf::RenderTexture and sf::Image.

 i implemented them in the game, now the game use single texture for shield and result some how acceptable.

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone
« Reply #17 on: September 22, 2015, 08:21:27 am »
i added new video for latest update, after implemented sprite masking and pixel collision detection.

here snippet from sprite masking by using sf::RenderTexture and sf::Image

void Shield::updateCurrent(sf::Time dt, CommandQueue& commands)
{
        if (!mOnHit)
                return;

        mRenderTexture.clear();

        mRenderTexture.draw(*this, sf::BlendNone);
        mRenderTexture.display();

        float radius = (mRectOnHit.height > ExplosionRadius) ? mRectOnHit.height : ExplosionRadius;
        sf::CircleShape circle(radius, 10);
        circle.setPosition(mPositionOnHit.x, mPositionOnHit.y + circle.getRadius() / 2.f * mSign);
        circle.setFillColor(sf::Color::Transparent);
        centerOrigin(circle);

        mRenderTexture.draw(circle, sf::BlendNone);
        mRenderTexture.display();

        sf::Vector2u position(static_cast<std::size_t>(getPosition().x - mTexture.getSize().x / 2u), static_cast<std::size_t>(getPosition().y - mTexture.getSize().y / 2u));
        mImage.copy(mRenderTexture.getTexture().copyToImage(), 0u, 0u, sf::IntRect(position.x, position.y, mTexture.getSize().x, mTexture.getSize().y));
        mImage.createMaskFromColor(sf::Color::Transparent);

        updateSprite();
}

and here the pixel collision detection for bullets:

bool PixelcollidesPair(const Shield& shield, const Projectile& bullet)
{
        auto bulletBounds = static_cast<sf::Rect<std::size_t>>(bullet.getBoundingRect());
        auto shieldBounds = static_cast<sf::Rect<std::size_t>>(shield.getBoundingRect());

        auto width = bulletBounds.left + bulletBounds.width;
        auto height = bulletBounds.top + bulletBounds.height;

        sf::Vector2u position(bulletBounds.left, bulletBounds.top);

        if (!bulletBounds.intersects(shieldBounds))
                return false;

        for (auto x = position.x; x < width; ++x)
        {
                for (auto y = position.y; y < height; ++y)
                {
                        auto relX = x - shieldBounds.left;

                        auto relY = (bullet.getCategory() & Category::PlayerProjectile) ? y - shieldBounds.top : y - shieldBounds.top - bulletBounds.height;

                        if (shield.getPixel(relX, relY))
                                return true;
                }
        }

        return false;
}

Hapax

  • Hero Member
  • *****
  • Posts: 3350
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Space Invaders Clone
« Reply #18 on: September 24, 2015, 08:19:34 pm »
Ah, this is the Space Invaders clone you were talking about!  :)

Just watched the videos.
In the 'new' one, it's evident that when a side of the group of invaders is removed, the remaining invaders don't continue to the edge of the screen; they move as if the entire group is still present. Just something I noticed. Not sure why the "mission" was "successful" either  ;D

I also find it weird that when you die, you just animate death but carry on as normal  :o

It looks good, though. Quite similar to what the original seems to have looked like (except with smoother motion in yours). The firing rate seems quite quick too. Maybe I'll keep this in mind for mine  :D

Keep it up. Looking forward to seeing the final result  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone
« Reply #19 on: September 25, 2015, 04:25:00 pm »
Quote
Ah, this is the Space Invaders clone you were talking about!
yup, this is my first graphics game. ;D

Quote
In the 'new' one, it's evident that when a side of the group of invaders is removed, the remaining invaders don't continue to the edge of the screen; they move as if the entire group is still present.
yes, this is due to that every invader ship moves independently by fixing distance. to change that it needs to be considered in early stage. for this game, it needs to re-write whole game structure which i don't like, it's better to start by using different game structure.

Quote
Not sure why the "mission" was "successful" either
hahaha, yeah you are right.. it seems i should die but fortunately i had 2 lives when that ship collided with me, i just lost one live but i won  :P

Quote
I also find it weird that when you die, you just animate death but carry on as normal
the original game perform death animation when the player got hit. i just mimic the original game.

Quote
Keep it up. Looking forward to seeing the final result
thanks alot sir.

Hapax

  • Hero Member
  • *****
  • Posts: 3350
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Space Invaders Clone
« Reply #20 on: September 25, 2015, 08:51:52 pm »
this is my first graphics game. ;D
Good work!  :)

the original game perform death animation when the player got hit. i just mimic the original game.
The original pauses while the animation plays and then resumes with a full ship. In yours, you can continue to move and fire while it's exploding, which looks a little bit odd.
https://www.youtube.com/watch?v=D1jZaIPeD5w&t=1m22s
(I left this as a link because it starts from a specific time, which seems to be ignored by the embedded player)

thanks alot sir.
You're welcome but please don't call me Sir  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone
« Reply #21 on: September 26, 2015, 06:20:57 pm »
update

i add a new video in main post for implement a new movement algorithm for invaders. result seems okay so far. inspired by what Hapax did  to his latest practice games. thanks millions Hapax

here code snippet of adapt enemy movements
void World::adaptEnemyMovements()
{
        bool changeDirection = false;

        for (const auto& i : mEnemyNodes)
        {
                Spaceship& enemy = static_cast<Spaceship&>(*i);

                if (enemy.getType() == Spaceship::Boss)
                        continue;

                if (!getBattlefieldBounds().contains(enemy.getPosition()))
                        changeDirection = true;
        }

        // let invaders moving down and update condition of change direction
        for (const auto& i : mEnemyNodes)
        {
                Spaceship& enemy = static_cast<Spaceship&>(*i);

                if (enemy.getType() == Spaceship::Boss)
                        continue;

                enemy.requestChangeDirection(changeDirection);
        }
}

and here update movement pattern it's exactly same mostly
void Spaceship::updateMovementPattern(sf::Time dt)
{
        // Enemy Spaceships: Movement pattern
        const std::vector<Direction>& directions = Table[mType].directions;

        if (!directions.empty())
        {
                // Moved long enough in horizontal direction: Change direction to move down
                if(mChaneDirction && directions[mDirectionIndex].distance == 0.f)
                {
                        mDirectionIndex = (mDirectionIndex + 1) % directions.size();
                        mTravelledDistance = 0.f;
                        mChaneDirction = false;
                }

                // Moved long enough in vertical direction: Change direction to move aside
                if (directions[mDirectionIndex].distance != 0.f && mTravelledDistance > directions[mDirectionIndex].distance)
                {
                        mDirectionIndex = (mDirectionIndex + 1) % directions.size();
                        mTravelledDistance = 0.f;
                }

                // Compute velocity from direction
                auto radians = toRadian(directions[mDirectionIndex].angle + 90.f);
                auto vx = getMaxSpeed() * std::cos(radians);
                auto vy = getMaxSpeed() * std::sin(radians);

                setVelocity(vx, vy);

                mTravelledDistance += getMaxSpeed() * dt.asSeconds();

                applyAnimation(dt);
        }
}



unfortunately, there is a bug, invaders some time drop down, especially when it got hit at both edges right and left of screen.



« Last Edit: September 29, 2015, 02:06:43 pm by MORTAL »

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone
« Reply #22 on: September 28, 2015, 01:56:46 pm »
update

- fixed the bug where invaders some time drop down, especially when it got hit at both edges right and left of screen
- Spaceship is become so hard to maintain, so that, it splitted into 3 classes Boss, Invaders and Player.
- old Player class renamed to PlayerController.


still damn bug is there. if you play long enough in the game the block of invaders SOME TIME drop down with no obvious reason why is that happen. it's hard to track down this kind of bugs to know whats really cause it and my compiler doesn't help me so much here.
« Last Edit: September 29, 2015, 02:12:13 pm by MORTAL »

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone
« Reply #23 on: September 30, 2015, 02:49:19 pm »
added new video for latest updates on the main post.

Latest update
- new movement pattern to invaders block by implementing simple state-mechanism
- implement dirty flag efficiently
- implement fixed time-step in game loop
- boss can spawn and entering the scene occasionally
- new bullet texture
- bullets can collide with each others
- fixed the bug where the block of invaders suddenly drop down


« Last Edit: October 01, 2015, 01:10:21 pm by MORTAL »

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone
« Reply #24 on: October 01, 2015, 09:33:39 pm »
i added video to latest update

https://youtu.be/0iaJHnNpWKo

update
- player can spawn after its death
- whole screen freeze while player animating death and game resume after player recreated
- player bullet only fire when current bullet is destroyed (no more fire rate in the game)
 

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone - Game finished
« Reply #25 on: October 04, 2015, 08:03:30 pm »
update

- upgraded to latest sfml version 2.3.2.
- reduced the death animation interval for player
- add LifeNode class
- add ScoreNode class
- add InvadersController class
- add green bottom line to SpriteNode class
- major clean up and code-style

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone - Game finished
« Reply #26 on: October 13, 2015, 04:29:11 am »
update

- re-write QuadTree class, now it is much readable
- re-write the helper function 'derivedAction' in Command class, by using SFINAE instead of dynamic_casting
- adding PlayerFactory Class for managing its spawning
- adding BossFactory class for managing its spawning
- adding GameConstants file for common constant variables
- fixed a bug where the button's sound always peep twice when user navigates throughout buttons by the mouse
- more clean up
« Last Edit: October 14, 2015, 09:00:44 pm by MORTAL »

Hapax

  • Hero Member
  • *****
  • Posts: 3350
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Space Invaders Clone - Game finished
« Reply #27 on: October 22, 2015, 08:39:41 pm »
Congratulations on completing the game!  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Space Invaders Clone - Game finished
« Reply #28 on: October 22, 2015, 09:12:55 pm »
thanks Hapax

i did what you have told me to do in earlier post, like player's behavior and bullets fire rate. the only left from what you have observed from first attempt is invaders movements where lowest row moves first then the one above until it reaches the most top row just like what is in the link that you gave it. i was attempting to wrap my head around this whole thing but i couldn't even it sounds like easy to implement.

Hapax

  • Hero Member
  • *****
  • Posts: 3350
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Space Invaders Clone - Game finished
« Reply #29 on: October 22, 2015, 09:35:58 pm »
The stuttering movement of the "invaders" isn't required; it's only aesthetic here really.
I see you changed the fast fire rate to the original Space Invaders style where it will only fire after the previous bullet ceases to exist. I prefer your original firing style but it was just too fast  ;)

One thing I did notice (I don't think I mentioned this previously) is that your enemies speed up based on their position (they speed up as they get closer to the bottom) whereas in the original, they speed up whenever an Invader was destroyed. Not sure which is better but I just thought I'd mention it.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything