Using localStorage to keep the high score
This commit is contained in:
		
							parent
							
								
									c398ba3087
								
							
						
					
					
						commit
						7c2ce752ee
					
				
							
								
								
									
										14
									
								
								src/scene.js
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/scene.js
									
									
									
									
									
								
							@ -1,9 +1,9 @@
 | 
				
			|||||||
class Scene extends Screen {
 | 
					class Scene extends Screen {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(canvas, player) {
 | 
					    constructor(canvas, player) {
 | 
				
			||||||
        super(canvas);
 | 
					        super(canvas);
 | 
				
			||||||
        this.player = player;
 | 
					        this.player = player;
 | 
				
			||||||
        this.currentHeight = 0;
 | 
					        this.currentHeight = 0;
 | 
				
			||||||
        this.maxHeight = 0;
 | 
					 | 
				
			||||||
        this.initialize();
 | 
					        this.initialize();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.addEventListener('touchstart', (event) => {
 | 
					        this.addEventListener('touchstart', (event) => {
 | 
				
			||||||
@ -11,6 +11,14 @@ class Scene extends Screen {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    get maxHeight() {
 | 
				
			||||||
 | 
					        return window.localStorage.getItem("maxHeight");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    set maxHeight(value) {
 | 
				
			||||||
 | 
					        window.localStorage.setItem("maxHeight", value);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    initialize() {
 | 
					    initialize() {
 | 
				
			||||||
        super.initialize();
 | 
					        super.initialize();
 | 
				
			||||||
        this.player.reset();
 | 
					        this.player.reset();
 | 
				
			||||||
@ -20,6 +28,10 @@ class Scene extends Screen {
 | 
				
			|||||||
        this.currentHeight = 0;
 | 
					        this.currentHeight = 0;
 | 
				
			||||||
        this.started = false;
 | 
					        this.started = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (this.maxHeight === undefined) {
 | 
				
			||||||
 | 
					            this.maxHeigth = 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Generate random initial platforms
 | 
					        // Generate random initial platforms
 | 
				
			||||||
        for (let i = 0.25; i <= 2; i += 0.33) {
 | 
					        for (let i = 0.25; i <= 2; i += 0.33) {
 | 
				
			||||||
            let platform = new Platform(Math.random(), i, 0.2);
 | 
					            let platform = new Platform(Math.random(), i, 0.2);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user