Saturday, 29 December 2012

UDK - Unreal Development Kit - Create basic terrain and use static meshes

I decided to create a series of tutorials for UDK. In this tutorial I will focus on base terrain creation, adding texture and finally adding static meshes.




Thursday, 27 December 2012

Messing with Unreal Engine 3 and UDK

Some of my latest work on small village. I am currently working on 2d platform game for IOs and I will use this level as a background.






Sunday, 18 November 2012

Render random image in android




Recently I have been working on android app that supposed to display random card image from set of 22 images.  To simplify this tutorial let’s create only 3 images.
Let’s create an array resource that will store reference to our images in resource/drawable  folder.

array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="cardImages">
        <item>@drawable/death</item>
         <item>@drawable/chariot</item>
          <item>@drawable/devil</item>
     
    </array>

</resources>

         To find more visit:  Official android reference

As you can see we have 3 images stored in an array.
Now create new Activity and call it Card.java
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.card);

       ImageView BackCard = (ImageView) findViewById(R.id.backcard);

              BackCard.setOnClickListener(new OnClickListener() {
                           
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                BackCard.setImageResource(R.drawable.backblur);
                                BackCard.postDelayed(new Runnable() {
                                   
                                    public void run() {
                                        // TODO Auto-generated method stub
                                        // Randomly choose card
                                       
                                        int randomCard = randomCard();
                                       
                                        BackCard.setImageResource(randomCard);
                                    }
                               
                                }, 150);
                               
                            }
                        });

}

   public int randomCard()
    {
        Resources res = getResources();
        TypedArray cards = res.obtainTypedArray(R.array.cardImages);
       
        int randomNumber =  (int)(Math.random() * ((2 - 0) + 1));
       
        int card = cards.getResourceId(randomNumber, randomNumber);
       
        return card;
    }

Now some explanation. I used postDelayed method, simply saying do something after time elapsed(in our case 150ms). Image backblur will be loaded for 150ms and then our actual card is displayed.

randomCard method returns int value of Image resource as setImageResource expects it.

We want to generate number from 0 to 2 where 0 is first element of our array.

Good explanation of random number generator in Java can be found here : http://stackoverflow.com/questions/363681/generating-random-number-in-a-range-with-java

Monday, 22 October 2012

Random password generator using Ajax in ASP.Net MVC


You can download the project from here : Download MVCPasswordExample 

As title says when user click a button it send ajax request to controller
$.post('@Url.Content("~/Home/GeneratePassword/")' ...
and returns Json with new 8 character password.


MODEL



public class RegisterModel
    {
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.EmailAddress)]
        [Display(Name = "Email address")]
        public string Email { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }
    }
 



VIEW


@{
    ViewBag.Title = "Home Page";
}

@using MVCPasswordExample.Models
@model RegisterModel

<script>
    $(document).ready(function () {
        $('#updateprofile').click(function () {
            $('form')[0].reset();

        });

        $('#autogenerate').click(function () {
            $.post('@Url.Content("~/Home/GeneratePassword/")', function (data) {

                $('#password, #confirmpassword').attr("value", data.password);

            });
        });

    });

</script>


<h2>@ViewBag.Message</h2>

<table style="margin-top:100px;width:40%">
 <tr>
 <th colspan="3">Change Password</th>
 </tr>


  <tr>
      <td>@Html.LabelFor(m => m.Password)
      </td>
     <td style="width:20%">
         @Html.TextBox("password", null, new { @class = "search_field", @id = "password", @Value = "" })
     </td>
      <td><input type="button" id="autogenerate" value="Auto generate" class="submit_button" /></td>
 </tr>
    
  <tr>
      <td>
         @Html.LabelFor(m => m.ConfirmPassword)
      </td>
     <td class="confirm" colspan="2">
          @Html.TextBox("confirmpassword", null, new { @class = "search_field", @id = "confirmpassword" })
      </td>

 </tr>


 </table>


CONTROLLER

        [HttpPost]
        public JsonResult GeneratePassword()
        {
           var pass = Guid.NewGuid().ToString().Substring(0, 8);


            return Json(new { password = pass });

        }

You can download the project from here : Download MVCPasswordExample