window.onload = init function init(){ // Engine.setResurs({ 'block' : 'resurs/sprite/block.jpg', 'bomb' : 'resurs/sprite/bombs.png', 'cop' : 'resurs/sprite/cops.png', 'mob' : 'resurs/sprite/mobs.png', 'player' : 'resurs/sprite/player.png', 'mask' : 'resurs/sprite/mask.png', '_palm' : 'resurs/sprite/_palm.png', '_lavk' : 'resurs/sprite/_lavk.png', 'fire' : 'resurs/sprite/fires.png' }) /* width - () canvas height - () canvas separator - id html canvas size - ( zoom) */ Engine.init({ width : 800, height : 512, separator : 'game_canvas', size : 32, }) /* "" (1-0 : 0 - , 1 - ) */ var map = new Array( new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1), new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1), new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1), new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1), new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1), new Array(1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1), new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1), new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1), new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) ) /* : Engine.Task.AddScene('map') - map // GameObject - , // GameObject box, Vec2 1 var block = new GameObject('box', new Vec2(x, y), 1, 1) // block.gravitati = false; // , scene.ObjectAdd(false, block) */ var scene = new SceneControl('scene1', map[0].length, map.length) for(var y = 0; y < map.length; y++){ for(var x = 0; x < map[0].length; x++){ var sprite = new SpriteControl('block', new Vec2(x, y), Setting.set('size'), Setting.set('size') var block = new GameObject('box', new Vec2(x, y), 1, 1) block.sprite = sprite; block.gravitati = false; scene.ObjectAdd(false, block) } } /* Player Vec2 */ var player = new PlayerObject(new Vec2(5, 5)) scene.ObjectAdd('player', player) Engine.Task.AddScene('scene1', scene) /* scene1*/ Engine.Task.PlayScene('scene1') // Engine.Play(); }
function PlayerObject(vec2){ // parrent - this.parrent = new GameObject('box', vec2, 1, 1 ) // events parrent this.eventKeyUp = function(){ // this.parrent.vec2 = this.parrent.vec2.summ(new Vec2(-2, 0)) } this.eventKeyLeft = function(){ // this.parrent.vec2 = this.parrent.vec2.summ(new Vec2(0, -1)) } this.eventKeyRight = function(){ // this.parrent.vec2 = this.parrent.vec2.summ(new Vec2(0, 1)) } this.eventKeyE = function(){ // E // var scene = Engine.Task.returnScene('map') // Bomb - var bomb = new Bomb(new Vec2(this.parrent.vec2.x, this.parrent.vec2.y)) scene.ObjectAdd(false, bomb) } this.eventKeySpace = function(){ // // bomb Detonation } this.collision = function(){ // // "" if(this.collisionFlagBottom){ // this.parrent.vec2.y = 0 // } } }
Source: https://habr.com/ru/post/163581/
All Articles