khleug35

Members
  • Content Count

    130
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by khleug35

  1. @Wolfsbane Thank you for playing and comment, I fixed the brown wall jumping problem, It may be more smoothly now. I agree with your suggestion. Panda editor can trial the plugin. @enpu Yes, This demo is export to web and uploads to itch io. Hope Panda2 have best future waiting for the Multiplayer plugin,thanks
  2. Matter.js is very good!!!! But I will think p2 and box2d are much better............................................
  3. I think this tutorial is very useful for phaser Matterjs newiable. https://itnext.io/modular-game-worlds-in-phaser-3-tilemaps-4-meet-matter-js-abf4dfa65ca1 https://itnext.io/modular-game-worlds-in-phaser-3-tilemaps-5-matter-physics-platformer-d14d1f614557 You also can see the matter.js example and docment https://github.com/liabru/matter-js#examples
  4. @Stephan @Wolfsbane Thank you for playing and comment
  5. A Simple Game example of the 8-direction movement template created using the Panda engine. controlled with WSAD keys. The User can shoot bullets by Mouse clicking. Demo Game Full Game Download: https://github.com/SuperFranco16/TopDownShooter_Panda2_Template Features: -Press WASD to move -Press P Pause the Game -Mouse to aim and shoot bullets Notes: -This template is not created by enpu, so my code maybe not good or more hardcode or not the best solution to achieve , Welcome to give me a feedback to improve my coding skill, Thanks -Game asset download from https://opengameart.org/users/rileygombart , https://opengameart.org/content/top-down-sci-fi-shooter-pack Full Code: main.js game.module( 'game.main' ) .body(function() { game.addAsset('bg.jpg'); game.addAsset('player.png'); game.addAsset('player_bullet.png'); game.addAsset('Enemy.png'); game.addAsset('explosion.png'); game.createScene('Main', { init: function() { var ths = this; this.world = new game.Physics(0, 0); this.container = new game.Container(); this.container.addTo(this.stage); //BackGround this.bg = new game.Sprite('bg.jpg').addTo(this.container); //Player this.player = new game.Player(200, 300); //Enemy game.Timer.add(1500, function() { new game.Enemy(Math.floor(game.scene.player.body.position.x + (Math.random(Math.random(-1000, -600),Math.random(600, 1000)))), game.scene.player.body.position.y + (Math.random(-800, 800))); }, true); // Left wall new game.Wall(0, 810, 30, 1650); // Right wall new game.Wall(2060, 810, 30, 1650); // Top wall new game.Wall(1030, 0, 2060, 30); // Bottom wall new game.Wall(1030, 1640, 2060, 30); //BackScreen this.blackscreen = new game.Graphics(); this.blackscreen.fillColor = '#000000'; this.blackscreen.alpha = 0; this.blackscreen.drawRect(0, 0, game.width, game.height); //Score, When you kill the enemy, you get 10 score. this.score = 0; this.scoretxt = new game.SystemText('Score : ' + this.score); this.scoretxt.size = 36; this.scoretxt.color = '#fdfdfd'; this.scoretxt.position.set(16, 0); this.scoretxt.addTo(this.stage); //How To Play new game.Dialogue(16, 50, '-Press WASD to move'); new game.Dialogue(16, 80, '-Press P Pause the Game'); new game.Dialogue(16, 110, '-Mouse to aim and shoot'); //Camera Follow Player this.camera = new game.Camera(this.player.sprite); this.camera.position.set(this.player.sprite); this.camera.limit.x = 0; this.camera.limit.y = 0; this.camera.limit.width = game.width - 500; this.camera.limit.height = game.height + 200; this.camera.acceleration = 20; this.camera.addTo(this.container); }, keydown: function(key) { if (key === 'P') { if (this.paused) { this.resume(); this.blackscreen.remove(); } else { this.pause(); this.blackscreen.addTo(this.stage); this.blackscreen.alpha = 0.5; } } }, update: function() {} }); game.createClass('Player', { selectTime: true, speed: 400, init: function(x, y) { var ths = this; this.sprite = new game.Sprite('player.png'); this.sprite.anchorCenter(); this.sprite.position.set(x, y); this.sprite.addTo(game.scene.container); this.body = new game.Body(); this.body.collisionGroup = game.Body.PLAYER; this.body.collideAgainst = [game.Body.WALL, game.Body.ENEMY]; this.body.position.set(x, y); var shape = new game.Rectangle(this.sprite.width / 2.5, this.sprite.height / 2.5); this.body.addShape(shape); this.body.addTo(game.scene.world); this.body.collide = this.collide.bind(this); this.worldPosition = new game.Vector(); }, play: function(anim) { if (this.sprite.currentAnim === this.sprite.anims[anim]) return; this.sprite.play(anim); }, collide: function(body) { if (body.collisionGroup === game.Body.ENEMY) { return false; } return true; }, shoot: function() { var bullet = new game.playerbullet('player_bullet.png', 0, 0, this.sprite.position.x, this.sprite.position.y); bullet.addTo(game.scene.container); var angle = game.input.mouse.angle(this.worldPosition); bullet.rotation = angle - Math.PI / 2; bullet.body.velocity.x = 2000 * Math.cos(angle - Math.PI); bullet.body.velocity.y = 2000 * Math.sin(angle - Math.PI); this.sprite.swap(bullet); }, reset: function(speed) { var ths = this; this.selectTime = false; if (!this.selectTime) { game.Timer.add(speed, function() { ths.selectTime = true; }); } }, update: function() { if (game.scene.isMouseDown && this.selectTime) { this.shoot(); this.reset(300); } this.worldPosition.copy(this.sprite.position); this.worldPosition.subtract(game.scene.camera.position); var angle = game.input.mouse.angle(this.worldPosition); this.sprite.rotation = angle - Math.PI / 2; if (game.keyboard.down('A')) { this.body.velocity.x = -this.speed; } else if (game.keyboard.down('D')) { this.body.velocity.x = this.speed; } else { this.body.velocity.x = 0; } // Set y velocity based on up and down keys if (game.keyboard.down('W')) this.body.velocity.y = -this.speed; else if (game.keyboard.down('S')) this.body.velocity.y = this.speed; else this.body.velocity.y = 0; /* this.sprite.rotation= this.sprite.position.angle(game.scene.circle2.position); */ this.sprite.position.x = this.body.position.x; this.sprite.position.y = this.body.position.y; } }); game.createClass('Enemy', { immortal: false, alive: true, health: 3, speed: 400, selectTime: true, init: function(x, y) { var ths = this; // Play animation this.sprite = new game.Sprite('Enemy.png'); this.sprite.anchorCenter(); this.sprite.position.set(x, y); this.sprite.addTo(game.scene.container); this.body = new game.Body(); this.body.collisionGroup = game.Body.ENEMY; this.body.collideAgainst = [game.Body.PLAYER, game.Body.PLAYERBULLET]; this.body.position.set(x, y); var shape = new game.Rectangle(this.sprite.width / 2, this.sprite.height / 2); this.body.addShape(shape); this.body.addTo(game.scene.world); this.body.collide = this.collide.bind(this); this.removeTimer = game.Timer.add(8000, this.remove.bind(this)); }, play: function(anim) { if (this.sprite.currentAnim === this.sprite.anims[anim]) return; this.sprite.play(anim); }, collide: function(body) { if (body.collisionGroup === game.Body.PLAYERBULLET) { this.hurt(); return false; } return true; }, hurt: function() { var ths = this; if (this.immortal == false) { this.immortal = true; this.health--; var ths = this; this.sprite.tint = '#ffffff'; game.Timer.add(100, function() { ths.sprite.tint = ''; ths.immortal = false; }); } }, remove: function() { this.body.remove(); this.sprite.remove(); game.scene.removeObject(this); }, dead: function() { var ths = this; if (this.health <= 0) { if (this.alive) { this.alive = false; game.scene.score = game.scene.score + 10; game.scene.scoretxt.text = 'Score : ' + game.scene.score; var explosion = new game.Explosion(this.body.position.x, this.body.position.y); explosion.sprite.addTo(game.scene.container); this.remove(); } } }, reset: function(speed) { var ths = this; this.selectTime = false; if (!this.selectTime) { game.Timer.add(speed, function() { ths.selectTime = true; }); } }, update: function() { this.dead(); this.sprite.rotation = this.body.position.angle(game.scene.player.body.position) + .1; var e = this.sprite.position.angle(game.scene.player.sprite.position); this.body.velocity.x = Math.cos(e) * 300, this.body.velocity.y = Math.sin(e) * 300; this.sprite.position.x = this.body.position.x; this.sprite.position.y = this.body.position.y; } }); game.createClass('playerbullet', 'PhysicsSprite', { // How fast playerbullet moves (pixels in second) init: function(texture, width, height, x, y) { this.anchorCenter(); this.body.position.set(x, y); this.body.collisionGroup = game.Body.PLAYERBULLET; this.body.collideAgainst = [game.Body.ENEMY]; }, collide: function(body) { this.remove(); }, remove: function() { // Extend remove function to also remove object from scene // So it's update function doesn't get called anymore this.super(); game.scene.removeObject(this); }, update: function() { // Remove playerbullet if out of screen if (!this.onScreen()) this.remove(); } }); game.createClass('Explosion', { init: function(x, y) { var ths = this; this.sheet = new game.SpriteSheet('explosion.png', 256, 256); this.sprite = new game.Animation(this.sheet.textures); this.sprite.addAnim('doexplode', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], { speed: 30, loop: false }); //Explosion animation completed, the boom will be destroyed this.sprite.anims.doexplode.onComplete = function() { ths.sprite.remove(); ths.body.remove(); game.scene.stage.removeChild(ths); }; this.sprite.anchorCenter(); this.sprite.position.set(x, y); this.sprite.play('doexplode'); this.body = new game.Body(); this.body.mass = 0; this.body.position.set(x, y); var shape = new game.Rectangle(this.sheet.width, this.sheet.height); this.body.addShape(shape); this.body.addTo(game.scene.world); }, play: function(anim) { if (this.sprite.currentAnim === this.sprite.anims[anim]) return; this.sprite.play(anim); } }); game.createClass('Wall', { init: function(x, y, width, height) { this.body = new game.Body(); var shape = new game.Rectangle(); shape.width = width; shape.height = height; this.body.position.x = x; this.body.position.y = y; this.body.addShape(shape); this.body.static = true; this.body.addTo(game.scene.world); } }); game.createClass('Dialogue', { init: function(x, y, txt) { this.text = new game.SystemText(txt); this.text.size = 25; this.text.color = '#fdfdfd'; this.text.position.set(x, y); this.text.addTo(game.scene.stage); } }); // Attributes for different body types game.addAttributes('Body', { WALL: 0, PLAYER: 1, PLAYERBULLET: 2, ENEMY: 3, ENEMYBULLET: 4 }); });
  6. A Simple Game example of platformer template created using the Panda2 engine + P2 plugin. This Template is remade base on Construct 3 platformer template. Demo Game Download:(not include p2.js plugin) https://github.com/SuperFranco16/p2-platformer-template Features: -Arrow keys or WASD to move -P key to pause the game -You can jump up across the brown walls Notes: -This template is not created by enpu, so my code maybe not good or more hardcode or not the best solution to achieve , Welcome to give me a feedback to improve my coding skill, Thanks -P2 Plugin is not open source, so the download file is not include p2.js. Full Code: Main.js game.module( 'game.main' ) .require( 'plugin.p2' ) .body(function() { game.addAsset('player.png'); game.addAsset('BackgroundTile.png'); game.createScene('Main', { backgroundColor: '#272727', init: function() { var ths = this; this.world = new game.Physics({ gravity: [0, 12], }); this.world.on('beginContact', function(data) { // Before collision }); this.world.on('impact', function(data) { // Collision }); this.world.on('postStep', function(data) { // After collision }); //Group this.groups = { PlayerGroup: Math.pow(2, 0), PlayerGroupFilter: Math.pow(2, 1), GROUND: Math.pow(2, 2), }; this.container = new game.Container(); this.container.addTo(this.stage); //Map this.bg = new game.TilingSprite('BackgroundTile.png', game.width, game.height).addTo(this.container); new game.Wall_Platform(32, 96, 32, 672); new game.Wall_Platform(160, 384, 32, 224); new game.Wall_Platform(1247, 0, 64, 1023); new game.Slope_Solid_Platform(675, 310, 200, 32, 8.9); new game.Slope_Solid_Platform(619, 463, 365, 32, 9.6); new game.Slope_Solid_Platform(322, 392, 219, 32, 9.8); new game.Solid_Platform(32, 768, 352, 128); new game.Solid_Platform(864, 800, 96, 32); new game.Solid_Platform(992, 928, 128, 32); new game.Solid_Platform(1088, 736, 96, 32); new game.Solid_Platform(992, 928, 128, 32); new game.Solid_Platform(1088, 736, 96, 32); new game.Solid_Platform(480, 240, 96, 30); new game.Solid_Platform(528, 432, 96, 32); new game.Solid_Platform(192, 320, 96, 32); new game.Solid_Platform(0, -28, 1280, 28); new game.Solid_Platform(32, 768, 352, 128); new game.JumpThru_Platform(1056, 624, 160, 16); new game.JumpThru_Platform(1056, 528, 160, 16); new game.JumpThru_Platform(160, 224, 96, 16); new game.JumpThru_Platform(320, 160, 96, 16); new game.JumpThru_Platform(528, 128, 96, 16); new game.JumpThru_Platform(1056, 128, 96, 16); new game.MovingSolid_Platformer_Horizon(450, 800, 128, 32, 730, 2000); new game.MovingSolid_Platformer_Horizon(640, 160, 128, 32, 800, 2000); new game.MovingSolid_Platformer_Vertical(928, 417, 96, 16, 190, 2000); //How To Play new game.Dialogue(42, 790, '-Arrow keys or WASD to move'); new game.Dialogue(42, 824, '-P key to pause the game'); new game.Dialogue(42, 858, '-You can jump up across the brown walls'); //Player this.player = new game.Player(128, 684); //Hide BackScreen this.blackscreen = new game.Graphics(); this.blackscreen.fillColor = '#000000'; this.blackscreen.alpha = 0; this.blackscreen.drawRect(0, 0, game.width, game.height); //Camera Follow Player this.camera = new game.Camera(this.player.sprite); this.camera.position.set(this.player.sprite.position.x,this.player.sprite.position.y); this.camera.limit.x = 0; this.camera.limit.y = 0; this.camera.limit.width = game.width; this.camera.limit.height = game.height; this.camera.acceleration = 20; this.camera.addTo(this.container); this.container.scale.x = 2; this.container.scale.y = 2; }, keydown: function(key) { if (key === 'P' && this.player.sprite.onScreen()) { if (this.paused) { this.resume(); this.blackscreen.remove(); } else { this.pause(); this.blackscreen.addTo(this.stage); this.blackscreen.alpha = 0.5; } } }, update: function() { this.bg.x = this.camera.position.x * 0.4; } }); game.createClass('Player', { classname: 'playerclass', speed: 3, alive: true, wall: false, isOnGround: false, init: function(x, y) { var ths = this; this.sprite = new game.Sprite("player.png"); this.sprite.position.set(x, y); this.sprite.anchorCenter(); this.sprite.addTo(game.scene.container); this.body = new game.Body({ mass: 1, fixedRotation: true, position: [ this.sprite.position.x / game.scene.world.ratio, this.sprite.position.y / game.scene.world.ratio ], }); this.shape = new p2.Box({ width: this.sprite.width / game.scene.world.ratio, height: this.sprite.height / game.scene.world.ratio }); this.shape.collisionGroup = game.scene.groups.PlayerGroup; this.shape.collisionMask = game.scene.groups.PlayerGroup | game.scene.groups.GROUND; this.body.addShape(this.shape); this.body.collisionGroup = game.Body.PlayerBody; this.body.addTo(game.scene.world); }, checkIfCanJump: function() { for (var i = 0; i < game.scene.world.narrowphase.contactEquations.length; i++) { var c = game.scene.world.narrowphase.contactEquations[i]; if (c.bodyA === this.body || c.bodyB === this.body) { this.isOnGround = true; var d = c.normalA[1]; if (c.bodyB === this.body) d *= -1; if (d > 0.5) { return true; } } } this.isOnGround = false; return false; }, Onslope: function() { var ths = this; for (var i = 0; i < game.scene.world.narrowphase.contactEquations.length; i++) { var c = game.scene.world.narrowphase.contactEquations[i]; if (game.scene.player.body.velocity[1] < 0 && ((c.bodyA === this.body && c.bodyB.collisionGroup === game.Body.SlopePlatformBody) || (c.bodyB === this.body && c.bodyA.collisionGroup === game.Body.SlopePlatformBody))) { this.body.mass = 0; this.body.velocity[1] = 0; var d = c.normalA[1]; if (c.bodyB === this.body) d *= -1; if (d > 0.5) { return true; } } } this.body.mass = 1; return false; }, OnWall: function() { var ths = this; if(this.wall){ game.Timer.add(150, function() { ths.wall= false; }); if (this.sprite.scale.x == -1) { //this.body.velocity[0] = 16; this.body.position[0] = this.body.position[0] + 0.06; }else{ //this.body.velocity[0] = -16; this.body.position[0] = this.body.position[0] - 0.06; } this.body.velocity[1] = -6; } for (var i = 0; i < game.scene.world.narrowphase.contactEquations.length; i++) { var c = game.scene.world.narrowphase.contactEquations[i]; if ((c.bodyA === this.body && c.bodyB.collisionGroup === game.Body.WallBody) || (c.bodyB === this.body && c.bodyA.collisionGroup === game.Body.WallBody)) { if(!this.isOnGround){ if (game.scene.player.body.velocity[1] > 2 && game.keyboard.down('W')) { this.wall = true; return true; } } } } return false; }, play: function(anim) { if (this.sprite.currentAnim === this.sprite.anims[anim]) return; this.sprite.play(anim); }, destroy: function() { game.scene.blackscreen.addTo(game.scene.stage); this.sprite.remove(); this.body.remove(); game.scene.removeObject(this) var tween1 = new game.Tween(game.scene.blackscreen); tween1.to({ alpha: 1 }, 1000); tween1.easing('Quadratic.InOut'); tween1.start(); tween1.onComplete(function() { game.system.loadScene('Main'); }); }, update: function() { var ths = this; console.log(this.wall); if (!this.sprite.onScreen()) { this.destroy(); } if (this.checkIfCanJump() || game.scene.player.body.velocity[1] > 2) { if (game.keyboard.down('S')) { ths.shape.collisionGroup = game.scene.groups.PlayerGroupFilter; } else { ths.shape.collisionGroup = game.scene.groups.PlayerGroup; } } else if (game.scene.player.body.velocity[1] < 2) { ths.shape.collisionGroup = game.scene.groups.PlayerGroupFilter; } this.OnWall(); this.sprite.position.x = this.body.position[0] * game.scene.world.ratio; this.sprite.position.y = this.body.position[1] * game.scene.world.ratio; this.sprite.rotation = this.body.angle; this.Onslope(); if(!this.wall){ if (game.keyboard.down('A')) { this.body.velocity[0] = -this.speed; this.sprite.scale.x = -1; } else if (game.keyboard.down('D')) { this.body.velocity[0] = this.speed; this.sprite.scale.x = 1; } else { this.body.velocity[0] = 0; } } //Jump if (this.checkIfCanJump()) { if (game.keyboard.down('W')) { this.isonSlope = false; this.body.velocity[1] = -6; } } }, }); game.createClass('Wall_Platform', { init: function(x, y, width, height) { this.sprite = new game.Graphics(); this.sprite.fillColor = '#895103'; this.sprite.drawRect(0, 0, width, height); this.sprite.position.set(this.sprite.width / 2 + x, this.sprite.height / 2 + y); this.sprite.anchorCenter(); this.sprite.addTo(game.scene.container); this.body = new game.Body({ mass: 0, fixedRotation: false, position: [ this.sprite.position.x / game.scene.world.ratio, this.sprite.position.y / game.scene.world.ratio ], }); var ratio = game.scene.world.ratio; this.shape = new p2.Box({ width: this.sprite.width / ratio, height: this.sprite.height / ratio }); this.shape.collisionGroup = game.scene.groups.GROUND; this.shape.collisionMask = game.scene.groups.PlayerGroup | game.scene.groups.PlayerGroupFilter | game.scene.groups.GROUND; this.body.addShape(this.shape); this.body.collisionGroup = game.Body.WallBody; this.body.addTo(game.scene.world); }, update: function() { this.sprite.position.x = this.body.position[0] * game.scene.world.ratio; this.sprite.position.y = this.body.position[1] * game.scene.world.ratio; this.sprite.rotation = this.body.angle; } }); game.createClass('Solid_Platform', { init: function(x, y, width, height) { this.sprite = new game.Graphics(); this.sprite.fillColor = '#2a2a2a'; this.sprite.drawRect(0, 0, width, height); this.sprite.position.set(this.sprite.width / 2 + x, this.sprite.height / 2 + y); this.sprite.anchorCenter(); this.sprite.addTo(game.scene.container); this.body = new game.Body({ mass: 0, fixedRotation: false, position: [ this.sprite.position.x / game.scene.world.ratio, this.sprite.position.y / game.scene.world.ratio ], }); var ratio = game.scene.world.ratio; this.shape = new p2.Box({ width: this.sprite.width / ratio, height: this.sprite.height / ratio }); this.shape.collisionGroup = game.scene.groups.GROUND; this.shape.collisionMask = game.scene.groups.PlayerGroup | game.scene.groups.PlayerGroupFilter | game.scene.groups.GROUND; this.body.addShape(this.shape); this.body.collisionGroup = game.Body.PlatformBody; this.body.addTo(game.scene.world); }, update: function() { this.sprite.position.x = this.body.position[0] * game.scene.world.ratio; this.sprite.position.y = this.body.position[1] * game.scene.world.ratio; this.sprite.rotation = this.body.angle; } }); game.createClass('JumpThru_Platform', { init: function(x, y, width, height) { this.sprite = new game.Graphics(); this.sprite.fillColor = 'blue'; this.sprite.drawRect(0, 0, width, height); this.sprite.position.set(this.sprite.width / 2 + x, this.sprite.height / 2 + y); this.sprite.anchorCenter(); this.sprite.addTo(game.scene.container); this.body = new game.Body({ mass: 0, fixedRotation: false, position: [ this.sprite.position.x / game.scene.world.ratio, this.sprite.position.y / game.scene.world.ratio ], }); var ratio = game.scene.world.ratio; this.shape = new p2.Box({ width: this.sprite.width / ratio, height: this.sprite.height / ratio }); this.shape.collisionGroup = game.scene.groups.GROUND; this.body.addShape(this.shape); this.body.collisionGroup = game.Body.PlatformBody; this.body.addTo(game.scene.world); }, update: function() { this.sprite.position.x = this.body.position[0] * game.scene.world.ratio; this.sprite.position.y = this.body.position[1] * game.scene.world.ratio; this.sprite.rotation = this.body.angle; } }); game.createClass('Slope_Solid_Platform', { init: function(x, y, width, height, angle) { this.sprite = new game.Graphics(); this.sprite.fillColor = '#860000'; this.sprite.drawRect(0, 0, width, height); this.sprite.position.set(this.sprite.width / 2 + x, this.sprite.height / 2 + y); this.sprite.anchorCenter(); this.sprite.addTo(game.scene.container); this.body = new game.Body({ mass: 0, angle: angle, fixedRotation: false, position: [ this.sprite.position.x / game.scene.world.ratio, this.sprite.position.y / game.scene.world.ratio ], }); var ratio = game.scene.world.ratio; this.shape = new p2.Box({ width: this.sprite.width / ratio, height: this.sprite.height / ratio }); this.shape.collisionGroup = game.scene.groups.GROUND; this.shape.collisionMask = game.scene.groups.PlayerGroup | game.scene.groups.PlayerGroupFilter | game.scene.groups.GROUND; this.body.addShape(this.shape); this.body.collisionGroup = game.Body.SlopePlatformBody; this.body.addTo(game.scene.world); }, update: function() { this.sprite.position.x = this.body.position[0] * game.scene.world.ratio; this.sprite.position.y = this.body.position[1] * game.scene.world.ratio; this.sprite.rotation = this.body.angle; } }); game.createClass('MovingSolid_Platformer_Horizon', { init: function(x, y, width, height, hx, speed) { this.speed = speed; this.sprite = new game.Graphics(); this.sprite.fillColor = '#2a2a2a'; this.sprite.drawRect(0, 0, width, height); this.sprite.position.set(this.sprite.width / 2 + x, this.sprite.height / 2 + y); this.sprite.anchorCenter(); this.sprite.addTo(game.scene.container); this.body = new game.Body({ mass: 0, fixedRotation: false, position: [ this.sprite.position.x / game.scene.world.ratio, this.sprite.position.y / game.scene.world.ratio ], }); var ratio = game.scene.world.ratio; this.shape = new p2.Box({ width: this.sprite.width / ratio, height: this.sprite.height / ratio }); this.shape.collisionGroup = game.scene.groups.GROUND; this.shape.collisionMask = game.scene.groups.PlayerGroup | game.scene.groups.PlayerGroupFilter | game.scene.groups.GROUND; this.body.addShape(this.shape); this.body.collisionGroup = game.Body.Float_PLATFORM_HORIZON; this.body.collideAgainst = [game.Body.PLAYER]; this.body.addTo(game.scene.world); game.Tween.add(this.sprite.position, { x: hx }, speed, { repeat: Infinity, yoyo: true }).start(); }, collidePlayer: function() { for (var i = 0; i < game.scene.world.narrowphase.contactEquations.length; i++) { var c = game.scene.world.narrowphase.contactEquations[i]; if ((c.bodyA === this.body && c.bodyB.collisionGroup === game.Body.PlayerBody) || (c.bodyB === this.body && c.bodyA.collisionGroup === game.Body.PlayerBody)) { return true; } } return false; }, update: function() { if (this.collidePlayer()) { game.scene.player.body.position[0] -= (this.body.position[0] - (this.sprite.position.x / game.scene.world.ratio)); } this.body.position[0] = this.sprite.position.x / game.scene.world.ratio; this.body.position[1] = this.sprite.position.y / game.scene.world.ratio; this.sprite.rotation = this.body.angle; } }); game.createClass('MovingSolid_Platformer_Vertical', { init: function(x, y, width, height, vy, speed) { this.speed = speed; this.sprite = new game.Graphics(); this.sprite.fillColor = '#2a2a2a'; this.sprite.drawRect(0, 0, width, height); this.sprite.position.set(this.sprite.width / 2 + x, this.sprite.height / 2 + y); this.sprite.anchorCenter(); this.sprite.addTo(game.scene.container); this.body = new game.Body({ mass: 0, fixedRotation: false, position: [ this.sprite.position.x / game.scene.world.ratio, this.sprite.position.y / game.scene.world.ratio ], }); var ratio = game.scene.world.ratio; this.shape = new p2.Box({ width: this.sprite.width / ratio, height: this.sprite.height / ratio }); this.shape.collisionGroup = game.scene.groups.GROUND; this.shape.collisionMask = game.scene.groups.PlayerGroup | game.scene.groups.PlayerGroupFilter | game.scene.groups.GROUND; this.body.addShape(this.shape); this.body.collisionGroup = game.Body.Float_PLATFORM_VERTICAL; this.body.collideAgainst = [game.Body.PLAYER]; this.body.addTo(game.scene.world); game.Tween.add(this.sprite.position, { y: vy }, speed, { repeat: Infinity, yoyo: true }).start(); }, collidePlayer: function() { for (var i = 0; i < game.scene.world.narrowphase.contactEquations.length; i++) { var c = game.scene.world.narrowphase.contactEquations[i]; if ((c.bodyA === this.body && c.bodyB.collisionGroup === game.Body.PlayerBody) || (c.bodyB === this.body && c.bodyA.collisionGroup === game.Body.PlayerBody)) { return true; } } return false; }, update: function() { if (this.collidePlayer()) { game.scene.player.body.position[1] -= (this.body.position[1] - (this.sprite.position.y / game.scene.world.ratio)); } this.body.position[0] = this.sprite.position.x / game.scene.world.ratio; this.body.position[1] = this.sprite.position.y / game.scene.world.ratio; this.sprite.rotation = this.body.angle; } }); game.createClass('Dialogue', { init: function(x, y, txt) { this.text = new game.SystemText(txt); this.text.size = 18; this.text.color = '#fdfdfd'; this.text.position.set(x, y); this.text.addTo(game.scene.container); } }); // Attributes for different body types game.addAttributes('Body', { PlayerBody: 0, PlayerAttackBody: 1, PlatformBody: 2, SlopePlatformBody: 3, WallBody: 4 }); });
  7. When using Mobile Ads Plugin to build android apk on Panda Editor It show this message Build error: No resource identifier found for attribute 'appComponentFactory' in package 'android' Did I miss something? Thanks
  8. @Wolfsbane sorry for reply lately, Thank you for your answer and advice, really thanks.
  9. Hello I using Panda2 + P2.js to develop my next project, When I add Camera function to Phaser Editor Debug mode. the sprite bound is not displaying correctly ?? https://imgur.com/a/lUYxKd2 My full code: backgroundColor: '#272727', init: function() { this.world = new game.Physics(); this.world.on('beginContact', function(data) { }); this.world.on('impact', function(data) { }); this.world.on('postStep', function(data) { }); this.container = new game.Container(); this.container.addTo(this.stage); var ratio = this.world.ratio; var wallShape, wallBody; // Left wall wallShape = new p2.Box({ width: 2, height: game.height / ratio }); wallBody = new game.Body({ position: [-1, game.height / 2 / ratio] }); .......... //same width Panda2 P2.js "Main" Example this.mouseBody = new game.Body(); this.mouseBody.addTo(this.world); this.player2 = new game.Player(game.width / 2, game.height / 2); //Add Camera Function this.camera = new game.Camera(this.player2.sprite); this.camera.setPosition(this.player2.sprite); this.camera.addTo(this.container); }, addConstraint: function(x, y, player) { this.mousemove(x, y); .......... //same width Panda2 P2.js Player class Example }, mousemove: function(x, y) { this.mouseBody.position[0] = x / this.world.ratio; this.mouseBody.position[1] = y / this.world.ratio; }, mouseup: function() { .......... //same width Panda2 P2.js Player class Example } }); game.createClass('Player', { init: function(x, y) { .......... //same width Panda2 P2.js Player class Example } });
  10. @Wolfsbane Thank you for reply, The following is my simple project I try to use chrome console debug to find the answer but still no idea, thx game.module( 'game.main' ) .body(function() { game.addAsset('player.png'); game.createScene('Main', { init: function() { this.sheet = new game.SpriteSheet('player.png', 149 ,237); this.anim = new game.Animation(this.sheet.textures); this.anim.addAnim('run', [3, 4, 5, 6, 7, 8, 9]); this.anim.play('run'); this.anim.addTo(this.stage); console.log(this.anim); } }); }); I can't upload the 'player.png' to this forum. so plz kindly download the 'player.png' to this link , thx https://www.panda2.io/content/examples/media/player.png
  11. Hello, The following example can help you: https://phaser.io/examples/v3/view/physics/arcade/overlap-zone My solution var player = this.physics.add.sprite(100, 450, 'player'); var tree = this.physics.add.sprite(400, 450, 'tree'); var DisplayText; var Text = this.add.text(16, 16, DisplayText, { fontSize: '32px', fill: '#000' }); this.physics.add.collider(player, tree); function update () { DisplayText = tree.body.touching.none ? 'Collided' : 'not Collided'; Text.setText(DisplayText); }
  12. Hello EveryOne How to get the TextureFrame number on Animation?? Thanks you very much this.sheet = new game.SpriteSheet('panda.png', 150 ,111); this.sprite = new game.Animation(this.sheet.textures); this.sprite.addAnim('attack', [43,44,45,46,47,48], { speed: 12, loop: false }); if(this.sprite.xxxxxxxxx.textureframe == 46){ // // dosomething....... } My solution is that, but I don't know Is it the best way to solve the problem?? Thanks if(this.sprite.currentAnim == this.sprite.anims['attack']){ for(var i =0; i < this.sprite.anims.attack.textures.length;i++){ if(i ===4){ // [43,44,45,46,47,48] = [0,1,2,3,4,5,6] due to I want to get frame 46, so i type 4. //doSomething } } } It is very easy to get the TextureFrame in Phaser 3, How about Panda2, Thank you //Phaser 3 if (this.sprite.anims.currentFrame.textureFrame === 46){ // dosomething }
  13. Thanks , One more question Is p2 plugin in Panda2 is not support direction of collision?? eg collide(body, dir) ?? collide: function(body, dir) { if (dir === 'UP' || dir === 'DOWN') { dosomething.... } } https://www.panda2.io/docs/api/Body
  14. khleug35

    p2.js plugin

    P2.js very very very powerful Physics Engines!!!!!!!!!
  15. @Stephan Hello, Thank you very much It work for me, I am Newbie for P2.js , I haven't set this code in Main scene Thank again!!!!!!!! Have a nice day
  16. I find the p2 example and try to type the following code to set player to Player collisionGroup and enemy to Enemy collisionGroup But I still no idea to check two object overlap and collision this.groups = { Player: Math.pow(2, 0), Enemy: Math.pow(2, 1), GROUND: Math.pow(2, 2) }; this.shape.collisionGroup= game.scene.groups.Player; this.shape.collisionMask= game.scene.groups.Player | game.scene.groups.Enemy; From Panda2 in Arcade Physics , I can try this method game.createClass('Player', { init: function() { ... this.body.collideAgainst = [game.Body.Enemy]; this.body.collide = this.collide.bind(this); }, collide: function(other) { if (other.collisionGroup === game.Body.Enemy) { //doSomething...... } }, ..... }); From phaser 2 in P2 Physics , I can refer to this link. http://www.phaser.io/examples/v2/p2-physics/collision-groups How about Panda2 in P2 Physics , Thank you very much
  17. How to detect collision between two objects in P2 Plugin?? I try to use the following code, but not work When collisionGroup 0 collide collisionGroup 1, It will trigger events (eg: hurt, tint, heart HP etc......) this.body.collisionGroup = 0; this.body.collideAgainst = [1]; this.body.collide = this.collide.bind(this); collide: function(body){ if (body.collisionGroup === 1) { console.log("You touch something"); } }, Anyidea check collision between two objects or check overlap in P2 Physics??? Thank you very much My full code of player class: game.createClass('Player', { init: function(x, y) { this.classname = 'playerclass'; this.sprite = new game.Sprite('panda.png'); this.sprite.position.set(x, y); this.sprite.anchorCenter(); this.sprite.addTo(game.scene.stage); this.body = new game.Body({ mass: 1, fixedRotation: false, position: [ this.sprite.position.x / game.scene.world.ratio, this.sprite.position.y / game.scene.world.ratio ], }); var shape = new p2.Circle({ radius: this.sprite.width / 2 / game.scene.world.ratio }); /* For Box var shape = new p2.Box({ width: this.sprite.width/ game.scene.world.ratio, height: this.sprite.height/ game.scene.world.ratio }); */ this.body.addShape(shape); this.body.collisionGroup = 0; this.body.collideAgainst = [1]; this.body.addTo(game.scene.world); this.body.collide = this.collide.bind(this); }, collide: function(body){ if (body.collisionGroup === 1) { console.log("You touch something"); } }, update: function(){ this.sprite.position.x = this.body.position[0] * game.scene.world.ratio; this.sprite.position.y = this.body.position[1] * game.scene.world.ratio; this.sprite.rotation = this.body.angle; if (game.keyboard.down('W')) { this.body.velocity[1] = -2; } else if (game.keyboard.down('S')) { this.body.velocity[1] = 2; }else{ } if (game.keyboard.down('A')) { this.body.velocity[0] = -1; } else if (game.keyboard.down('D')) { this.body.velocity[0] = 1; } else { this.body.velocity[0] = 0; } } });
  18. Your game assets also can access for everyone
  19. Nice Game good work!!!!!!!
  20. @Wolfsbane Thank you for your playing Yes, This game no sound at present, I will add sound soon hope you enjoy it
  21. Hello Everyone. My new HTML5 shoot em up game made using Panda2 This game can play on mobile or desktop, but this game is no sound yet. Special thanks to @enpu, @Stephan and @Wolfsbaneteaching me coding skill, really thanks This game can play on mobile or desktop Try the game in here , hope you enjoy: https://superfranco.itch.io/space-shooterjh Android Version: Google Store Link ScreenShot: How to Play? For desktop control W key - Up A key - Left D key - Right S key - Down P Key - Pause the Game Space - use subweapon For Mobile control You can control the ship movement with JoyStick Click or press the icon to use subweapon and Pause the game. You can destroy the enemy and get money to buy a new ship and upgrade them. Mega Bomb - Mega Bombs damage and clears all forms of the enemy from the screen. When upgraded to level 3 or above,it can also clear enemy gunfire or bullet. Laser - Laser allows you to deal massive damage onto your enemies. Energy Shield - Energy Shield can protect player, When upgraded, it improves the duration of the shield. Mobile version. Android This is a classic vertically scrolling space shoot 'em up game. It has 9 levels with Easy and Hard unlocking regimen. The Hard mode can make double the amount of stars as your reward. You can go to store to upgrade your ship and buy a new ship. How to play -Control the ship movement with JoyStick -Click the icon to use subweapon and Pause the game. Item- Coin - Dropped from enemies , you can take this to upgrade your ship and buy a new ship. Health - Heals 20% of your ship. Subweapon item - increase one Subweapon amount of use. SupWeapon Mega Bomb - Mega Bombs damage and clears all forms of enemy from the screen. When upgraded to level 3 or above,it can also clears enemy gunfire or bullet. Laser - Laser allows you to deal massive damage onto your enemies. Energy Shield - Energy Shield can protect player, When upgraded, it improves the duration of the shield. Ship upgrades are Attack -power of bullets from main cannon. Speed - speed of ship. Health - endurance of the ship. SupWeapon - increase your SupWeapon power or improves the duration of the shield. If you clear all the stage with Hard mode. You are successful to complete the game. Made With: https://www.panda2.io/
  22. @Stephan Awesome !!! it work!!!!! Thank you very much for the awesome code and teaching me!!!  Have a nice day!!! Thanks again!!!
  23. @taoprox Thank you for a reply and remind, my apologies for misspelling but I using 'paused' now and not work : (
  24. How to check if the timer is paused?? the following is my example code game.createScene('Main', { init: function() { this.animation = game.Timer.add(100, function() { //dosomething }, true); this.animation.pause(); }, I try to using "this.animation.pasued", but not work update: function() { if(this.animation.pasued){ //check if the timer is paused, but not work this.animation.resume(); } any idea??? Thank you very much.