Skip to content

Commit fec1873

Browse files
committed
Blank slate for lesson 3
1 parent 2e2ff15 commit fec1873

File tree

11 files changed

+6598
-0
lines changed

11 files changed

+6598
-0
lines changed

lessons/3-objects/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Lesson 3: Add interactive objects
2+
3+
## Goals
4+
5+
## Getting set up
6+
7+
- Download [this lesson]() onto your computer
8+
9+
- Create a folder for your project and put the lesson files there
10+
11+
- Open up `index.html`
12+
13+
## objects.js
14+
15+
## Your assignment
16+
17+
18+
## Free time
19+

lessons/3-objects/character.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
game.addEventListener("load", function(){
2+
3+
// Get a character
4+
character = new Sprite(32, 32)
5+
character.image = game.assets['images/girl.gif']
6+
character.frame = 0
7+
character.x = 100
8+
character.y = 100
9+
game.rootScene.addChild(character)
10+
11+
speed = 2
12+
13+
function movement(){
14+
15+
x = this.x
16+
y = this.y
17+
18+
if (game.input.left) {
19+
x -= 1 * speed
20+
character.frame = 3
21+
}
22+
if (game.input.right) {
23+
x += 1 * speed
24+
character.frame = 6
25+
}
26+
if (game.input.down) {
27+
y += 1 * speed
28+
character.frame = 0
29+
}
30+
if (game.input.up) {
31+
y -= 1 * speed
32+
character.frame = 9
33+
}
34+
35+
// Did our character run into something?
36+
var top = y
37+
var bottom = y + 32
38+
var left = x
39+
var right = x + 32
40+
41+
if ( map.hitTest(left, top) ) {
42+
if (this.x != x) {
43+
x += speed
44+
}
45+
if (this.y != y){
46+
y += speed
47+
}
48+
}
49+
50+
if ( map.hitTest(right, top) ) {
51+
if (this.x != x) {
52+
x -= speed
53+
}
54+
if (this.y != y){
55+
y += speed
56+
}
57+
}
58+
59+
if ( map.hitTest(left, bottom) ) {
60+
if (this.x != x) {
61+
x += speed
62+
}
63+
if (this.y != y){
64+
y -= speed
65+
}
66+
}
67+
68+
if ( map.hitTest(right, bottom) ) {
69+
if (this.x != x) {
70+
x -= speed
71+
}
72+
if (this.y != y){
73+
y -= speed
74+
}
75+
}
76+
77+
78+
this.x = x
79+
this.y = y
80+
81+
}
82+
character.addEventListener("enterframe", movement)
83+
84+
})

lessons/3-objects/images/boy.gif

2.42 KB
Loading

lessons/3-objects/images/girl.gif

3.51 KB
Loading

lessons/3-objects/images/map.png

3.47 KB
Loading

lessons/3-objects/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Objects Example</title>
5+
<link rel="stylesheet" type="text/css" href="lib/styles.css">
6+
</head>
7+
<body>
8+
9+
<h1>Objects Example</h1>
10+
11+
<script src="lib/enchant.js" type="text/javascript" charset="utf-8"></script>
12+
<script src="lib/game.js" type="text/javascript" charset="utf-8"></script>
13+
<script src="character.js" type="text/javascript" charset="utf-8"></script>
14+
<script src="objects.js" type="text/javascript" charset="utf-8"></script>
15+
<script src="map.js" type="text/javascript" charset="utf-8"></script>
16+
17+
<script>
18+
game.start()
19+
</script>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)