@@ -28,21 +28,8 @@ let spriteStandRight = createImage('./img/spriteStandRight.png');
28
28
canvas . width = window . innerWidth ;
29
29
canvas . height = window . innerHeight ;
30
30
31
- // Scrolling Background
32
- let backgroundX = 0 ; // Initial background X position
33
- const backgroundSpeed = 3 ; // Speed of background scrolling
34
-
35
- // Scrolling Hills
36
- let backgroundX2 = 0 ; // Initial hills X position
37
- const backgroundSpeed2 = 2 ; // Speed of hills scrolling
38
-
39
- // Function init() Variables
40
31
let player = { } ;
41
32
let platforms = [ ] ;
42
- let objects = [ ] ;
43
-
44
- // Winning Situation
45
- let offSet = 0 ;
46
33
47
34
function init ( ) {
48
35
@@ -122,18 +109,23 @@ function init(){
122
109
// { x: 6000, y: canvas.height - 50, width: 15000, height: 10 },
123
110
// Add more platforms as needed
124
111
] ;
125
-
126
- // Platforms
127
- objects = [
128
- { image : background , y : 0 , width : background . width , height : canvas . height } ,
129
- { image : hills , y : 0 , width : hills . width , height : hills . height } ,
130
- // { x: platformImage.width - 2, y: canvas.height - 130, width: platformImage.width, height: platformImage.height },
131
- ] ;
132
112
133
113
offSet = 0 ;
134
114
backgroundX = 0 ;
115
+ backgroundX2 = 0 ;
135
116
}
136
117
118
+ // Scrolling Background
119
+ let backgroundX = 0 ; // Initial background X position
120
+ const backgroundSpeed = 3 ; // Speed of background scrolling
121
+
122
+ // Scrolling Hills
123
+ let backgroundX2 = 0 ; // Initial background X position
124
+ const backgroundSpeed2 = 2 ; // Speed of background scrolling
125
+
126
+ // Winning Situation
127
+ let offSet = 0 ;
128
+
137
129
// A function to draw the player character
138
130
function drawPlayer ( ) {
139
131
@@ -153,28 +145,12 @@ function drawPlayer() {
153
145
154
146
// A function to draw platforms
155
147
function drawPlatforms ( ) {
148
+ ctx . fillStyle = "green" ;
156
149
platforms . forEach ( ( platform ) => {
157
150
ctx . drawImage ( platformImage , platform . x , platform . y , platformImage . width , platformImage . height ) ;
158
151
} ) ;
159
152
}
160
153
161
- // A function to draw hills and background
162
- function drawHills ( ) {
163
- objects . forEach ( ( object ) => {
164
- ctx . drawImage ( object . image , backgroundX , object . y , object . width , object . height ) ;
165
- } ) ;
166
- }
167
-
168
- // A function to draw hills and background
169
- // function drawHills() {
170
- // ctx.drawImage(hills, hills.x, hills.y, platformImage.width, platformImage.height);
171
- // }
172
-
173
- // A function to draw hills and background
174
- // function drawBackground() {
175
- // ctx.drawImage(platformImage, platform.x, platform.y, platformImage.width, platformImage.height);
176
- // }
177
-
178
154
// Define a function to update the game's logic.
179
155
function updateGame ( ) {
180
156
ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
@@ -194,13 +170,12 @@ function updateGame() {
194
170
player . frame = 0 ;
195
171
}
196
172
197
- /* ctx.drawImage(background, backgroundX, 0, background.width, canvas.height);*/
173
+ ctx . drawImage ( background , backgroundX , 0 , background . width , canvas . height ) ;
198
174
// ctx.drawImage(image, backgroundX, 0, image.width, canvas.height);
199
175
// ctx.drawImage(image, backgroundX + canvas.width, 0, canvas.width, canvas.height);
200
- /* ctx.drawImage(hills, backgroundX2, 20, hills.width, hills.height);
201
- ctx.drawImage(hills, backgroundX2+800, 20, hills.width, hills.height);*/
176
+ ctx . drawImage ( hills , backgroundX2 , 20 , hills . width , hills . height ) ;
177
+ ctx . drawImage ( hills , backgroundX2 + 800 , 20 , hills . width , hills . height ) ;
202
178
// ctx.drawImage(platformImage, 0, canvas.height-platformImage.height, platformImage.width, platformImage.height);
203
- drawHills ( ) ;
204
179
drawPlayer ( ) ;
205
180
drawPlatforms ( ) ;
206
181
0 commit comments