# Search the Community

Showing results for tags 'walls'.

• ### Search By Tags

Type tags separated by commas.

### Forums

• HTML5 Game Coding
• News
• Game Showcase
• Facebook Instant Games
• Coding and Game Design
• Frameworks
• Phaser 3
• Phaser 2
• Pixi.js
• Babylon.js
• Panda 2
• melonJS
• Haxe JS
• Kiwi.js
• General
• General Talk
• Business
• Collaborations (un-paid)
• Jobs (Hiring and Freelance)
• Services Offered

• 0 Comments

• 0 Replies

• 0 Views

### Interests

Found 4 results

1. ## phaser Rotating walls around the player.

Hello, so I'm trying to make it so that the player can 'rotate' the camera around them. For example when they press E and Q the world rotates and things like walls get repositioned and their angle changes. Here is the code I have written: function rotateWorld(angle) { for (var i = 0; i < walls.getAll().length; i++) { var wall = walls.getAll()[i]; wall.angle += angle; var delta_x = wall.x - player.x; var delta_y = wall.y - player.y; var thetaAngle = Math.atan2(delta_y, delta_x) * 180 / Math.PI; wall.x = player.x + lengthdir_x(distance(wall.x, player.x, wall.y, player.y), thetaAngle + angle); wall.y = player.y + lengthdir_y(distance(wall.x, player.x, wall.y, player.y), thetaAngle + angle); } } function lengthdir_x(length, direction) { return Math.cos(direction * Math.PI / 180) * length; } function lengthdir_y(length, direction) { return Math.sin(direction * Math.PI / 180) * length; } function distance(x1, x2, y1, y2) { return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } So far this sort of works but objects lose proper positioning after rotating a bit. It seems like they are not rotating around a perfect circle. Any help would really be appreciated and if there is a way to do this that's easier please let me know. Thanks!
2. Hi guys, I'm a new student and I knew Phaser since 5 days and it's fantastic. So I'm a beginner. I'm trying to create one simple platform game, I have one issue but I don't know how to solve it. I'll appreciate your help. I need that when the animation hit the wall he changes the direction, right or left and keep running. Here's the part of the code that I think is necessary for analyses: // Collide the player with the walls var hitWalls = game.physics.arcade.collide(player, walls); game.physics.arcade.collide(stars, walls) //My animation starts running to right and I want it player.body.velocity.x = 200; player.animations.play('right',15,true); if (hitWalls) ???? { //Here I tried: player.body.velocity.x = -150; but the animation is crazy now } Thanks and have a good day!
3. I have a problem in plotting points when trying to create WALLS. The problem in dissection : - I have 4 points in XOZ plane That I want them to produce 4 walls, as each 2 points are a line and I want each line to become a wall by computing the other 2 points of the wall. I assume the height of the wall (3 meters, for example). This wall might contain holes later (Doors & Windows). Finally I need an enclosed room. I want to create these walls without importing from blender, I get those points from elsewhere. Here is the steps, I use to solve the problem: 1) I split the array into 4 lines. Each line contains 2 points. 2) I have to compute the 2 other points for each line. and here is the problem. I used the dimension Y which is wrong when using ExtrudedPolygon Object. So I have to work in the same XOZ plane and rotate. Here I face other problems like How to calculate the angle of rotation? plus the way of computing the 2 other points will be through having 2 data : The length of the wall (3 meter for example) and the angle which is also a variable that depends on the slope of our line. Here is a sample of my try: https://www.babylonjs-playground.com/#SF0BN6 You can find that in the last loop, I create a wall but with points that contain a Y dimension, which resulted in corrupted shape, But I hope to avoid the suffering of Computing the other 2 points in the same XOZ plane which enforces me to respect the slope of the line and so on as I illustrated in the second point. If you have any alternative ideas, I welcome that. Thanks in advance.
4. I am currently making my first game in phaser, where a fish bounces around the screen and eats fish that you spawn in yourself. I am having 2 issues. First off when he bounces off the walls the walls move and occasionally disappear and also when you spawn more than one fish only the most recent fish will be eaten. Here's my code: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /><title>Fishtank Game</title><script type="text/javascript" src="js/phaser.min.js"></script> <style type="text/css"> body { margin: 0; } </style></head><body> <script type="text/javascript"> var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload() {game.load.image('water', 'assets/water1.png');game.load.image('fish', 'assets/fish.png');game.load.image('wall', 'assets/hidden wall.png');game.load.image('wall2', 'assets/wall flipped.png');game.load.image('smallfish', 'assets/smallfish.png'); var begin = true; var fish;var wallRight;var wallLeft;var smallFish; var createKey; //var fishAngles = ['-100', '100', '-150', '150', '-200', '200', '-250', '250', '-300', '300'];//var angle = fishAngles[Math.floor(Math.random()*fishAngles.length)]; } function create() { smallFish = 'smallfish'; createKey = game.input.keyboard.addKey(Phaser.Keyboard. ; game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.arcade.checkCollision.down = true; game.add.sprite(0,0, 'water'); wallRight = game.add.sprite(799, 0, 'wall'); game.physics.enable(wallRight, Phaser.Physics.ARCADE); wallRight.body.bounce.set(1); wallLeft = game.add.sprite(-80, 0, 'wall'); game.physics.enable(wallLeft, Phaser.Physics.ARCADE); wallLeft.body.bounce.set(1); ceiling = game.add.sprite(0, -80, 'wall2'); game.physics.enable(ceiling, Phaser.Physics.ARCADE); ceiling.body.bounce.set(1); floor = game.add.sprite(0, 599, 'wall2'); game.physics.enable(floor, Phaser.Physics.ARCADE); floor.body.bounce.set(1); fish = game.add.sprite(0, 250, 'fish');fish.anchor.set(0.5);fish.checkWorldBounds = true; game.physics.enable(fish, Phaser.Physics.ARCADE); fish.body.collideWorldBounds = true;fish.body.bounce.set(1); game.input.onDown.add(releasefish, this); createKey.onDown.add(creation, this); } function creation () { smallFish = game.add.sprite(300, 400, 'smallfish');smallFish.anchor.set(0.5);smallFish.checkWorldBounds = true; game.physics.enable(smallFish, Phaser.Physics.ARCADE); smallFish.body.collideWorldBounds = true;smallFish.body.bounce.set(1); smallFish.body.velocity.x = 300;smallFish.body.velocity.y = 400;} function releasefish () { if(begin = true){begin = false;fish.body.velocity.y = -500 - Math.random();fish.body.velocity.x = -300 - Math.random(); wallLeft.x = -79;wallRight.x = 799;ceiling.y = -80;floor.y = 599;}} function update() { game.physics.arcade.collide(fish, wallRight, fishHitRight, null, this);game.physics.arcade.collide(fish, wallLeft, fishHitLeft, null, this);game.physics.arcade.collide(fish, ceiling, fishHitCeiling, null, this);game.physics.arcade.collide(fish, floor, fishHitFloor, null, this); game.physics.arcade.collide(smallFish, wallRight, smallFishHitRight, null, this);game.physics.arcade.collide(smallFish, wallLeft, smallFishHitLeft, null, this);//game.physics.arcade.collide(smallFish, ceiling, smallFishHitCeiling, null, this);//game.physics.arcade.collide(smallFish, floor, smallFishHitFloor, null, this); game.physics.arcade.collide(fish, smallFish, eating, null, this);} function fishHitRight() { var diff = 0; fish.scale.x = -1;wallLeft.x = -80;ceiling.y = -80;floor.y = 599; if (fish.y < wallRight.y) { diff = wallRight.y - fish.y; fish.body.velocity.y = (-2 * diff + Math.random()); }else if (fish.y > wallRight.y) { diff = fish.y - wallRight.y; fish.body.velocity.y = (2 * diff - Math.random()); }else { fish.body.velocity.y = 2 + Math.random() * 12; }} function fishHitLeft() { var diff = 0; fish.scale.x = 1;wallRight.x = 799;ceiling.y = -80;floor.y = 599; if (fish.y < wallLeft.y) { diff = wallLeft.y - fish.y; fish.body.velocity.y = (2 * diff - Math.random()); }else if (fish.y > wallLeft.y) { diff = fish.y - wallLeft.y; fish.body.velocity.y = (-2 * diff + Math.random()); }else { fish.body.velocity.y = 2 + Math.random() * 12; } } function fishHitCeiling() { var diff = 0; wallLeft.x = -80;wallRight.x = 799;floor.y = 599; if (fish.x < ceiling.x) { diff = ceiling.x - fish.x; fish.body.velocity.x = (-2 * diff + Math.random()); }else if (fish.x > ceiling.x) { diff = fish.x - ceiling.x; fish.body.velocity.x = (2 * diff - Math.random()); }else { fish.body.velocity.x = 2 + Math.random() * 12; }} function fishHitFloor() { var diff = 0; wallLeft.x = -80;wallRight.x = 799;ceiling.y = -80; if (fish.x < floor.x) { diff = floor.x - fish.x; fish.body.velocity.x = (-2 * diff + Math.random()); }else if (fish.x > floor.x) { diff = fish.x - floor.x; fish.body.velocity.x = (2 * diff - Math.random()); }else { fish.body.velocity.x = 2 + Math.random() * 12; }} function smallFishHitRight() { smallFish.scale.x = -1;wallLeft.x = -80;} function smallFishHitLeft() { smallFish.scale.x = 1;wallRight.x = 799; } function eating(fish, smallfish) { smallFish.kill();} </script> </body></html>