Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Commit 8d5cc12

Browse files
committed
Import working content from Our First Game chapter
1 parent ee808a0 commit 8d5cc12

File tree

4 files changed

+200
-4
lines changed

4 files changed

+200
-4
lines changed

‎assets/elm/elm.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"elm/core": "1.0.2",
1111
"elm/html": "1.0.0",
1212
"elm/http": "2.0.0",
13-
"elm/json": "1.1.2"
13+
"elm/json": "1.1.2",
14+
"elm/svg": "1.0.1"
1415
},
1516
"indirect": {
1617
"elm/bytes": "1.0.7",

‎assets/elm/src/Games/Platformer.elm‎

Lines changed: 144 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,149 @@
11
module Games.Platformer exposing (main)
22

3-
import Html exposing (..)
3+
import Browser
4+
import Html exposing (Html, div)
5+
import Svg exposing (..)
6+
import Svg.Attributes exposing (..)
7+
8+
9+
10+
-- MAIN
411

512

6-
main : Html msg
713
main =
8-
text "Platformer Game"
14+
Browser.element
15+
{ init = init
16+
, update = update
17+
, subscriptions = subscriptions
18+
, view = view
19+
}
20+
21+
22+
23+
-- MODEL
24+
25+
26+
type alias Model =
27+
{ characterPositionX : Int
28+
, characterPositionY : Int
29+
, itemPositionX : Int
30+
, itemPositionY : Int
31+
}
32+
33+
34+
initialModel : Model
35+
initialModel =
36+
{ characterPositionX = 50
37+
, characterPositionY = 300
38+
, itemPositionX = 500
39+
, itemPositionY = 300
40+
}
41+
42+
43+
init : () -> ( Model, Cmd Msg )
44+
init _ =
45+
( initialModel, Cmd.none )
46+
47+
48+
49+
-- UPDATE
50+
51+
52+
type Msg
53+
= NoOp
54+
55+
56+
update : Msg -> Model -> ( Model, Cmd Msg )
57+
update msg model =
58+
case msg of
59+
NoOp ->
60+
( model, Cmd.none )
61+
62+
63+
64+
-- SUBSCRIPTIONS
65+
66+
67+
subscriptions : Model -> Sub Msg
68+
subscriptions model =
69+
Sub.none
70+
71+
72+
73+
-- VIEW
74+
75+
76+
view : Model -> Html Msg
77+
view model =
78+
div [ class "container" ]
79+
[ viewGame model ]
80+
81+
82+
viewGame : Model -> Svg Msg
83+
viewGame model =
84+
svg [ version "1.1", width "600", height "400" ]
85+
[ viewGameWindow
86+
, viewGameSky
87+
, viewGameGround
88+
, viewCharacter model
89+
, viewItem model
90+
]
91+
92+
93+
viewGameWindow : Svg Msg
94+
viewGameWindow =
95+
rect
96+
[ width "600"
97+
, height "400"
98+
, fill "none"
99+
, stroke "black"
100+
]
101+
[]
102+
103+
104+
viewGameSky : Svg Msg
105+
viewGameSky =
106+
rect
107+
[ x "0"
108+
, y "0"
109+
, width "600"
110+
, height "300"
111+
, fill "#4b7cfb"
112+
]
113+
[]
114+
115+
116+
viewGameGround : Svg Msg
117+
viewGameGround =
118+
rect
119+
[ x "0"
120+
, y "300"
121+
, width "600"
122+
, height "100"
123+
, fill "green"
124+
]
125+
[]
126+
127+
128+
viewCharacter : Model -> Svg Msg
129+
viewCharacter model =
130+
image
131+
[ xlinkHref "/images/character.gif"
132+
, x (String.fromInt model.characterPositionX)
133+
, y (String.fromInt model.characterPositionY)
134+
, width "50"
135+
, height "50"
136+
]
137+
[]
138+
139+
140+
viewItem : Model -> Svg Msg
141+
viewItem model =
142+
image
143+
[ xlinkHref "/images/coin.svg"
144+
, x (String.fromInt model.itemPositionX)
145+
, y (String.fromInt model.itemPositionY)
146+
, width "20"
147+
, height "20"
148+
]
149+
[]

‎assets/static/images/character.gif‎

4 KB
Loading[フレーム]

‎assets/static/images/coin.svg‎

Lines changed: 54 additions & 0 deletions
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /