Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Google's Fun Facts

Google's Fun Facts.

Use Google to learn a Quick Facts each day, Go to www.google.com and search "Fun Facts", you will get some interesting information to read. The result could be any fun facts from any of the information in this world or out of the world. Give it a try, you will be surprised with some of the facts.


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.





Most Difficult Hardest Android Games

Most Difficult Hardest Android Games 

1) World's Hardest Game


(Crossing More than 6th stage is difficult)



Description:
This is The World’s Hardest Game! Work your way through 30 incredibly hard levels, and if you can finish all of them you can compete for a spot on the world leader board!
Instructions:
You are RED square, avoid the BLUE circles and collect Yellow circles. Once you have collected all the yellow circles move to GREEN beacon to complete the level.
Your score is a reflection of how many times you have died; the less, the better.

2) Parachute Penguins


(Crossing More than 8 Level is Difficult)



Description:

Parachute Penguins. Save Penguins from the hungry and sharp jaws of Sharks waiting at the bottom of the sea.
Make use of Three Exciting Bonus Powers
1) Freeze - Freeze the flappy penguins bird for short period of time in the sky and let you save the penguins easily
2) Slow Motion - Flappy penguins bird drop at slow motion which will give you plenty time to save the penguins before it drops to sea under waiting sharks jaw.
3) Brush - Just swipe the screen with your finger to save multiple flappy bird penguins at the same time. This makes you little easier to save the penguins for particular period of time.
Bonus Powers Drop from the sky.
Frequently Bonus Powers Drop from the sky along with the the cute parachute penguins, catch Bonus Power Parachutes to increase your bonus power counts.
KidMode
KidMode Suitable for your kids to play, Save flappy bird penguins by just swiping the screen. KidMode doesnt support Highscore but it has 100 Life and just swiping the screen saves the flappy bird penguins drop from parachute.


3) Hardest Game Ever 2


Description:
Hardest Game Ever 2 is a series of fun and exciting mini-game that measures your reaction time to the milliseconds and pixels! See how fast you can slap and how sharp is your reaction to catch the eggs before they touch the floor in milliseconds! Hardest Game Ever 2 promises to bring you hours of adrenaline drain! Challenge your family and friends and find out who's got the fastest reaction on Android!
Featuring:
- Simple 3 Button Control
- 48 Stages with 4 Challenging Levels
- Ranking with Facebook Pals
- Simple yet addictive gameplay
- Multi-language Instructions