Jump to content

Search the Community

Showing results for tags 'pathfinder'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 5 results

  1. Hi! I need some help with pathfinder written in phaser and easystar. I'm not too experienced with it, but I trying mix it togather :> Look at code (sorry for chaos... its my 1000`th attempt .__. ) There is probably one little mistake and it doesnt work :< daaamn map 40x40 tiles: 1,2,3,4 --> acceptable 1 and 4. Thanks! var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); var easystar = new EasyStar.js(); var currentCowboyXtile var currentCowboyYtile function preload() { game.load.tilemap('desert', 'img/desert.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'img/objects.png'); game.load.image('bullet', 'img/bullet.png'); game.load.image('arrow', 'img/arrow.png'); game.load.image('cactus1', 'img/cactus1.png'); game.load.image('cowboy', 'img/arrow.png'); currentCowboyXtile = 400; currentCowboyYtile = 400; } var map; var layer; var marker; var currentTile; var cursors; var sprite; var weapon; var fireButton; var enemyDirection; var tileSize = 32; var mapSize = 40; var currentPlayerXtile; var currentPlayerYtile; easystar.setGrid(map); easystar.setAcceptableTiles([1,4]); easystar.enableDiagonals(); easystar.enableCornerCutting(); easystar.setIterationsPerCalculation(1000); easystar.enableDiagonals(); function create() { obstacleGroup = game.add.group(); game.add.tileSprite(0, 0, 1920, 1920, 'desert'); game.world.setBounds(0, 0, 1920, 1920); game.physics.startSystem(Phaser.Physics.ARCADE); map = game.add.tilemap('desert'); map.addTilesetImage('Desert', 'tiles'); currentTile = map.getTile(24, 28); layer = map.createLayer('Ground'); layer.resizeWorld(); marker = game.add.graphics(); marker.lineStyle(2, 0x000000, 1); marker.drawRect(0, 0, 32, 32); cursors = game.input.keyboard.createCursorKeys(); /////////////////////////////////////////////// // Creates 30 bullets, using the 'bullet' graphic weapon = game.add.weapon(30, 'bullet'); // The bullet will be automatically killed when it leaves the world bounds weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; // Because our bullet is drawn facing up, we need to offset its rotation: weapon.bulletAngleOffset = 90; // The speed at which the bullet is fired weapon.bulletSpeed = 700; // Speed-up the rate of fire, allowing them to shoot 1 bullet every 60ms weapon.fireRate = 90; // Add a variance to the bullet angle by +- this value weapon.bulletAngleVariance = 5; sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'arrow'); sprite.anchor.setTo(0.5, 0.5); cowboy = game.add.sprite(currentCowboyXtile, currentCowboyYtile, 'arrow' ,obstacleGroup); cowboy.anchor.setTo(0.5, 0.5); //map.putTile(30, 30, 10, layer); map.setCollisionByExclusion([1,4]); game.physics.enable(sprite, Phaser.Physics.ARCADE); game.physics.enable(cowboy, Phaser.Physics.ARCADE); sprite.body.collideWorldBounds = true; //game.physics.startSystem(sprite, Phaser.Physics.P2JS); weapon.trackSprite(sprite, 18, 6, true); game.camera.follow(sprite, Phaser.Camera.FOLLOW_LOCKON, 0.1, 0.1); ///////////////////////////////////////////////////////// fireButton = this.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR); var cactus1; for (var yt = 0; yt < map.length; yt++) { var tile = map[yt]; for (var xt = 0; xt < map[yt].length; xt++) { if (tile[xt] == 1) { cactus1 = game.add.isoSprite(xt * tileSize, yt * tileSize, 0, 'cactus1', 0, obstacleGroup); } else if (tile[xt] == 2) { cactus1 = game.add.isoSprite(xt * tileSize, yt * tileSize, 0, 'cactus2', 0, obstacleGroup); } if (tile[xt] == 1 || tile[xt] == 2) { cactus1.anchor.set(0.5); // Let the physics engine do its job on this tile type game.physics.enable(cactus1, Phaser.Physics.ARCADE); // This will prevent our physic bodies from going out of the screen cactus1.body.collideWorldBounds = true; // Make the cactus body immovable cactus1.body.immovable = true; } } } setInterval(function(){ easystar.findPath(currentCowboyXtile, currentCowboyYtile, currentPlayerXtile, currentPlayerYtile, function( path ) { if (path === null) { console.log("The path to the destination point was not found."); } if (path) { currentNextPointX = path[1].x; currentNextPointY = path[1].y; } if (currentNextPointX < currentCowboyXtile && currentNextPointY < currentCowboyYtile) { // left up console.log("GO LEFT UP"); enemyDirection = "NW"; } else if (currentNextPointX == currentCowboyXtile && currentNextPointY < currentCowboyYtile) { // up console.log("GO UP"); enemyDirection = "N"; } else if (currentNextPointX > currentCowboyXtile && currentNextPointY < currentCowboyYtile) { // right up console.log("GO RIGHT UP"); enemyDirection = "NE"; } else if (currentNextPointX < currentCowboyXtile && currentNextPointY == currentCowboyYtile) { // left console.log("GO LEFT"); enemyDirection = "W"; } else if (currentNextPointX > currentCowboyXtile && currentNextPointY == currentCowboyYtile) { // right console.log("GO RIGHT"); enemyDirection = "E"; } else if (currentNextPointX > currentCowboyXtile && currentNextPointY > currentCowboyYtile) { // right down console.log("GO RIGHT DOWN"); enemyDirection = "SE"; } else if (currentNextPointX == currentCowboyXtile && currentNextPointY > currentCowboyYtile) { // down console.log("GO DOWN"); enemyDirection = "S"; } else if (currentNextPointX < currentCowboyXtile && currentNextPointY > currentCowboyYtile) { // left down console.log("GO LEFT DOWN"); enemyDirection = "SW"; } else { enemyDirection = "STOP"; } }); easystar.calculate(); }, timeStep); } function update() { game.physics.arcade.collide(sprite, layer); marker.x = layer.getTileX(game.input.activePointer.worldX) * 32; marker.y = layer.getTileY(game.input.activePointer.worldY) * 32; if (game.input.mousePointer.isDown) { /* if (game.input.keyboard.isDown(Phaser.Keyboard.SHIFT)) { currentTile = map.getTile(layer.getTileX(marker.x), layer.getTileY(marker.y)); } else*/ { if (map.getTile(layer.getTileX(marker.x), layer.getTileY(marker.y)) != currentTile) { map.putTile(currentTile, layer.getTileX(marker.x), layer.getTileY(marker.y)) } } } if (game.input.keyboard.isDown(Phaser.Keyboard.A)) { game.camera.x -= 4; } else if (game.input.keyboard.isDown(Phaser.Keyboard.D)) { game.camera.x += 4; } if (game.input.keyboard.isDown(Phaser.Keyboard.W)) { game.camera.y -= 4; } else if (game.input.keyboard.isDown(Phaser.Keyboard.S)) { game.camera.y += 4; } if (fireButton.isDown) { weapon.fire(); } ////////////////////////////////////////////////// sprite.body.velocity.x = 0; sprite.body.velocity.y = 0; sprite.body.angularVelocity = 0; if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { sprite.body.angularVelocity = -250; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { sprite.body.angularVelocity = 250; } if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.physics.arcade.velocityFromAngle(sprite.angle, 125, sprite.body.velocity); } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.physics.arcade.velocityFromAngle(sprite.angle, -125, sprite.body.velocity); } /////////////////////////////////////// var enemySpeed = 90; if (enemyDirection == "N") { cowboy.body.velocity.x = -enemySpeed; cowboy.body.velocity.y = -enemySpeed; } else if (enemyDirection == "S") { cowboy.body.velocity.x = enemySpeed; cowboy.body.velocity.y = enemySpeed; } else if (enemyDirection == "E") { cowboy.body.velocity.x = enemySpeed; cowboy.body.velocity.y = -enemySpeed; } else if (enemyDirection == "W") { cowboy.body.velocity.x = -enemySpeed; cowboy.body.velocity.y = enemySpeed; } else if (enemyDirection == "SE") { cowboy.body.velocity.x = enemySpeed; cowboy.body.velocity.y = 0; } else if (enemyDirection == "NW") { cowboy.body.velocity.x = -enemySpeed; cowboy.body.velocity.y = 0; } else if (enemyDirection == "SW") { cowboy.body.velocity.x = 0; cowboy.body.velocity.y = enemySpeed; } else if (enemyDirection == "NE") { cowboy.body.velocity.x = 0; cowboy.body.velocity.y = -enemySpeed; } else if (enemyDirection == "STOP") { cowboy.body.velocity.x = 0; cowboy.body.velocity.y = 0; } else // JUST IN CASE IF enemyDirection wouldnt exist we stop the cowboy movement { cowboy.body.velocity.x = 0; cowboy.body.velocity.y = 0; } currentPlayerXtile = Math.floor(sprite.body.position.x / tileSize); currentPlayerYtile = Math.floor(sprite.body.position.y / tileSize); if (currentPlayerXtile < 0) currentPlayerXtile = 0; if (currentPlayerYtile < 0) currentPlayerYtile = 0; if (currentPlayerXtile > 28) currentPlayerXtile = 28; if (currentPlayerYtile > 28) currentPlayerYtile = 28; currentCowboyXtile = Math.floor(cowboy.body.position.x / tileSize); currentCowboyYtile = Math.floor(cowboy.body.position.y / tileSize); // PREVENT FROM GOING OUT FROM THE LOGICAL ARRAY BECAUSE OF THE PHASER PHYSICS ENGINE if (currentCowboyXtile < 0) currentCowboyXtile = 0; if (currentCowboyYtile < 0) currentCowboyYtile = 0; if (currentCowboyXtile > 28) currentCowboyXtile = 28; if (currentCowboyYtile > 28) currentCowboyYtile = 28; } function render() { }
  2. I wanted to implement pathfinder in my game. I couldnt find any examples in google. Can smeone help me!
  3. So, I'm using both the isometric plugin and the pathfinder plugin in my game. The isometric plugin doesn't use a tilemap to generate the tiles but instead sprites (extended isoSprites). Problem is that the pathfinder plugin needs a tilemap to generate a grid (with walkables and non-walkables) for pathfinding. e.g.: map = map = game.add.tilemap('desert'); pathfinder.setGrid(map.layers[0].data, walkables); Does anyone know of a workaround? Is there a way to convert the isoSprites into a tilemap or, perhaps, extend them further so they can have the layer Member with data (walkable, non-walkable) on each tile? I'm completely new here so forgive me if I'm not using the right terms. I'd be grateful for any help!
  4. Hello all, I'm pretty new on game development and I've chosen Phaser as the framework for our project. We are a Brazilian dev team (to be honest we're just two atm lol). The project home: http://www.in8game.com Blog (Portuguese): http://www.in8game.com/blog/ And tests I'm doing with Phaser: http://www.in8game.com/prototipo/ Well, I've made some tests using the pathfinder plugin and it's cool. I'd like to ask you what do you think would be the better approach to a point and click player movement using the pathfinder. The player will have a "velocity" defined by the "vehicle" he is using atm. Idk if maybe I can add a tween tile by tile using the plugin or if it's better to use some physics here. Hope I made myself understandable. Sorry about my poor English. I'm willing to make something new and cool using Phaser to share with you guys. Thanks in advance. Rainer Lopez
  5. Hello guys, First sorry for my English. I need help for move a sprite in a layer using the plugin ( PathFinder). I can move the sprite, when using the update method. But when I try to create a specific method (MoveSprite) I can not move the sprite. follow the link to view: http://jsbin.com/hutomuqi/3/edit
×
×
  • Create New...