Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var game;
- var gameOptions = {
- bigCircleRadius: 250,
- playerRadius: 25,
- playerSpeed: 6000
- }
- window.onload = function() {
- var gameConfig = {
- thpe: Phaser.CANVAS,
- width: 800,
- height: 800,
- scene: [playGame]
- }
- game = new Phaser.Game(gameConfig);
- window.focus()
- resize();
- window.addEventListener("resize", resize, false);
- }
- class playGame extends Phaser.Scene{
- constructor(){
- super("PlayGame");
- }
- preload(){
- this.load.image("bigcircle", "bigcircle.png");
- this.load.image("player", "player.png");
- }
- create(){
- this.bigCircle = this.add.sprite(game.config.width / 2, game.config.height / 2, "bigcircle");
- this.bigCircle.displayWidth = gameOptions.bigCircleRadius * 2;
- this.bigCircle.displayHeight = gameOptions.bigCircleRadius * 2;
- this.player = this.add.sprite(game.config.width / 2, game.config.height / 2 - gameOptions.bigCircleRadius - gameOptions.playerRadius, "player");
- this.player.displayWidth = gameOptions.playerRadius * 2;
- this.player.displayHeight = gameOptions.playerRadius * 2;
- this.player.currentAngle = -90;
- }
- update(t, dt){
- var deltaAngle = 360 * (dt / gameOptions.playerSpeed);
- this.player.currentAngle = Phaser.Math.Angle.WrapDegrees(this.player.currentAngle + deltaAngle);
- var radians = Phaser.Math.DegToRad(this.player.currentAngle);
- var distanceFromCenter = gameOptions.bigCircleRadius + gameOptions.playerRadius;
- this.player.x = this.bigCircle.x + distanceFromCenter * Math.cos(radians);
- this.player.y = this.bigCircle.y + distanceFromCenter * Math.sin(radians);
- var revolutions = gameOptions.bigCircleRadius / gameOptions.playerRadius + 1;
- this.player.angle = this.player.currentAngle * revolutions;
- }
- }
- // pure javascript to scale the game
- function resize() {
- var canvas = document.querySelector("canvas");
- var windowWidth = window.innerWidth;
- var windowHeight = window.innerHeight;
- var windowRatio = windowWidth / windowHeight;
- var gameRatio = game.config.width / game.config.height;
- if(windowRatio < gameRatio){
- canvas.style.width = windowWidth + "px";
- canvas.style.height = (windowWidth / gameRatio) + "px";
- }
- else{
- canvas.style.width = (windowHeight * gameRatio) + "px";
- canvas.style.height = windowHeight + "px";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement