Subversion Repositories AndroidProjects

Rev

Rev 1439 | Rev 1460 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

using BauzoidNET.graphics.sprite;
using BauzoidNET.parser;
using BauzoidNET.math;

namespace BurutaruEditor.file.elements
{
    public class BackgroundElement : LevelElement
    {
        private String mTextureFile = null;
        private SpriteTransform mTransform = new SpriteTransform();
        private Vector2 mScrollFactor = new Vector2(1, 1);


        private SimpleSprite mSprite = null;

        [TypeConverter(typeof(ExpandableObjectConverter))]
        public Vector2 ScrollFactor
        {
            get { return mScrollFactor; }
        }

        public BackgroundElement(Document doc, string name)
            : base(doc, name)
        {
        }

        public override void Init()
        {
            string s = Path.Combine(Application.StartupPath, @"..\\..\\..\\..\\..\\BauzoidApps\\BurutaruZ_v2\\burutaru-android\\assets");
            string fullPath = Path.GetFullPath(s) + "\\" + mTextureFile;

            mSprite = new SimpleSprite(MainForm.App.getGraphics(), fullPath);
            mSprite.init();
        }

        public override void Exit()
        {
            if (mSprite != null)
            {
                mSprite.dispose();
                mSprite = null;
            }
        }

        public override void Render()
        {
            mSprite.getSpriteTransform().set(mTransform);
            mSprite.getSpriteTransform().x += Doc.View.CurrentPosition.x * mScrollFactor.x;
            mSprite.getSpriteTransform().y += Doc.View.CurrentPosition.y * mScrollFactor.y;
            mSprite.render();
        }

        public override bool IsInside(float x, float y)
        {
            // TODO:
            return false;
        }

        public override void MoveBy(float x, float y)
        {
            // TODO:
        }

        public override bool ReadParameter(Tokenizer t, string id)
        {
            // texture
            if (id.Equals("texture", StringComparison.OrdinalIgnoreCase))
            {
                mTextureFile = t.readString();
            }
            // scroll speed
            else if (id.Equals("scrollFactor", StringComparison.OrdinalIgnoreCase))
            {
                mScrollFactor = ParseUtil.readVector2(t);
            }
            // read other parameter types
            else if (!parseSpriteTransform(t, id, mTransform))
            {
                // no other parameter type, so check super-class
                return base.ReadParameter(t, id);
            }

            t.readToken(";");
            return true;
        }
    }
}