-
Notifications
You must be signed in to change notification settings - Fork 2
/
TileTest1.html
113 lines (106 loc) · 3.33 KB
/
TileTest1.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
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>AnimationTest.html</title>
<script type = "text/javascript"
src = "simpleGame.js"></script>
<script type = "text/javascript">
var scene;
var stickMan;
var tileManager;
var speed = 1000;
var togglePause = false;
var resetSpeedFlag = false;
function getRandomInt(min, max){
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function tileCollision( hitTile ){
resetSpeedFlag = true;
stickMan.setSpeed(0);
}
function init(){
scene = new Scene();
//I do not know what license walkCycle.png is under. I grabbed it from here: http://www.dreamincode.net/forums/topic/194878-xna-animated-sprite/
stickMan = new Sprite(scene, "walkCycle.png", 32, 48);
stickMan.loadAnimation(512, 48, 32, 48);
stickMan.generateAnimationCycles(SINGLE_ROW, 4);
cycleNames = new Array("down", "left", "right", "up");
stickMan.renameCycles(cycleNames);
stickMan.setSpeed(4);
stickMan.setPosition(100, 100);
//stickMan.turnOnGravity();
tileSymbols = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");
tileMap = new Array();
for(i = 0; i < 10; i++){
temp = new Array();
for(j = 0; j < 50; j++){
temp[j] = tileSymbols[ getRandomInt(0, 11) ];
//if( i == 3){ temp[j] = "blank"; }
}
tileMap[i] = temp;
}
collisionMap = new Array();
collisionMap.push( new Array( "1", tileCollision ) );
tileManager = new TileMap(scene);
tileManager.loadTileSheet(32, 32, 320, 320, "TileSet.png", tileSymbols);
tileManager.loadMapData(tileMap);
tileManager.loadCollisionMap( collisionMap );
tileManager.cameraFollowSprite(stickMan, 30, 30);
tileManager.makeSpriteMapRelative(stickMan);
scene.start();
} // end init
function update(){
//tileManager.mapScroll(3, 0);
//document.getElementById("alertText").innerHTML = "";
scene.clear();
if (keysDown[K_LEFT]){
stickMan.setCurrentCycle("left");
stickMan.setMoveAngle(180);
if(resetSpeedFlag){ stickMan.setSpeed(4);}
}
if (keysDown[K_RIGHT]){
stickMan.setCurrentCycle("right");
stickMan.setMoveAngle(0);
if(resetSpeedFlag){ stickMan.setSpeed(4);}
}
if (keysDown[K_UP]){
stickMan.setCurrentCycle("up");
stickMan.setMoveAngle(270);
if(resetSpeedFlag){ stickMan.setSpeed(4);}
}
if (keysDown[K_DOWN]){
stickMan.setCurrentCycle("down");
stickMan.setMoveAngle(90);
if(resetSpeedFlag){ stickMan.setSpeed(4);}
}
if (keysDown[K_S]){
speed -= 30;
stickMan.setAnimationSpeed(speed);
}
if (keysDown[K_W]){
speed += 30;
stickMan.setAnimationSpeed(speed);
}
if (keysDown[K_P]){
if( togglePause ){ stickMan.playAnimation(); }
else{ stickMan.pauseAnimation(); }
togglePause = !togglePause;
keysDown[K_P] = false;
}
if (keysDown[K_R]){
stickMan.resetAnimation();
}
tileManager.checkCollisions( stickMan );
tileManager.drawMap();
stickMan.update();
} // end update
</script>
</head>
<body onload = "init()">
<title>Tile Test1.html</title>
<h1>Tile Test</h1>
<div id="FPS" name="FPS"> </div>
<div id="alertText" name="alertText"> </div>
</body>
</html>