DisabledGamer7 Posted January 24, 2015 Share Posted January 24, 2015 Hi all!,I'm a newbie in coding game and starting from example and a lot of google i came up with my first test.You can see a live preview here http://montericco-beb.it/test/gioco/macchina.html using my parent site to test... The problem i'm having is that i wish the zombies to have a little of drag and also that when they hit each other, with a certain velocity they will play the dead animation.Also adding mobile and mouse control...Here is the code:var w = window.innerWidth * window.devicePixelRatio, h = window.innerHeight * window.devicePixelRatio;var game = new Phaser.Game((h > w) ? h : w, (h > w) ? w : h, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });function preload() { game.load.spritesheet('car', 'assets/car.png', 76, 47); game.load.image('ice', 'assets/ice.jpg'); game.load.spritesheet('pedone', 'assets/pedone.png', 32, 48);}var car;var cursors;var score = 0;var scoreText;var land;function create() { game.physics.startSystem(Phaser.Physics.P2JS); land = game.add.tileSprite(0, 0, (h > w) ? h : w, (h > w) ? w : h, 'ice'); game.physics.p2.setImpactEvents(true); game.physics.p2.restitution = 0.7; scoreText = game.add.text(16, 16, 'score: 0', { fontSize: '32px', fill: '#000' }); var playerCollisionGroup = game.physics.p2.createCollisionGroup(); var pedoneCollisionGroup = game.physics.p2.createCollisionGroup(); game.physics.p2.updateBoundsCollisionGroup(); var pedones = game.add.group(); pedones.enableBody = true; pedones.physicsBodyType = Phaser.Physics.P2JS; for (var i = 0; i < 70; i++) { var pedone = pedones.create(game.world.randomX, game.world.randomY, 'pedone'); pedone.body.setRectangle(32, 48); pedone.body.setCollisionGroup(pedoneCollisionGroup); pedone.body.collides([pedoneCollisionGroup, playerCollisionGroup]); pedone.body.collides(pedoneCollisionGroup, pedonehitpedone, this); // this is my tentative but not work pedone.body.angle = game.rnd.integerInRange(-180, 180); var angleped = pedone.body.rotation + (Math.PI/2); pedone.body.velocity.x = -30 * Math.cos(angleped); pedone.body.velocity.y = -30 * Math.sin(angleped); pedone.body.mass = 0.3; //test for drag pedone.body.linearDamping = 1; //test for drag pedone.angularDamping = 1; //test for drag pedone.damping = 1; //test for drag pedone.inertia = 0.2; //test for drag all no effect } pedones.callAll('animations.add', 'animations', 'walk', [0, 1, 2, 3, 4, 5, 6, 7]); pedones.callAll('play', null, 'walk', 7, true); car = game.add.sprite(200, 200, 'car'); game.physics.p2.enable(car, false); car.body.setRectangle(76, 47); car.body.allowRotation = true; car.body.immovable = true; car.body.mass = 1; car.body.setCollisionGroup(playerCollisionGroup); car.body.collides(pedoneCollisionGroup, hitpedone, this); cursors = game.input.keyboard.createCursorKeys(); this.input.onDown.add(click, this); //mouse and touch control test not working this.input.onUp.add(release, this); //mouse and touch control test not working this.input.addMoveCallback(move, this); //mouse and touch control test not working}function click() { var angleclick = car.body.rotation + (Math.PI); car.body.velocity.x = -500 * Math.cos(angleclick); car.body.velocity.y = -500 * Math.sin(angleclick);}function release() {}function move() {}function hitpedone(body1, body2) { body2.sprite.animations.add('dead', [7, 8, 9, 10]); body2.sprite.animations.play('dead', 12, false,true); body1.sprite.animations.add('schizzo', [1, 2, 3]); body1.sprite.animations.play('schizzo', 1, false); score += 10; scoreText.text = 'Score: ' + score;}function pedonehitpedone(body1, body2) { body2.sprite.animations.add('dead', [7, 8, 9, 10]); body2.sprite.animations.play('dead', 12, false,true); score += 10; scoreText.text = 'Score: ' + score;}function update() { car.body.setZeroRotation(); car.body.setZeroVelocity(); var angle = car.body.rotation + (Math.PI); if (cursors.left.isDown) { car.body.angularVelocity = -7; } else if (cursors.right.isDown) { car.body.angularVelocity = 7; } if (cursors.up.isDown) { car.body.velocity.x = -500 * Math.cos(angle); car.body.velocity.y = -500 * Math.sin(angle); } if (cursors.down.isDown) { car.body.velocity.x = 500 * Math.cos(angle); car.body.velocity.y = 500 * Math.sin(angle); }}function render() {}Thank you very much if you will help!Have a nice day ! Link to comment Share on other sites More sharing options...
Recommended Posts