public void HandleMessages(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam) { switch (msg) { // Handle the keyboard case NativeMethods.WindowMessage.KeyDown: CursorKeys mappedKeyDown = MapKey(wParam); if (mappedKeyDown != (CursorKeys)byte.MaxValue) { // Valid key was pressed, mark it as 'down' keys[(int)mappedKeyDown] = true; } break; case NativeMethods.WindowMessage.KeyUp: CursorKeys mappedKeyUp = MapKey(wParam); if (mappedKeyUp != (CursorKeys)byte.MaxValue) { // Valid key was let go, mark it as 'up' keys[(int)mappedKeyUp] = false; } break; case NativeMethods.WindowMessage.RightButtonDown: rightButtonDown = true; break; case NativeMethods.WindowMessage.RightButtonUp: rightButtonDown = false; break; } }
public override void Create() { world = game.world; game.time.slowMotion = 2.0; view = game.camera.view; space = game.add.tileSprite(0, 0, view.width, view.height, "space"); space.fixedToCamera = true; ship = game.add.sprite(250, game.height - 270, "ship"); ship.angle = -68; ship.anchor.set(0.5); game.physics.enable(ship, Physics.ARCADE); game.physics.arcade.gravity.y = 37.1; var shipBody = (Physics.Arcade.Body)ship.body; //shipBody.angularDrag = 100; //shipBody.bounce.setTo(1); //shipBody.drag.set(10); shipBody.friction.setTo(0); shipBody.maxVelocity.set(150); //debugText = game.add.text(10, 10, "" , new { font = "34px Arial", fill = "#fff" }); konumText = game.add.text(10, 10, "", new { font = "18px Arial", fill = "#fff" }); aciText = game.add.text(10, 40, "", new { font = "18px Arial", fill = "#fff" }); hizText = game.add.text(10, 70, "", new { font = "18px Arial", fill = "#fff" }); ivmeText = game.add.text(10, 100, "", new { font = "18px Arial", fill = "#fff" }); ground = new Phaser.Polygon(new Phaser.Point(0, 300), new Phaser.Point(0, 290), new Phaser.Point(100, 250), new Phaser.Point(150, 150), new Phaser.Point(300, 200), new Phaser.Point(400, 285), new Phaser.Point(550, 285), new Phaser.Point(699, 220), new Phaser.Point(699, 300) ); var graphics = game.add.graphics(0, 0); graphics.beginFill(0xFF33ff); graphics.drawPolygon(ground.points); graphics.endFill(); motor = 40; keyboard = game.input.keyboard; cursors = keyboard.createCursorKeys(); }
public override void Create() { game.physics.startSystem(Physics.P2JS); _bullets = game.add.group(); for (var i = 0; i < 10; i++) { var bullet = _bullets.create(game.rnd.integerInRange(200, 1700), game.rnd.integerInRange(-200, 400), "tinycar"); game.physics.p2.enable(bullet, false); } _cursors = game.input.keyboard.createCursorKeys(); _ship = game.add.sprite(32, game.world.height - 150, "car"); game.physics.p2.enable(_ship); }
public override void Create() { game.physics.startSystem(Physics.ARCADE); // The scrolling starfield background _starfield = game.add.tileSprite(0, 0, 800, 600, "starfield"); // Our bullet group _bullets = game.add.group(); _bullets.enableBody = true; _bullets.physicsBodyType = Physics.ARCADE; _bullets.createMultiple(30, "bullet"); _bullets.setAll("anchor.x", 0.5); _bullets.setAll("anchor.y", 1); _bullets.setAll("outOfBoundsKill", true); _bullets.setAll("checkWorldBounds", true); // The enemy"s bullets _enemyBullets = game.add.group(); _enemyBullets.enableBody = true; _enemyBullets.physicsBodyType = Physics.ARCADE; _enemyBullets.createMultiple(30, "enemyBullet"); _enemyBullets.setAll("anchor.x", 0.5); _enemyBullets.setAll("anchor.y", 1); _enemyBullets.setAll("outOfBoundsKill", true); _enemyBullets.setAll("checkWorldBounds", true); // The hero! _player = game.add.sprite(400, 500, "ship"); _player.anchor.setTo(0.5, 0.5); game.physics.enable(_player, Physics.ARCADE); // The baddies! _aliens = game.add.group(); _aliens.enableBody = true; _aliens.physicsBodyType = Physics.ARCADE; CreateAliens(); // The score _scoreString = "Score : "; _scoreText = game.add.text(10, 10, _scoreString + _score, new { font = "34px Arial", fill = "#fff" }); // Lives _lives = game.add.group(); game.add.text(game.world.width - 100, 10, "Lives : ", new { font = "34px Arial", fill = "#fff" }); // Text _stateText = game.add.text(game.world.centerX, game.world.centerY, " ", new { font = "84px Arial", fill = "#fff" }); _stateText.anchor.setTo(0.5, 0.5); _stateText.visible = false; for (var i = 0; i < 3; i++) { var ship = (Sprite)_lives.create(game.world.width - 100 + (30 * i), 60, "ship"); ship.anchor.setTo(0.5, 0.5); ship.angle = 90; ship.alpha = 0.4; } // An explosion pool _explosions = game.add.group(); _explosions.createMultiple(30, "kaboom"); _explosions.forEach((Action <Sprite>)SetupInvader, this); // And some controls to play the game with _cursors = game.input.keyboard.createCursorKeys(); _fireButton = game.input.keyboard.addKey(Keyboard.SPACEBAR); }