Showing posts with label Software. Show all posts
Showing posts with label Software. Show all posts

Develop your first Android Game

How to develop android games?

Developing android games is simpler than you think.

Check out this android game. Which is built using this technique.
Save Super Penguins
https://play.google.com/store/apps/details?id=com.positivesthinking.parachutepenguinsfree


Before starting the tutorial familiar yourself with android.

1. Set up the Android Workspace
https://developer.android.com/training/basics/firstapp/index.html

2. Create your Hello World Android application
https://developer.android.com/training/basics/firstapp/creating-project.html

Lets start the game development.

Just follow this Four Steps to start your first simple android game.
Step 1: Create a Game Loop Thread that renders the Frames.
Step 2: Create a SurfaceView class that will show the game UI and controls the game.
Step 3: Create a Image handler class that will help you in collision detection and loading bitmap images.
Step 4: Wire up your MainActivity.

Post your comments in case of any difficulty and help.

Step 1: Create a Game Loop Thread that renders the Frames.
MainThread.java.
package com.coolcomputerpctricks.tutorialgame;
import android.graphics.Canvas;
import android.util.Log;
import android.view.SurfaceHolder;

/** 
 *  www.coolcomputerpctricks.com
 *  Android Game development tutorial * 
 */

public class MainThread extends Thread {
 
 private static final String TAG = MainThread.class.getSimpleName();
 
 // Frames Per seconds
 public  int MAX_FPS = 150; 
 private  int FRAME_PERIOD = 1000 / MAX_FPS; 
 private SurfaceHolder surfaceHolder;
 private ViewGamePlay gamePanel;
 private boolean running;
 
 public void setRunning(boolean running) {
  this.running = running;
 }

 public MainThread(SurfaceHolder surfaceHolder, ViewGamePlay gamePanel) {
  super();
  this.surfaceHolder = surfaceHolder;
  this.gamePanel = gamePanel;
 }

 @Override
 public void run() {
  Canvas canvas;
  long beginTime;  
  long timeDiff;  
  int sleepTime;  
  sleepTime = 0;
  while (running) {   
   canvas = null;
   try {
    canvas = this.surfaceHolder.lockCanvas();
    synchronized (surfaceHolder) {
     beginTime = System.currentTimeMillis();
     this.gamePanel.render(canvas);    
     timeDiff = System.currentTimeMillis() - beginTime;
     sleepTime = (int)(FRAME_PERIOD - timeDiff);
     if (sleepTime > 0) { 
      try {
       Thread.sleep(sleepTime); 
      } catch (InterruptedException e) {}
     }
     
    }
   } finally {
    if (canvas != null) {
     surfaceHolder.unlockCanvasAndPost(canvas);
    }
   } 
  }
 } 
}

Step 2: Create a SurfaceView class that will show the game UI and controls the game.
ViewGamePlay.java
package com.coolcomputerpctricks.tutorialgame;

import java.util.Random;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
/** 
 *  www.coolcomputerpctricks.com
 *  Android Game development tutorial * 
 */

public class ViewGamePlay extends SurfaceView{

 
 MainThread thread;
 ItemImages bgImage,parachute;
 int max,min;
 
 public ViewGamePlay(Context context) {
  super(context);
  thread = new MainThread(getHolder(), this);
  getHolder().addCallback(new SurfaceHolder.Callback() {
   public void surfaceDestroyed(SurfaceHolder holder) {
    boolean retry = true;
    while (retry) {
     try {
      thread.setRunning(false);
      thread.join();
      retry = false;
     } catch (Exception e) {
      e.printStackTrace();      
     }
    }
   }
   public void surfaceCreated(SurfaceHolder holder) {
           
     Canvas c = holder.lockCanvas(null);
     initializeGame(c);
     drawGame(c);
     holder.unlockCanvasAndPost(c); 
     thread.setRunning(true);
     try{
      thread.start();
     }catch(Exception e){
      e.printStackTrace();
     }
   }

   public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    //Surface changed
   }
  });  

 }



 public void initializeGame(Canvas canvas){
  
  bgImage =  new  ItemImages(BitmapFactory.decodeResource(getResources(), R.drawable.sky),0,0);
  parachute = new  ItemImages(BitmapFactory.decodeResource(getResources(), R.drawable.parachute),0,0);
  
  //Random left position for the parachute
  max=(int) (canvas.getWidth()-parachute.getWidth());
  min=0;
  Random rand = new Random();  
  int randomNum = rand.nextInt((max - min) + 1) + min;
  parachute.setLeft(randomNum);
 
 }
 
 protected void drawGame(Canvas canvas) { 
  
  bgImage.drawBMP(canvas);
  parachute.drawBMP(canvas);
   
 } 
 
 
 public boolean onTouchEvent(MotionEvent event) {
  float x = event.getX();
  float y = event.getY();
  if(parachute.isCollition(x, y))
   {
    // If player touched, reset the parachute location
    parachute.setTop(0);
    Random rand = new Random();  
    int randomNum = rand.nextInt((max - min) + 1) + min;
    parachute.setLeft(randomNum);
    
   }
  return true;
 }
 
 public void render(Canvas canvas) {
  
  parachute.setTop(parachute.getTop()+2);
  
  if(parachute.getTop()>canvas.getHeight()){
   parachute.setTop(0);
   // Reset the parachute location
   parachute.setTop(0);
   Random rand = new Random();  
   int randomNum = rand.nextInt((max - min) + 1) + min;
   parachute.setLeft(randomNum);
  }  
  drawGame(canvas);
 }
 
 
}


Step 3: Create a Image handler class that will help you in collision detection and loading bitmap images.
ItemImages.java
package com.coolcomputerpctricks.tutorialgame;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Rect;


/** 
 *  www.coolcomputerpctricks.com
 *  Android Game development tutorial * 
 */

public class ItemImages {
 private float width;
    private float height;
    private float left;
    private float top;
    private Bitmap bmp;
    private boolean visible; 
    
    public ItemImages(Bitmap bmp,float left, float top)
    {
     this.width = bmp.getWidth();  
        this.height = bmp.getHeight();
        this.bmp=bmp;
  this.left=left;
  this.top=top;
  this.setVisible(true);
    }
    public void setBmp(Bitmap bmp) {
  this.bmp = bmp;
 }
 public void drawBMP(Canvas canvas) {
  if(canvas!=null && bmp!=null)
   canvas.drawBitmap(bmp, left, top, null);
    }
    public void drawBMP(Canvas canvas,Rect src,Rect dst) {
  if(canvas!=null && bmp!=null)
   canvas.drawBitmap(bmp, src, dst, null);
    }
    public boolean isCollition(float x2, float y2) {
        return x2 > left && x2 < left + width && y2 > top && y2 < top + height;
    }
 public float getWidth() {
  return width;
 }
 public void setWidth(float width) {
  this.width = width;
 }
 public float getHeight() {
  return height;
 }
 public void setHeight(float height) {
  this.height = height;
 }
 public float getTop() {
  return top;
 }
 public void setTop(float top) {
  this.top = top;
 }
 public float getLeft() {
  return left;
 }
 public void setLeft(float left) {
  this.left = left;
 }
 public boolean isVisible() {
  return visible;
 }
 public void setVisible(boolean visible) {
  this.visible = visible;
 } 
}

Step 4: Wire up your MainActivity.
MainActivity.java


package com.coolcomputerpctricks.tutorialgame;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
/** 
 *  www.coolcomputerpctricks.com
 *  Android Game development tutorial * 
 */

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  setContentView( new ViewGamePlay(this)); 
 }


}

Here is the two images used in this tutorial


Sky.png

parachute.png




Download Project here

GitHub - https://github.com/karthikeyan98/SimpleGame-AndroidExample

Post your comments for any doubts and helps.





Are we trusting Google too much?

Are we trusting Google too much?

1. why should chrome warn us with a message when we clear browsing history?


Whenever we try to clear browsing history, chromes tells that there is incognito mode to use, is Google worried if you clear your entire browsing history from chrome?

What does Google do with your browsing history?
Here's a clear evidence, "YouTube", Google's YouTube shows video contents relevant to our browsing history stored in chrome. that's how your information is used to make you use their product(YouTube) more than what you do normally.
you can find the difference when you go to "YouTube" home page in both conditions
1. first without browsing history - everything cleared in chrome- visit YouTube home page
2. after doing couple of Google searches, let chrome shows some history and visit YouTube, you will feel the difference

2. why should chrome has separate log in session separating it from other google products.

when you logged in chrome, also when you logged in some of other google product like gmail, when you signout of gmail,chrome logged in session wont go.

chrome separate login session stores all your data ( you can control it by visiting settings, how many of us do that, what about people who doesn't have enough computer experience to change the settings ) user specific data stored in each of our google account right from browsing history to form input data's.

3. How does google map works - showing traffic information in the road we travel.



It does collect our location information including in which speed we are traveling, it collects every one who uses android mobile or signed in to google map atleast once and using some algorithm it gives back.


4. What will happen with Google Glass?

                    XX_____XX 

5. Not just above four items, there are lot more things.. like

     At first time when you open Google Chrome, it asks you to sign in with Google account. How many of you signed in without knowing that it is a log in for Google chrome to save your personal browsing data  in your account?
      Many would have no idea initially that it is a log-in specially for Google Chrome. and would have signed in directly thinking it is normal google product sign-in.

 Obviously, we are very much benefited and addicted to all those products, and there are ways we can control sharing our data to a certain level, but how many of us are really concerned about it, going to settings, searching where it is and switching it off?

Make Desktop wallpaper screensaver unchangeable

Make Your Desktop Wallpaper , ScreenSaver to be unchanged by anyone.



This trick is for Windows 7, it will work with windows vista and previous versions as well.



Step1: Open Run Window..



To open Run Window press( WindowsKey+R) or Click StartMenu and type Run to get it





Step2: Enter gpedit.msc in Run Window and press enter.



Step3: Now the Local Group Policy Editor Window will be opened ( look the picture below )







Step4: In the Left Pane of Local Group Policy Editor window Click User Configuration--> Templates ( look the picture below )







Step5: In the Right Pane of Local Group Policy Editor window Double Click Control Panel ( look the picture below )





Step6: Now In the Right Pane of Local Group Policy Editor window Open Personalization--> Changing desktop background ( look the picture below )







Step8: Now you will get a Prevent changing desktop background window, click Enabled Option and press Ok. ( look the picture below )







Step9: Now you can’t change your Desktop background Image. ( look the picture below )







Step10: To Once again Make the Desktop background to changeable Make the Option as Not Configured in Prevent changing desktop background window.



Step 11: Do the Same for Screen saver, Desktop icons, mouse pointers etc..

Google Chrome gets a new Icon

Google Chrome icon changed


New Chrome ICON
Old Chrome ICON


The new Google Chrome Icon is very simple and looks like it's a 2 dimension of the old chrome icon.

The new Icon has been changed automatically for all the users of chrome browser. it seems like update is going on for the application without the users knowledge.

Simple things are always powerful - secret of Google.

Make Acrobat Reader load faster

Make Acrobat Reader load faster

1. Go to C:\Program Files\Adobe\Acrobat 6.0\Reader (replace the C if you installed on another drive, like I did).

2. Create a new folder called plug_ins_disabled.

3. Move all files from the plug_ins folder to the plug_ins_disabled folder except EWH32.api, printme.api, and search.api. There should only be these 3 files in the plug_ins folder.

4. You're done.

Photoshop Shortcuts for Tools

Photoshop Shortcuts for Tools

m : Marquee Tool
l : Lasso Tool
j : Airbrush Tool
b : Paintbrush Tool
s : Rubber Stamp Tool
y : History Brush Tool
e : Eraser Tool
n : Pencil Tool
r : Blur Tool


o : Dodge Tool
p : Pen Tool
t : Type Tool
u : Measure Tool
g : Linear Gradient Tool
k : Paint Bucket Tool
i : Eyedropper Tool
h : Hand Tool
z : Zoom Tool. Double click on the Zoom tool will zoom document to 100%.
d : Set Default foreground (white) and background (black) colors.
x : Switches between foreground and background colors.
q : Switches between standard mode or quick mask mode.