Alien shooter : A HTML 5 game

This game is developed in HTML 5 using canvas and Javascript. The objective of the game is to shoot all the enemies. The enemies also shoot at the player. The background is scrolled in order to give a fast moving action feel. Sprites are self made.

 

introScreen

This is the main menu

 

 

Game screen

Game screen

Download : https://app.box.com/s/7ualzgwo88nuqf5720ha

Painting a Circle using TouchListener in Android

This program is used to create a colored circle using a View context whenever the user touch the screen.The color generated is random and changes rapidly when dragged…

Note:A basic knowledge in Android needed .

Project structure:-


Source 1:

This is the Activity class.We simply create an instance of our “drawingView” class(which extends View) and add it to current content view…

package com.android;

import android.app.Activity;
import android.os.Bundle;

public class Activity1 extends Activity{
    /** Called when the activity is first created. */

    drawingView dview;                    //creating the reference

    public void onCreate(Bundle savedInstanceState)
   {
        super.onCreate(savedInstanceState);
        dview=new drawingView(this); //creating the instance
        setContentView(dview);         //adding to the activity
    }
}

Source 2:

This is our “drawingView” class which extends the “View” class from “import android.view.View” package.  This class contains the following logic,

  • Generating a random color value .
  • Implements “OnTouchListener” for generating touch events.
  • Drawing the circle.
package com.android;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class drawingView extends View implements OnTouchListener{

	static int x,y,r=255,g=255,b=255;
	final static int radius=30;
	Paint paint;     //using this ,we can draw on canvas

	public drawingView(Context context)
	{
		super(context);
	        paint=new Paint();
		paint.setAntiAlias(true);       //for smooth rendering
		paint.setARGB(255, r, g, b);    //setting the paint color

		//to make it focusable so that it will receive touch events properly
		setFocusable(true);

		//adding touch listener to this view
		this.setOnTouchListener(this);
	}

	//overriding the View's onDraw(..) method
	public void onDraw(Canvas canvas)
	{
		paint.setARGB(255, r, g, b);

		//drawing the circle
		canvas.drawCircle(x,y,radius,paint);

	}

	//this is the interface method of "OnTouchListener"
	public boolean onTouch(View view,MotionEvent event)
	{
		x=(int)event.getX()-(radius/2);      //some math logic to plot the circle  in exact touch place
		y=(int)event.getY()-(radius/2);
		  //System.out.println("X,Y:"+"x"+","+y);      //see this output in "LogCat"
		randColor();       //calls this method to generate a color before drawing
		invalidate();      //calls onDraw method
		return true;
	}

	//this method sets a random color using Math.random()
	//Note: RGB color values ranges from 0 to 255..
	public void randColor()
	{
		r=(int)(Math.random()*255);
		g=(int)(Math.random()*255);
		b=(int)(Math.random()*255);
		//Toast.makeText(c, "r,g,b="+r+","+g+","+b,Toast.LENGTH_SHORT).show();
	}
}

Output:
Some screenshots in Emulator,

This slideshow requires JavaScript.

Note:The above slideshow(a wordpress plugin) has some bug and so it displays the file structure picture…ignore it