Code Monkey home page Code Monkey logo

spaceinvaders's Introduction

SpaceInvaders

Build Status Version on Hackage

This is a Haskell Space Invaders game implemented using the Functional Reactive Programming library Yampa.

The game has been created for educational purposes, but tries to feature a substantial amount of the complexity often found in real arcade games. For example, differentiated subsystems for physics/collisions, input, rendering/multimedia, logic, etc.

SpaceInvaders on Debian

Installation

The game is available on hackage and you can install it with*:

$ cabal update
$ cabal install SpaceInvaders
$ export PATH="$HOME/.cabal/bin:$PATH"
$ spaceInvaders

If you want to explore the code and possibly make changes, do the following:

$ cabal update
$ cabal unpack SpaceInvaders        # or git clone https://github.com/ivanperez-keera/SpaceInvaders.git
$ cd SpaceInvaders*                 # Game resources are here
$ cabal install
$ export PATH="$HOME/.cabal/bin:$PATH"
$ spaceInvaders

*Additional notes: For the use of the above installation instructions you need GHC and the command-line interface for cabal. On debian/ubuntu, you can install them with:

$ sudo apt-get install ghc cabal-install

Documentation

To try and make things as clear as possible, the code includes a much haddock documentation and comments as we could reasonably fit. You can compile those with:

$ cabal unpack SpaceInvaders        # or git clone https://github.com/ivanperez-keera/SpaceInvaders.git
$ cd SpaceInvaders*                 # Game resources are here
$ cabal haddock --haddock-executables

Related slides and projects

Educators

If you find this game attractive and would like to use it to teach functional programming or other subjects, we'd be very happy to know about it. We can provide extra material that you can show to students (videos, screenshots, etc.).

Help and collaboration

You can collaborate at least in two ways:

  • File an issue.
  • Write documentation (send a link and/or a pull request).

We would like to call on Haskell programmers, game developers and anyone with an interest in Functional Reactive Programming and/or Game Programming to review the code, ask for clarification when it is not clear enough, and help us improve the game, and the state of FRP/Yampa programming as well.

Author

  • Henrik Nilsson
  • Antony Courtney

Maintainer

  • Ivan Perez

spaceinvaders's People

Contributors

chriz-uniba avatar chriz-zeller avatar ivanperez-keera avatar kimsaehun avatar moritzsternemann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

spaceinvaders's Issues

Add a changelog to space invaders

Add a CHANGELOG following the format in Yampa or Haskanoid.

The first entry could be dated as of today, with @chriz-keera 's name, and mention that it adds the picture to the cabal file.

Update README.md installation

Update README.md installation:

$ cabal update
$ cabal sandbox init
$ cabal unpack SpaceInvaders        # or git clone https://github.com/ivanperez-keera/SpaceInvaders.git
$ cd SpaceInvaders-*                # Game resources are here
$ cabal install
$ ./dist/build/spaceInvaders/spaceInvaders

should be

$ cabal update
$ cabal unpack SpaceInvaders        # or git clone https://github.com/ivanperez-keera/SpaceInvaders.git
$ cd SpaceInvaders-*                # Game resources are here
$ cabal sandbox init
$ cabal install
$ ./dist/build/spaceInvaders/spaceInvaders

Haddock documentation is broken

Haddock complains about the main module being present in multiple files.

This error message is quite misleading.

The problem is that files contain a $ symbol, usually in the very first line, used to make the control version system fill in some data inside the file (something that is no longer supported), which haddock thinks it's a haddock variable name.

For example: https://github.com/ivanperez-keera/SpaceInvaders/blob/develop/src/Animate.hs#L1

The only thing that's necessary is to go through all the files and remove that first line with the $Id.

won't build; Windows + Haskell Platform

Neither the "master" or "development" branch build. Both seem to fail with a chorus of errors such as;

Can you advise on how to fix this?

Graphics\HGL\Win32\WND.hs:243:37: error:
    * Couldn't match type `Foreign.C.Types.CIntPtr'
                     with `GHC.Int.Int32'
      Expected type: LONG
        Actual type: LPARAM
    * In the expression: x
      In the first argument of `toPoint', namely `(x, y)'
      In the `pt' field of a record
    |
243 |         send (Button {pt = toPoint (x,y), isLeft=isLeft, isDown=isDown})
    |                                     ^

Graphics\HGL\Win32\WND.hs:260:43: error:
    * Couldn't match type `Foreign.C.Types.CIntPtr'
                     with `GHC.Int.Int32'
      Expected type: LONG
        Actual type: LPARAM
    * In the expression: y
      In the first argument of `toPoint', namely `(x, y)'
      In the `pt' field of a record
    |
260 |         send (MouseMove { pt = toPoint (x,y) })
    |                                           ^

CI build fails due to postgresql dropping `xenial` support

Builds on the CI server are failing with the following error messages:

Ign:1 http://apt.postgresql.org/pub/repos/apt xenial-pgdg InRelease
Ign:2 http://apt.postgresql.org/pub/repos/apt xenial-pgdg Release
Ign:3 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages
Ign:4 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages
Hit:5 http://ppa.launchpad.net/hvr/ghc/ubuntu xenial InRelease
Hit:6 http://archive.ubuntu.com/ubuntu xenial InRelease
Hit:7 http://security.ubuntu.com/ubuntu xenial-security InRelease
Ign:8 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main all Packages
Hit:9 https://esm.ubuntu.com/infra/ubuntu xenial-infra-security InRelease
Ign:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US
Hit:11 https://esm.ubuntu.com/infra/ubuntu xenial-infra-updates InRelease
Hit:12 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Ign:13 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en
Ign:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US.UTF-8
Ign:3 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages
Hit:15 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
Ign:4 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages
Ign:8 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main all Packages
Ign:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US
Ign:13 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en
Ign:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US.UTF-8
Ign:3 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages
Ign:4 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages
Ign:8 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main all Packages
Ign:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US
Ign:13 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en
Ign:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US.UTF-8
Ign:3 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages
Ign:4 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages
Ign:8 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main all Packages
Ign:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US
Ign:13 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en
Ign:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US.UTF-8
Ign:3 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages
Ign:4 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages
Ign:8 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main all Packages
Ign:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US
Ign:13 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en
Ign:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US.UTF-8
Ign:3 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages
Ign:4 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages
Ign:8 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main all Packages
Ign:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US
Ign:13 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en
Ign:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US.UTF-8
Err:3 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 Packages
  404  Not Found [IP: 72.32.157.246 80]
Ign:4 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main i386 Packages
Ign:8 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main all Packages
Ign:10 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US
Ign:13 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en
Ign:14 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main Translation-en_US.UTF-8
Reading package lists...
W: The repository 'http://apt.postgresql.org/pub/repos/apt xenial-pgdg Release' does not have a Release file.
E: Failed to fetch http://apt.postgresql.org/pub/repos/apt/dists/xenial-pgdg/main/binary-amd64/Packages  404  Not Found [IP: 72.32.157.246 80]
E: Some index files failed to download. They have been ignored, or old ones used instead.
The command "sudo apt-get update" failed 3 times.
The command "travis_retry sudo apt-get update" failed and exited with 100 during .
Your build has been stopped.

The reason why it's failing is that postgresql no longer supports xenial, as evidenced by their current list of distributions (from http://apt.postgresql.org/pub/repos/apt/dists/):

../
bionic-pgdg/                                       30-Sep-2022 11:10                   -
bionic-pgdg-snapshot/                              02-Oct-2022 14:05                   -
bionic-pgdg-testing/                               02-Oct-2022 20:47                   -
bookworm-pgdg/                                     30-Sep-2022 11:10                   -
bookworm-pgdg-snapshot/                            02-Oct-2022 14:04                   -
bookworm-pgdg-testing/                             02-Oct-2022 20:47                   -
bullseye-pgdg/                                     30-Sep-2022 11:10                   -
bullseye-pgdg-snapshot/                            02-Oct-2022 14:04                   -
bullseye-pgdg-testing/                             02-Oct-2022 20:47                   -
buster-pgdg/                                       30-Sep-2022 11:10                   -
buster-pgdg-snapshot/                              02-Oct-2022 14:04                   -
buster-pgdg-testing/                               02-Oct-2022 20:47                   -
focal-pgdg/                                        30-Sep-2022 11:10                   -
focal-pgdg-snapshot/                               02-Oct-2022 14:04                   -
focal-pgdg-testing/                                02-Oct-2022 20:47                   -
jammy-pgdg/                                        30-Sep-2022 11:10                   -
jammy-pgdg-snapshot/                               02-Oct-2022 14:04                   -
jammy-pgdg-testing/                                02-Oct-2022 20:47                   -
kinetic-pgdg/                                      30-Sep-2022 11:10                   -
kinetic-pgdg-snapshot/                             02-Oct-2022 14:04                   -
kinetic-pgdg-testing/                              02-Oct-2022 20:47                   -
sid-pgdg/                                          30-Sep-2022 11:10                   -
sid-pgdg-snapshot/                                 02-Oct-2022 14:04                   -
sid-pgdg-testing/                                  02-Oct-2022 20:47                   -
stretch-pgdg/                                      11-Aug-2022 12:47                   -
stretch-pgdg-snapshot/                             12-Aug-2022 15:13                   -
stretch-pgdg-testing/                              11-Aug-2022 10:46                   -

Installation instructions are outdated

The installation instructions mention a sandbox command that no longer exists in newer versions of Cabal.

While users can still use v1-sandbox in cabal-install 3.2, that command is also gone in newer versions of cabal-install.

Execution is very slow.

After about 10 seconds of normal playing, the execution become very slow.

Environment: Ubuntu 22.04.3 LTS, GHC 9.4.8.

At the moment, SpaceInvaders is unable to run on Windows (I encountered the same problem with #31), Therefore, the above test was in VMWare.

While the problem might be related to the virtual machine (I don't think so though since it's a so small app and I could play other games and apps normally), I would like to confirm whether you was experiencing the same performance issues on your system?

Thanks.

Some related issues #33

Slow execution with GHC 8.6.5

When using GHC 8.6.5, the execution is slow.

I have not looked into the details, but it resembles the behaviour I'd seen when games are garbage collecting heavily mid-game.

Collaborators is outdated

The collabroators section contains people no longer working on this project.

It should be updated.

EDIT: updated to match actual section name.

compile error

When following the installation instructions, I am getting the following error:

[13 of 14] Compiling ObjectBehavior   ( src/ObjectBehavior.hs, dist/dist-sandbox-5c221c1a/build/spaceInvaders/spaceInvaders-tmp/ObjectBehavior.o )

src/ObjectBehavior.hs:20:1: warning: [-Wunused-imports]
    The qualified import of ‘System.Random’ is redundant
      except perhaps to import instances from ‘System.Random’
    To import instances alone, use: import System.Random()

src/ObjectBehavior.hs:23:1: warning: [-Wunused-imports]
    The import of ‘FRP.Yampa.Integration’ is redundant
      except perhaps to import instances from ‘FRP.Yampa.Integration’
    To import instances alone, use: import FRP.Yampa.Integration()

src/ObjectBehavior.hs:24:1: warning: [-Wunused-imports]
    The import of ‘FRP.Yampa.Utilities’ is redundant
      except perhaps to import instances from ‘FRP.Yampa.Utilities’
    To import instances alone, use: import FRP.Yampa.Utilities()

src/ObjectBehavior.hs:256:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      gravity :: Vector2 Velocity

src/ObjectBehavior.hs:263:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      limit :: Ord a => a -> a -> a -> a

src/ObjectBehavior.hs:265:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      symLimit :: (Num t, Ord t) => t -> t -> t
ghc: panic! (the 'impossible' happened)
  (GHC version 8.0.2 for x86_64-unknown-linux):
	StgCmmEnv: variable not found
  $dNum_aoyU
  local binds for:
  $s$fVectorSpaceVector2a_$s$fVectorSpaceVector2a_$cnorm
  $s$fVectorSpaceVector2a_$s$fVectorSpaceVector2a_$cp1VectorSpace
  $sintegralAux_rsVn
  integralAux_rsVo
  lvl_rsVp
  lvl1_rsVq
  lvl2_rsVr
  lvl3_rsVs
  $sintegralAux1_rsVt
  integralAux1_rsVu
  $sintegralAux2_rsVv
  integralAux2_rsVw
  lvl4_rsVx
  lvl5_rsVy
  lvl6_rsVz
  lvl7_rsVA
  lvl8_rsVB
  lvl9_rsVC
  lvl10_rsVD
  lvl11_rsVE
  lvl13_rsVM
  lvl14_rsVN
  lvl15_rsVO
  lvl16_rsVP
  lvl17_rsVQ
  lvl18_rsVR
  lvl19_rsVS
  lvl20_rsVT
  lvl21_rsVU
  lvl22_rsVV
  lvl23_rsVW
  lvl24_rsVX
  lvl25_rsVY
  dt_rsVZ
  dt1_rsW0
  sf_rsW1
  dt2_rsW2
  lvl26_rsW3
  lvl27_rsW4
  lvl28_rsW5
  lvl29_rsW6
  lvl30_rsW7
  lvl31_rsW8
  lvl32_rsW9
  lvl33_rsWa
  lvl34_rsWb
  lvl35_rsWc
  lvl36_rsWd
  lvl37_rsWe
  lvl38_rsWf
  lvl39_rsWg
  lvl40_rsWh
  lvl41_rsWi
  lvl42_rsWj
  lvl43_rsWk
  lvl44_rsWl
  lvl45_rsWm
  lvl46_rsWn
  lvl47_rsWo
  lvl48_rsWp
  lvl49_rsWq
  lvl50_rsWr
  lvl51_rsWs
  lvl52_rsWt
  lvl53_rsWu
  lvl54_rsWv
  lvl55_rsWw
  lvl56_rsWx
  lvl57_rsWy
  lvl58_rsWz
  lvl59_rsWA
  lvl60_rsWB
  lvl61_rsWC
  lvl62_rsWD
  lvl63_rsWE
  lvl64_rsWF
  $sintegralAux3_rsWG
  integralAux5_rsWH
  ll_rsWI

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Any idea what may be causing that?

does only redraw on mouse and key events - but not while idling

When I run the game, the display only gets updated when something happens (mouse moved or pressed, key pressed). I expect that updates (redraw of moving bullets) should also happen while there is no input event.

(SpaceInvaders-0.4.5 (current master from git), X11-1.8, Yampa-0.10.6.2, HGL-3.2.3.1, ghc-8.2.1, fedora 26)

Conformace with style guide

Description

Several files are not conformant with our own style guide.

A quick search shows the following potential violations:

3 File structure, no blank lines at top
./src/Animate.hs
./src/ColorBindings.hs
./src/Colors.hs
./src/Command.hs
./src/Diagnostics.hs
./src/IdentityList.hs
./src/Main.hs
./src/ObjectBehavior.hs
./src/Object.hs
./src/Parser.hs
./src/PhysicalDimensions.hs
./src/RenderLandscape.hs
./src/RenderObject.hs
./src/WorldGeometry.hs

3.3 All Haskell files must include a copyright notice in a comment
src/Animate.hs
src/ColorBindings.hs
src/Colors.hs
src/Command.hs
src/Diagnostics.hs
src/IdentityList.hs
src/Main.hs
src/ObjectBehavior.hs
src/Object.hs
src/Parser.hs
src/PhysicalDimensions.hs
src/RenderLandscape.hs
src/RenderObject.hs
src/WorldGeometry.hs

4.3 The column limit for Haskell files is 80 characters
src/Main.hs
src/Animate.hs

4.5.4.2 No trailing spaces
src/RenderObject.hs
src/WorldGeometry.hs
src/Parser.hs
src/Colors.hs
src/Object.hs

4.7 Comments must always be line comments
./src/RenderObject.hs
./src/WorldGeometry.hs
./src/ColorBindings.hs
./src/PhysicalDimensions.hs
./src/Parser.hs
./src/Colors.hs
./src/ObjectBehavior.hs
./src/Main.hs
./src/Command.hs
./src/IdentityList.hs
./src/Animate.hs
./src/Diagnostics.hs
./src/Object.hs
./src/RenderLandscape.hs

does not respect window size (cannon moves outside mountains)

When I resize (increase width) the window in which the game runs, then the mountain range stays the same size (so, part of the window is black) but the "cannon" (the thing that fires the bullets) will move over the full width (so, outside mountains).

This is particularily bad under XMonad (tiling window manager) because the size of the window will be determined according to (current) tiling, and not to preferences of the application.

(SpaceInvaders-0.4.5 (current master from git), X11-1.8, Yampa-0.10.6.2, HGL-3.2.3.1, ghc-8.2.1, fedora 26)

Improve README

This project keeps being relevant because it is useful to teach (A)FRP, and because it is referenced in slides and papers.

There should be links to those, including videos if possible.

Add animated GIF

It would be cool to add an animated GIF for the image shown in the README.

It would just require installing the game, recording a few seconds of gameplay, and sending the replacement image.

Failure to compile with latest Yampa


src/PhysicalDimensions.hs:55:1: error:
    Could not find module ‘FRP.Yampa.Miscellany’
    Use -v to see a list of the files searched for.
   |
55 | import FRP.Yampa.Miscellany (fMod)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/PhysicalDimensions.hs:56:1: error:
    Could not find module ‘FRP.Yampa.Geometry’
    Use -v to see a list of the files searched for.
   |
56 | import FRP.Yampa.Geometry (Vector2, Vector3, Point2, Point3)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Compile using ghcjs

Would require changing the backend (htmldom).

Would allow playing from any browser, which is great when giving talks about FRP.

Update GHC compilation matrix

The Travis CI setup is testing SpaceInvaders against old versions of GHC.

As interesting as that is, virtually nobody probably still uses GHC 7.*.

It would be more useful to compile SpaceInvaders with more recent versions of GHC.

Release next version of Space Invaders

Steps:

git checkout develop
cabal install #with whatever flags are necessary to check that it works
cabal check # no errors should be reported
git checkout -b release-<version_number> # check last version number in cabal file
emacs SpaceInvaders.cabal # And increase the minor or the major by one
cabal sdist # no errors should be reported
git add SpaceInvaders.cabal
git commit -m "Version bump <version number>"
emacs CHANGELOG # Add cabal change and version bump to last entry, new if none.
git add CHANGELOG
git commit -m "Documents release in changelog."
git checkout master
git merge --no-ff release-<version_number>
git tag -a -m "<version_number>" v<version_number>
git checkout develop
git merge --no-ff master
git branch -d release-<version_number>
git push --all
git push --tags

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.