-
Notifications
You must be signed in to change notification settings - Fork 10
/
Lesson-1.html
192 lines (157 loc) · 8.8 KB
/
Lesson-1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<title>Snake Game-Phaser</title>
<!-- Meta -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="favicon.ico">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- Global CSS -->
<link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">
<!-- Plugins CSS -->
<link rel="stylesheet" href="assets/plugins/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="assets/plugins/prism/prism.css">
<link rel="stylesheet" href="assets/plugins/elegant_font/css/style.css">
<!-- Theme CSS -->
<link id="theme-style" rel="stylesheet" href="assets/css/styles.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="body-green">
<div class="page-wrapper">
<!-- ******Header****** -->
<header id="header" class="header">
<div class="container">
<div class="branding">
<h1 class="logo">
<a href="index.html">
<span aria-hidden="true" class="icon_documents_alt icon"></span>
<span class="text-highlight">Game Development</span>
</a>
</h1>
</div>
<!--//branding-->
<ol class="breadcrumb">
<li><a href="index.html">Home</a></li>
<li class="active">Game Development</li>
</ol>
</div>
<!--//container-->
</header>
<!--//header-->
<div class="doc-wrapper">
<div class="container">
<div id="doc-header" class="doc-header text-center">
<h1 class="doc-title"><i class="icon fa fa-paper-plane"></i>Game Development</h1>
<div class="meta"><i class="fa fa-clock-o"></i> Snake Game using Phaser</div>
</div>
<div class="doc-body">
<div class="doc-content">
<div class="content-inner">
<section id="introduction-section" class="doc-section">
<h2 class="section-title">Loading an Image</h2>
<div class="section-block">
<p>Right now, our game doesn't do anything. Let's code the <b>Menu</b> state, and make it display the title screen.
During the setup we included the Phaser library in our HTML file. This gives us a global object called <b>Phaser</b>. Through it, we can access the library's methods and functions for building games.
Now we will use the global Phaser object, and create a new game instance. This is an object which represents our entire game. We will add the states to it.
</p>
</div>
</section>
<!--//doc-section-->
<section id="gamesdev-section" class="doc-section">
<h2 class="section-title">main.js</h2>
<div id="step1" class="section-block">
<pre><code class="language-markup">
var game;
// Create a new game instance 600px wide and 450px tall:
game = new Phaser.Game(600, 450, Phaser.AUTO, '');
// First parameter is how our state will be called.
// Second parameter is an object containing the needed methods for state functionality
game.state.add('Menu', Menu);
game.state.start('Menu');
</code></pre>
</div>
<!--//section-block-->
</section>
</div>
<!--//content-inner-->
<div class="content-inner">
<section id="nextsteps-section" class="doc-section">
<h2 class="section-title">menu.js</h2>
<div class="section-block">
<p>Now we need to initialize our Menu state object. In <b>menu.js</b> define a new object and add the functions below. When the state is started, the <b>preload</b> function will be called first, loading all the needed assets for our game. Once preloading finishes, <b>create</b> gets called, initializing the playing field and everything we want on it:</p>
<pre><code class="language-markup">
var Menu = {
preload : function() {
// Loading images is required so that later on we can create sprites based on the them.
// The first argument is how our image will be refered to,
// the second one is the path to our file.
game.load.image('menu', './assets/images/menu.png');
},
create: function () {
// Add a sprite to your game, here the sprite will be the game's logo
// Parameters are : X , Y , image name (see above)
this.add.sprite(0, 0, 'menu');
}
};
</code></pre>
<p>Because of browser security restrictions, to start the game you'll need a locally running web server. This page from the Phaser guidelines has plenty of options for all operating systems - <a href="http://phaser.io/tutorials/getting-started/part2">here</a>. <b>In other words, it won't work if you simply double click your index.html</b>.
<br>If everything has been done right, a page with the the start screen should appear in your browser.
</p>
</div>
</section>
<!--//doc-section-->
<!--//doc-section-->
</div>
<!--//content-inner-->
</div>
<!--//doc-content-->
<div class="doc-sidebar hidden-xs">
<nav id="doc-nav">
<ul id="doc-menu" class="nav doc-menu" data-spy="affix">
<li><a href="Game-Development.html">Intro & Setup</a></li>
<li><a href="Lesson-1.html">Loading an Image</a></li>
<li><a href="Lesson-2.html">Drawing the Snake</a></li>
<li><a href="Lesson-3.html">Movement and Control</a></li>
<li><a href="Lesson-4.html">Collision Detection</a></li>
</ul>
<!--//doc-menu-->
</nav>
</div>
<!--//doc-sidebar-->
</div>
<!--//doc-body-->
</div>
<!--//container-->
</div>
<!--//doc-wrapper-->
</div>
<!--//page-wrapper-->
<footer id="footer" class="footer text-center">
<div class="container">
<!--/* This template is released under the Creative Commons Attribution 3.0 License. Please keep the attribution link below when using for your own project. Thank you for your support. :) If you'd like to use the template without the attribution, you can check out other license options via our website: themes.3rdwavemedia.com */-->
<small class="copyright"><p class="license">Portions of this content are ©1998–2016 by individual mozilla.org contributors. Content available under a <a href="https://www.mozilla.org/foundation/licensing/website-content/">Creative Commons license</a>.</p></small>
</div>
<!--//container-->
</footer>
<!--//footer-->
<!-- Main Javascript -->
<script type="text/javascript" src="assets/plugins/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/plugins/prism/prism.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-scrollTo/jquery.scrollTo.min.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-match-height/jquery.matchHeight-min.js"></script>
<script type="text/javascript" src="assets/js/main.js"></script>
</body>
</html>