Monday , January 10 2022

Android Game Development Tutorial – Simple 2d Game Part 2 – Android Coding by DMTechnolab

The package The trap.Simplified coding.Astronaut;

Import Android.App.The activity;

Import Android.App.AlertDialog;

Import Android.App.Service;

Import Android.Content.Component Name;

Import Android.Content.Context;

Import Android.Content.Dialog interface;

Import Android.Content.Intent;

Import Android.Content.Serviceconnect;

Import Android.Content.Sharing;

Import Android.The graphics.Canvas;

Import Android.The graphics.colour;

Import Android.The graphics.colour;

Import Android.The graphics.Cult;

Import Android.Media.media Player;

Import Android..IBinder;

Import Android.Opinion.Motion;

Import Android.Opinion.Surfaceorder;

Import Android.Opinion.Surface view;

Import Android.Widget.Toast;

Import Java.Useful.array list;

public class Gameview Is spread Surface view come into force Moveable {{

Unstable Boolean Are playing;

Private The thread GameThread = Invalid;

Private The player The player;

Private colour colour;

Private Canvas Canvas;

Private Surfaceorder Surface folder;

Private Enemy enemy;

// Made a reference to class friend

Private friend friend;

Private array list<Star> Stars = New

array list<Star>());

// Defining a boom object to display the explosion

Private Boom Boom;

public Gameview()Context The reference, int The script, int Screen) {{

Super()The reference);

The player = New The player()The reference, The script, Screen);

Surface folder = getHolder());

colour = New colour());

int StarNums = 100;

For ()int I am = 0; I am < StarNums; I am++) {{

Star s = New Star()The script, Screen);

Stars.Add up()s);

}

// single enemy initialization

enemy = New Enemy()The reference, The script, Screen);

// early boom object

Boom = New Boom()The reference);

// Initialize Friend Class Object

friend = New friend()The reference, The script, Screen);

}

@Override

public Zero Daud()) {{

whereas ()Are playing) {{

Update());

To pull());

Control());

}

}

Private Zero Update()) {{

The player.Update());

// Installing Boom Off Screen

Boom.setX()250);

Boom.Sets()250);

For ()Star s : Stars) {{

s.Update()The player.Get()));

}

enemy.Update()The player.Get()));

// If there is a conflict with the player

If ()Cult.The squares()The player.getDetectCollision()), enemy.getDetectCollision()))) {{

// the bounce appearing at that location

Boom.setX()enemy.getX()));

Boom.Sets()enemy.Get()));

// will play a sound on the collision between the player and the enemy

enemy.setX()200 rupees);

}

// coordinates updating friend ships

friend.Update()The player.Get()));

}

Private Zero To pull()) {{

If ()Surface folder.getSurface()).This is correct())) {{

Canvas = Surface folder.Lockcanvas());

Canvas.To summon()colour.Black);

colour.Setcolor()colour.White);

colour.set on()20);

For ()Star s : Stars) {{

colour.setStrokeWidth()s.getStarWidth()));

Canvas.Droppoint()s.getX()), s.Get()), colour);

}

Canvas.Drawbatmap()

The player.getBitmap()),

The player.getX()),

The player.Get()),

colour);

Canvas.Drawbatmap()

enemy.getBitmap()),

enemy.getX()),

enemy.Get()),

colour

);

// drawing boom image

Canvas.Drawbatmap()

Boom.getBitmap()),

Boom.getX()),

Boom.Get()),

colour

);

// Drawing friends

Canvas.Drawbatmap()

friend.getBitmap()),

friend.getX()),

friend.Get()),

colour

);

Surface folder.unlockCanvasAndPost()Canvas);

}

}

Private Zero Control()) {{

try {{

GameThread.Sleep()1.);

} Hold ()Hindrance I) {{

I.Printstacktress());

}

}

public Zero Stay()) {{

Are playing = false;

try {{

GameThread.Join());

} Hold ()Hindrance I) {{

}

}

public Zero Resume()) {{

Are playing = True;

GameThread = New The thread()this);

GameThread.Start());

}

@Override

public Boolean onTouchEvent()Motion Speed) {{

to switch ()Speed.Gotation()) And Motion.ACTION_MASK) {{

matter Motion.ACTION_UP:

The player.stop());

break;

matter Motion.ACTION_DOWN:

The player.Setboosting());

break;

}

The return True;

}

}


Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

Leave a Reply

Your email address will not be published. Required fields are marked *