Repository navigation
Expand file tree
/
Copy pathTest.php
More file actions
230 lines (170 loc) · 5.85 KB
/
Copy pathTest.php
File metadata and controls
230 lines (170 loc) · 5.85 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!-- **Game comments**-->
<!--*Please report any bugs or changes you would like-->
<!--**Notes-->
<!-- We can currently detect collisons but it is True|False value which doesn't-->
<!-- help us determine where the collision is-->
<!---->
<!DOCTYPE html>
<?php $pageid = 'game'; include('../../TheQuestion.php'); ?>
<html>
<head>
<title>Jeff's Games</title>
<meta charset="utf-8"/>
<style>
canvas {
border: 1px solid #d3d3d3;
background-color: #f1f1f1;
position: relative;
width:80%;
left:10%;
top:40px;
}
.scorebutton{
position: absolute;
top: 7%;
left:10.5%;
width:80px;
}
.picupsbutton{
position: absolute;
top: 12%;
left:10.5%;
width:80px;
}
</style>
</head>
<body onload = "init()">
<script src="sprite.js"></script>
<script src="gameObjects.js"></script>
<script src="Jeff.js"></script>
<script type="text/javascript">
var myGame = {
canvas : document.createElement("canvas"),
level1 : {
level1Background : new level1BackgroundObject,
level1GamePieces : {milk : new MikeMilk(600,720), milk1 : new MikeMilk(1000,720), mike2 : new MikeMilk(1400,720),mike3 : new MikeMilk(2500,720),mike4 : new MikeMilk(4000,720),mike5 : new MikeMilk(5000,720),trash : new trashCan(3000,720)},
buildMap : function(){
},
levelMaker : function(){
myGame.level1.level1Background.draw();
for (var gameObject in myGame.level1.level1GamePieces){
if(myGame.level1.level1GamePieces[gameObject].visible && viewPoint.inFrame(myGame.level1.level1GamePieces[gameObject])){
myGame.level1.level1GamePieces[gameObject].draw();
}
}
},
finishLine : 9660,
},
currentLevel :1,
start : function() {
this.canvas.width= 1800;
this.canvas.height= 885;
this.context = this.canvas.getContext('2d');
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
this.interval = setInterval(update, 10);
window.addEventListener('keydown', function (e) {
myGame.keys = (myGame.keys || []);
myGame.keys[e.keyCode] = true;
})
window.addEventListener('keyup', function (e) {
myGame.keys[e.keyCode] = false;
})
},
stop : function() {
clearInterval(this.interval); }
}
function init(){
myGame.start();
myGame.level1.buildMap();
}
function update(){
viewPoint.camera(Jeff, myGame.context);
if(myGame.currentLevel ==1){
myGame.level1.levelMaker();
Jeff.draw(myGame.level1.level1GamePieces);
if(Jeff.xaxis >= myGame.level1.finishLine){
cashIn();
}
}
//document.getElementById("display").innerHTML = "Your score is: " + highscore;
//document.getElementById("pickups").innerHTML = "Your pickups amount is: " + pickups;
}
brian = new dude(); //Main Character
myFloor = new floor(400,400,400,100);//Main platform -> testing collision
myFloor2 = new floor(600,400,100,100);//Main platform -> testing collision
Jeff = new Jeff({
context: myGame.canvas.getContext("2d"),
width: 600,
height: 200,
numberOfFrames: 4,
ticksPerFrame: 15,
xaxis: 100,
yaxis: 30
})
var garretBackground1 = new Image;
garretBackground1.src = "images/Level_1_v2.png";
var viewPoint ={
x1Point : (1920 /2) - 500,
x2Point : (1920/2) + 400,
viewPointClearStart: 0,
viewPointClearEnd: 1920,
moveCameraRight: function(){
viewPoint.x1Point += 6;
viewPoint.x2Point += 6;
viewPoint.viewPointClearStart +=6;
viewPoint.viewPointClearEnd +=6;
myGame.context.translate(- 6,0);
//updatehighscore(); //his is causing lag on camera motion
},
moveCameraLeft : function(){
viewPoint.x1Point -= 6;
viewPoint.x2Point -= 6;
viewPoint.viewPointClearStart -= 6;
viewPoint.viewPointClearEnd -= 6;
myGame.context.translate(6,0);
},
centerCamera : function(gameObject){
if(gameObject.xaxis <= viewPoint.x1Point && this.viewPointClearStart >0){
viewPoint.moveCameraLeft();
}else if((gameObject.xaxis + gameObject.fakeWidth) >= viewPoint.x2Point && (this.viewPointClearStart + 1920) < myGame.level1.level1Background.length){
viewPoint.moveCameraRight();
}
},
camera : function(gameObject, context){
viewPoint.centerCamera(gameObject);
context.clearRect(this.viewPointClearStart,0, (this.viewPointClearStart + 1920),900)
},
gameMaker : function (){
var level1 = {};
var level2 = {};
},
inFrame :function (gamePiece){
if(gamePiece.xaxis >= this.viewPointClearStart && gamePiece.xaxis <= this.viewPointClearEnd){
return true;
}
}
}
function cashIn(){
for(var item =0; item <Jeff.inventory.length;item++){
console.log(Jeff.inventory[item]);
}
}
function SaveCurrentScoreToCookie(){
//alert(highscore);
//EddyHighscore = highscore
//document.cookie = 'EddyHighscore='+EddyHighscore;
document.cookie="EddyHighscore= " + highscore + ";path=/";
}
</script>
<?php include('../../scroll.php'); ?>
<div class='scorebutton'>
<a type="button" id="display" class=" btn btn-primary btn-sm "><span class=" " aria-hidden="true"></span> </a>
</div>
<div class='picupsbutton'>
<a type="button" id="pickups" class=" btn btn-primary btn-sm "><span class="" aria-hidden="true"></span> </a>
</div>
<div class='exitbutton'>
<a href="../../AskTheQuestion.php" type="button" onclick="SaveCurrentScoreToCookie()" class=" btn btn-danger btn-sm "><span class=" " aria-hidden="true"></span> X </a>
</div>
</body>
</html>