Rev 923 |
Rev 925 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.burutaru.game.entities;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.gebauz.bauzoid.graphics.sprite.AtlasSpriteInstance;
import com.gebauz.bauzoid.graphics.sprite.Sprite;
import com.gebauz.bauzoid.graphics.sprite.SpriteInstance;
import com.gebauz.bauzoid.graphics.sprite.SpriteParameters;
import com.gebauz.bauzoid.graphics.sprite.TileBatch;
import com.gebauz.bauzoid.math.Matrix4;
import com.gebauz.bauzoid.math.Vector4;
import com.gebauz.bauzoid.math.collision.Shape;
import com.gebauz.bauzoid.math.collision.ShapeUtil;
import com.gebauz.burutaru.GameConsts;
import com.gebauz.burutaru.game.GameLogic;
public class PlasmaShots
extends Entity
{
// Constants========================================================================================
final static int MAX_PLASMA_SHOTS =
10;
final static float PLASMA_SHOT_WIDTH =
40;
final static float PLASMA_SHOT_HEIGHT =
10;
//final static float PLASMA_SHOT_SPEED = 1500;
final static float PLASMA_SHOT_SPEED =
150;
// Embedded Types===================================================================================
public class Shot
{
//public float x = 0;
//public float y = 0;
public boolean isActive =
false;
public SpriteInstance spriteInstance =
null;
public Shot
()
{
spriteInstance =
new SpriteInstance
(getGraphics
(), mShotSprite, mShotShape
);
}
public void spawn
(float x,
float y
)
{
isActive =
true;
spriteInstance.
param.
x = x
;
spriteInstance.
param.
y = y
;
spriteInstance.
param.
w = PLASMA_SHOT_WIDTH
;
spriteInstance.
param.
h = PLASMA_SHOT_HEIGHT
;
spriteInstance.
param.
centerPivot();
}
public void update
(float deltaTime
)
{
spriteInstance.
param.
x += PLASMA_SHOT_SPEED
* deltaTime
;
// check for hits
/*if (getGameLogic().checkForHit(x, y, PLASMA_SHOT_WIDTH, PLASMA_SHOT_HEIGHT))
{
isActive = false;
}*/
if (getGameLogic
().
checkForHit(spriteInstance.
getShape(), spriteInstance.
param.
getTransform()))
{
getGameLogic
().
getExplosions().
spawn(spriteInstance.
param.
x, spriteInstance.
param.
y);
isActive =
false;
}
if (spriteInstance.
param.
x > GameConsts.
VIRTUAL_SCREEN_WIDTH + PLASMA_SHOT_WIDTH
)
{
isActive =
false;
}
}
public void render
()
{
if (!isActive
)
return;
/*mShotSprite.param.x = x;
mShotSprite.param.y = y;
mShotSprite.param.w = PLASMA_SHOT_WIDTH;
mShotSprite.param.h = PLASMA_SHOT_HEIGHT;
mShotSprite.centerPivot();*/
spriteInstance.
render();
float pX = 0.03125f
;
float pY = 0.125f
;
float p2X = pX + 0.9375f
;
float p2Y = pY
;
float p3X = pX + 0.9375f
;
float p3Y = pY + 0.75f
;
float p4X = pX
;
float p4Y = pY + 0.75f
;
//Vector2 p2 = mCarrotFrames[frame].param.transformPoint(p2X, p2Y);
Matrix4 transform = spriteInstance.
param.
getTransform();
Vector4 p = transform.
transform(new Vector4
(pX, pY,
0,
1));
Vector4 p2 = transform.
transform(new Vector4
(p2X, p2Y,
0,
1));
Vector4 p3 = transform.
transform(new Vector4
(p3X, p3Y,
0,
1));
Vector4 p4 = transform.
transform(new Vector4
(p4X, p4Y,
0,
1));
//Gdx.app.log("BLA", "1) " + p2.x + ", " + p2.y + " - " + p.x + ", " + p.y + ", " + p.z + ", " + p.w);
mTester.
param.
x = p.
x;
mTester.
param.
y = p.
y;
/*mTester.param.w = p2.x-p.x;
mTester.param.h = p2.y-p.y;
mTester.param.pivotX = 0;
mTester.param.pivotY = 0;*/
mTester.
param.
w =
4;
mTester.
param.
h =
4;
mTester.
param.
centerPivot();
mTester.
render();
mTester.
param.
x = p2.
x;
mTester.
param.
y = p2.
y;
mTester.
render();
mTester.
param.
x = p3.
x;
mTester.
param.
y = p3.
y;
mTester.
render();
mTester.
param.
x = p4.
x;
mTester.
param.
y = p4.
y;
mTester.
render();
}
}
// Fields===========================================================================================
private Sprite mShotSprite =
null;
private Shape mShotShape =
null;
private Shot mShotList
[] =
new Shot
[MAX_PLASMA_SHOTS
];
private Sound mShotSound =
null;
private Sprite mTester =
null;
// Methods==========================================================================================
public PlasmaShots
(GameLogic gameLogic
)
{
super(gameLogic
);
mShotSprite =
new Sprite
(getGraphics
(),
"data/textures/plasma_shot.png");
mTester =
new Sprite
(getGraphics
(),
"data/textures/tester.png");
}
@
Override
public void initAsync
()
{
mShotSprite.
initAsync();
mTester.
initAsync();
}
@
Override
public void init
()
{
mTester.
init();
mShotSound = getAudio
().
newManagedSound("data/sounds/plasma_shot.wav");
mShotShape = ShapeUtil.
createShapeFromFile("data/textures/plasma_shot.shape");
mShotSprite.
init();
mShotSprite.
getTexture().
setFilter(TextureFilter.
Linear, TextureFilter.
Linear);
for (int i =
0; i
< MAX_PLASMA_SHOTS
; i++
)
{
mShotList
[i
] =
new Shot
();
}
}
@
Override
public void exit
()
{
mShotShape =
null;
if (mTester
!=
null)
{
mTester.
dispose();
mTester =
null;
}
if (mShotSprite
!=
null)
{
mShotSprite.
dispose();
mShotSprite =
null;
}
if (mShotSound
!=
null)
{
getAudio
().
removeManagedSound(mShotSound
);
mShotSound =
null;
}
}
@
Override
public void update
(float deltaTime
)
{
for (int i =
0; i
< MAX_PLASMA_SHOTS
; i++
)
{
if (mShotList
[i
].
isActive)
mShotList
[i
].
update(deltaTime
);
}
}
@
Override
public void render
()
{
for (int i =
0; i
< MAX_PLASMA_SHOTS
; i++
)
{
mShotList
[i
].
render();
}
}
public void spawnShot
(float x,
float y
)
{
for (int i =
0; i
< MAX_PLASMA_SHOTS
; i++
)
{
if (!mShotList
[i
].
isActive)
{
mShotList
[i
].
spawn(x, y
);
mShotSound.
play();
break;
}
}
}
// Getters/Setters==================================================================================
}