feat: added player position
This commit is contained in:
		
							parent
							
								
									d748b21dfe
								
							
						
					
					
						commit
						d53b8ce4d3
					
				| 
						 | 
					@ -22,6 +22,13 @@
 | 
				
			||||||
            "width": 3,
 | 
					            "width": 3,
 | 
				
			||||||
            "alt_tile": [477, 479]
 | 
					            "alt_tile": [477, 479]
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "sprites": [
 | 
				
			||||||
 | 
					         {
 | 
				
			||||||
 | 
					            "type": "player",
 | 
				
			||||||
 | 
					            "x": 5,
 | 
				
			||||||
 | 
					            "y": 19
 | 
				
			||||||
 | 
					         }
 | 
				
			||||||
      ]
 | 
					      ]
 | 
				
			||||||
   },
 | 
					   },
 | 
				
			||||||
   "exit": {
 | 
					   "exit": {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,7 @@ import { UIElementType } from "../../Wolfie2D/Nodes/UIElements/UIElementTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class Tutorial extends GameLevel{
 | 
					export default class Tutorial extends GameLevel{
 | 
				
			||||||
    private map: TiledTilemapData;
 | 
					    private map: TiledTilemapData;
 | 
				
			||||||
 | 
					    private rmg: RandomMapGenerator;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    loadScene(): void {
 | 
					    loadScene(): void {
 | 
				
			||||||
| 
						 | 
					@ -18,8 +19,8 @@ export default class Tutorial extends GameLevel{
 | 
				
			||||||
        // this.load.tilemap("forest1", "shattered_sword_assets/tilemaps/Tutorial.json");
 | 
					        // this.load.tilemap("forest1", "shattered_sword_assets/tilemaps/Tutorial.json");
 | 
				
			||||||
        // let map = localStorage.getItem("map");
 | 
					        // let map = localStorage.getItem("map");
 | 
				
			||||||
        this.randomSeed = Math.floor(Math.random()*10000000000);
 | 
					        this.randomSeed = Math.floor(Math.random()*10000000000);
 | 
				
			||||||
        let rmg = new RandomMapGenerator("shattered_sword_assets/jsons/forest_template.json", this.randomSeed);
 | 
					        this.rmg = new RandomMapGenerator("shattered_sword_assets/jsons/forest_template.json", this.randomSeed);
 | 
				
			||||||
        this.map = rmg.getMap();
 | 
					        this.map = this.rmg.getMap();
 | 
				
			||||||
        this.load.tilemapFromObject("forest1", this.map);
 | 
					        this.load.tilemapFromObject("forest1", this.map);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        this.load.spritesheet("player", "shattered_sword_assets/spritesheets/Hiro.json")
 | 
					        this.load.spritesheet("player", "shattered_sword_assets/spritesheets/Hiro.json")
 | 
				
			||||||
| 
						 | 
					@ -36,10 +37,11 @@ export default class Tutorial extends GameLevel{
 | 
				
			||||||
        // Add the level 1 tilemap
 | 
					        // Add the level 1 tilemap
 | 
				
			||||||
        this.add.tilemap("forest1", new Vec2(2, 2));
 | 
					        this.add.tilemap("forest1", new Vec2(2, 2));
 | 
				
			||||||
        console.log("width,height:"+this.map.width,this.map.height);
 | 
					        console.log("width,height:"+this.map.width,this.map.height);
 | 
				
			||||||
        this.viewport.setBounds(0, -500, this.map.width*32, this.map.height*32);
 | 
					        this.viewport.setBounds(0, 0, this.map.width*32, this.map.height*32);
 | 
				
			||||||
        this.viewport.follow(this.player);
 | 
					        this.viewport.follow(this.player);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.playerSpawn = new Vec2(5*32, 9*32);
 | 
					        console.log(this.rmg.getPlayer().toString());
 | 
				
			||||||
 | 
					        this.playerSpawn = this.rmg.getPlayer().scale(32);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Do generic setup for a GameLevel
 | 
					        // Do generic setup for a GameLevel
 | 
				
			||||||
        super.startScene();
 | 
					        super.startScene();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -252,8 +252,6 @@ export default class RandomMapGenerator {
 | 
				
			||||||
            let roomHeight = room.bottomRight.y - room.topLeft.y + 1;
 | 
					            let roomHeight = room.bottomRight.y - room.topLeft.y + 1;
 | 
				
			||||||
            room.topLeft.x -= this.minX;
 | 
					            room.topLeft.x -= this.minX;
 | 
				
			||||||
            room.topLeft.y -= this.minY;
 | 
					            room.topLeft.y -= this.minY;
 | 
				
			||||||
            room.bottomRight.x -= this.minX;
 | 
					 | 
				
			||||||
            room.bottomRight.y -= this.minY;
 | 
					 | 
				
			||||||
            for (let i = 0; i < roomHeight; i++)
 | 
					            for (let i = 0; i < roomHeight; i++)
 | 
				
			||||||
                for (let j = 0; j < roomWidth; j++) {
 | 
					                for (let j = 0; j < roomWidth; j++) {
 | 
				
			||||||
                    this.map.layers[0].data[(room.topLeft.y + i) * width + room.topLeft.x + j] = room.bottomLayer[i * roomWidth + j];
 | 
					                    this.map.layers[0].data[(room.topLeft.y + i) * width + room.topLeft.x + j] = room.bottomLayer[i * roomWidth + j];
 | 
				
			||||||
| 
						 | 
					@ -362,7 +360,7 @@ export default class RandomMapGenerator {
 | 
				
			||||||
                    if (this.gen.random() <= sprite.possibility) {
 | 
					                    if (this.gen.random() <= sprite.possibility) {
 | 
				
			||||||
                        let tmp = new Enemy();
 | 
					                        let tmp = new Enemy();
 | 
				
			||||||
                        tmp.type = sprite.type;
 | 
					                        tmp.type = sprite.type;
 | 
				
			||||||
                        tmp.position = new Vec2(posX + sprite.x, posY + sprite.y);
 | 
					                        tmp.position = new Vec2(sprite.x, sprite.y);
 | 
				
			||||||
                        room.enemies.push(tmp);
 | 
					                        room.enemies.push(tmp);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user