Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************/
- /* GAME++ COMMUNITY CHALLENGE 6 */
- /* */
- /* CAVERUSH */
- /* v0.1 */
- /* by HeroQbe */
- /********************************/
- #include <tigcclib.h>
- #include "extgraph.h"
- // debug
- //#define FAST_START
- typedef struct {
- float X, Y;
- } Vector2;
- // screen buffer
- LCD_BUFFER light, dark,
- chunk_light, chunk_dark;
- #define TILES 7
- #define ENTITY_TYPES 3
- #define DIRECTIONS 2
- #define FRAMES 2
- enum Menu {NEW_GAME, LOAD_GAME, EXIT};
- enum Tiles {TILE_AIR, TILE_GRASS, TILE_STONE, TILE_STALACTIT, TILE_VINE, TILE_CEILING, TILE_LADDER};
- enum EntityTypes {ENTITY_NONE, ENTITY_PLAYER, ENTITY_SPIDER};
- enum Directions {DIR_LEFT, DIR_RIGHT};
- enum Planes {PLANE_LIGHT, PLANE_DARK, PLANE_MASK};
- /***********************/
- /* SPRITE DECLERATIONS */
- /***********************/
- // button
- unsigned long button_off_light[] = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
- unsigned long button_off_dark[] = {0x00000000,0x7FFFFFFE,0x7FFFFFFE,0x60000006,0x60000006,0x60000006,0x60000006,0x60000006,0x60000006,0x60000006,0x60000006,0x60000006,0x60000006,0x7FFFFFFE,0x7FFFFFFE,0x00000000};
- unsigned long button_on_light[] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
- unsigned long button_on_dark[] = {0xFFFFFFFF,0xFFFFFFFF,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xC0000003,0xFFFFFFFF,0xFFFFFFFF};
- // player
- unsigned short player_left0_light[] = {0x0FC0,0x1FF0,0x1FF8,0x0FF8,0x0FF0,0x0FF0,0x0FF0,0x07E0,0x0850,0x3AE8,0x3CF0,0x1820,0x0FE0,0x0920,0x1320,0x3DF0};
- unsigned short player_left0_dark[] = {0x0FC0,0x1FF0,0x1838,0x0A98,0x0A90,0x0810,0x0810,0x07E0,0x0FF0,0x3FB8,0x2FF0,0x1FE0,0x0FE0,0x0FE0,0x1FE0,0x3DF0};
- unsigned short player_left0_mask[] = {~0x0FC0,~0x1FF0,~0x1FF8,~0x0FF8,~0x0FF0,~0x0FF0,~0x0FF0,~0x07E0,~0x0FF0,~0x3FF8,~0x3FF0,~0x1FE0,~0x0FE0,~0x0FE0,~0x1FE0,~0x3DF0};
- unsigned short player_left1_light[] = {0x0FC0,0x1FF0,0x1FF8,0x0FF8,0x0FF0,0x0FF0,0x0FF0,0x07E0,0x1810,0x3A68,0x3CF0,0x0860,0x0FE0,0x0920,0x0640,0x0FC0};
- unsigned short player_left1_dark[] = {0x0FC0,0x1FF0,0x1838,0x0A98,0x0A90,0x0810,0x0810,0x07E0,0x1FF0,0x2FF8,0x3FB0,0x0FE0,0x0FE0,0x0FE0,0x07C0,0x0FC0};
- unsigned short player_left1_mask[] = {~0x0FC0,~0x1FF0,~0x1FF8,~0x0FF8,~0x0FF0,~0x0FF0,~0x0FF0,~0x07E0,~0x1FF0,~0x3FF8,~0x3FF0,~0x0FE0,~0x0FE0,~0x0FE0,~0x07C0,~0x0FC0};
- unsigned short player_right0_light[] = {0x03F0,0x0FF8,0x1FF8,0x1FF0,0x0FF0,0x0FF0,0x0FF0,0x07E0,0x0A10,0x175C,0x0F3C,0x0418,0x07F0,0x0490,0x04C8,0x0FBC};
- unsigned short player_right0_dark[] = {0x03F0,0x0FF8,0x1C18,0x1950,0x0950,0x0810,0x0810,0x07E0,0x0FF0,0x1DFC,0x0FF4,0x07F8,0x07F0,0x07F0,0x07F8,0x0FBC};
- unsigned short player_right0_mask[] = {~0x03F0,~0x0FF8,~0x1FF8,~0x1FF0,~0x0FF0,~0x0FF0,~0x0FF0,~0x07E0,~0x0FF0,~0x1FFC,~0x0FFC,~0x07F8,~0x07F0,~0x07F0,~0x07F8,~0x0FBC};
- unsigned short player_right1_light[] = {0x03F0,0x0FF8,0x1FF8,0x1FF0,0x0FF0,0x0FF0,0x0FF0,0x07E0,0x0818,0x165C,0x0F3C,0x0610,0x07F0,0x0490,0x0260,0x03F0};
- unsigned short player_right1_dark[] = {0x03F0,0x0FF8,0x1C18,0x1950,0x0950,0x0810,0x0810,0x07E0,0x0FF8,0x1FF4,0x0DFC,0x07F0,0x07F0,0x07F0,0x03E0,0x03F0};
- unsigned short player_right1_mask[] = {~0x03F0,~0x0FF8,~0x1FF8,~0x1FF0,~0x0FF0,~0x0FF0,~0x0FF0,~0x07E0,~0x0FF8,~0x1FFC,~0x0FFC,~0x07F0,~0x07F0,~0x07F0,~0x03E0,~0x03F0};
- // spider
- unsigned short spider_0_light[] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1818,0x2424,0x43C2,0x1DB8,0x27E4,0x4DB2,0x53CA,0x9429,0xB66D};
- unsigned short spider_0_dark[] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1818,0x2424,0x4242,0x1BD8,0x27E4,0x4BD2,0x524A,0x9429,0x9429};
- unsigned short spider_0_mask[] = {~0x0000,~0x0000,~0x0000,~0x0000,~0x0000,~0x0000,~0x0000,~0x1818,~0x2424,~0x43C2,~0x1FF8,~0x27E4,~0x4FF2,~0x53CA,~0x9429,~0xB66D};
- unsigned short spider_1_light[] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x381C,0x4422,0x03C0,0x3DBC,0x47E2,0x9FF9,0xA425,0xFA5F};
- unsigned short spider_1_dark[] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x381C,0x4422,0x0240,0x3BDC,0x47E2,0x9BD9,0xA5A5,0xA815};
- unsigned short spider_1_mask[] = {~0x0000,~0x0000,~0x0000,~0x0000,~0x0000,~0x0000,~0x0000,~0x0000,~0x381C,~0x4422,~0x03C0,~0x3FFC,~0x47E2,~0x9FF9,~0xA5A5,~0xFA5F};
- // tiles
- unsigned short tile1_light[] = {0x6BB7,0x9448,0x0001,0xD327,0xFF7F,0xFFFF,0xFFFF,0xFFFF,0xEA7F,0x8006,0x0000,0x0000,0x3E78,0xFFFF,0xFFFF,0xFFFF};
- unsigned short tile1_dark[] = {0x6BB7,0xFFFF,0xFFFE,0x2CD8,0x0080,0x0000,0x0000,0x0000,0x1580,0x7FF9,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
- unsigned short tile2_light[] = {0xFFFF,0xFFE3,0xFFC3,0xE1E7,0xC0FF,0xC03F,0xC03F,0xE07F,0xF0FF,0xFFE3,0xFFC0,0xF3C0,0xE1E0,0xE0F1,0xE0FF,0xF1FF};
- unsigned short tile2_dark[] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
- unsigned short tile3_light[] = {0x8FFA,0xEA2A,0x79AA,0x51AC,0x5104,0x6144,0x2140,0x20C0,0x20C0,0x2080,0x0080,0x0080,0x0080,0x0000,0x0000,0x0000};
- unsigned short tile3_dark[] = {0xFFFE,0xDBEE,0x596E,0x716C,0x71C4,0x61C4,0x21C0,0x20C0,0x20C0,0x2080,0x0080,0x0080,0x0080,0x0000,0x0000,0x0000};
- unsigned short tile4_light[] = {0xFFFF,0x74DE,0x3090,0x0902,0x4442,0x2011,0x1710,0x0228,0x1101,0x3228,0x0049,0x1041,0x2610,0x0000,0x0364,0x544A};
- unsigned short tile4_dark[] = {0xFFFF,0x75DA,0x6088,0x3088,0x108C,0x18C4,0x0846,0x0842,0x0C42,0x0482,0x0486,0x0D06,0x090A,0x088B,0x1411,0x2020};
- unsigned short tile5[] = {0xFFFF,0x4CF6,0x0040,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
- unsigned short tile6_light[] = {0x1004,0x1184,0x5FF6,0x1004,0x3004,0x5704,0x5FF6,0x1004,0x3004,0x1386,0x5FF6,0x1004,0x3004,0x11C4,0x7FF6,0x3004};
- unsigned short tile6_dark[] = {0x300C,0x7FFE,0x7FFE,0x300C,0x300C,0x7FFE,0x7FFE,0x300C,0x300C,0x7FFE,0x7FFE,0x300C,0x300C,0x7FFE,0x7FFE,0x300C};
- struct entitySprt {
- unsigned short *light, *dark, *mask;
- } EntitySprite[ENTITY_TYPES][DIRECTIONS][FRAMES] = {
- {{{NULL,NULL,NULL},{NULL,NULL,NULL}},{{NULL,NULL,NULL},{NULL,NULL,NULL}}},
- {{{player_left0_light,player_left0_dark,player_left0_mask},{player_left1_light,player_left1_dark,player_left1_mask}},{{player_right0_light,player_right0_dark,player_right0_mask},{player_right1_light,player_right1_dark,player_right1_mask}}},
- {{{spider_0_light,spider_0_dark,spider_0_mask},{spider_1_light,spider_1_dark,spider_1_mask}},{{spider_0_light,spider_0_dark,spider_0_mask},{spider_1_light,spider_1_dark,spider_1_mask}}},
- };
- struct tileSprt {
- unsigned short *light, *dark;
- } TileSprite[TILES] = {
- {NULL,NULL},
- {tile1_light,tile1_dark},
- {tile2_light,tile2_dark},
- {tile3_light,tile3_dark},
- {tile4_light,tile4_dark},
- {tile5 ,tile5 },
- {tile6_light,tile6_dark}
- };
- // functions
- void waitKey(void) {
- while (_rowread(0));
- while (!_rowread(0));
- }
- void ClearBuffer(void) {
- ClearGrayScreen2B(light, dark);
- }
- void FillBuffer(LCD_BUFFER *light_plane, LCD_BUFFER *dark_plane) {
- FastCopyScreen(light_plane, light);
- FastCopyScreen(dark_plane, dark);
- }
- void Draw(void) {
- FastCopyScreen(light, GetPlane(LIGHT_PLANE));
- FastCopyScreen(dark, GetPlane(DARK_PLANE));
- }
- void ClearDraw(void) {
- ClearBuffer();
- Draw();
- }
- short TitleScreen(void);
- void newGame(void);
- void Game(void);
- void DrawMap(void);
- static signed char savegame = 0;
- void _main(void)
- {
- INT_HANDLER save_int_1, save_int_5;
- save_int_1 = GetIntVec(AUTO_INT_1);
- save_int_5 = GetIntVec(AUTO_INT_5);
- SetIntVec(AUTO_INT_1, DUMMY_HANDLER);
- SetIntVec(AUTO_INT_5, DUMMY_HANDLER);
- if (!GrayOn())
- return;
- short menu;
- while (TRUE) {
- #ifdef FAST_START
- menu = NEW_GAME;
- #else
- menu = TitleScreen();
- #endif
- if (menu == NEW_GAME) {
- newGame();
- Game();
- } else if (menu == LOAD_GAME) {
- if (savegame)
- Game();
- else
- GrayDrawStrExt2B(96, 100, "No game!", A_NORMAL, F_6x8, light, dark);
- } else if (menu == EXIT)
- break; // exit
- }
- GrayOff();
- SetIntVec(AUTO_INT_1, save_int_1);
- SetIntVec(AUTO_INT_5, save_int_5);
- }
- short TitleScreen(void) {
- static signed char selected = LOAD_GAME;
- struct Buttons {
- short textPosX;
- const char * text;
- } MenuButton[3] = {{110, "New"},
- {107, "Load"},
- {107, "Exit"}};
- while (1) {
- signed char i, y;
- for (i = 0; i < 3; i++) {
- y = 39+i*18;
- if (i == selected)
- GraySprite32_OR(104, y, 16, button_on_light, button_on_dark, light, dark);
- else
- GraySprite32_OR(104, y, 16, button_off_light, button_off_dark, light, dark);
- GrayDrawStrExt2B(MenuButton[i].textPosX, y+5, MenuButton[i].text, A_NORMAL, F_6x8, light, dark);
- }
- GrayDrawStrExt2B(0, 120, "CAVERUSH v0.1 - by HeroQbe", A_NORMAL, F_6x8, light, dark);
- Draw();
- ClearBuffer();
- waitKey();
- if (_keytest(RR_UP) && selected > 0)
- selected--;
- else if (_keytest(RR_DOWN) && selected < 2)
- selected++;
- else if (_keytest(RR_ENTER) || _keytest(RR_ENTER2))
- return selected;
- }
- return -1;
- }
- #define MIN_POSX 1
- #define MAX_POSX 223
- #define MIN_POSY 1
- #define MAX_POSY 111
- #define CHUNK_WIDTH 15
- #define CHUNK_HEIGHT 8
- #define WORLD_WIDTH 8
- #define WORLD_HEIGHT 8
- #define MAX_ENTITIES 4
- #define HURT_TIME 20
- static const float velocity[ENTITY_TYPES] = {0, 3.0, 1.0},
- jumpBoost[ENTITY_TYPES] = {0, 6.0, 8.0},
- climbingSpeed = 2.0,
- gravity = 0.5;
- typedef struct {
- unsigned char Type, inAir, frame, direction;
- signed char Health, maxHealth, Defense, Attack, HurtTime;
- Vector2 Pos, Mot;
- } Entity;
- static Entity player;
- static struct {
- unsigned char Tile[CHUNK_HEIGHT][CHUNK_WIDTH];
- Entity entity[MAX_ENTITIES];
- } Chunk[WORLD_HEIGHT][WORLD_WIDTH];
- unsigned char SolidTile[CHUNK_HEIGHT][CHUNK_WIDTH];
- static unsigned char chunkX, chunkY;
- static signed char attack;
- void EntityLogic(Entity * entity) {
- if (SolidTile[(short)(entity->Pos.Y-1)/16][(short)(entity->Pos.X+8)/16]) {
- entity->Mot.Y = 0;
- entity->inAir = TRUE;
- }
- if (entity->inAir)
- entity->Mot.Y += gravity;
- if (entity->Mot.Y > 0 && SolidTile[(short)(entity->Pos.Y+16)/16][(short)(entity->Pos.X+8)/16]) {
- entity->inAir = FALSE;
- entity->Mot.X = entity->Mot.Y = 0;
- entity->Pos.Y = (short)(entity->Pos.Y/16)*16;
- } else {
- entity->inAir = TRUE;
- }
- entity->Pos.X += entity->Mot.X;
- entity->Pos.Y += entity->Mot.Y;
- }
- void EntityDraw(Entity * entity) {
- static struct entitySprt es;
- if (entity->Type) {
- es = EntitySprite[entity->Type][entity->direction][entity->frame];
- GraySprite16_MASK(entity->Pos.X, entity->Pos.Y, 16, es.light, es.dark, es.mask, es.mask, light, dark);
- if (entity->HurtTime) {
- if (entity->HurtTime%2)
- GraySprite16_XOR(entity->Pos.X, entity->Pos.Y, 16, es.dark, es.light, light, dark);
- entity->HurtTime--;
- }
- }
- }
- void nextFrame(Entity * entity) {
- entity->frame++;
- if (entity->frame == FRAMES)
- entity->frame = 0;
- }
- short getTile(signed char chunkX, signed char chunkY, signed char tileX, signed char tileY) {
- return Chunk[chunkY][chunkX].Tile[tileY][tileX];
- }
- void setTile(signed char chunkX, signed char chunkY, signed char tileX, signed char tileY, unsigned char tile) {
- Chunk[chunkY][chunkX].Tile[tileY][tileX] = tile;
- }
- Entity * getEntity(signed char chunkX, signed char chunkY, unsigned char entity) {
- return &Chunk[chunkX][chunkY].entity[entity];
- }
- void entityJump(Entity * entity) {
- entity->Mot.Y = -jumpBoost[entity->Type];
- entity->inAir = TRUE;
- }
- short doesCollide(Entity * entity, signed char negativeX, signed char positiveX, signed char negativeY, signed char positiveY) {
- return entity->Pos.X-player.Pos.X > -negativeX && entity->Pos.X-player.Pos.X < positiveX && entity->Pos.Y-player.Pos.Y > -negativeY && entity->Pos.Y-player.Pos.Y < positiveY;
- }
- void entityHit(Entity * entity1, Entity * entity2) {
- entity2->Health -= entity1->Attack;
- entity2->HurtTime = HURT_TIME;
- entity2->Mot.X = (entity2->Pos.X-entity1->Pos.X)/2;
- entity2->Mot.Y = (entity2->Pos.Y-2-entity1->Pos.Y)/2;
- }
- void newChunk(signed char new_chunkX, signed char new_chunkY) {
- struct tileSprt ts;
- if (new_chunkX == -1 || new_chunkX == 8 || new_chunkY == -1 || new_chunkY == 8)
- return;
- chunkX = new_chunkX;
- chunkY = new_chunkY;
- GrayClearScreen2B(chunk_light, chunk_dark);
- unsigned char tileX, tileY, tile;
- for (tileY = 0; tileY < CHUNK_HEIGHT; tileY++) {
- for (tileX = 0; tileX < CHUNK_WIDTH; tileX++) {
- tile = getTile(chunkX, chunkY, tileX, tileY);
- if (tile != TILE_AIR) {
- ts = TileSprite[tile];
- GraySprite16_OR(tileX*16, tileY*16, 16, ts.light, ts.dark, chunk_light, chunk_dark); // render screen
- }
- if (tile == TILE_GRASS || tile == TILE_STONE) // create solid tilemap
- SolidTile[tileY][tileX] = TRUE;
- else
- SolidTile[tileY][tileX] = FALSE;
- }
- }
- }
- void newGame(void) {
- /*******************/
- /* WORLD GENERATOR */
- /*******************/
- // prototype
- short i;
- for (i = 0; i < CHUNK_WIDTH; i++) {
- setTile(0,0,i,0,TILE_STONE);
- }
- for (i = 0; i < CHUNK_WIDTH; i++) {
- setTile(0,0,i,1,TILE_CEILING);
- }
- for (i = 0; i < CHUNK_WIDTH; i++) {
- setTile(0,0,i,7,TILE_STONE);
- }
- setTile(0,0,7,6,TILE_STONE);
- setTile(0,0,7,5,TILE_GRASS);
- setTile(0,0,1,1,TILE_VINE);
- for (i = 8; i < CHUNK_WIDTH; i++) {
- setTile(0,0,i,6,TILE_GRASS);
- }
- for (i = 2; i < 7; i++) {
- setTile(0,0,3,i,TILE_LADDER);
- }
- setTile(0,0,0,3,TILE_GRASS);
- setTile(0,0,1,3,TILE_GRASS);
- setTile(0,0,2,3,TILE_GRASS);
- getEntity(0,0,0)->Type = ENTITY_SPIDER;
- getEntity(0,0,0)->Pos.X = 16*1;
- getEntity(0,0,0)->Pos.Y = 16*2;
- getEntity(0,0,0)->Attack = 2;
- getEntity(0,0,1)->Type = ENTITY_SPIDER;
- getEntity(0,0,1)->Pos.X = 16*8;
- getEntity(0,0,1)->Pos.Y = 16*2;
- getEntity(0,0,1)->Attack = 2;
- getEntity(0,0,2)->Type = ENTITY_SPIDER;
- getEntity(0,0,2)->Pos.X = 16*12;
- getEntity(0,0,2)->Pos.Y = 16*2;
- getEntity(0,0,2)->Attack = 2;
- player.Type = ENTITY_PLAYER;
- player.Pos.X = 16*4;
- player.Pos.Y = 16*4;
- player.maxHealth = 10;
- player.Health = player.maxHealth;
- chunkX = 0;
- chunkY = 0;
- savegame = 1;
- }
- void Game(void) {
- Entity * eptr;
- short en;
- newChunk(chunkX, chunkY);
- while (!_keytest(RR_ESC)) {
- BEGIN_KEYTEST
- if (_keytest_optimized(RR_RIGHT) && !SolidTile[(short)(player.Pos.Y+15)/16][(short)(player.Pos.X+12)/16] && !SolidTile[(short)(player.Pos.Y-1)/16][(short)(player.Pos.X+12)/16]) { // move right
- player.Pos.X += velocity[ENTITY_PLAYER];
- if (!_keytest_optimized(RR_SHIFT)) // strafe
- player.direction = DIR_RIGHT;
- nextFrame(&player);
- } else if (_keytest_optimized(RR_LEFT) && !SolidTile[(short)(player.Pos.Y+15)/16][(short)(player.Pos.X+4)/16] && !SolidTile[(short)(player.Pos.Y-1)/16][(short)(player.Pos.X+4)/16]) { // move left
- player.Pos.X -= velocity[ENTITY_PLAYER];
- if (!_keytest_optimized(RR_SHIFT)) // strafe
- player.direction = DIR_LEFT;
- nextFrame(&player);
- } if (_keytest_optimized(RR_UP) && !player.inAir) { // jump
- entityJump(&player);
- } if (_keytest_optimized(RR_HAND) && attack) { // attack
- for (en = 0; en < MAX_ENTITIES; en++) {
- eptr = &Chunk[chunkY][chunkX].entity[en];
- if (player.direction == DIR_LEFT && doesCollide(eptr, 20, 4, 8, 8))
- entityHit(&player, eptr);
- else if (player.direction == DIR_RIGHT && doesCollide(eptr, 4, 20, 8, 8))
- entityHit(&player, eptr);
- }
- attack = FALSE;
- } if (!_keytest_optimized(RR_HAND)) {
- attack = TRUE;
- } if (_keytest_optimized(RR_2ND)) { // special
- }
- if (getTile(chunkX, chunkY, (short)(player.Pos.X+8)/16, (short)(player.Pos.Y+15)/16) != TILE_LADDER)
- EntityLogic(&player);
- else {
- if (_keytest_optimized(RR_UP))
- player.Pos.Y -= climbingSpeed;
- if (_keytest_optimized(RR_DOWN))
- player.Pos.Y += climbingSpeed;
- }
- END_KEYTEST
- for (en = 0; en < MAX_ENTITIES; en++) {
- eptr = &Chunk[chunkY][chunkX].entity[en];
- if (eptr->Type) {
- if (eptr->Pos.X < player.Pos.X) {
- if (!SolidTile[(short)(eptr->Pos.Y+15)/16][(short)(eptr->Pos.X+12)/16]) {
- eptr->Pos.X += velocity[eptr->Type];
- nextFrame(eptr);
- } else if (!eptr->inAir)
- entityJump(eptr);
- } else {
- if (!SolidTile[(short)(eptr->Pos.Y+15)/16][(short)(eptr->Pos.X+4)/16]) {
- eptr->Pos.X -= velocity[eptr->Type];
- nextFrame(eptr);
- } else if (!eptr->inAir)
- entityJump(eptr);
- }
- }
- EntityLogic(eptr);
- }
- // entity collision detection
- for (en = 0; en < MAX_ENTITIES; en++) {
- eptr = &Chunk[chunkY][chunkX].entity[en];
- if (eptr->Type && !player.HurtTime && doesCollide(eptr, 8, 8, 8, 8))
- entityHit(eptr, &player);
- }
- // new chunk detection
- if ((short)player.Pos.X < MIN_POSX) {
- newChunk(chunkX-1, chunkY);
- player.Pos.X = MAX_POSX;
- } if ((short)player.Pos.X > MAX_POSX) {
- newChunk(chunkX+1, chunkY);
- player.Pos.X = MIN_POSX;
- } if ((short)player.Pos.Y < MIN_POSY) {
- newChunk(chunkX, chunkY-1);
- player.Pos.Y = MAX_POSY;
- } if ((short)player.Pos.Y > MAX_POSY) {
- newChunk(chunkX, chunkY+1);
- player.Pos.Y = MIN_POSY;
- }
- for (en = 0; en < MAX_ENTITIES; en++) {
- eptr = &Chunk[chunkY][chunkX].entity[en];
- if ((short)eptr->Pos.X < MIN_POSX)
- eptr->Pos.X = MIN_POSX;
- if ((short)eptr->Pos.X > MAX_POSX)
- eptr->Pos.X = MAX_POSX;
- if ((short)eptr->Pos.Y < MIN_POSY)
- eptr->Pos.Y = MIN_POSY;
- if ((short)eptr->Pos.Y > MAX_POSY)
- eptr->Pos.Y = MAX_POSY;
- }
- // copy rendered chunk to buffer
- FastCopyScreen(chunk_light, light);
- FastCopyScreen(chunk_dark, dark);
- // draw to buffer
- for (en = 0; en < MAX_ENTITIES; en++) {
- EntityDraw(&Chunk[chunkY][chunkX].entity[en]);
- }
- EntityDraw(&player);
- // draw gui
- Draw();
- ClearBuffer();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement