Páginas

XNA Bezier Curve

A Bézier curve is a type of curve that is easy to use, and can describe many shapes. Bézier curves are famously used for representing characters in fonts, and shapes in vehicle design. Bézier curves are also used in vector art packages for curve drawing, and in 3D animation tools to represent animation paths.

In games, Bézier curves are sometimes useful to describe paths: the racing line in a racing game, or the line in line-drawing games such as Flight Control, or the looping butterfly that enlivens an RPG.

Bézier curves are popular because their mathematical descriptions are compact, intuitive, and elegant. They are easy to compute, easy to use in higher dimensions (3D and up), and can be stitched together to represent any shape you can imagine.


Thanks to http://blog.icode.com/ I can implement a XNA Bezier Curve, here's what it look like.



BezierCurve.cs

using Microsoft.Xna.Framework;

    public class BezierCurve
    {
        public static Vector2 GetPoint(float t, Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)
        {
            float cx = 3 * (p1.X - p0.X);
            float cy = 3 * (p1.Y - p0.Y);

            float bx = 3 * (p2.X - p1.X) - cx;
            float by = 3 * (p2.Y - p1.Y) - cy;

            float ax = p3.X - p0.X - cx - bx;
            float ay = p3.Y - p0.Y - cy - by;

            float Cube = t * t * t;
            float Square = t * t;

            float resX = (ax * Cube) + (bx * Square) + (cx * t) + p0.X;
            float resY = (ay * Cube) + (by * Square) + (cy * t) + p0.Y;

            return new Vector2(resX, resY);
        }
    }

Game.cs (main game loop class)
public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Vector2 PlotPoint, p0, p1,p2, p3;

        private Texture2D dummyTexture;

        private float t;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        ///
        /// Permite que el juego realice la inicialización que necesite para empezar a ejecutarse.
        /// Aquí es donde puede solicitar cualquier servicio que se requiera y cargar todo tipo de contenido
        /// no relacionado con los gráficos. Si se llama a base.Initialize, todos los componentes se enumerarán
        /// e inicializarán.
        ///
        protected override void Initialize()
        {
            // TODO: agregue aquí su lógica de inicialización
            p0 = new Vector2(75, 250);
            p1 = new Vector2(100, 150); 
            p2 = new Vector2(500, 100);
            p3 = new Vector2(550, 200);

            base.Initialize();
        }

        ///
        /// LoadContent se llama una vez por juego y permite cargar
        /// todo el contenido.
        ///
        protected override void LoadContent()
        {
            // Crea un SpriteBatch nuevo para dibujar texturas.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content para cargar aquí el contenido del juego
            this.dummyTexture = new Texture2D(GraphicsDevice, 1, 1);
            this.dummyTexture.SetData(new[] { Color.White });
        }

        ///
        /// UnloadContent se llama una vez por juego y permite descargar
        /// todo el contenido.
        ///
        protected override void UnloadContent()
        {
            // TODO: descargue aquí todo el contenido que no pertenezca a ContentManager
        }

        ///
        /// Permite al juego ejecutar lógica para, por ejemplo, actualizar el mundo,
        /// buscar colisiones, recopilar entradas y reproducir audio.
        ///
        /// Proporciona una instantánea de los valores de tiempo.
        protected override void Update(GameTime gameTime)
        {
            // Permite salir del juego
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            
            var keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.R))
            {
                t = 0.0f;
            }
            
            t += (float)gameTime.ElapsedGameTime.Milliseconds / 1000;

            if (t > 1.0f)
            {
                return;
            }

            // TODO: agregue aquí su lógica de actualización
            //for (float t = 0; t <= 1.0f; t += 0.01f)
            //{
                PlotPoint = BezierCurve.GetPoint(t, p0, p1, p2, p3);

                // now call some function to plot the PlotPoint
            //    YourDrawFunction(PlotPoint);
            //}

            base.Update(gameTime);
        }

        ///
        /// Se llama cuando el juego debe realizar dibujos por sí mismo.
        ///
        /// Proporciona una instantánea de los valores de tiempo.
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: agregue aquí el código de dibujo
            spriteBatch.Begin();

            this.spriteBatch.Draw(
                    this.dummyTexture,
                    PlotPoint,
                    new Rectangle(0, 0, 20, 20),
                    Color.Red);

            this.spriteBatch.Draw(
                    this.dummyTexture,
                    p0,
                    new Rectangle(0, 0, 20, 20),
                    Color.Green);

            this.spriteBatch.Draw(
                    this.dummyTexture,
                    p1,
                    new Rectangle(0, 0, 20, 20),
                    Color.Blue);

            this.spriteBatch.Draw(
                    this.dummyTexture,
                    p2,
                    new Rectangle(0, 0, 20, 20),
                    Color.Yellow);

            this.spriteBatch.Draw(
                    this.dummyTexture,
                    p3,
                    new Rectangle(0, 0, 20, 20),
                    Color.Black);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }



If you want the project source code, just tweet me https://twitter.com/vackup

A comic of zombies new website launched!

We are very happy to announce that, in addition to our facebook community, we have a new web site for A comic of zombies!

You can visit it from http://acoz.mylittlebets.com and stay in touch with us!



ImageCropper for iOs c# monotouch version

I have ported the excellent ImageCropper for iOs control from Objective C to C# Monotouch

ImageCropper for iOs is a drop-in image cropper for iOS (as seen in Photos app, UIImagePickerController)

I like this controle because it's so so simply and it shows images like iPhone Photos app (and I was looking for any sample!)




As always, you can download source source from https://bitbucket.org/hzaldivar/imagecroppersharp

I made a PhotoAlbumViewController based on this control and Escoz's PagedViewController. I'll upload source code soon!

Download original Platformer Starter Kit Source Code for XNA 4

As Microsoft discontinue the XNA development for Windows 8, he removes all links to download XNA 4 starter kits.

I upload original Platformer source code to bitbucket. Here you can download original Platformer Starter Kit Source Code for XNA 4

https://bitbucket.org/hzaldivar/plaformerxna4/

A new (and better) PopOver port than FPPopover to c# Xamarion Monotouch iOs

Here you have my new (and better) PopOver port from Objective C to c# Xamarion Monotouch iOs than FPPopover.
I started a new port because my last popover port was so buggy and not so beautiful like this! You can find it here: https://bitbucket.org/hzaldivar/popoverviewsharp/



Use it to display:
  • Single String
  • Multiple Strings
  • Single UIView
  • Multiple UIViews
  • All Above + Titles


You can find the original popOver at http://blog.getsherpa.com/blog/2012/09/14/popoverview-a-flexible-modal-content-view-for-ios/ with usage information and more samples. It's really easy and awesome!

Drop me a line or follow me:
https://twitter.com/vackup


Please support my work by downloading my game "A comic of zombies" starring Obama and visting ad banners! Thanks!

A Comic of Zombies for iOs

A Comic of Zombies for PC



Last but not least, here you have the articles I found useful while porting

NSArray

The MonoTouch runtime automatically takes care of converting C# arrays to NSArrays and doing the conversion back,.
The idea is to use a strongly typed C# array as this will allow the IDE to provide proper code completion with the actual type without forcing the user to guess, or look up the documentation to find out the actual type of the objects contained in the array.
In cases where you can not track down the actual most derived type contained in the array, you can use NSObject [] as the return value.
http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types#Arrays

If you go to the MonoTouch API Design page and do an in-page search for "NSArray", you'll find this: Instead of dealing with NSString and NSArray the runtime instead exposes these as C# strings and strongly typed arrays throughout the API.
http://stackoverflow.com/questions/1855478/using-nsarray-with-monotouch

MonoTouch: Where is Frame.Origin?

http://stackoverflow.com/questions/8826697/monotouch-where-is-frame-origin

What's the point of NSAssert, actually?

Assert is to make sure a value is what its suppose to be. If assertion fails that means something went wrong and so the app quits
http://stackoverflow.com/questions/1375786/whats-the-point-of-nsassert-actually

Using UIGestureRecognizer in MonoTouch

Using selector

http://dan.clarke.name/2012/08/using-uigesturerecognizer-in-monotouch/
http://docs.xamarin.com/index.php?title=ios/recipes/content_controls/scroll_view/implement_tap-to-zoom&action=source

Using lambda expression

http://monotouch.2284126.n4.nabble.com/UITapGestureRecognizer-can-t-get-to-work-td4656380.html
https://github.com/xamarin/monotouch-samples/blob/master/Touch/Screens/iPhone/GestureRecognizers/GestureRecognizers_iPhone.xib.cs

Animate Using Blocks

http://docs.xamarin.com/ios/recipes/Animation/CoreAnimation/Animate_Using_Blocks

respondsToSelector - Delegates

http://monotouch.2284126.n4.nabble.com/respondsToSelector-td3536741.html

UIBezierPath

http://es.scribd.com/doc/53062638/88/UIBezierPath

http://docs.xamarin.com/ios/Guides/Advanced_Topics/Binding_Objective-C_Libraries
http://iosapi.xamarin.com/index.aspx?link=M%3AMonoTouch.UIKit.UIColor.SetFill()

Private methods

http://macdevelopertips.com/objective-c/private-methods.html
http://stackoverflow.com/questions/2158660/why-doesnt-objective-c-support-private-methods

Introduction to Objective C

http://blog.teamtreehouse.com/an-introduction-to-objective-c
+ static (class) methods
- normal (instance) methods





EVA 2012 - Indie Show Room "A Comic Of Zombies v1" (version PC)



El zombiepocalipsis ha llegado!! y eres uno de los ultimos sobrevivientes en el mundo! Entonces trata de permanecer vivo en un lucha sin fin por sobrevivir!!!! Ayuda al Presidente Obama en su camino por recuperar el control y la Casa Blanca.


Gana dinero matando zombies y compra hasta 12 armas y municiones mientras un infierno inevitable te rodea... solo tienes 2 armas por nivel

La pregunta es, cuanto tiempo podras sobrevivir? 

A comic of zombies (un comic de zombies) es un juego diverido y adictivo sin comparacion!

Caracteristicas:
- Arte de tipo comic
- Soporte para Retina Display
- Solo 2 armas por nivel
- Controles de usuarios simples
- 12 armas diferentes
- Varios tipos de zombies distintos
- Sistema de compra

Aca pueden descargarse la version final (v1) para PC del videojuego "A comic of zombies"




El mismo fue realizado en XNA y actualmente esta se encuentra disponible en iOs (version free y paga). El proyecto fue migrado reutilizando el mismo codigo fuente con el proyecto open source ExEn



La idea del juego es sobrevivir e ir pasando nivel tras nivel sin fin donde la dificultad se ira incrementando. Nivel tras nivel podremos comprar armas y municiones.


Para manejar al jugador, se usa el teclado y las teclas:
IZQUIERDA = A
DERECHA = D
ARMA MANUAL = J
ARMA DE FUEGO = K
RECARGAR ARMA = L
CAMBIO DE ARMA = O
ESC = Pausa

Recuerden que para poder ejecutar el juego, necesitan:
Cualquier duda o feedback: https://twitter.com/vackup

Si te gusta este juego, cuentale a tus amigos! y compartelo

Rounding up the corners of a UIView, Monotouch c# version

Today I needed to round some corners of an UIView in an app I'm developing and I remember a great article from our friends of Infinixsoft at http://infinixsoft.com/2012/09/rounding-up-the-corners-of-a-uiview/

But, as I'm a Monotouch c# developer and the article was written in objetive C here's the port:


using MonoTouch.UIKit;
using MonoTouch.CoreAnimation;
using System.Drawing;


public static class Utils
{
        public static void RoundView(this UIView self, UIRectCorner rectCorner, float radius)
        {
            var maskPath = UIBezierPath.FromRoundedRect(self.Bounds, rectCorner, new SizeF(radius, radius));
            var maskLayer = new CAShapeLayer();
            maskLayer.Frame = self.Bounds;
            maskLayer.Path = maskPath.CGPath;
            self.Layer.Mask = maskLayer;
            maskLayer.Dispose();
        }
}

I developed it as static extension method of UIView, so to use it just (for eg)

NavigationController.NavigationBar.RoundView(UIRectCorner.TopLeft | UIRectCorner.TopRight, 5.0f);

Enjoy it!
https://twitter.com/vackup