GithubHelp home page GithubHelp logo

guoyu07 / space-invaders Goto Github PK

View Code? Open in Web Editor NEW

This project forked from olbrew/space-invaders

0.0 1.0 0.0 11.2 MB

Minimal MVC Space Invaders implemenation in C++11 with SFML

CMake 38.45% Shell 0.48% C++ 61.07%

space-invaders's Introduction

Space Invaders

Brief

This project implements the arcade game Space Invaders in the C++ language with modern constructs from the c++11 standard. It hopes to achieve modularity by implementing it in different stand-alone libraries. For more info on the design reconsiderations see under the Design subsection.

Install

There is an included run.sh script which will automatically compile, install and start the game for you. You can find it in the root directory. Remember that this will take some time for the compilation phase on the first run.

./run.sh

Design

The Observer pattern of MVC was closely followed in this project. The controller sets up and runs the game in the main loop in the GameSFML class. Other classes for other frameworks could be made.

SFMLGame sets up an SFML window on which to run the loop and initiates a model and a view. It registers the model and the window with the view. The view is thus an observer which can get data out of the model to draw the model entities on an SFML window.

The main loop watches for input from the Keyboard helper class and if received sends an according action to the view.

No SFML related code is found in the model so it can be easy to couple it with another controller and/or view.

This strict separation of duties can be seen in the dependency graph:

![dependency graph](./doc/dependency graph.png)

After the events have been polled it is time to update the entities.
This is quite easy because the world contains all the entities.
Though not one big list of all entities. I thought about doing this, but
decided in the end that advantage of having one big list of entitities
didn't weigh up against the disadvantages of constantly having to do
checks for which object the entity actually pointed to which were not solvable
via polymorphic function calls.

Though the world still holds all the current entities and the `update` function
from the ABC entity updates on its part all the enitities the world
contains. So this is still an application from the Composite design pattern.

In the UML diagram for Entity and its children you can clearly see the Entity
and its virtual functions `update` and `getPosition`. `getPosition` is used
polymorphically in the view to calculate the position for
Enemyships and Bullets which are stored in containers with Entity pointers.

![UML diagram for Entity and its children](./doc/uml diagram model.png)

I tried to limit memory consumption through extensive use of pointers whenever
the variables needed accessing across the libraries (model, view & controller
        are all defined in their separate libraries to maximise reusability.). I did
still take care to not pollute the heap with variables which don't need this
global access.

Because a construct to store 2 variables is often needed, for example for a
Position or Size on a 2D grid, I made a `Vector2D` template which can be reused
across different types. It can be found in the `util` library together with a
`RandomGenerator` class
This Vector2D is then typedef'd with an appropriate type in some classes to
make it more easily recognizable.

I also try to only make methods public when they need to actually be publicly
accessible.

For more information you can read the extensively documented source or
use the generated Doxygen documentation by opening `doc/html/index.html` in your
browser of choice.

Author
------
Olivier Brewaeys

space-invaders's People

Contributors

olbrew avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.