Rev 864 |
Rev 867 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.burutaru.game.entities;
import com.gebauz.bauzoid.graphics.sprite.Sprite;
import com.gebauz.burutaru.GameConsts;
import com.gebauz.burutaru.game.GameLogic;
public class PlasmaShots
extends Entity
{
// Constants========================================================================================
final int MAX_PLASMA_SHOTS =
10;
final float PLASMA_SHOT_WIDTH =
40;
final float PLASMA_SHOT_HEIGHT =
10;
final float PLASMA_SHOT_SPEED =
1500;
// Embedded Types===================================================================================
public class Shot
{
public float x =
0;
public float y =
0;
public boolean isActive =
false;
public Shot
()
{
}
public void spawn
(float _x,
float _y
)
{
x = _x
; y = _y
;
isActive =
true;
}
public void update
(float deltaTime
)
{
x += PLASMA_SHOT_SPEED
* deltaTime
;
// check for hits
if (x
> GameConsts.
VIRTUAL_SCREEN_WIDTH + PLASMA_SHOT_WIDTH
)
{
isActive =
false;
}
}
public void render
()
{
if (!isActive
)
return;
mShotSprite.
x = x
;
mShotSprite.
y = y
;
mShotSprite.
w = PLASMA_SHOT_WIDTH
;
mShotSprite.
h = PLASMA_SHOT_HEIGHT
;
mShotSprite.
centerPivot();
mShotSprite.
render();
}
}
// Fields===========================================================================================
private Sprite mShotSprite =
null;
private Shot mShotList
[] =
new Shot
[MAX_PLASMA_SHOTS
];
// Methods==========================================================================================
public PlasmaShots
(GameLogic gameLogic
)
{
super(gameLogic
);
mShotSprite =
new Sprite
(getGraphics
(),
"data/textures/plasma_shot.png");
}
@
Override
public void initAsync
()
{
mShotSprite.
initAsync();
}
@
Override
public void init
()
{
mShotSprite.
init();
for (int i =
0; i
< MAX_PLASMA_SHOTS
; i++
)
{
mShotList
[i
] =
new Shot
();
}
}
@
Override
public void exit
()
{
if (mShotSprite
!=
null)
{
mShotSprite.
dispose();
mShotSprite =
null;
}
}
@
Override
public void update
(float deltaTime
)
{
for (int i =
0; i
< MAX_PLASMA_SHOTS
; i++
)
{
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
);
break;
}
}
}
// Getters/Setters==================================================================================
}