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

Author Topic: Simple Super-Mario game  (Read 4807 times)

0 Members and 1 Guest are viewing this topic.

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Simple Super-Mario game
« on: June 25, 2016, 08:01:52 pm »
hello everyone.

here my first attempt to create simple platform game-alike, it is super mario game. game not yet finished, i just implemented basic components like physic, animation and collision detection. but the levels still need more.

i used Tiled software editor for tile-map  and pugixml lib for map parser.

whole project is meant for educational purpose,  it is suitable for beginner in both sfml/c++.

here main references:
For C++, SFML and animation: "SFML Game Development" book.
For Physics, Graphic Effects and Collision Detection: http://trederia.blogspot.com/

here video demo:(apologises for bad quality of video)

http://www.youtube.com/watch?v=KHOsrcTPdWQ


i would like to know if someone had a chance to compile it, to give me feed back about this game.

thanks in advance
« Last Edit: April 13, 2020, 08:07:02 pm by Mortal »

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Simple Super-Mario game
« Reply #1 on: June 26, 2016, 10:31:46 am »
Looks very nice, great job!

I've looked at your code, I like it, it's nice and clean, though I have two tips:
1) There's almost reason to use std::bind anymore
Code like this:
std::bind(&Player::applyForce, _1, sf::Vector2f(-40.f, 0.f))
Can be easily rewritten like this in C++14:
[force = sf::Vector2f(-40.f, 0.f)]
(auto& player)
{
    player.applyForce(force);
}

2) Use enum class instead of enum.
* Enum class values can't be implicitly casted
* Enum classes are scoped (simple enums "leak" their values in scope which you declared them in)

Check out "Effective Modern C++" on why lambdas are better than std::bind and why enum classes are awesome. :D
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Simple Super-Mario game
« Reply #2 on: June 26, 2016, 09:53:02 pm »
thanks Elias for your time to review the code, really i appreciate it.  :)

I have two tips:
1) There's almost reason to use std::bind anymore
Code like this:
std::bind(&Player::applyForce, _1, sf::Vector2f(-40.f, 0.f))
Can be easily rewritten like this in C++14:
[force = sf::Vector2f(-40.f, 0.f)]
(auto& player)
{
    player.applyForce(force);
}

2) Use enum class instead of enum.
* Enum class values can't be implicitly casted
* Enum classes are scoped (simple enums "leak" their values in scope which you declared them in)

Check out "Effective Modern C++" on why lambdas are better than std::bind and why enum classes are awesome. :D

For readability sake, i chose std::bind over lambda. of course if the performance is critical the lambda is going to be better. also, for VC++12-13 IDE has a bug with std::bind implementation, fortunately they fixed it in VC++14. i'm going to switch it to `lambda`

thanks once again to mention "Effective Modern C++" book. i almost forget that i usually mentioned all references that i was inspired by in my projects. i will add it to main post.
i have used few things from this book in this game. but i didn't get much time to complete it, definitely i will go back to read it from a cover to cover this time.

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Simple Super-Mario game
« Reply #3 on: June 26, 2016, 11:45:17 pm »
thanks Elias for your time to review the code, really i appreciate it.  :)
You're welcome!

For readability sake, i chose std::bind over lambda. of course if the performance is critical the lambda is going to be better. also, for VC++12-13 IDE has a bug with std::bind implementation, fortunately they fixed it in VC++14. i'm going to switch it to `lambda`
To be honest, I find lambda syntax to be a lot prettier because it looks just like a simple function, especially if you need to do more than just one call or pass parameters which will be result of some expression. And yeah, there's a lot of stuff that is fixed in recent Visual Studio, so I strongly recommend you to upgrade (and lots of C++14 stuff is only available there! There's even some C++17 stuff already)

thanks once again to mention "Effective Modern C++" book. i almost forget that i usually mentioned all references that i was inspired by in my projects. i will add it to main post.
i have used few things from this book in this game. but i didn't get much time to complete it, definitely i will go back to read it from a cover to cover this time.
I re-read it recently and I found lots of stuff a lot more understandable on the second read.
When I first read it, I was just getting used to modern C++, so a lot of stuff left me very confused. Such a great book, wish there was more stuff like it.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Simple Super-Mario game
« Reply #4 on: June 27, 2016, 01:23:12 am »
i'm totally agree with you regrading "Effective Modern C++" book and by the way, Scott Meyers has many books one of which is "Effective STL". speaking of re-read those great books. sure that true. for example, when i read "Effective STL" book for first time,  particularly item 17 which is known by "swap to fit".
it is considered the most precious "trick" to gain maximum efficiency of STL containers like std::vector by calling its swap function:

std::vector<T>(v).swap(v);

I was very naive, i was thinking it reduces the capacity by changing its value just like what vector::resize do. but later i realized that is wrong. the only way for the capacity of a vector can be altered is by calling its vector::reserve when it is constructed. the swap trick actually performs copying for itself or the correct phrase "non-binding" for internal memory allocated. the aftermath the capacity will be reduced.

later in c++11. they inerduced shrink_to_fit as they stated it from The draft standard section 23.2.6.2

Quote
shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations.]
« Last Edit: June 27, 2016, 02:46:59 am by MORTAL »

 

anything