I'm making an Asteroids clone in Haskell using Gloss.
I want the spaceship to come back from the left if it goes out on the right side of the screen.
This is made unnecessarily tricky by the fact that the origin (0, 0)
is in the middle of the screen.
Is there a way to move the origin to the top (or bottom) left?
My Main
module (where I'm interacting with Gloss
) looks like this:
module Main where
import Graphics.Gloss (Display (InWindow), black, play)
-- my own imported code
import Assets (loadAssets)
import GameState (defaultHeight, defaultWidth, initGameState)
import HandleInput (handleInput)
import ProgressGameState (progressGameState)
import Render (render)
windowDisplay :: Display
windowDisplay = InWindow "Window" (defaultWidth, defaultHeight) (10, 10)
main :: IO ()
main = do
assets <- loadAssets
play
windowDisplay
black
60
initGameState
(render assets)
handleInput
progressGameState
I don't think there's an easy way to move the origin. But the conversion between whatever your format is a simple translation. You can use a function (or even a smart constructor) to do the calculation between the two.
For example, if (0,0) is at the center of a picture with the dimensions
(x,y)
, but you would want it to be at the top left, all you have to do is substract(x/2,y/2)
from all your points to make the math right again.