Створення та оптимізація засобів штучного інтелекту на основі генетичних алгоритмів



Сторінка10/10
Дата конвертації12.04.2017
Розмір0.65 Mb.
1   2   3   4   5   6   7   8   9   10
0) {

cacheCanvas.drawBitmap(blik, -blik.getWidth()/2, b-blik.getHeight()/2, null);

}

if ((((angle - 90)>270 && (angle - 90)<360) || ((angle - 90)>0 && (angle - 90)<90)) && (k*width+b)0) {



cacheCanvas.drawBitmap(blik, width-blik.getWidth()/2, (k*width+b)-blik.getHeight()/2, null);

}
for(Enemy enemy : enemies){

appXcenter = enemy.getX() + apple.getWidth() / 2;

appYcenter = enemy.getY() + apple.getHeight() / 2;

if (20 > ( Math.abs(A*appXcenter + B*appYcenter + C) / Math.sqrt(B*B + A*A)) ){

if (((angle - 90)>0 && (angle - 90)<180 && (coordinates.pictureY + myBitmap.getHeight()/2)

||((angle - 90)>180 && (angle - 90)<360 && (coordinates.pictureY + myBitmap.getHeight()/2)>appYcenter)) {

enemy.setHp(enemy.getHp() - 10);

if(enemy.getHp()<1) {

hits++;


hitPoints++;

hitsForNextEnemy++;

addBlood(enemy.getX(), enemy.getY());

Random r = new Random();

appleX = r.nextInt(width - 100);

appleY = r.nextInt(height - 100);

enemy.setX(appleX);

enemy.setY(appleY);

int hp = r.nextInt(100) + 1;

enemy.setMaxHp(hp);

enemy.setHp(hp);

}

}



}

}
}


}
public void hitEnemy(){

for(Enemy enemy : enemies){

appXcenter = enemy.getX() + apple.getWidth() / 2;

appYcenter = enemy.getY() + apple.getHeight() / 2;

if (((Math.abs(appXcenter - bulletXcenter) < 30 + attackRadius) && (Math.abs(appYcenter - bulletYcenter)) < 30 + attackRadius)

||((Math.abs(appXcenter - (bulletXcenter - bullet.getWidth() * Math.cos(comboAngleBegin) / 2)) < 30 + attackRadius) && (Math.abs(appYcenter - (bulletYcenter - bullet.getHeight() * Math.sin(comboAngleBegin) / 2))) < 30 + attackRadius)

||((Math.abs(appXcenter - (bulletXcenter + bullet.getWidth() * Math.cos(comboAngleBegin) / 2)) < 30 + attackRadius) && (Math.abs(appYcenter - (bulletYcenter + bullet.getHeight() * Math.sin(comboAngleBegin) / 2))) < 30 + attackRadius)){
hits++;

hitPoints++;

hitsForNextEnemy++;

if (energy > 100){

energy = 100;

}

addBlood(enemy.getX(), enemy.getY());



Random r = new Random();

appleX = r.nextInt(width - 100);

appleY = r.nextInt(height - 100);

enemy.setX(appleX);

enemy.setY(appleY);

}

}



}
public void showUpgrades(){

if (hitPoints>speedUpgrade * 4){

cacheCanvas.drawText("HERO SPEED", width - 320, 45, upgradePaint);

cacheCanvas.drawBitmap(upgrade, width - 65, 0, null);

if (coordinates.isSpeedUp){

coordinates.isSpeedUp = false;

hitPoints = hitPoints - speedUpgrade * 4;

speedUpgrade = speedUpgrade * 4;

coordinates.speedUp = coordinates.speedUp + 1;

}

coordinates.isSpeedUp = false;



}
if (hitPoints>Math.pow(5f, (double)generatorUpgrade)){

cacheCanvas.drawText("POWER GENERATOR", width - 320, 155, upgradePaint);

cacheCanvas.drawBitmap(upgrade, width - 65, 110, null);

if (coordinates.isGeneratorUp){

coordinates.isGeneratorUp = false;

hitPoints = hitPoints - (int)Math.pow(5f, (double)generatorUpgrade);

generatorUpgrade++;

}

coordinates.isGeneratorUp = false;



}
if (hitPoints>bullSpeedUpgrade * 3){

cacheCanvas.drawText("BULLET SPEED", width - 320, 100, upgradePaint);

cacheCanvas.drawBitmap(upgrade, width - 65, 55, null);

if (coordinates.isBulletSpeedUp){

coordinates.isBulletSpeedUp = false;

hitPoints = hitPoints - bullSpeedUpgrade * 3;

bullSpeedUpgrade = bullSpeedUpgrade * 3;

bulletSpeed = (float)(bulletSpeed + 0.1);

}

coordinates.isBulletSpeedUp = false;



}

// if (coordinates.isSpeedUp){

// coordinates.isSpeedUp = false;

// if (hitPoints>speedUpgrade * 5){

// hitPoints = hitPoints - speedUpgrade * 5;

// speedUpgrade = speedUpgrade * 5;

// coordinates.speedUp = coordinates.speedUp + 1;

// }


// }

//

// if (coordinates.isGeneratorUp){



// coordinates.isGeneratorUp = false;

// if (hitPoints>Math.pow(7f, (double)generatorUpgrade)){

// hitPoints = hitPoints - (int)Math.pow(7f, (double)generatorUpgrade);

// generatorUpgrade++;

// }

// }


//

// if (coordinates.isBulletSpeedUp){

// coordinates.isBulletSpeedUp = false;

// if (hitPoints>bullSpeedUpgrade * 3){

// hitPoints = hitPoints - bullSpeedUpgrade * 3;

// bullSpeedUpgrade = bullSpeedUpgrade * 3;

// bulletSpeed = (float)(bulletSpeed + 0.1);

// }


// }

}
public void newBullet(){

isComboRunning = false;

comboAngleBegin = -1;

comboX = 0;

comboY = 0;

}
public void updateHits(){

// paint = new Paint();

textSize = 20;

text = "";

if (hits < 300) {

paint.setColor(Color.BLUE);

} else {

paint.setColor(Color.RED);

}

if (hits <= 19){



text = "You kill " + hits + " apples";

textSize = 22;

}

if (hits == 1){



if (media == 0){

media++;


mediaPlayer = MediaPlayer.create(getContext(), R.raw.firstblood);

mediaPlayer.start();

}

text = "FIRST BLOOD";



textSize = 24;

}

if (hits>19){



if (media == 1){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.ownage);

mediaPlayer.start();

appleSpeed = 4;

}

text = "You kill " + hits + " apples, OWNAGE!";



textSize = 24;

}

if (hits>49){



if (media == 2){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.megakill);

mediaPlayer.start();

skillPoint++;

}

text = "You kill " + hits + " apples, MEGA KILL!";



textSize = 24;
}

if (hits>99){

if (media == 3){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.monsterkill);

mediaPlayer.start();

appleSpeed = 5;

}

text = "You kill " + hits + " apples, MONSER KILL!";



textSize = 24;

}

if (hits>199){



if (media == 4){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.killingspree);

mediaPlayer.start();

skillPoint++;

}

text = "You kill " + hits + " apples, KILLING SPREE!";



textSize = 26;

}

if (hits>349){



if (media == 5){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.dominating);

mediaPlayer.start();

appleSpeed = 6;

}

text = "You kill " + hits + " apples, DOMINATING!";



textSize = 26;

}

if (hits>599){



if (media == 6){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.unstoppable);

mediaPlayer.start();

skillPoint++;

}

text = "You kill " + hits + " apples, UNSTOPPABLE!";



textSize = 26;

}

if (hits>999){



if (media == 7){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.whickedsick);

mediaPlayer.start();

appleSpeed = 7;

}

text = "You kill " + hits + " apples, WHICKED SICK!";



textSize = 26;

}

if (hits>1599){



if (media == 8){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.holyshit);

mediaPlayer.start();

skillPoint++;

}

text = "You kill " + hits + " apples, HOLY SHIT!!!";



textSize = 26;

}

if (hits>2399){



if (media == 9){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.combowhore);

mediaPlayer.start();

appleSpeed = 8;

}

text = "You kill " + hits + " apples, SOMEBODY STOP HIM!!!";



textSize = 28;

}

if (hits>2999){



if (media == 10){

mediaPlayer.stop();

media++;

mediaPlayer = MediaPlayer.create(getContext(), R.raw.godlike);

mediaPlayer.start();

skillPoint++;

appleSpeed = 9;

}

text = "You kill " + hits + " apples, Kill 'Em All!!!";



textSize = 28;

}
paint.setTextSize((textSize-5) * 2);

}
public void setShipParams(int currentWeapon){

if(currentWeapon == 2){

coordinates.speedUp = 4;

}

}


public void setCurrentWeapon(int currentWeapon) {

this.currentWeapon = currentWeapon;

}
@SuppressLint("NewApi")

private int getClientHeight() {

Rect rect= new Rect();

Window window = ((Activity)context).getWindow();

window.getDecorView().getWindowVisibleDisplayFrame(rect);

int statusBarHeight= rect.top;

int contentViewTop= window.findViewById(Window.ID_ANDROID_CONTENT).getTop();

int titleBarHeight= contentViewTop - statusBarHeight;


Display display = ((Activity)context).getWindowManager().getDefaultDisplay();

Point size = new Point();

display.getSize(size);

int height = size.y;

return height - statusBarHeight - titleBarHeight;

}
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)

private int getClientWidth() {

Rect rect= new Rect();

Window window = ((Activity)context).getWindow();

window.getDecorView().getWindowVisibleDisplayFrame(rect);

Display display = ((Activity)context).getWindowManager().getDefaultDisplay();

Point size = new Point();

display.getSize(size);

int width = size.x;

return width;

}
@Override

public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

}
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)

@SuppressLint("NewApi")

@Override

public void surfaceCreated(SurfaceHolder holder) {

width = getWidth();

height = getHeight();

cacheCanvas = new Canvas();

backBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); // back buffer

cacheCanvas.setBitmap(backBuffer);


Bitmap background = BitmapFactory.decodeResource(getResources(), backgrounds[backgroundId]);
Bitmap backgroundScreenParams = Bitmap.createScaledBitmap(background, width,

height, false);


mFastDF = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG, 0);
mShader = new BitmapShader(backgroundScreenParams, Shader.TileMode.MIRROR,

Shader.TileMode.MIRROR);


backgroundPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
backgroundPaint.setShader(mShader);

updateCanvas(0, 0);


isSurfaceCreated = true;
if(_thread.state==GameThread.PAUSED){

//When game is opened again in the Android OS

_thread = new GameThread(getHolder(), context, new Handler(),this);

_thread.start();

}else{

//creating the game Thread for the first time



_thread.start();

}

}


@Override

public void surfaceDestroyed(SurfaceHolder holder) {

if(_thread.state==GameThread.RUNNING){

_thread.interrupt();



}

}

}


Поділіться з Вашими друзьями:
1   2   3   4   5   6   7   8   9   10


База даних захищена авторським правом ©divovo.in.ua 2017
звернутися до адміністрації

войти | регистрация
    Головна сторінка


загрузить материал