Exemplo n.º 1
0
    /// <summary>
    /// Performs initialization of Game object.
    /// </summary>
    public void Initialize(GameMode gameMode)
    {
        this.gameMode = gameMode;
        this.state    = new NoState(this);
        gc            = GameObject.Find(GameController.NAME).GetComponent <GameController>();

        // Initialize fields
        this.holeBag           = new HoleBag(gameMode);
        this.itemBag           = new ItemBag("good");
        this.badItemBag        = new ItemBag("bad");
        this.playerAttributes  = new PlayerAttributes();
        this.terrainAttributes = new TerrainAttributes();

        inputController = new InputController(this);
        target          = Target.BALL;

        wind            = new Wind(this);
        ball            = new Ball(this);
        cursor          = new Cursor(this);
        currentDistance = new CurrentDistance(this);
        bag             = new Bag(this);
        powerbar        = new Powerbar(this);
        shotMode        = new ShotMode(this);
        score           = new Score(this);

        // Send Game reference to other objects
        GodOfUI ui = GameObject.Find(GodOfUI.NAME).GetComponent <GodOfUI>();

        ui.gameRef = this;
    }
Exemplo n.º 2
0
    public bool Strike(string[] arr)
    {
        string errorMessage = "Strike power [accuracy]";

        if (game.GetState() is IdleState && arr.Length < 3)
        {
            Powerbar powerbar = game.GetPowerbar();
            float    power    = 1f;
            float    accuracy = 0f;
            if (arr.Length == 1)
            {
                power = Floatify(arr[0]);
            }
            if (arr.Length == 2)
            {
                accuracy = Floatify(arr[1]);
            }
            powerbar.SetPower(power);
            powerbar.SetAccuracy(accuracy);
            game.GetCursorGraphics().Disable();
            game.SetState(new StrikingState(game));
            return(true);
        }
        Reply(errorMessage);
        return(true);
    }
    // Start is called before the first frame update
    void Start()
    {
        traj     = FindObjectOfType <TrajectorySelect>();
        powerbar = FindObjectOfType <Powerbar>();
        prompt   = FindObjectOfType <Prompt>();
        audio    = FindObjectOfType <Audio>();

        rb = GetComponent <Rigidbody2D>();
        // So it cannot move
        rb.gravityScale = 0;
        // Initial state
        currentState = GameState.TRAJECTORY_SELECTION;

        //Helper menu initially.
        helperMenu.SetActive(true);
        Time.timeScale = 0f;
    }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        //get controller, player and some scripts
        gameController = GameObject.FindWithTag("GameController");
        cont           = gameController.gameObject.GetComponent <Controller>();
        player         = GameObject.FindGameObjectWithTag("Player");

        //rb.useGravity = false;
        power = 0.0f;

        // startPosition = new Vector3(-17.73f, 1.68f, 2.38f);
        loadSound();

        if (!aimAssistScript)
        {
            aimAssistScript = GetComponent <AimAssist>();
        }

        if (!powerBar)
        {
            powerBar = GameObject.FindGameObjectWithTag("ScoreBoard").GetComponent <Powerbar>();
        }
        scoreBoardScript = GameObject.FindGameObjectWithTag("ScoreBoard").GetComponent <Scoreboard>();
    }
Exemplo n.º 5
0
        public GameScreen(Game1 game)
            : base(game)
        {
            // SPRITES

            this.tilemap = new Tilemap("tilemap2", this);
            this.Add(tilemap);

            this.tank = new Tank("body", "cannon", 84, 68, 0.10f);
            this.tank.Origin = new Vector2(84 / 2, 68 / 2);
            this.tank.BodyRotation = (float)Math.PI / 2;

            tank.Position = new Vector2(400, 240);

            this.Add(tank.Body);
            this.Add(tank.Cannon);

            var offset0 = new Vector2(1000, 1000);
            var enemy = new Target("snake", 84, 84, 0.1f, this) { Position = new Vector2(0, 0) + offset0 };
            this.Enemies.Add(enemy);
            this.Add(enemy);

            enemy = new Target("snake", 84, 84, 0.1f, this) { Position = new Vector2(65, 189) + offset0 };
            this.Enemies.Add(enemy);
            this.Add(enemy);

            enemy = new Target("snake", 84, 84, 0.1f, this) { Position = new Vector2(560, 256) + offset0 };
            this.Enemies.Add(enemy);
            this.Add(enemy);

            enemy = new Target("snake", 84, 84, 0.1f, this) { Position = new Vector2(300, 300) + offset0 };
            this.Enemies.Add(enemy);
            this.Add(enemy);

            // UI ELEMENTS
            var offset = new Vector2(7, 155);

            var buttonUp = new Button("joystick_button_v") { Position = offset + new Vector2(115, 0) };
            buttonUp.Pressed += new EventHandler<TouchEventArgs>(buttonUp_Touch);
            buttonUp.Released += new EventHandler<TouchEventArgs>(buttonNavigation_Released);
            this.Add(buttonUp);

            var buttonDown = new Button("joystick_button_v2") { Position = offset + new Vector2(115, 210) };
            buttonDown.Pressed += new EventHandler<TouchEventArgs>(buttonDown_Touch);
            buttonDown.Released += new EventHandler<TouchEventArgs>(buttonNavigation_Released);
            this.Add(buttonDown);

            var buttonLeft = new Button("joystick_button_h") { Position = offset + new Vector2(0, 115) };
            buttonLeft.Pressed += new EventHandler<TouchEventArgs>(buttonLeft_Touch);
            buttonLeft.Released += new EventHandler<TouchEventArgs>(buttonNavigation_Released);
            this.Add(buttonLeft);

            var buttonRight = new Button("joystick_button_h2") { Position = offset + new Vector2(210, 115) };
            buttonRight.Pressed += new EventHandler<TouchEventArgs>(buttonRight_Touch);
            buttonRight.Released += new EventHandler<TouchEventArgs>(buttonNavigation_Released);
            this.Add(buttonRight);

            // DO NOT CHANGE THE ORDERING OF BUTTONS - IT IS EXTREMELY IMPORTANT THAT THE SHOOTING IS
            // ADDED AFTER THE ARROW BUTTONS
            var buttonShooting = new Button("transparent");
            buttonShooting.Pressed += new EventHandler<TouchEventArgs>(buttonShooting_Pressed);
            buttonShooting.Released += new EventHandler<TouchEventArgs>(buttonShooting_Released);
            this.buttonShooting = buttonShooting;
            this.Add(buttonShooting);

            var powerbar = new Powerbar() { Position = new Vector2(800 - 150, 480 - 70) };
            this.powerbar = powerbar;
            this.Add(powerbar);

            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(this.Game1.MySong);

            this.SceneOffset = new Vector2(-1000, -1000);
        }
Exemplo n.º 6
0
 public PowerState(Game game) : base(game)
 {
     this.powerbar = game.GetPowerbar();
 }
Exemplo n.º 7
0
 public AccuracyState(Game game) : base(game)
 {
     this.powerbar = game.GetPowerbar();
 }