示例#1
0
    public void Start()
    {
        viewport = AtomicNET.GetSubsystem <Renderer>().GetViewport(0);

        var cache = GetSubsystem <ResourceCache>();

        boxSprite  = cache.GetResource <Sprite2D>("Sprites/Box.png");
        ballSprite = cache.GetResource <Sprite2D>("Sprites/Ball.png");

        var ground = Scene.CreateChild("Ground");

        ground.Position = new Vector3(0.0f, -5.0f, 0.0f);
        ground.Scale    = new Vector3(200.0f, 1.0f, 0.0f);

        ground.CreateComponent <RigidBody2D>();
        ground.CreateComponent <StaticSprite2D>().Sprite = boxSprite;

        // Create box collider for ground
        var groundShape = ground.CreateComponent <CollisionBox2D>();

        // Set box size
        groundShape.Size = new Vector2(0.32f, 0.32f);
        // Set friction
        groundShape.Friction = 0.5f;
    }
示例#2
0
    public void Start()
    {
        if (halfWidth == 0.0f)
        {
            random = new FloatRandom();

            var graphics = AtomicNET.GetSubsystem <Graphics>();
            halfWidth  = graphics.Width * Constants.PIXEL_SIZE * 0.5f;
            halfHeight = graphics.Height * Constants.PIXEL_SIZE * 0.5f;

            var cache = GetSubsystem <ResourceCache>();
            animationSet = cache.GetResource <AnimationSet2D>("Sprites/butterfly.scml");
        }

        speed     = 1 + 2.0f * random.Random();
        direction = random.Random() * (float)Math.PI * 2.0f;

        pos = Node.Position2D;

        sprite              = (AnimatedSprite2D)Node.CreateComponent("AnimatedSprite2D");
        sprite.Speed        = .1f + random.Random() * 2.0f;
        sprite.AnimationSet = animationSet;
        sprite.SetAnimation("idle");
        sprite.Color     = new Color(.1f + random.Random() * .9f, .1f + random.Random() * .9f, .1f + random.Random() * .9f, 1);
        sprite.BlendMode = BlendMode.BLEND_ALPHA;
    }
示例#3
0
    public override void Start()
    {
        Scene scene = AtomicNET.GetSubsystem <Player>().LoadScene("Scenes/Scene.scene");

        // Test the ability to get instances of components from default and external dlls
        // using various Node methods
        var defaultDllComponent = scene.GetCSComponent <DefaultDllComponent>(true);

        Assert(defaultDllComponent != null, "Could not get DefaultDllComponent with GetCSComponent");
        var defaultDllDerivedComponent = scene.GetCSComponent <DefaultDllDerivedComponent>(true);

        Assert(defaultDllComponent != null, "Could not get DefaultDllDerivedComponent with GetCSComponent");
        var defaultDllComponents = new Vector <DefaultDllComponent>();

        scene.GetDerivedCSComponents(defaultDllComponents, true);
        Assert(defaultDllComponents.Count >= 2, "Could not get all DefaultDllComponents with GetDerivedCSComponents");

        var externalDllComponent = scene.GetCSComponent <ExternalDllComponent>(true);

        Assert(externalDllComponent != null, "Could not get ExternalDllComponent with GetCSComponent");
        var externalDllDerivedComponent = scene.GetCSComponent <ExternalDllDerivedComponent>(true);

        Assert(externalDllDerivedComponent != null, "Could not get ExternalDllDerivedComponent with GetCSComponent");
        var externalDllComponents = new Vector <ExternalDllComponent>();

        scene.GetDerivedCSComponents(externalDllComponents, true);
        Assert(externalDllComponents.Count >= 2, "Could not get all ExternalDllComponents with GetDerivedCSComponents");
    }
示例#4
0
        public override void Start()
        {
            Art.Load();

            var   graphics = AtomicNET.GetSubsystem <Graphics>();
            float width    = graphics.Width;
            float height   = graphics.Height;

            ScreenSize   = new Vector2(width, height);
            ScreenBounds = new IntRect(0, 0, (int)ScreenSize.X, (int)ScreenSize.Y);

            var renderer = AtomicNET.GetSubsystem <Renderer>();
            var viewport = renderer.GetViewport(0);

            renderer.HDRRendering = true;

            var cache      = GetSubsystem <ResourceCache>();
            var renderpath = viewport.GetRenderPath().Clone();

            renderpath.Append(cache.GetResource <XMLFile>("RenderPath/BloomHDR.xml"));
            renderpath.Append(cache.GetResource <XMLFile>("RenderPath/Blur.xml"));
            viewport.SetRenderPath(renderpath);

            Scene = new Scene();
            Scene.CreateComponent <Octree>();

            var camera = Scene.CreateChild("Camera").CreateComponent <Camera>();

            camera.Node.Position = new Vector3(width / 2.0f, height / 2.0f, 0.0f);
            camera.Orthographic  = true;
            camera.OrthoSize     = height;

            viewport.Scene  = Scene;
            viewport.Camera = camera;

            CustomRenderer.Initialize();

            ParticleManager = new ParticleManager <ParticleState>(1024 * 20, ParticleState.UpdateParticle);

#if ATOMIC_DESKTOP
            const int maxGridPoints = 1600;
#else
            const int maxGridPoints = 400;
#endif

            float   amt         = (float)Math.Sqrt(ScreenBounds.Width * ScreenBounds.Height / maxGridPoints);
            Vector2 gridSpacing = new Vector2(amt, amt);

            IntRect expandedBounds = ScreenBounds;
            expandedBounds.Inflate((int)gridSpacing.X, (int)gridSpacing.Y);
            Grid = new Grid(expandedBounds, gridSpacing);

            EntityManager.Add(PlayerShip.Instance);

            SubscribeToEvent("Update", HandleUpdate);
            SubscribeToEvent("RenderPathEvent", HandleRenderPathEvent);
        }
示例#5
0
        public static void Initialize()
        {
            var graphics = AtomicNET.GetSubsystem <Graphics>();

            pixelShader  = graphics.GetShader(ShaderType.PS, "Atomic2D");
            vertexShader = graphics.GetShader(ShaderType.VS, "Atomic2D");

            vertexBuffer = new VertexBuffer();
            vertexBuffer.SetSize(maxVertices, Constants.MASK_POSITION | Constants.MASK_COLOR | Constants.MASK_TEXCOORD1, true);
        }
示例#6
0
        public static void Main(string[] args)
        {
            // create the service
            var app = NETServiceApplication.Create();

            // Subscribe to IPC NET commands
            app.SubscribeToEvent("IPCCmd", (eventType, eventData) =>
            {
                // get the command
                string command = eventData["command"];

                switch (command)
                {
                // parse assembly for component information
                case "parse":

                    // Get the assembly to parse
                    string assemblyPath = eventData["assemblyPath"];

                    // Inspect the assembly for components
                    var assemblyJSON = AtomicTools.InspectAssembly(assemblyPath);

                    // Return result
                    var vmap = new ScriptVariantMap();

                    // FIXME: update index operator to a generic
                    vmap.SetUInt("id", eventData.GetUInt("id"));

                    vmap["command"] = command;
                    vmap["result"]  = assemblyJSON;

                    AtomicNET.GetSubsystem <IPC>().SendEventToBroker("IPCCmdResult", vmap);

                    break;

                // exit service
                case "exit":

                    app.SendEvent("ExitRequested");
                    break;
                }
            });

            // Managed code in charge of main loop
            while (app.RunFrame())
            {
            }

            // Shut 'er down
            app.Shutdown();
        }
示例#7
0
    void Update(float timeStep)
    {
        var input = AtomicNET.GetSubsystem <Input>();

        if (input.GetMouseButtonDown(Constants.MOUSEB_LEFT))
        {
            var mousePos = input.GetMousePosition();

            for (var i = 0; i < 10; i++)
            {
                createButterflyNode(new Vector2(mousePos.X, mousePos.Y));
            }
        }
    }
示例#8
0
    private static void LoadFile()
    {
        ResourceCache cache = AtomicNET.GetSubsystem <ResourceCache>();

        using (Stream stream = cache.GetFileStream("Test.txt"))
        {
            using (StreamReader reader = new StreamReader(stream))
            {
                string str = reader.ReadToEnd();
                Log.Debug(str);
            }
        }
        GC.Collect();
        GC.WaitForPendingFinalizers();
    }
示例#9
0
        }                                                          // a single white pixel

        public static void Load()
        {
            var cache = AtomicNET.GetSubsystem <ResourceCache>();

            SpriteSheet2D sheet = cache.GetResource <SpriteSheet2D>("Sprites/AtomicBlasterSprites.xml");

            Player    = new CustomSprite(sheet.GetSprite("Player"));
            Seeker    = new CustomSprite(sheet.GetSprite("Seeker"));
            Wanderer  = new CustomSprite(sheet.GetSprite("Wanderer"));
            Bullet    = new CustomSprite(sheet.GetSprite("Bullet"));
            Pointer   = new CustomSprite(sheet.GetSprite("Pointer"));
            BlackHole = new CustomSprite(sheet.GetSprite("BlackHole"));

            LineParticle = new CustomSprite(sheet.GetSprite("Laser"));
            Glow         = new CustomSprite(sheet.GetSprite("Glow"));
            Pixel        = new CustomSprite(sheet.GetSprite("Pixel"));
        }
示例#10
0
    public override void Start()
    {
        Scene scene = AtomicNET.GetSubsystem <Player>().LoadScene("Scenes/Scene.scene");

        Vector <Camera> cameras = new Vector <Camera>();

        scene.GetComponents(cameras, true);

        Graphics graphics   = GetSubsystem <Graphics>();
        Renderer renderer   = GetSubsystem <Renderer>();
        int      numCameras = cameras.Count;

        views = new UIView[numCameras];
        renderer.SetNumViewports((uint)numCameras);
        int viewportWidth = graphics.Width / numCameras;

        for (int i = 0; i < numCameras; ++i)
        {
            Viewport viewport = new Viewport(scene, cameras[i]);
            viewport.Rect = new IntRect(
                i * viewportWidth, 0,
                (i + 1) * viewportWidth, graphics.Height);
            renderer.SetViewport((uint)i, viewport);

            UIView   view   = new UIView();
            UILayout layout = new UILayout()
            {
                // See for a layout cheatsheet: https://github.com/AtomicGameEngine/AtomicGameEngine/wiki/Turbobadger-Layout-Cheat-Sheet

                // Specifies which y position widgets in a AXIS_X layout should have, or which x position widgets in a AXIS_Y layout should have.
                LayoutPosition = UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_RIGHT_BOTTOM,

                // Specifies how widgets should be moved horizontally in a AXIS_X layout(or vertically in a AXIS_Y layout) if there is extra space available.
                LayoutDistributionPosition = UI_LAYOUT_DISTRIBUTION_POSITION.UI_LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM,

                Rect = viewport.Rect
            };
            layout.AddChild(new UITextField()
            {
                FontDescription = fontDescription,
                Text            = cameras[i].Node.Name
            });
            view.AddChild(layout);
            views[i] = view;
        }
    }
示例#11
0
    private void CreateSceneLoadButton(string sceneName)
    {
        UIButton emptyButton = new UIButton()
        {
            Text            = sceneName,
            FontDescription = fontDescription,
            Gravity         = UI_GRAVITY.UI_GRAVITY_NONE
        };

        emptyButton.SubscribeToEvent <WidgetEvent>(emptyButton, (eventData) =>
        {
            if (eventData.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
            {
                var player = AtomicNET.GetSubsystem <Player>();


                if (sceneName != "Clear")
                {
                    if (currentScene != null)
                    {
                        // This tests that CSComponents (and other components) and cleaned up when keeping scene, though removing all the nodes
                        currentScene.RemoveAllChildren();
                    }

                    currentScene = player.LoadScene("Scenes/" + sceneName + ".scene");
                    player.SetCurrentScene(currentScene);
                }
                else
                {
                    currentScene = null;
                    player.UnloadAllScenes();
                }

                GetSubsystem <ResourceCache>().ReleaseAllResources(true);

                System.GC.Collect();
            }
        });

        layout.AddChild(emptyButton);
    }
示例#12
0
    public override void Start()
    {
        AtomicNET.GetSubsystem <Player>().LoadScene("Scenes/Scene.scene");

        // set up the DebugHud to show metrics and update at 10hz
        var ui = GetSubsystem <UI>();

        ui.SetDebugHudProfileMode(DebugHudProfileMode.DEBUG_HUD_PROFILE_METRICS);
        ui.ShowDebugHud(true);
        ui.DebugHudRefreshInterval = 0.1f;

        SubscribeToEvent <UpdateEvent>(e =>
        {
            loadFileTime -= e.TimeStep;
            if (loadFileTime <= 0.0f)
            {
                loadFileTime = 10.0f;

                LoadFile();
            }
        });
    }
示例#13
0
 public override void Start()
 {
     AtomicNET.GetSubsystem <Player>().LoadScene("Scenes/Scene.scene");
 }
示例#14
0
        public static bool WasBombButtonPressed()
        {
            var input = AtomicNET.GetSubsystem <Input>();

            return(input.GetKeyPress((int)SDL.SDL_Keycode.SDLK_SPACE));
        }
示例#15
0
 void Start()
 {
     viewport = AtomicNET.GetSubsystem <Renderer>().GetViewport(0);
 }
示例#16
0
    public override void Start()
    {
        AtomicNET.GetSubsystem <Player> ().LoadScene("Scenes/Scene.scene");

        var ui = GetSubsystem <UI> ();

        ui.AddFont("Textures/BrokenGlass.ttf", "BrokenGlass"); // add a gooder font
        ui.LoadSkin("Textures/desktop.tb.txt");                // load in the app skin

        ResourceCache cache    = GetSubsystem <ResourceCache> ();
        Graphics      graphics = GetSubsystem <Graphics> ();

        graphics.SetWindowTitle("PeriodicApp");
        Image icon = cache.GetResource <Image> ("Textures/AtomicLogo32.png");

        graphics.SetWindowIcon(icon);

        myuivew  = new UIView();
        mylayout = new UILayout();                  // make the host widget for all visible ui
        mylayout.SetId("UIPeriodicTable");          // tag it, like a big game scientist
        mylayout.SetRect(myuivew.GetRect());        //size it to fill the screen area
        mylayout.SetLayoutConfig("YAGAC");          //all-in-one setting
        mylayout.SetSkinBg("background_solid");     // make it look gooder
        mylayout.Load("Scenes/main_layout.ui.txt"); // load the main layout
        myuivew.AddChild(mylayout);                 // And make it show up.

        UITabContainer maintb    = (UITabContainer)mylayout.GetWidget("maintabs");
        UITabContainer acttb     = (UITabContainer)mylayout.GetWidget("primarytabs");
        UITabContainer semitb    = (UITabContainer)mylayout.GetWidget("moretabs");
        UITabContainer viewtb    = (UITabContainer)mylayout.GetWidget("supporttabs");
        UITabContainer supporttb = (UITabContainer)mylayout.GetWidget("atomictabs");

        supporttb.SetCurrentPage(0);
        viewtb.SetCurrentPage(0);
        semitb.SetCurrentPage(0);
        acttb.SetCurrentPage(0);
        maintb.SetCurrentPage(0);  // do this or else the tab contents look like crap!
        mylog = (UITextField)mylayout.GetWidget("LogText");
        UIWidget ea = mylayout.GetWidget("exitapp");

        var cota = new code_table();

        cota.Setup(mylayout);
        var cobg = new code_uibargraph();

        cobg.Setup(mylayout.GetWidget("pageuibargraph"));
        var cobu = new code_uibutton();

        cobu.Setup(mylayout.GetWidget("pageuibutton"));
        var cocb = new code_uicheckbox();

        cocb.Setup(mylayout.GetWidget("pageuicheckbox"));
        var cocl = new code_uiclicklabel();

        cocl.Setup(mylayout.GetWidget("pageuiclicklabel"));
        var coch = new code_uicolorwheel();

        coch.Setup(mylayout.GetWidget("pageuicolorwheel"));
        var cocw = new code_uicolorwidget();

        cocw.Setup(mylayout.GetWidget("pageuicolorwidget"));
        var coco = new code_uicontainer();

        coco.Setup(mylayout.GetWidget("pageuicontainer"));
        var coef = new code_uieditfield();

        coef.Setup(mylayout.GetWidget("pageuieditfield"));
        var cofw = new code_uifinderwindow();

        cofw.Setup(mylayout.GetWidget("pageuifinderwindow"));
        var cofd = new code_uifontdescription();

        cofd.Setup(mylayout.GetWidget("pageuifontdescription"));
        var coiw = new code_uiimagewidget();

        coiw.Setup(mylayout.GetWidget("pageuiimagewidget"));
        var cois = new code_uiinlineselect();

        cois.Setup(mylayout.GetWidget("pageuiinlineselect"));
        var colo = new code_uilayout();

        colo.Setup(mylayout.GetWidget("pageuilayout"));
        var colp = new code_uilayoutparams();

        colp.Setup(mylayout.GetWidget("pageuilayoutparams"));
        var comi = new code_uimenuitem();

        comi.Setup(mylayout.GetWidget("pageuimenuitem"));
        var comw = new code_uimenuwindow();

        comw.Setup(mylayout.GetWidget("pageuimenuwindow"));
        var come = new code_uimessagewindow();

        come.Setup(mylayout.GetWidget("pageuimessagewindow"));
        var copw = new code_uipromptwindow();

        copw.Setup(mylayout.GetWidget("pageuipromptwindow"));
        var copd = new code_uipulldownmenu();

        copd.Setup(mylayout.GetWidget("pageuipulldownmenu"));
        var corb = new code_uiradiobutton();

        corb.Setup(mylayout.GetWidget("pageuiradiobutton"));
        var cosv = new code_uisceneview();

        cosv.Setup(mylayout.GetWidget("pageuisceneview"));
        var cosb = new code_uiscrollbar();

        cosb.Setup(mylayout.GetWidget("pageuiscrollbar"));
        var cosc = new code_uiscrollcontainer();

        cosc.Setup(mylayout.GetWidget("pageuiscrollcontainer"));
        var cose = new code_uisection();

        cose.Setup(mylayout.GetWidget("pageuisection"));
        var cosd = new code_uiselectdropdown();

        cosd.Setup(mylayout.GetWidget("pageuiselectdropdown"));
        var cosi = new code_uiselectitem();

        cosi.Setup(mylayout.GetWidget("pageuiselectitem"));
        var cosl = new code_uiselectlist();

        cosl.Setup(mylayout.GetWidget("pageuiselectlist"));
        var cosp = new code_uiseparator();

        cosp.Setup(mylayout.GetWidget("pageuiseparator"));
        var cosk = new code_uiskinimage();

        cosk.Setup(mylayout.GetWidget("pageuiskinimage"));
        var cosa = new code_uislider();

        cosa.Setup(mylayout.GetWidget("pageuislider"));
        var cotc = new code_uitabcontainer();

        cotc.Setup(mylayout.GetWidget("pageuitabcontainer"));
        var cotf = new code_uitextfield();

        cotf.Setup(mylayout.GetWidget("pageuitextfield"));
        var cotw = new code_uitexturewidget();

        cotw.Setup(mylayout.GetWidget("pageuitexturewidget"));
        var cowd = new code_uiwidget();

        cowd.Setup(mylayout.GetWidget("pageuiwidget"));
        var cowi = new code_uiwindow();

        cowi.Setup(mylayout.GetWidget("pageuiwindow"));

        SubscribeToEvent <WidgetEvent> (ea, ev => {
            if (ev.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
            {
                GetSubsystem <Engine> ().Exit();
            }
        });

        SubscribeToEvent <KeyDownEvent> (e => {
            if (e.Key == Constants.KEY_ESCAPE)
            {
                GetSubsystem <Engine> ().Exit();
            }
        });
    }
示例#17
0
        public static Vector2 GetMovementDirection()
        {
            var input = AtomicNET.GetSubsystem <Input>();

            Vector2 direction = new Vector2(0, 0);

#if ATOMIC_DESKTOP
            if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_a))
            {
                direction.X -= 1;
            }
            if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_d))
            {
                direction.X += 1;
            }
            if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_s))
            {
                direction.Y -= 1;
            }
            if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_w))
            {
                direction.Y += 1;
            }
#endif

#if ATOMIC_MOBILE
            var touchPos = lastTouchPos;

            if (input.NumTouches == 1)
            {
                touchPos     = input.GetTouchPosition(0);
                lastTouchPos = touchPos;
            }

            if (touchPos != IntVector2.Zero)
            {
                direction = new Vector2((float)touchPos.X, (float)touchPos.Y);
            }


            Vector2 shipPos = PlayerShip.Instance.Position;

            shipPos.Y = GameRoot.ScreenBounds.Height - shipPos.Y;

            direction -= shipPos;

            direction.Y = -direction.Y;

            if (touchPos == IntVector2.Zero || direction.Length < 4.0f)
            {
                direction = Vector2.Zero;
            }
#endif

#if ATOMIC_IOS
            uint numJoySticks = 0;
#else
            uint numJoySticks = input.GetNumJoysticks();
#endif

            if (numJoySticks > 0)
            {
                var state = input.GetJoystickByIndex(0);

                float x = state.GetAxisPosition(0);
                float y = state.GetAxisPosition(1);

                if (x < -0.15f)
                {
                    direction.X = x;
                }
                if (x > 0.15f)
                {
                    direction.X = x;
                }

                if (y < -0.15f)
                {
                    direction.Y = -y;
                }
                if (y > 0.15f)
                {
                    direction.Y = -y;
                }
            }

            // Clamp the length of the vector to a maximum of 1.
            if (direction.LengthSquared > 1)
            {
                direction.Normalize();
            }

            return(direction);
        }
示例#18
0
    void Start()
    {
        SubscribeToEvent <KeyDownEvent>(e =>
        {
            if (e.Key == Constants.KEY_ESCAPE)
            {
                GetSubsystem <Engine>().Exit();
            }
        });

        Node objectNode = Scene.CreateChild("AtomicMutant");

        objectNode.Scale    = new Vector3(1.5f, 1.5f, 1.5f);
        objectNode.Position = Node.Position;

        // spin node
        Node adjustNode = objectNode.CreateChild("AdjNode");

        adjustNode.Rotation = Quaternion.FromAxisAngle(new Vector3(0, 1, 0), 180);

        // Create the rendering component + animation controller
        AnimatedModel animatedModel = adjustNode.CreateComponent <AnimatedModel>();

        var cache = GetSubsystem <ResourceCache>();

        animatedModel.Model       = cache.GetResource <Model>("Models/Mutant/Mutant.mdl");
        animatedModel.Material    = cache.GetResource <Material>("Models/Mutant/Materials/mutant_M.material");
        animatedModel.CastShadows = true;

        // Create animation controller
        adjustNode.CreateComponent <AnimationController>();

        // Create rigidbody, and set non-zero mass so that the body becomes dynamic
        RigidBody body = objectNode.CreateComponent <RigidBody>();

        body.CollisionLayer = 1;
        body.Mass           = 1.0f;

        // Set zero angular factor so that physics doesn't turn the character on its own.
        // Instead we will control the character yaw manually
        body.AngularFactor = Vector3.Zero;

        // Set the rigidbody to signal collision also when in rest, so that we get ground collisions properly
        body.CollisionEventMode = CollisionEventMode.COLLISION_ALWAYS;

        // Set a capsule shape for collision
        CollisionShape shape = objectNode.CreateComponent <CollisionShape>();

        shape.SetCapsule(1.5f, 1.8f, new Vector3(0.0f, 0.9f, 0.0f));

        character = objectNode.CreateComponent <Character>();


        AtomicNET.GetSubsystem <Renderer>().ShadowMapSize = 2048;

        // Get Camera from Scene
        Vector <Node> children = new Vector <Node>();

        Scene.GetChildrenWithComponent <Camera>(children, true);
        if (children.Size > 0)
        {
            cameraNode = children[0];
        }
    }
示例#19
0
        unsafe public static void End()
        {
            List <DrawItem> drawList = new List <DrawItem>();


            if (totalVertex == 0)
            {
                return;
            }

            IntPtr vertexData = vertexBuffer.Lock(0, totalVertex, true);

            if (vertexData == IntPtr.Zero)
            {
                return;
            }

            uint startVertex = 0;

            PositionColorUVVertex *vout = (PositionColorUVVertex *)vertexData;

            foreach (var layer in layerBatches)
            {
                foreach (var batch in layer.Value.Values)
                {
                    if (totalVertex + batch.VertexCount >= maxVertices)
                    {
                        throw new System.InvalidOperationException("Ran out of vertices");
                    }

                    if (batch.VertexCount == 0)
                    {
                        continue;
                    }

                    // faster blit possible?
                    for (uint i = 0; i < batch.VertexCount; i++, vout++)
                    {
                        *vout = batch.Vertices[i];
                    }

                    var item = new DrawItem();
                    item.Texture     = batch.Texture;
                    item.StartVertex = startVertex;
                    item.VertexCount = batch.VertexCount;

                    startVertex += batch.VertexCount;
                    drawList.Add(item);
                }
            }


            vertexBuffer.Unlock();

            var renderer = AtomicNET.GetSubsystem <Renderer>();
            var graphics = AtomicNET.GetSubsystem <Graphics>();

            var view   = renderer.GetViewport(0).View;
            var camera = renderer.GetViewport(0).Camera;

            if (view == null || camera == null)
            {
                return;
            }

            graphics.SetBlendMode(BlendMode.BLEND_ADDALPHA);
            graphics.SetCullMode(CullMode.CULL_NONE);
            graphics.SetFillMode(FillMode.FILL_SOLID);
            graphics.SetDepthTest(CompareMode.CMP_ALWAYS);

            graphics.SetShaders(vertexShader, pixelShader);

            view.SetCameraShaderParameters(camera);
            graphics.SetShaderParameter(ShaderParams.VSP_MODEL, Matrix3x4.IDENTITY);

            graphics.SetShaderParameter(ShaderParams.PSP_MATDIFFCOLOR, Color.White);

            graphics.SetVertexBuffer(vertexBuffer);

            foreach (var item in drawList)
            {
                graphics.SetTexture((int)TextureUnit.TU_DIFFUSE, item.Texture);
                graphics.Draw(PrimitiveType.TRIANGLE_LIST, item.StartVertex, item.VertexCount);
            }

            graphics.SetTexture(0, null);
        }
示例#20
0
    void Update(float timeStep)
    {
        if (spawnDelta > 0)
        {
            spawnDelta -= timeStep;
            return;
        }

        var input = AtomicNET.GetSubsystem <Input>();

        if (input.GetMouseButtonDown(Constants.MOUSEB_LEFT))
        {
            var mousePos = input.GetMousePosition();

            var screenPos = viewport.ScreenToWorldPoint(mousePos.X, mousePos.Y, 0);

            if ((lastSpawn - screenPos).Length < 0.35)
            {
                return;
            }

            lastSpawn  = screenPos;
            spawnDelta = .025f;

            var node = Scene.CreateChild("RigidBody");

            node.SetPosition(new Vector3(screenPos.X, screenPos.Y, 0.0f));

            // Create rigid body
            var body = node.CreateComponent <RigidBody2D>();

            body.BodyType = BodyType2D.BT_DYNAMIC;

            var staticSprite = node.CreateComponent <StaticSprite2D>();

            if (spawnCount % 2 == 0)
            {
                staticSprite.Sprite = boxSprite;

                // Create box
                var box = node.CreateComponent <CollisionBox2D>();
                // Set size
                box.Size = new Vector2(0.32f, 0.32f);
                // Set density
                box.Density = 1.0f;
                // Set friction
                box.Friction = 0.5f;
                // Set restitution
                box.Restitution = 0.1f;
            }
            else
            {
                staticSprite.Sprite = ballSprite;

                // Create circle
                var circle = node.CreateComponent <CollisionCircle2D>();
                // Set radius
                circle.Radius = 0.16f;
                // Set density
                circle.Density = 1.0f;
                // Set friction.
                circle.Friction = 0.5f;
                // Set restitution
                circle.Restitution = 0.1f;
            }

            spawnCount++;
        }
    }
示例#21
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     AtomicNET.GetSubsystem <Player>().LoadScene("Scenes/Scene.scene");
 }
示例#22
0
        private static Vector2 GetMouseAimDirection()
        {
            var input = AtomicNET.GetSubsystem <Input>();

            Vector2 direction = new Vector2();

#if ATOMIC_DESKTOP
            direction = new Vector2((float)input.GetMousePosition().X, (float)input.GetMousePosition().Y);
#endif

#if ATOMIC_IOS
            uint numJoySticks = 0;
#else
            uint numJoySticks = input.GetNumJoysticks();
#endif

            if (numJoySticks > 0)
            {
                Vector2 dir = new Vector2(0, 0);

                var state = input.GetJoystickByIndex(0);

                float x = state.GetAxisPosition(0);
                float y = state.GetAxisPosition(1);

                if (x < -0.15f)
                {
                    dir.X = x;
                }
                if (x > 0.15f)
                {
                    dir.X = x;
                }

                if (y < -0.15f)
                {
                    dir.Y = -y;
                }
                if (y > 0.15f)
                {
                    dir.Y = -y;
                }

                // Clamp the length of the vector to a maximum of 1.
                if (dir.LengthSquared > 1)
                {
                    dir.Normalize();
                }

                return(dir);
            }

#if !ATOMIC_MOBILE
            direction = new Vector2((float)input.GetMousePosition().X, (float)input.GetMousePosition().Y);
#else
            {
                direction = PlayerShip.Instance.Velocity;
                return(Vector2.Normalize(direction));
            }
#endif

            Vector2 shipPos = PlayerShip.Instance.Position;

            shipPos.Y = GameRoot.ScreenBounds.Height - shipPos.Y;

            direction -= shipPos;

            direction.Y = -direction.Y;

            if (direction == Vector2.Zero)
            {
                return(Vector2.Zero);
            }
            else
            {
                return(Vector2.Normalize(direction));
            }
        }