Rev 859 |
Rev 867 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.burutaru.game.entities;
import java.util.Vector;
import com.gebauz.bauzoid.graphics.sprite.AtlasSprite;
import com.gebauz.bauzoid.graphics.sprite.AtlasSpriteInstance;
import com.gebauz.bauzoid.math.MathUtil;
import com.gebauz.burutaru.game.GameLogic;
public class BlobEnemies
extends Entity
{
// Constants========================================================================================
public final int INITIAL_NUM_INSTANCES =
16;
public final int NUM_FRAMES_X =
4;
public final int NUM_FRAMES_Y =
4;
public final int NUM_FRAMES = NUM_FRAMES_X
* NUM_FRAMES_Y
;
public final int FRAME_SIZE =
128;
public final int SPRITE_SIZE =
80;
public final float ANIM_SPEED =
15;
// Embedded Types===================================================================================
public class Instance
{
public float x
;
public float y
;
public float lifeTime = 0.0f
;
public Instance
(float _x,
float _y
)
{
x = _x
; y = _y
;
lifeTime = 0.0f
;
}
public void update
(float deltaTime
)
{
lifeTime += deltaTime
;
}
public void render
()
{
int frame = MathUtil.
clamp((int)((lifeTime
* ANIM_SPEED
) % NUM_FRAMES
),
0, NUM_FRAMES-
1);
mBlobFrames
[frame
].
x = x
;
mBlobFrames
[frame
].
y = y
;
mBlobFrames
[frame
].
w = SPRITE_SIZE
;
mBlobFrames
[frame
].
h = SPRITE_SIZE
;
mBlobFrames
[frame
].
centerPivot();
mBlobFrames
[frame
].
render();
}
}
// Fields===========================================================================================
private Vector<Instance
> mEnemies =
new Vector<Instance
>();
private AtlasSprite mBlobEnemySprite =
null;
private AtlasSpriteInstance mBlobFrames
[] =
new AtlasSpriteInstance
[NUM_FRAMES
];
// Methods==========================================================================================
public BlobEnemies
(GameLogic gameLogic
)
{
super(gameLogic
);
mBlobEnemySprite =
new AtlasSprite
(getGraphics
(),
"data/textures/blob_enemy.png",
"data/textures/blob_enemy.txt");
}
@
Override
public void initAsync
()
{
mBlobEnemySprite.
initAsync();
}
@
Override
public void init
()
{
mBlobEnemySprite.
init();
mBlobEnemySprite.
createSpriteInstances(mBlobFrames
);
spawn
(480,
280);
}
@
Override
public void exit
()
{
for (int i =
0; i
< NUM_FRAMES
; i++
)
mBlobFrames
[i
] =
null;
if (mBlobEnemySprite
!=
null)
{
mBlobEnemySprite.
dispose();
mBlobEnemySprite =
null;
}
}
@
Override
public void update
(float deltaTime
)
{
for (int i =
0; i
< mEnemies.
size(); i++
)
{
mEnemies.
get(i
).
update(deltaTime
);
}
}
@
Override
public void render
()
{
for (int i =
0; i
< mEnemies.
size(); i++
)
{
mEnemies.
get(i
).
render();
}
}
public void spawn
(float x,
float y
)
{
mEnemies.
add(new Instance
(x, y
));
}
// Getters/Setters==================================================================================
}