Skip to content

Instantly share code, notes, and snippets.

View funrep's full-sized avatar

Karl-Oskar Rikås funrep

View GitHub Profile
@funrep
funrep / SO
Created August 11, 2013 11:46
I'm writing a pong game, I need some help with the game logic. My problem is that is that I got problems to detect if the ball is out of the map or not, this causes that the ball just gets out-of-bounds and no score is counted. Currently it works like this:
stepScore :: State -> State
stepScore s
| s^.ball.pos.x <= 15 = resetGame $ score.right +~ 1 $ s
| s^.ball.pos.x >= 585 = resetGame $ score.left +~ 1 $ s
| otherwise = s
and resetGame works as such:
@funrep
funrep / pong.hs
Last active December 20, 2015 19:29
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens
import FRP.Elerea.Simple hiding (delay)
import FRP.Helm
import FRP.Helm.Time
import qualified FRP.Helm.Keyboard as Keyboard
import qualified FRP.Helm.Window as Window
import qualified FRP.Helm.Text as Text
-- Pong in Haskell using Helm game engine and Lens for mutating the nested data structures.
-- For some bloody reason this doesn't work, stay away from Haskell, stay away from abtractions and theory.
-- It will ruin your brain. Sad but true, Haskell sucks.
-- "If it compiles it's correct"... what a joke...
{-# LANGUAGE TemplateHaskell #-}
module Pong where
import Control.Lens
{-# LANGUAGE TemplateHaskell #-}
module Pong where
import Control.Lens
import FRP.Elerea.Simple hiding (delay)
import FRP.Helm
import FRP.Helm.Time
import qualified FRP.Helm.Keyboard as Keyboard
import qualified FRP.Helm.Window as Window
import qualified FRP.Helm.Text as Text
@funrep
funrep / Pong.hs
Last active December 20, 2015 18:09
{-# LANGUAGE TemplateHaskell #-}
module Pong where
import Control.Lens
import FRP.Elerea.Simple hiding (delay)
import FRP.Helm
import FRP.Helm.Time
import qualified FRP.Helm.Keyboard as Keyboard
import qualified FRP.Helm.Window as Window
import qualified FRP.Helm.Text as Text
-- This is an translation of http://elm-lang.org/edit/examples/Intermediate/Mario.elm
-- to Haskell using Helm game engine
-- This is WIP
import Prelude hiding (Either(..))
import FRP.Elerea.Simple
import FRP.Helm
import FRP.Helm.Time
import qualified FRP.Helm.Window as Window
import Prelude hiding (Either(..))
import FRP.Helm
data Direction = Left | Right
data Mario =
Mario { mX :: Double, mY :: Double,
vX :: Double, vY :: Double,
dir :: Direction }
(Based on 1st figure: http://doc.cat-v.org/bell_labs/utah2000/)
A high-end workstation then, sometime ago and now
1990 2000 2013
Hardware
33 MHz Mips R 3000 600 MHz Alpha or Pentium III Intel Core i7 3.5 GHz 4 cores or AMD FX-9590 4,7Ghz 8 cores
32 megabytes of RAM 512 megabytes of RAM 16 GB RAM
-- NOTE: I'm using pipes 4.0 here.
module Main where
import Pipes
import qualified Pipes.Prelude as P
import Control.Monad (forever)
main = runEffect $ client >>~ server
-- NOTE: I'm using pipes 4.0 here.
module Main where
import Pipes
import qualified Pipes.Prelude as P
main = runEffect $ server >-> client
server :: () -> Server String String IO ()