How to make an AI Enemy Car in which it follows the track during the Race ?

The AI for enemy car can be done by using waypoints method..

the following code is used

var waypoint : Transform[];

var speed : float =20;

private var currentWaypoint : int;

var loop : boolean = true;

function Awake()

{waypoint[0]=transform;}

function Update ()

{ if(currentWaypoint < waypoint.Length)

{ var target : Vector3 = waypoint[currentWaypoint].position;

var moveDirection : Vector3 = target-transform.position;

var velocity = rigidbody.velocity;

if(moveDirection.magnitude<1)

{ currentWaypoint++;}

else { velocity = moveDirection.normalized * speed;  //velocity = Vector3.forward * speed; }  }

else { if(loop)  {  currentWaypoint=0; }

else   { velocity = Vector3.zero; }

} rigidbody.velocity = velocity;

}

 

How to move the image on touch in android


image.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
layoutParams1 = (RelativeLayout.LayoutParams) image.getLayoutParams();

switch(event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
break;

case MotionEvent.ACTION_UP:
x_cord = (int) event.getRawX();
if (x_cord la.getWidth()) {
x_cord= la.getWidth();
if(isCouponbuttonscroll==false){
isCouponbuttonscroll=true;
showDialog();
}
}
if (x_cord <windowwidth-la.getWidth()) {
x_cord =windowwidth-la.getWidth();
}
layoutParams1.leftMargin = x_cord -(image.getWidth()+0);
image.setLayoutParams(layoutParams1);
image.bringToFront();
image.setPadding(5, 5, 5, 5);

break;
}
return true;
}
});

How to pick music file from music library in iPhone application

Like UIImagePickerView to pick image from image gallery we can also pick up any music file from the music gallery of the device and can use it in our application with the help of MPMediaPickerController.

For that you need to add AVFoundation framework in your application. also to play the picked file we need to add MediaPlayer framework. and to use them just import them in respective view controller. Also in .h file you have to add MPMediaPickerControllerDelegate.

In button click action  write the following

MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

picker.delegate = self;

picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController: picker animated: YES];

This will present a controller from where we will be able to access the device’s music library. Also to get the picked file override the delegate method

– (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {

// Dismiss the media item picker.

[self dismissModalViewControllerAnimated: YES];

MPMediaItem *item = [[mediaItemCollection items] objectAtIndex:0];

NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];

[self dismissModalViewControllerAnimated: YES];

// Play the item using MPMusicPlayer

MPMusicPlayerController* appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];

[appMusicPlayer setQueueWithItemCollection:mediaItemCollection];

[appMusicPlayer play];

AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];

AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];

[player play];

}

Done. Now you can play any music file from device music library into your application.

Happy Coding…..!

 

Custom Fonts in Blackberry Application

Download the .ttf (True Type Font)file and include it in src folder.

Include this code into the constructor.

EditField edField1 = new EditField (“”, “TestEditField”, 30, EditField.READONLY| EditField.FIELD_VCENTER){
protected void layout(int width, int height)
{
super.layout(customWidth, customHeight);
setExtent(customWidth, customHeight);
}
};

Font fo3 = loadCustomFonts(“digital-7.ttf”, “ThirdFont”, 0, 40);
edField1.setFont(fo3);

 

Include this function.

public Font loadCustomFonts (String path, String fontname,int fontStyle, int fontSize){
InputStream stream = this.getClass().getResourceAsStream(path);
if (FontManager.getInstance().load(stream, fontname,                 FontManager.APPLICATION_FONT) == FontManager.SUCCESS){
try{
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
}
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
}
else {
try{
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
}
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
}
return null;
}

By Using this we can add custom font into our Application.

thank you.

How to get parameters passed to a URL in salesforce apex

If we pass parameter while creating a page in salesforce apex like this

public PageReference setParameter()

{

public papageReference ref = new PageReference(‘/apex/print?email=’ + textEmail1);    ref.setRedirect(true);

return ref;

}

where email is the parameter. Then using the following function we can get the value of the parameter passed

public getParameter()

{

email = ApexPages.currentPage().getParameters().get(’email’);

}

Function For returning Multiple values in iphone

Function For returning Multiple values in iphone
– (void)viewDidLoad
{
[super viewDidLoad];

//Return In Dictionary
NSDictionary *FullName = [Self FullnameDict:@”AAAA,BBBB”];

NSString *FName = [Name objectForKey:@”firstame”];
NSString *LName = [Name objectForKey:@”lastname”];

//Return In Array
NSArray *FullName1 = [Self FullnameArray:@”AAAA,BBBB,CCCC”];

NSString *FName1 = [FullName1 objectAtIndex:0];
NSString *MName1 = [FullName1 objectAtIndex:1];
NSString *LName1 = [FullName1 objectAtIndex:2];
}

– (NSDictionary *)FullnameDict :(NSString *)responseData;
{
NSString *FullName = [NSString stringWithFormat:@”%@”,responseData];
NSArray *NameArray = [FullName componentsSeparatedByString:@”,”];

NSString *FName = [NSString stringWithFormat:@”%@”,[NameArray objectAtIndex:0]];
NSString *LName = [NSString stringWithFormat:@”%@”,[NameArray objectAtIndex:1]];

return [NSDictionary dictionaryWithObjectsAndKeys:FName, @”FName”,LName, @”LName”, nil];
}

– (NSArray *)FullnameArray :(NSString *)responseData;
{
NSString *FullName = [NSString stringWithFormat:@”%@”,responseData];
NSArray *NameArray = [FullName componentsSeparatedByString:@”,”];

return NameArray;
}

Conversion of NSString to NSDate and NSDate to NSString

 

Here is the way to convert NSDate to NSString in objective C

Conversion of NSDate to NSString :

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

[dateFormat setDateFormat:@”yyyy-dd-MMM”];

NSString *dateString = [dateFormat stringFromDate:today];

NSLog(@”date: %@”, dateString);

[dateFormat release];

Note that today should be your NSDate object which you want to convert to NSString.

Conversion from NSString to NSDate :

NSString *dateString = @”01-02-2010″;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@”dd-MM-yyyy”];

NSDate *dateFromString = [[NSDate alloc] init];

dateFromString = [dateFormatter dateFromString:dateString];

[dateFormatter release];

You can set the date format which you want.

So simple…..!!!!!!! Enjoy coding…….!!!!!

 

 

 

 

Extracting data from Apple iTunes

I tried a lot to find RSS feeds for latest apps getting posted on Apple iTunes store under all categories but couldnt find anywhere, not sure why Apple does not provide such feed.

So I decided to write one of my own and below is how I accomplished the task using curl in php. Through httpfiddler I first out request headers sent by iTunes software and used the same.

 

<?php

function gunzip($zipped) {
$offset = 0;
if (substr($zipped,0,2) == "x1fx8b")
$offset = 2;
if (substr($zipped,$offset,1) == "x08")  {
# file_put_contents("tmp.gz", substr($zipped, $offset - 2));
return gzinflate(substr($zipped, $offset + 8));
}
return "Unknown Format";
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/browse?path=%2F36%2F6000%2F1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Apple-Tz: 29600',
'X-Apple-Store-Front: 253477,27',
'Accept-Encoding: gzip',
'Accept-Language: en-us, en;q=0.50',
));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo gunzip($output);

?>

 

 

 

How to import Chinese characters in Mysql Table?

I know proper way to do this does exists but I was falling short of time and wasnt able to find perfect solution, so used this a way around to import a list of chinese cities in chinese language to one of my mysql table.

1. 1st changed the table structure to make the city field collation as big5_chinese_ci

2. I had the list of chinese cities in chinese language in excel sheet. Using a small VBA below code, i created mysql insert into query for each of the record:

Sub CreateQueries()
      r1 = 1
      While Range(“A” & r1) <> “”
           Range(“C” & r1) = “insert into cities values(‘” & Range(“A” & r1) & “‘);”

        r1 = r1 + 1
      Wend
End Sub

3. Then just copy pasted all these generated queries in mysql SQL window and executed the queries and I had proper characters in mysql table 🙂

Initially, I tried to export excel to csv and then importing it in mysql, but it was showing ???? symbols in mysql after import. So this turned out to be cool quick solution. Hope it can help somebody solve similar problem I was facing.