void Awake() {
        GameObject mapGO = GameObject.Find("Map");
        if (mapGO!=null) {
            map = mapGO.GetComponent<Map>();
		}
        mode = inputMode.PLAYER;
	}
Exemple #2
0
        private void doTextMode(char command)
        {
            displayName(true);
            if (command == '~')
            {
                if (iMode == inputMode.movementMode)
                {
                    iMode = inputMode.textMode;
                }
                else
                {
                    iMode = inputMode.movementMode;
                }
            }
            else
            {
                if (command != '\b')
                {
                    message += command;
                }
                else
                {
                    if (message.Length >= 1)
                    {
                        message = message.Substring(0, message.Length - 1);
                    }
                }
            }

            displayName(false);
        }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (currentState == gameState.playing)
        {
            if (Input.GetKey(KeyCode.R))
            {
                ModeSelector = inputMode.repair;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                ModeSelector = inputMode.build;
            }
            else
            {
                ModeSelector = inputMode.attack;
            }

            if (Input.GetKey(KeyCode.Escape))
            {
                PauseGame();
            }
        }

        if (currentState == gameState.pause)
        {
            Time.timeScale = 0;
        }
        else
        {
            Time.timeScale = 1;
        }
    }
Exemple #4
0
        private void doMoveMode(char command)
        {
            vector2 pos = new vector2(pcPos.x, pcPos.y);

            if (command == 'w')
            {
                if (pcPos.y - 1 >= 0 && pcPos.y - 1 < worldManager.size.y)
                {
                    pos.y -= 1;
                }
            }

            if (command == 's')
            {
                if (pcPos.y + 1 >= 0 && pcPos.y + 1 < worldManager.size.y)
                {
                    pos.y += 1;
                }
            }

            if (command == 'a')
            {
                if (pcPos.x - 1 >= 0 && pcPos.x - 1 < worldManager.size.x)
                {
                    pos.x -= 1;
                }
            }

            if (command == 'd')
            {
                if (pcPos.x + 1 >= 0 && pcPos.x + 1 < worldManager.size.x)
                {
                    pos.x += 1;
                }
            }

            if (command == '~')
            {
                if (iMode == inputMode.movementMode)
                {
                    iMode = inputMode.textMode;
                    displayName(true);
                    message = "";
                }
                else
                {
                    iMode = inputMode.movementMode;
                }
            }

            move(pos);
        }
 void ToggleMode()
 {
     CamZoom camera = Camera.main.GetComponent<CamZoom>();
     if (camera.IsZooming) return;
     if (mode == inputMode.MAP)
     {
         mode = inputMode.PLAYER;
         camera.ZoomTo(player.storedTile.transform);
     }
     else if (mode == inputMode.PLAYER)
     {
         mode = inputMode.MAP;
         camera.ZoomTo(map.transform);
     }
     //Debug.Log("Mode: " + mode);
 }
    // Update is called once per frame
    void Update()
    {
        Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetMouseButtonDown(0))
        {
            //Vector2 clickPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            if (currMode == inputMode.NONE)
            {
                currMode = inputMode.SCALE;
                position = mousePos;
            }
            else if (currMode == inputMode.SCALE)
            {
                radius   = Vector2.Distance(position, mousePos) / 2f;
                currMode = inputMode.VELOCITY;
            }
            else if (currMode == inputMode.VELOCITY)
            {
                velocity = (mousePos - position);
                MakeNewPhysObject();
                currMode = inputMode.NONE;
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            if (currMode == inputMode.VELOCITY)
            {
                velocity = Vector2.zero;
                MakeNewPhysObject();
                currMode = inputMode.NONE;
            }
        }

        if (currMode == inputMode.SCALE)
        {
            Utils.DrawDebugCircle(position, 32, Vector2.Distance(position, mousePos) / 2f, Color.white);
        }
        else if (currMode == inputMode.VELOCITY)
        {
            Debug.DrawLine(position, mousePos);
            Utils.DrawDebugCircle(position, 32, radius, Color.white);

            if (gravity)
            {
                PhysicsData dat = new PhysicsData();
                dat.velocity = (mousePos - position);
                dat.position = (position);
                dat.circ     = new Circle {
                    radius = radius
                };
                float m = Mathf.PI * radius * radius;
                dat.mass = m * m * m;

                PhysicsData[] bigEnts  = new PhysicsData[3];
                float[]       highMass = new float[3];

                for (int i = 0; i < physicsEngine.physEnts.Length; i++)
                {
                    PhysicsData other = physicsEngine.physEnts[i];
                    if (other == null)
                    {
                        continue;
                    }

                    Vector2 gForce = Calc.GravityForce(other, dat);
                    float   f      = gForce.magnitude;
                    float   low    = Mathf.Min(highMass);
                    if (f > low)
                    {
                        for (int j = 0; j < highMass.Length; j++)
                        {
                            if (highMass[j] == low)
                            {
                                highMass[j] = f;
                                bigEnts[j]  = physicsEngine.physEnts[i];
                                break;
                            }
                        }
                    }
                }

                if (highMass[0] != 0f)
                {
                    Vector2[] preview = physicsEngine.gravityPreview(bigEnts, dat, 400);

                    for (int i = 0; i < preview.Length - 1; i++)
                    {
                        Debug.DrawLine(preview[i], preview[i + 1], Color.magenta);
                    }
                }
            }
        }

        for (int i = 0; i < 10; i++)
        {
            if (Input.GetKeyDown(i.ToString()))
            {
                steps = speeds[i];
            }
        }

        float scroll = Input.mouseScrollDelta.y;

        if (Mathf.Abs(scroll) > 0.01f)
        {
            //Debug.Log(Camera.main.orthographicSize * f);
            Camera.main.orthographicSize += (Camera.main.orthographicSize * scroll * 0.04f);
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            runPhysics = !runPhysics;
        }

        if (Input.GetKey(KeyCode.W))
        {
            Camera.main.transform.position += Vector3.up * Camera.main.orthographicSize * Time.deltaTime;
        }

        if (Input.GetKey(KeyCode.A))
        {
            Camera.main.transform.position += Vector3.left * Camera.main.orthographicSize * Time.deltaTime;
        }

        if (Input.GetKey(KeyCode.S))
        {
            Camera.main.transform.position += Vector3.down * Camera.main.orthographicSize * Time.deltaTime;
        }

        if (Input.GetKey(KeyCode.D))
        {
            Camera.main.transform.position += Vector3.right * Camera.main.orthographicSize * Time.deltaTime;
        }

        if (Input.GetKey(KeyCode.Backspace))
        {
            physicsEngine.Purge(1);
        }

        if (Input.GetKey(KeyCode.Delete))
        {
            physicsEngine.Purge(0);
        }
    }