let gba engine auto-detect changes to scene

This commit is contained in:
wgroeneveld 2018-08-09 20:09:25 +02:00
parent b6c461ad4d
commit e457021953
3 changed files with 13 additions and 11 deletions

View File

@ -63,7 +63,7 @@ VECTOR randomDestinations[6] = {
void FoodScene::tick(u16 keys) { void FoodScene::tick(u16 keys) {
avatar->animateToFrame(0); avatar->animateToFrame(0);
bool bulletAdded, allowedToShoot; bool allowedToShoot = false;
if(bulletCooldown > 0) { if(bulletCooldown > 0) {
bulletCooldown--; bulletCooldown--;
@ -78,7 +78,6 @@ void FoodScene::tick(u16 keys) {
TextStream::instance().setText(std::string("angle pc/pd: ") + hex(avatar->getMatrix()->pc) + std::string("/") + hex(avatar->getMatrix()->pd), 4, 1); TextStream::instance().setText(std::string("angle pc/pd: ") + hex(avatar->getMatrix()->pc) + std::string("/") + hex(avatar->getMatrix()->pd), 4, 1);
/* /*
int defaultx = hex_int(GBA_SCREEN_WIDTH / 2 - 20), defaulty = hex_int(GBA_SCREEN_HEIGHT - 20); int defaultx = hex_int(GBA_SCREEN_WIDTH / 2 - 20), defaulty = hex_int(GBA_SCREEN_HEIGHT - 20);
auto newx = toDecimal((avatar->getMatrix()->pa * defaultx + avatar->getMatrix()->pb * defaulty) >> 8); auto newx = toDecimal((avatar->getMatrix()->pa * defaultx + avatar->getMatrix()->pb * defaulty) >> 8);
@ -88,10 +87,8 @@ void FoodScene::tick(u16 keys) {
*/ */
if(keys & KEY_LEFT) { if(keys & KEY_LEFT) {
avatarRotation -= AVATAR_ROTATION_DIFF; avatarRotation -= AVATAR_ROTATION_DIFF;
TextStream::instance().clear();
} else if(keys & KEY_RIGHT) { } else if(keys & KEY_RIGHT) {
avatarRotation += AVATAR_ROTATION_DIFF; avatarRotation += AVATAR_ROTATION_DIFF;
TextStream::instance().clear();
} }
if((keys & KEY_A)) { if((keys & KEY_A)) {
avatar->animateToFrame(1); avatar->animateToFrame(1);
@ -99,7 +96,6 @@ void FoodScene::tick(u16 keys) {
if(allowedToShoot && bullets.size() < MAX_AMOUNT_OF_BULLETS) { if(allowedToShoot && bullets.size() < MAX_AMOUNT_OF_BULLETS) {
bulletCooldown = BULLET_COOLDOWN_START; bulletCooldown = BULLET_COOLDOWN_START;
bullets.push_back(createBullet()); bullets.push_back(createBullet());
bulletAdded = true;
auto &b = bullets.at(bullets.size() - 1); auto &b = bullets.at(bullets.size() - 1);
b->setDestination(randomDestinations[rand() % 6]); b->setDestination(randomDestinations[rand() % 6]);
@ -111,10 +107,6 @@ void FoodScene::tick(u16 keys) {
for(auto &b : bullets) { for(auto &b : bullets) {
b->tick(); b->tick();
} }
if(bulletAdded) {
engine->updateSpritesInScene();
}
} }
std::unique_ptr<Bullet> FoodScene::createBullet() { std::unique_ptr<Bullet> FoodScene::createBullet() {

View File

@ -59,6 +59,7 @@ void TextStream::setText(std::string text, int row, int col) {
// http://cs.umw.edu/~finlayson/class/spring18/cpsc305/ // http://cs.umw.edu/~finlayson/class/spring18/cpsc305/
void TextStream::setText(const char* text, int row, int col) { void TextStream::setText(const char* text, int row, int col) {
int index = row * TILE_WIDTH + col; int index = row * TILE_WIDTH + col;
int i = 0;
volatile auto ptr = &se_mem[screenBlockIndex][0]; volatile auto ptr = &se_mem[screenBlockIndex][0];
while (*text) { while (*text) {
@ -66,8 +67,13 @@ void TextStream::setText(const char* text, int row, int col) {
index++; index++;
text++; text++;
i++;
}
while(i < TILE_WIDTH) {
ptr[index] = 0;
index++;
i++;
} }
} }
TextStream& TextStream::operator<<(const int s) { TextStream& TextStream::operator<<(const int s) {

View File

@ -115,7 +115,11 @@ void GBAEngine::update() {
} }
u16 keys = readKeys(); u16 keys = readKeys();
this->currentScene->tick(keys); currentScene->tick(keys);
if(currentScene->sprites().size() != spriteManager.getSpriteSize()) {
updateSpritesInScene();
}
spriteManager.render(); spriteManager.render();
} }