formatting, mostly
This commit is contained in:
parent
f338476aaf
commit
435f0c6274
@ -15,21 +15,53 @@ Sprite sprites_info[] = {
|
||||
.acc = { .x = 0, .y = 0},
|
||||
|
||||
.bitmap_indexes[SI_UP] = 12, .bitmap_prop[SI_UP] = 0,
|
||||
.collision_offset[SI_UP] = { 3, 8, 1, 1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP] = {
|
||||
3, 8, 1, 7,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN] = 12, .bitmap_prop[SI_DOWN] = S_FLIPY,
|
||||
.collision_offset[SI_DOWN] = { 3,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_DOWN] = {
|
||||
3, 2, 1, 1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_LEFT] = 11, .bitmap_prop[SI_LEFT] = 0,
|
||||
.collision_offset[SI_LEFT] = { 8,3, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_LEFT] = {
|
||||
8, 3, 7, 1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_RIGHT] = 11, .bitmap_prop[SI_RIGHT] = S_FLIPX,
|
||||
.collision_offset[SI_RIGHT] = { 8,3, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_RIGHT] = {
|
||||
2, 3, 1, 1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_UP_RIGHT] = 13, .bitmap_prop[SI_UP_RIGHT] = 0,
|
||||
.collision_offset[SI_UP_RIGHT] = { 7,8, 1,2, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP_RIGHT] = {
|
||||
2, 8, 1, 7,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_UP_LEFT] = 13, .bitmap_prop[SI_UP_LEFT] = S_FLIPX,
|
||||
.collision_offset[SI_UP_LEFT] = { 8,8, 2,2, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP_LEFT] = {
|
||||
8, 8, 7, 7,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN_LEFT] = 13, .bitmap_prop[SI_DOWN_LEFT] = S_FLIPX | S_FLIPY,
|
||||
.collision_offset[SI_DOWN_LEFT] = { 8,7, 2,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_DOWN_LEFT] = {
|
||||
8, 2, 7, 1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN_RIGHT] = 13, .bitmap_prop[SI_DOWN_RIGHT] = S_FLIPY,
|
||||
.collision_offset[SI_DOWN_RIGHT] = { 7,7, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, }
|
||||
.collision_offset[SI_DOWN_RIGHT] = {
|
||||
2, 2, 1, 1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
}
|
||||
},
|
||||
{
|
||||
.frames_since_last_dash = 0,
|
||||
@ -43,21 +75,53 @@ Sprite sprites_info[] = {
|
||||
.acc = { .x = 0, .y = 0},
|
||||
|
||||
.bitmap_indexes[SI_UP] = 14, .bitmap_prop[SI_UP] = 0,
|
||||
.collision_offset[SI_UP] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN] = 15, .bitmap_prop[SI_DOWN] = 0,
|
||||
.collision_offset[SI_DOWN] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_DOWN] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_LEFT] = 14, .bitmap_prop[SI_LEFT] = 0,
|
||||
.collision_offset[SI_LEFT] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_LEFT] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_RIGHT] = 14, .bitmap_prop[SI_RIGHT] = S_FLIPX,
|
||||
.collision_offset[SI_RIGHT] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_RIGHT] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_UP_RIGHT] = 14, .bitmap_prop[SI_UP_RIGHT] = 0,
|
||||
.collision_offset[SI_UP_RIGHT] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP_RIGHT] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_UP_LEFT] = 14, .bitmap_prop[SI_UP_LEFT] = S_FLIPX,
|
||||
.collision_offset[SI_UP_LEFT] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP_LEFT] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN_LEFT] = 15, .bitmap_prop[SI_DOWN_LEFT] = 0,
|
||||
.collision_offset[SI_DOWN_LEFT] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_DOWN_LEFT] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN_RIGHT] = 15, .bitmap_prop[SI_DOWN_RIGHT] = S_FLIPX,
|
||||
.collision_offset[SI_DOWN_RIGHT] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, }
|
||||
.collision_offset[SI_DOWN_RIGHT] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
}
|
||||
},
|
||||
{
|
||||
.frames_since_last_dash = 0,
|
||||
@ -71,20 +135,52 @@ Sprite sprites_info[] = {
|
||||
.acc = { .x = 0, .y = 0},
|
||||
|
||||
.bitmap_indexes[SI_UP] = 25, .bitmap_prop[SI_UP] = 0,
|
||||
.collision_offset[SI_UP] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN] = 22, .bitmap_prop[SI_DOWN] = 0,
|
||||
.collision_offset[SI_DOWN] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_DOWN] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_LEFT] = 21, .bitmap_prop[SI_LEFT] = 0,
|
||||
.collision_offset[SI_LEFT] = { 8,5, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_LEFT] = {
|
||||
8,5, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_RIGHT] = 21, .bitmap_prop[SI_RIGHT] = S_FLIPX,
|
||||
.collision_offset[SI_RIGHT] = { 8,5, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_RIGHT] = {
|
||||
8,5, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_UP_RIGHT] = 23, .bitmap_prop[SI_UP_RIGHT] = 0,
|
||||
.collision_offset[SI_UP_RIGHT] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP_RIGHT] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_UP_LEFT] = 23, .bitmap_prop[SI_UP_LEFT] = S_FLIPX,
|
||||
.collision_offset[SI_UP_LEFT] = { 8,8, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_UP_LEFT] = {
|
||||
8,8, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN_LEFT] = 24, .bitmap_prop[SI_DOWN_LEFT] = S_FLIPX,
|
||||
.collision_offset[SI_DOWN_LEFT] = { 8,7, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, },
|
||||
.collision_offset[SI_DOWN_LEFT] = {
|
||||
8,7, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
},
|
||||
.bitmap_indexes[SI_DOWN_RIGHT] = 24, .bitmap_prop[SI_DOWN_RIGHT] = 0,
|
||||
.collision_offset[SI_DOWN_RIGHT] = { 8,7, 1,1, 255, 255, 255, 255, 255, 255, 255, 255, }
|
||||
.collision_offset[SI_DOWN_RIGHT] = {
|
||||
8,7, 1,1,
|
||||
255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -35,8 +35,10 @@ void main(void)
|
||||
|
||||
|
||||
memcpy(&(screen_sprites[0]), &(sprites_info[2]), sizeof(Sprite));
|
||||
for (i = 1; i < NO_SCREEN_SPRITES; i++) memcpy(&(screen_sprites[i]), &(sprites_info[0]), sizeof(Sprite));
|
||||
screen_sprites[0].has_joypad = 1;
|
||||
memcpy(&(screen_sprites[1]), &(sprites_info[1]), sizeof(Sprite));
|
||||
for (i = 2; i < NO_SCREEN_SPRITES; i++) memcpy(&(screen_sprites[i]), &(sprites_info[0]), sizeof(Sprite));
|
||||
|
||||
screen_sprites[4].has_joypad = 1;
|
||||
|
||||
for (i = 0; i < NO_SCREEN_SPRITES; i++) {
|
||||
screen_sprites[i].bitmap_index_prev = -1;
|
||||
|
60
src/sprite.c
60
src/sprite.c
@ -6,6 +6,8 @@
|
||||
#include "./flags.h"
|
||||
#include "./map.h"
|
||||
|
||||
|
||||
#define LYO 8
|
||||
#define GET_TILE_INDEX_BY_COORD(x, y) ((((y) / PIXELS_PER_TILE) * 20) + ((x) / PIXELS_PER_TILE))
|
||||
|
||||
typedef struct Sprites {
|
||||
@ -34,12 +36,10 @@ void sprite_update_bitmap(Sprite *sprite);
|
||||
// update a sprite for stuff that changes every frame
|
||||
void sprite_iter_frame(Sprite *sprite, Map *map, int joypad, unsigned int *fc)
|
||||
{
|
||||
int lyo = 8;
|
||||
unsigned int colx, coly;
|
||||
UVec original_position;
|
||||
|
||||
// target displacement is sprite->vel but may collide, giving actual displacment
|
||||
Vec displacement = {.x = 0, .y = 0};
|
||||
UVec original_position;
|
||||
|
||||
if (sprite->frames_since_last_jump <= JUMP_TIMEOUT_FRAMES) sprite->frames_since_last_jump++;
|
||||
if (sprite->frames_since_last_dash <= DASH_TIMEOUT_FRAMES) sprite->frames_since_last_dash++;
|
||||
@ -96,8 +96,8 @@ void sprite_iter_frame(Sprite *sprite, Map *map, int joypad, unsigned int *fc)
|
||||
int *offsets = sprite->collision_offset[sprite->bitmap_index];
|
||||
// jump if on platform
|
||||
if ((joypad & J_A) && (sprite->frames_since_last_jump > JUMP_TIMEOUT_FRAMES)) {
|
||||
coly = map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[3]-lyo+1)];
|
||||
if (!coly) coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[3]-lyo+1)];
|
||||
coly = map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[3]-LYO+1)];
|
||||
if (!coly) coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[3]-LYO+1)];
|
||||
if(coly) {
|
||||
sprite->vel.y = -JUMP_VEL;
|
||||
sprite->frames_since_last_jump = 0;
|
||||
@ -113,34 +113,34 @@ void sprite_iter_frame(Sprite *sprite, Map *map, int joypad, unsigned int *fc)
|
||||
coly = sprite->vel.y == 0;
|
||||
|
||||
//for (int step = collision_check_steps; step >= 0; step--) {
|
||||
if(sprite->vel.y != 0){
|
||||
sprite->pos.y = original_position.y + sprite->vel.y;
|
||||
if(sprite->vel.y != 0){
|
||||
sprite->pos.y = original_position.y + sprite->vel.y;
|
||||
|
||||
if (sprite->vel.y < 0) {
|
||||
coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[1]-lyo)];
|
||||
if (!coly) coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[1]-lyo)];
|
||||
} else if (sprite->vel.y > 0) {
|
||||
coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[3]-lyo)];
|
||||
if (!coly) coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[3]-lyo)];
|
||||
}
|
||||
|
||||
if (coly) sprite->pos.y = original_position.y;
|
||||
if (sprite->vel.y < 0) {
|
||||
coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[1]-LYO)];
|
||||
if (!coly) coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[1]-LYO)];
|
||||
} else if (sprite->vel.y > 0) {
|
||||
coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[3]-LYO)];
|
||||
if (!coly) coly += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[3]-LYO)];
|
||||
}
|
||||
|
||||
if(sprite->vel.x != 0) {
|
||||
sprite->pos.x = original_position.x + sprite->vel.x;
|
||||
if (coly) sprite->pos.y = original_position.y;
|
||||
}
|
||||
|
||||
if (sprite->vel.x < 0) {
|
||||
colx += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[1]-lyo)];
|
||||
if(!colx) colx += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[3]-lyo)];
|
||||
} else if (sprite->vel.x > 0) {
|
||||
colx += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[1]-lyo)];
|
||||
if(!colx) colx += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[3]-lyo)];
|
||||
}
|
||||
if(sprite->vel.x != 0) {
|
||||
sprite->pos.x = original_position.x + sprite->vel.x;
|
||||
|
||||
if (colx) sprite->pos.x = original_position.x;
|
||||
if (sprite->vel.x < 0) {
|
||||
colx += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[1]-LYO)];
|
||||
if(!colx) colx += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[0], sprite->pos.y - offsets[3]-LYO)];
|
||||
} else if (sprite->vel.x > 0) {
|
||||
colx += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[1]-LYO)];
|
||||
if(!colx) colx += map->data[GET_TILE_INDEX_BY_COORD(sprite->pos.x - offsets[2], sprite->pos.y - offsets[3]-LYO)];
|
||||
}
|
||||
|
||||
if (colx) sprite->pos.x = original_position.x;
|
||||
}
|
||||
|
||||
sprite_update_bitmap(sprite);
|
||||
sprite_draw_to_screen(sprite);
|
||||
}
|
||||
@ -163,9 +163,11 @@ void sprite_update_bitmap(Sprite *sprite)
|
||||
|
||||
void sprite_draw_to_screen(Sprite *sprite)
|
||||
{
|
||||
if (sprite->bitmap_index_prev != sprite->bitmap_index) {
|
||||
set_sprite_tile(sprite->gb_sprite_index, sprite->bitmap_indexes[sprite->bitmap_index]);
|
||||
set_sprite_prop(sprite->gb_sprite_index, sprite->bitmap_prop[sprite->bitmap_index]);
|
||||
int bmi = sprite->bitmap_index;
|
||||
|
||||
if (sprite->bitmap_index_prev != bmi) {
|
||||
set_sprite_tile(sprite->gb_sprite_index, sprite->bitmap_indexes[bmi]);
|
||||
set_sprite_prop(sprite->gb_sprite_index, sprite->bitmap_prop[bmi]);
|
||||
}
|
||||
move_sprite(sprite->gb_sprite_index, sprite->pos.x, sprite->pos.y);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user