Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Oct 3, 2014
0 parents commit c495f14
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
.psci_modules
bower_components
built-tests
coverage
lib
node_modules
26 changes: 26 additions & 0 deletions LICENSE
@@ -0,0 +1,26 @@
Copyright (c) 2014, Michael Ficarra. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the project nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are
disclaimed. In no event shall the copyright holder be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages (including,
but not limited to, procurement of substitute goods or services; loss of use,
data, or profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including negligence
or otherwise) arising in any way out of the use of this software, even if
advised of the possibility of such damage.
61 changes: 61 additions & 0 deletions Makefile
@@ -0,0 +1,61 @@
default: build doc
all: build doc test

MODULE = Mario

build: lib/$(MODULE).js
build-tests: $(TESTSOUT)
externs: lib/$(MODULE).externs.purs
deps: node_modules bower_components
doc: docs/README.md


BOWER_DEPS = $(shell find bower_components/purescript-*/src -name '*.purs' -type f | sort)
SRC = $(shell find src -name '*.purs' -type f | sort)
TESTS = $([ -d test ] && shell find test -name '*.purs' -type f | sort)
TESTSOUT = $(TESTS:test/%.purs=built-tests/%.js)

BOWER = node_modules/.bin/bower
ISTANBUL = node_modules/.bin/istanbul
MOCHA = node_modules/.bin/_mocha
MOCHA_OPTS = --inline-diffs --check-leaks -R dot

lib/$(MODULE).js: bower_components src/$(MODULE).purs
@mkdir -p '$(@D)'
psc --verbose-errors \
--main $(MODULE) \
${BOWER_DEPS} $(SRC) \
> lib/$(MODULE).js

.PHONY: default all build externs deps doc clean test build-tests

lib/$(MODULE).externs.purs: bower_components src/$(MODULE).purs
@mkdir -p '$(@D)'
psc --verbose-errors \
-m $(MODULE) \
--codegen $(MODULE) \
-e lib/$(MODULE).externs.purs \
${BOWER_DEPS} $(SRC) \
> /dev/null

docs/README.md: lib/$(MODULE).externs.purs
@mkdir -p '$(@D)'
docgen lib/$(MODULE).externs.purs > docs/README.md

built-tests/%.js: bower_components test/%.purs
@mkdir -p '$(@D)'
psc --verbose-errors -m Tests \
$(BOWER_DEPS) '$<' \
>'$@'

node_modules:
npm install

bower_components: node_modules
$(BOWER) install

test: node_modules $(TESTSOUT) lib/$(MODULE).js
[ -d test ] && $(ISTANBUL) cover --root lib $(MOCHA) -- $(MOCHA_OPTS) -- built-tests

clean:
rm -rf lib built-tests coverage bower_components node_modules
18 changes: 18 additions & 0 deletions README.md
@@ -0,0 +1,18 @@
purescript-demo-mario
=====================

Implementation of [Elm's Mario demo](http://elm-lang.org/edit/examples/Intermediate/Mario.elm) in PureScript.

![](https://raw.githubusercontent.com/michaelficarra/purescript-demo-mario/master/demo.gif)

## Usage

```sh
make
```

Open `index.html` to interact.

## Documentation

See the [auto-generated documentation](./docs).
28 changes: 28 additions & 0 deletions bower.json
@@ -0,0 +1,28 @@
{
"name": "purescript-demo-mario",
"homepage": "https://github.com/michaelficarra/purescript-demo-mario",
"description": "implementation of Elm's Mario demo in PureScript",
"keywords": [
"purescript",
"demo",
"mario",
"example",
"sample",
"frp",
"elm"
],
"license": "BSD-3-Clause",
"ignore": [
"**/.*",
"bower_components",
"node_modules",
"bower.json",
"package.json"
],
"dependencies": {
"purescript-dom": "*",
"purescript-math": "*",
"purescript-signal": "git@github.com:bodil/purescript-signal.git"
},
"devDependencies": {}
}
Binary file added demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions docs/README.md
@@ -0,0 +1,72 @@
# Module Documentation

## Module Mario

### Types

data Direction where
Left :: Direction
Right :: Direction

data Verb where
Jumping :: Verb
Walking :: Verb
Standing :: Verb


### Values

accel :: Mario.GameState -> Number

airAccel :: Number

airFriction :: Number

applyFriction :: Mario.GameState -> Mario.GameState

applyGravity :: Mario.GameState -> Mario.GameState

currentActivity :: Mario.GameState -> Mario.Verb

friction :: Mario.GameState -> Number

gravity :: Number

groundAccel :: Number

groundFriction :: Number

groundHeight :: Number

initialState :: Mario.GameState

isAirborne :: Mario.GameState -> Boolean

jump :: Boolean -> Mario.GameState -> Mario.GameState

jumpKeyCode :: Number

jumpSpeed :: Number

leftKeyCode :: Number

main :: forall t1844. Control.Monad.Eff.Eff t1844 Prelude.Unit

marioLogic :: Mario.Inputs -> Mario.GameState -> Mario.GameState

marioSpriteUrl :: Mario.Verb -> Mario.Direction -> String

maxMoveSpeed :: Number

mkInputs :: Boolean -> Boolean -> Boolean -> Mario.Inputs

offsetGround :: Number -> Mario.DOM.Coordinate -> Mario.DOM.Coordinate

rightKeyCode :: Number

velocity :: Mario.GameState -> Mario.GameState

walk :: Boolean -> Boolean -> Mario.GameState -> Mario.GameState



29 changes: 29 additions & 0 deletions index.html
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>purescript-demo-mario</title>
<script src="lib/Mario.js"></script>
<style>
html, body {
padding: 0;
margin: 0;
background-color: rgb(174, 238, 238);
}
#ground {
position: absolute;
background-color: rgb(74, 163, 41);
width: 100%;
height: 8%;
bottom: 0;
}
#mario {
position: absolute;
}
</style>
</head>
<body>
<img id="mario" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" alt="mario" />
<div id="ground"></div>
</body>
</html>
33 changes: 33 additions & 0 deletions package.json
@@ -0,0 +1,33 @@
{
"name": "purescript-demo-mario",
"version": "0.0.0",
"description": "implementation of Elm's Mario demo in PureScript",
"main": "index.js",
"scripts": {
"test": "make test"
},
"repository": {
"type": "git",
"url": "https://github.com/michaelficarra/purescript-demo-mario"
},
"keywords": [
"purescript",
"demo",
"mario",
"example",
"sample",
"frp",
"elm"
],
"author": "Michael Ficarra",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/michaelficarra/purescript-demo-mario/issues"
},
"homepage": "https://github.com/michaelficarra/purescript-demo-mario",
"devDependencies": {
"bower": "^1.3.12",
"istanbul": "^0.3.2",
"mocha": "^1.21.4"
}
}

0 comments on commit c495f14

Please sign in to comment.