Skip to content

Commit 2b35831

Browse files
committed
feat: add Sprite example
1 parent 7564132 commit 2b35831

7 files changed

Lines changed: 70 additions & 11 deletions

File tree

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
*.hs text eol=lf
3+
*.jpg binary

assets/logo.jpg

9.06 KB
Loading

aztecs-examples.cabal

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,33 @@ executable ecs
2222
ghc-options: -Wall
2323
build-depends:
2424
base,
25-
aztecs >=0.17 && <0.18
25+
aztecs >=0.17.1 && <0.18
26+
27+
executable sprite
28+
main-is: src/Sprite.hs
29+
default-language: Haskell2010
30+
ghc-options: -Wall
31+
build-depends:
32+
base,
33+
aztecs >=0.17.1 && <0.18,
34+
aztecs-gl >=0.1 && <0.2,
35+
aztecs-glfw >=0.2 && <0.3
2636

2737
executable lifecycle
2838
main-is: src/Lifecycle.hs
2939
default-language: Haskell2010
3040
ghc-options: -Wall
3141
build-depends:
3242
base,
33-
aztecs >=0.17 && <0.18
43+
aztecs >=0.17.1 && <0.18
3444

3545
executable observers
3646
main-is: src/Observers.hs
3747
default-language: Haskell2010
3848
ghc-options: -Wall
3949
build-depends:
4050
base,
41-
aztecs >=0.17 && <0.18
51+
aztecs >=0.17.1 && <0.18
4252

4353
executable pong
4454
main-is: src/Pong.hs

cabal.project

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packages:
2+
.
3+
../aztecs-gl

src/2D.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,39 @@ main = runAccess_ $ do
2626
spawn $
2727
bundle (Rectangle 100 80)
2828
<> bundle (transform2d {transformTranslation = V2 200 150} :: Transform2D)
29-
<> bundle (Color 1 0 0 1)
29+
<> bundle (color 1 0 0 1)
3030
<> bundle (Parent windowEntity)
3131

3232
-- Spawn a green circle
3333
_ <-
3434
spawn $
3535
bundle (Circle 50 32)
3636
<> bundle (transform2d {transformTranslation = V2 400 300} :: Transform2D)
37-
<> bundle (Color 0 1 0 1)
37+
<> bundle (color 0 1 0 1)
3838
<> bundle (Parent windowEntity)
3939

4040
-- Spawn a blue triangle
4141
_ <-
4242
spawn $
4343
bundle (Triangle (-40) 40 40 40 0 (-40))
4444
<> bundle (transform2d {transformTranslation = V2 600 200} :: Transform2D)
45-
<> bundle (Color 0 0 1 1)
45+
<> bundle (color 0 0 1 1)
4646
<> bundle (Parent windowEntity)
4747

4848
-- Spawn a yellow rectangle (rotated)
4949
_ <-
5050
spawn $
5151
bundle (Rectangle 60 60)
5252
<> bundle (transform2d {transformTranslation = V2 300 450, transformRotation = 45} :: Transform2D)
53-
<> bundle (Color 1 1 0 1)
53+
<> bundle (color 1 1 0 1)
5454
<> bundle (Parent windowEntity)
5555

5656
-- Spawn a magenta circle (scaled)
5757
_ <-
5858
spawn $
5959
bundle (Circle 30 24)
6060
<> bundle (transform2d {transformTranslation = V2 550 450, transformScale = V2 1.5 1.5} :: Transform2D)
61-
<> bundle (Color 1 0 1 1)
61+
<> bundle (color 1 0 1 1)
6262
<> bundle (Parent windowEntity)
6363

6464
runAccessGLFW $ do

src/Pong.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ setupAndRun = do
8282
spawn $
8383
bundle (Rectangle 4 (fromIntegral windowH))
8484
<> bundle (transform2d {transformTranslation = V2 (round centerX) (round centerY)} :: Transform2D)
85-
<> bundle (Color 0.2 0.2 0.2 1)
85+
<> bundle (color 0.2 0.2 0.2 1)
8686
<> bundle (Parent windowEntity)
8787

8888
-- Spawn paddles
8989
let spawnPaddle pos =
9090
spawn $
9191
bundle (Rectangle paddleW paddleH)
9292
<> bundle (transform2d {transformTranslation = pos} :: Transform2D)
93-
<> bundle (Color 1 1 1 1)
93+
<> bundle (color 1 1 1 1)
9494
<> bundle (Parent windowEntity)
9595
<> bundle (Paddle 0)
9696

@@ -102,7 +102,7 @@ setupAndRun = do
102102
spawn $
103103
bundle (Circle ballR 16)
104104
<> bundle (transform2d {transformTranslation = V2 (round centerX) (round centerY)} :: Transform2D)
105-
<> bundle (Color 1 1 0 1)
105+
<> bundle (color 1 1 0 1)
106106
<> bundle (Parent windowEntity)
107107
<> bundle (Ball ballInitSpeedX ballInitSpeedY)
108108

src/Sprite.hs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{-# LANGUAGE TypeApplications #-}
2+
3+
module Main where
4+
5+
import Aztecs
6+
import Aztecs.GL
7+
import Aztecs.GLFW
8+
import Control.Monad.IO.Class
9+
import System.IO
10+
import Prelude hiding (lookup)
11+
12+
main :: IO ()
13+
main = runAccess_ $ do
14+
-- Create the window
15+
windowEntity <-
16+
spawn . bundle $
17+
Window
18+
{ windowTitle = "Aztecs GL",
19+
windowWidth = 800,
20+
windowHeight = 600
21+
}
22+
23+
img <- liftIO $ loadImage "assets/logo.jpg"
24+
imgEntity <- spawn $ bundle img
25+
_ <-
26+
spawn $
27+
bundle (sprite imgEntity)
28+
<> bundle (transform2d {transformTranslation = V2 200 150} :: Transform2D)
29+
<> bundle (Parent windowEntity)
30+
31+
runAccessGLFW $ do
32+
render
33+
mKeys <- lookup @_ @Keys windowEntity
34+
case mKeys of
35+
Just keys ->
36+
if keyJustPressed Key'Escape keys
37+
then do
38+
liftIO $ do
39+
putStrLn "Escape key just pressed, exiting..."
40+
hFlush stdout
41+
return True
42+
else return False
43+
Nothing -> return False

0 commit comments

Comments
 (0)