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

Author Topic: Red Plane (Rotes Flugzeug)  (Read 8876 times)

0 Members and 1 Guest are viewing this topic.

argh

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • my blog
    • Email
Red Plane (Rotes Flugzeug)
« on: October 04, 2015, 04:02:53 pm »
Hi all!

BACKGROUND:
For the last month I have been learning SFML by developing my first game. I call it Rotes Flugzeug (Red Plane in English) after one of my childhood favorites. Another inspiration for Red Plane was Starray by Atari (from the '80s).

GAMELOGIC:
You - the plane - flies around in a circle (gamemap is a circle) and needs to destroy all the bombs that fall from the sky. You destroy enemies by shooting at them and blowing them up. You must do so before they hit the ground - if too many reach the ground you lose. Survive long enough and you will advance a level. To fly around use arrows(all directions) and to shoot press space.

INFO:
Screensize: 800x600
OS: Windows only
Size: 1,20MB (with artwork and sfml dlls)
Code: GitHub
Preview:

download Rotes Flugzeug(.zip)
The download contains the game.exe, artwork and SFML dll-s. Should be everything you need to run it on windows.



Future updates still TODO:
  • Make the game challenging
  • Make the background loop smooth
« Last Edit: October 16, 2015, 08:27:52 pm by argh »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Red Plane
« Reply #1 on: October 05, 2015, 11:14:18 am »
It's quite a fun little game even if some stuff doesn't work yet.
I especially like the bullet direction bug, it looks funny when your bullets all of a sudden fly into the other direction. ;D

I find the movement a bit strange. Like it's hard to make out why you stick to the left or right side. Also there's barely any "feel" for the speed, with some text that shows the speed it might be better.

At the moment it's not really challenging, but maybe with some more levels this might change?

Will be looking forward to updates. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

argh

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • my blog
    • Email
Re: Red Plane
« Reply #2 on: October 05, 2015, 04:48:55 pm »
tyvm for your feedback, eXpl0it3r, it helps a lot!

I find the movement a bit strange. Like it's hard to make out why you stick to the left or right side. Also there's barely any "feel" for the speed, with some text that shows the speed it might be better.
The movement is inspired by Ataris Starray. Wanted it to be something like . The speed-o-meter is a good idea. I will definitely add it.

At the moment it's not really challenging, but maybe with some more levels this might change?
Lol. A friend I gave it to try said it's a bit hard for him. You are just too good  8)


Will post updates and a new version in couple of weeks.

AFS

  • Full Member
  • ***
  • Posts: 115
    • View Profile
Re: Red Plane
« Reply #3 on: October 05, 2015, 07:04:28 pm »
I'm a sucker for shooters so I tried it for a few minutes  ;D.

While the game right now feels incomplete, at least you got the basics down (collision detection and so on), so many props for that. Now it's just a matter of improving the details and adding content (easier said than done)

I was confused by the movement a little bit. You can change direction using left or right, which is fine, but the transition is so weird, I don't know how to explain it. If your plane is at the center of the screen and you press the right key, the plane points right but moves left and only when it's on the edge it starts moving right (?). I understand what you are trying to do with the camera, but for that you don't need to move the plane and/or the background, you just apply an offset to your view depending of the plane's speed.

Anyway, keep up the good work ;)

argh

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • my blog
    • Email
Re: Red Plane
« Reply #4 on: October 06, 2015, 08:48:41 am »
I understand what you are trying to do with the camera, but for that you don't need to move the plane and/or the background, you just apply an offset to your view depending of the plane's speed.

ty for the tips, AFS.
I will rewamp the movement. that was the first thing i wrote so it is lacking a bit  ;).
at least you understood what i was trying to do :D i wanted to first move the plane to left or right and then start normal movement.
(like in the starray video i linked).

edit: updated the movement. ty
« Last Edit: October 06, 2015, 01:34:07 pm by argh »

argh

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • my blog
    • Email
Re: Red Plane (Rotes Flugzeug) - new version
« Reply #5 on: October 09, 2015, 06:00:26 pm »
I added some updates to the game. Now it is starting to feel/look like a real game.

UPDATES
  • revamped the movement (tho still not perfekt)
  • added a speedometer
  • fixed the bulletbug by writting a enemy and bullet class(much better now)
  • added levels(the game is still easymode, but its so i can find bugs)
  • rewrote a lot of my spaghetticode

Still TODO:
  • Gameradar
  • Add depth to the background
  • Make the game challenging
  • Work on the movement

link to download
« Last Edit: October 16, 2015, 04:27:35 pm by argh »

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Red Plane (Rotes Flugzeug) - new version
« Reply #6 on: October 09, 2015, 09:09:36 pm »
hi
it looks nice game. i like it.

i have looked your code. i think there are many things you may need to do. i recommend you to try this site codereview.stackexchange.com to give you better code review.

however. i will briefly review your code, btw, i'm still beginner i just learnt c++ last years. :-\. for comprehensive code review check the site above.

in your Enemy class
- it is better to put a class declaration and definition in two separate files like .cpp and .h or .hpp.

- it's preferable to use float for position and time calculation rather than int.

- use const for member data that won't change throughout game like speedPerSecond, maximumDistance

- no need for "this->" pointer, you may use Constructor initialization lists  for members data

here Enemy class after modification:

Enemy.h
#include <SFML/Graphics.hpp>

class Enemy final : public sf::Drawable
{
public:
        Enemy(const sf::Texture& texture, float posx, float posy);

        // usually the member function start with small letter in c++
        // also, it uses in SFML
        void update(float speedX, float timeDelta);

        sf::FloatRect getGlobalBounds() const;
        bool isAlive() const;


private:
        // draw can be declare as private
        void draw(sf::RenderTarget &target, sf::RenderStates states) const override;


private:
        // there are many style guides for c++ most known and widely uses is camelCase
        // for member data. personally i like camelCase over snake_case. in Both of them thay
        // used 'm' prefix to indecate the data is member data like below
        sf::Sprite              mSprite;
        const float             mSpeedPerSecond;
        float                   mDistanceTravelled;
        const float             mMaximumDistance;
};


Enemy.cpp
#include "Enemy.h"

Enemy::Enemy(const sf::Texture& texture, float posx, float posy)
        : mSprite(texture)
        , mSpeedPerSecond(20.f)
        , mDistanceTravelled() // by default is zero
        , mMaximumDistance(472.f)
{
        mSprite.setPosition(posx, posy);
}

void Enemy::update(float speedX, float timeDelta)
{
        auto distanceTravlledThisUpdate = mSpeedPerSecond * timeDelta;

        mDistanceTravelled += distanceTravlledThisUpdate;

        mSprite.move(speedX*timeDelta, distanceTravlledThisUpdate);

        if (mSprite.getPosition().x > 1600)
        {
                mSprite.setPosition(-800, mSprite.getPosition().y);
        }
        if (mSprite.getPosition().x < -800)
        {
                mSprite.setPosition(1600, mSprite.getPosition().y);
        }
}

sf::FloatRect Enemy::getGlobalBounds() const
{
        return mSprite.getGlobalBounds();
}

bool Enemy::isAlive() const
{
        return mDistanceTravelled < mMaximumDistance;
}

void Enemy::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
        target.draw(mSprite, states);
}


in Game class
it should be separated in .cpp and .h files

you may use std::unique_ptr instead of std::share_ptr.
std::unique_ptr<Enemy> eEnemy(new Enemy(enemy, posx, posy));
enemies.push_back(std::move(eEnemy));

i don't really like loop inside loop for the vector of enemies in this snippet
for (auto i = enemies.begin(); i != enemies.end(); i++)
{
        if (!(*i)->IsAlive())
        {
                // no need for loop whole enemies vector in here
                enemies.erase(std::remove_if(enemies.begin(), enemies.end(), [](const std::shared_ptr<Enemy>& o) { return !o->IsAlive(); }), enemies.end());
                hitTheGround++;
                enemiesLeft--;
                break;// <-- maight be a bug
        }
        else
        {
                (*i)->Update(speedX, timeSinceStart.asSeconds());
        }
}

it would be much easier if you just make it like this:
for (const auto& enemy : enemies)
        enemy->update(speedX, timeSinceStart.asSeconds());

enemies.erase(std::remove_if(enemies.begin(), enemies.end(),
        [this](const std::unique_ptr<Enemy>& o)
{
        if (!o->isAlive())
        {
                hitTheGround++;
                enemiesLeft--;
                return true;
        }
        else
                return false;
}), enemies.end());


why you call collision() multiple times in game-loop, only one call is enough.
backgroundLoop();
collision();
render();
createBullet();
collision();
createEnemies();
collision();
processEvent();


also, no need for "enemiesLeft" you can check the enemies left by vector size. i don't know if your compiler support std::to_string(), if so, you can use it like this:
showEnemiesLeft.setString("Enemies left: " + std::to_string(enemies.size()));


and there are more but for time being it is better to concentrate on code styling and files organizing
« Last Edit: October 10, 2015, 04:22:59 am by MORTAL »

argh

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • my blog
    • Email
Re: Red Plane (Rotes Flugzeug) - new version
« Reply #7 on: October 10, 2015, 10:59:03 am »
ty, MORTAL, for the time you took to review my code. that's why i posted it. I'm still very new to programming in general so a lot to learn. I will tried to improve and follow the guidelines you gave. A lot of good points you made, for someone who just been learning C++ a year. I think you know your stuff  8)

argh

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • my blog
    • Email
Re: Red Plane (Rotes Flugzeug)
« Reply #8 on: October 16, 2015, 08:17:26 pm »
Almost done with my first game. Gameplay and code still need some work, but added/fixed a bunch of stuff since last week.

For example:
  • better movement
  • build in radar
  • animated explosions
  • improved parallax scrolling


download the new version
« Last Edit: October 16, 2015, 08:20:23 pm by argh »

Cirrus Minor

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Red Plane (Rotes Flugzeug)
« Reply #9 on: October 19, 2015, 08:56:09 am »
I've tried it.
Fun but quite repetitive, you should add more content and challenge. And sound ;)
Good job for a first game!

argh

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • my blog
    • Email
Re: Red Plane (Rotes Flugzeug)
« Reply #10 on: October 20, 2015, 09:02:14 am »
I've tried it.
Fun but quite repetitive, you should add more content and challenge. And sound ;)
Good job for a first game!

ty for the feedback. you are totally right. i'm thinking of adding new types of enemies. changing the background every level would also be a nice easy change to make.

i will not be adding any sounds. i never play games with sounds. i find them mostly annoying :D

 

anything