summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimponic <loganthebean222@gmail.com>2020-08-15 15:59:31 -0600
committerSimponic <loganthebean222@gmail.com>2020-08-15 15:59:31 -0600
commitee3af6b1f0e2ce6b8f27f7f4e33703cca6aaa876 (patch)
tree1a4bf5ac8ac895c7ffd66fd2b2736f5add44ebb5
parent3020917b0b1b03acb52cf9c26a45132c73715de3 (diff)
downloadgeometry-dash-gba-ee3af6b1f0e2ce6b8f27f7f4e33703cca6aaa876.tar.gz
geometry-dash-gba-ee3af6b1f0e2ce6b8f27f7f4e33703cca6aaa876.zip
Optimized level-loading a bit
-rw-r--r--include/map.h4
-rw-r--r--include/playerObject.h1
-rw-r--r--source/main.c55
-rw-r--r--source/map.c20
-rw-r--r--source/playerObject.c2
-rw-r--r--source/toolbox.c2
6 files changed, 49 insertions, 35 deletions
diff --git a/include/map.h b/include/map.h
index 1bef313..e81f190 100644
--- a/include/map.h
+++ b/include/map.h
@@ -1,8 +1,8 @@
#include "types.h"
+#include <string.h>
#ifndef MAP_H
#define MAP_H
-extern const int map1[9][20];
-
+extern const int map1[9][40];
#endif // MAP_H
diff --git a/include/playerObject.h b/include/playerObject.h
index acfadbc..49f6011 100644
--- a/include/playerObject.h
+++ b/include/playerObject.h
@@ -29,5 +29,4 @@ void applyGravity();
void scalePlayer();
void updatePlayer();
-
#endif // PLAYEROBJECT_H
diff --git a/source/main.c b/source/main.c
index 5842b60..bfff550 100644
--- a/source/main.c
+++ b/source/main.c
@@ -18,7 +18,9 @@ OBJ_ATTR obj_buffer[128];
OBJ_AFFINE *obj_aff_buffer= (OBJ_AFFINE*)obj_buffer; // Object affine-buffer
int main() {
- memcpy(pal_obj_mem, blockPal, blockPalLen);
+
+ memcpy(pal_obj_mem, blockPal, blockPalLen); // Copy block pallete to pallete bank
+ // Copy sprites to OAM
memcpy(&tile_mem[4][0], playerTiles, playerTilesLen);
memcpy(&tile_mem[4][4], blockTiles, blockTilesLen);
memcpy(&tile_mem[4][8], spikeTiles, spikeTilesLen);
@@ -29,15 +31,21 @@ int main() {
playerObject player = createPlayerObject(&obj_buffer[0], &obj_aff_buffer[0],0, 0);
player.camera = createCamera(-10, 0);
- int currentGroundLevel = 140;
- int currentXLevel = 1;
-
- while(1) {
+ int currentXLevel = 0;
+ int playing = 1;
+ while(playing) {
vid_vsync();
- player.camera.x += 1;
+ if (key_is_down(KEY_START) || currentXLevel >= 39) {
+ oam_init(obj_buffer, 128);
+ currentXLevel = 0;
+ player = createPlayerObject(&obj_buffer[0], &obj_aff_buffer[0],0, 0);
+ player.camera = createCamera(-10, 0);
+ }
+
+ player.camera.x += 2;
key_poll();
- if (player.camera.x % 16 == 15) {
+ if ((player.camera.x + 10)% 16 == 0) {
currentXLevel++;
}
@@ -45,6 +53,7 @@ int main() {
player.vel.dy -= 9 << FIX_SHIFT;
}
+
//updatePlayer(&player, 80);
obj_affine_copy(obj_aff_mem, player.affine, 1);
obj_copy(obj_mem, player.obj, 1);
@@ -60,26 +69,32 @@ int main() {
ATTR1_SIZE_16,
ATTR2_PALBANK(0) | 8
);
+
int x, y;
+ int currentMemoryLocation = 3;
for (int i = 0; i < 9; i++) {
- for (int j = 0; j < 15; j++){
- x = (j * 16);
+ for (int j = currentXLevel - 1; j < (currentXLevel + 15); j++){
y = (i * 16);
+ x = (j * 16);
applyCameraShift(&player.camera, &x, &y);
- if (map1[i][j] == 1) {
- if (j == currentXLevel) {
- updatePlayer(&player, 16 * i - 16);
- }
- obj_set_pos(&blockObject, x, y);
- obj_copy(obj_mem + (16 * i + j) + 1, &blockObject, 1);
- }
- else if (map1[i][j] == 2) {
- obj_set_pos(&spikeObject, x, y);
- obj_copy(obj_mem + (16 * i + j) + 1, &spikeObject, 1);
+ if (x + 16 > 0 && x <= 240 && (currentXLevel) < 40){
+ if (map1[i][j] == 1) {
+ currentMemoryLocation++;
+ if (j == currentXLevel) {
+ updatePlayer(&player, 16 * i - 16);
+ }
+ obj_set_pos(&blockObject, x, y);
+ obj_copy(obj_mem + currentMemoryLocation, &blockObject, 1);
+ }
+ else if (map1[i][j] == 2) {
+ currentMemoryLocation++;
+ obj_set_pos(&spikeObject, x, y);
+ obj_copy(obj_mem + currentMemoryLocation, &spikeObject, 1);
+
+ }
}
}
}
-
}
return 0;
diff --git a/source/map.c b/source/map.c
index fd08e39..1a56851 100644
--- a/source/map.c
+++ b/source/map.c
@@ -1,12 +1,12 @@
#include "../include/map.h"
-const int map1[9][20] = {
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+const int map1[9][40] = {
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 1 },
+ {0, 0, 0, 0, 2, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1 },
+ {0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1 },
+ {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 },
};
diff --git a/source/playerObject.c b/source/playerObject.c
index 98135a2..78b0307 100644
--- a/source/playerObject.c
+++ b/source/playerObject.c
@@ -3,7 +3,7 @@
void initializePlayerObject (playerObject *object) {
// Initialize the point and velocity of a player object
object->vel = createVelocity(0, 0);
- object->pt = createPoint(15 << FIX_SHIFT, 0 << FIX_SHIFT);
+ object->pt = createPoint(0 << FIX_SHIFT, 60 << FIX_SHIFT);
}
playerObject createPlayerObject (OBJ_ATTR *obj_buffer, OBJ_AFFINE *affine_buffer, int pallete_bank, int tile_id) {
diff --git a/source/toolbox.c b/source/toolbox.c
index 32042a0..ff09fab 100644
--- a/source/toolbox.c
+++ b/source/toolbox.c
@@ -78,5 +78,5 @@ void obj_affine_copy (OBJ_AFFINE *dst, const OBJ_AFFINE *src, u32 count) {
void obj_affine_identity(OBJ_AFFINE *aff) {
// Make a pointer point to a identity affine matrix
aff->pa = 1 << 8; aff->pb = 0;
- aff->pc = 0 ; aff->pd = 1 << 8;
+ aff->pc = 0 ; aff->pd = 1 << 8;
}