Coins, starting a new layout from ground up (WIP)

master
KikooDX 3 years ago
parent b7c057304b
commit 65f5f04f13
  1. BIN
      assets-cg/img/coin.png
  2. 2
      include/draw.h
  3. 2
      include/levels.h
  4. 130
      levels.lua
  5. BIN
      platform.g3a
  6. 22
      src/draw.c
  7. 33
      src/main.c

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

@ -1,5 +1,5 @@
void draw_player(int old_x, int old_y, int x, int y);
void draw_level(char level[], char upgrades[], unsigned int step);
void draw_level(char level[], char upgrades[], char erase_coin);
void draw_level_anims(char level[], char upgrades[], unsigned int step);
void erase_tile(int x, int y, char level[]);
void draw_upgrade_message(char item);

@ -1 +1 @@
void set_level(int level_id, char level[]);
void set_level(int level_id, char level[], unsigned int *coin_id);

@ -9,97 +9,97 @@
--
-- level id format : YYXX with YY and XX being the Y and X position on the map
levels = {[5049] = [[
----------------------------
-00000000000000000000000000-
-00000000000000000000000000-
-00......................00-
-00..00000000000000..00^.00-
-00..000000000000v...00^.00-
-00..000000000000..0000^.00-
-00.00000000000v...0000^.00-
-00..0000000000..000000^.00-
-00..00000000v...000000^.00-
-00..00000000..00000000^...-
-000.000000v...00000000^...-
-000.........0000000000^...-
-000....j....00000000000000-
-00000000000000000000000000-
-00000000000000000000000000-
----------------------------
]],
[5050] = [[
levels = {[5050] = [[
----------------------------
-0000000....000000000000000-
-0000000....000000000000000-
-00000000....00000000000000-
-00000000..................-
-00000000....00000.........-
-00000000..................-
-00000000...........0000000-
-0000000000.....00000000000-
-0000000000.....00000000000-
-00000000..........00000000-
-00000.............00000000-
-00000000...........0000000-
-00000..............0000000-
-.............0000000000000-
-..........0000000000000000-
-.......0000000000000000000-
-00000000000000000000000000-
-00000000000000000000000000-
-00000000000000000000000000-
-00000000000000000000000000-
----------------------------
]],
[5051] = [[
[5049] = [[
----------------------------
-00000000000000000000000000-
-00000000000000000000000000-
-00......................00-
-........................00-
-........................00-
-00......................00-
-00......................00-
-00.....0...0.000.000....00-
-00.....0...0..0..0.0....00-
-00.....0.0.0..0..000....00-
-00.....0.0.0..0..0......00-
-00......0.0..000.0....vv00-
-00....................vv00-
-00~~~~~~~~~~~~~~~~~~~~~~00-
-00000000000000000000000000-
-00......................00-
-00......................00-
-........................00-
-........................00-
-00........................-
-000.......................-
-000.0000000000000000000000-
-..........0000000000000000-
-00000000..0000000000000000-
-00000000..0000000000000000-
----------------------------
]],
[4950] = [[
[5048] = [[
----------------------------
-00000000000000000000000000-
-00000000000000000000000000-
-....................000000-
-....................000000-
-00^...................0000-
-00^.......vv0v.........000-
-00^.....0v0000vv.......000-
-00^.....v00000000.......00-
-00^.....v0000000v.......00-
-000v0vvv000000000vvvv0..v0-
-000000000......vv0vv0vv.00-
-0000000.................v0-
-0000000......v..........00-
-0000000....000000vvv0v0v00-
-0000000....000000000000000-
-00......................00-
-00......................00-
-00......................00-
-00......................00-
-00......................00-
-00........................-
-00........................-
-00.................0000000-
-00.................0000000-
-00.................0000000-
-00.................00..c..-
-000000000000000000000.0000-
-000000000000000000000.0000-
----------------------------
]],
[4949] = [[
[5148] = [[
----------------------------
-00000000000000000000000000-
-00000000000000000000000000-
-00........................-
-00........................-
-000000000000000000000.0000-
-000000000000000000000.....-
-00..................000000-
-00......................00-
-00......................00-
-00......................00-
-00......00......00......00-
-00......00......00......00-
-00......................00-
-00......................00-
-00......0........0......00-
-00.......00000000.......00-
-00......................00-
-00v.....................00-
-00......................00-
-00......................00-
-00......................00-
-00......................00-
-00000000000000000000000000-
-00000000000000000000000000-
----------------------------
]],
[5149] = [[
----------------------------
-00000000..0000000000000000-
-...00000..0000000000000000-
-00......................00-
-00......................00-
-0000000000000000..vv000000-
-0000000000000000...0000000-
-00000......0000.......0000-
-000.........00....00...000-
-00^.........00.........000-
-00^.j................00000-
-00^....................000-
-00^.........0^.........000-
-0000^.......0^.......00000-
-00000000000000000000000000-
-00000000000000000000000000-
----------------------------
@ -128,15 +128,21 @@ levels = {[5049] = [[
to_write = ""
--remove all "\n" from level strings
current = 0
for i, v in pairs(levels) do
v = string.gsub(v, "\n", "")
to_write = to_write.." case "..i..":\n memcpy(level, \""..v.."\", "..#v..");\n break;\n"
to_write = to_write.." case "..i..":\n memcpy(level, \""..v.."\", "..#v..");\n"
if string.find(v, 'c') then
to_write = to_write.." *coin_id = "..current..";\n"
end
to_write = to_write.." break;\n"
current = current + 1
end
--finish and write
to_write = [[#include "levels.h"
#include <gint/std/string.h>
void set_level(int level_id, char *level) {
void set_level(int level_id, char level[], unsigned int *coin_id) {
switch (level_id)
{
]]..to_write.." }\n}\n"

Binary file not shown.

@ -13,6 +13,7 @@ extern image_t img_spike; //spike texture, 16x16
extern image_t img_ice; //ice texture, 16x8
extern image_t img_glue; //glue texture, 16x8
extern image_t img_jitem; //jump item texture, 16x16
extern image_t img_coin; //coin item texture, 16x16
//animated textures
extern image_t img_elevator1, img_elevator2, img_elevator3, img_elevator4;
extern image_t img_elevator5, img_elevator6, img_elevator7, img_elevator8;
@ -35,7 +36,7 @@ void draw_player(int old_x, int old_y, int x, int y)
}
}
void draw_level(char level[], char upgrades[], unsigned int step)
void draw_level(char level[], char upgrades[], char erase_coin)
{
dclear(BG_COLOR);
unsigned int i = 0;
@ -59,6 +60,12 @@ void draw_level(char level[], char upgrades[], unsigned int step)
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_ground);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_glue);
break;
case 'j':
if (upgrades[0]) erase_tile(x, y, level);
break;
case 'c':
if (erase_coin) erase_tile(x, y, level);
break;
}
x += 16;
if (x == 16*LEVEL_WIDTH)
@ -83,7 +90,6 @@ void draw_level_anims(char level[], char upgrades[], unsigned int step)
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, ani_elevator[(step/2)%16]);
break;
case 'j':
if (!upgrades[0])
{
unsigned int buffer = (step/20)%4 - 1;
if (buffer == 2) buffer = 0;
@ -91,7 +97,15 @@ void draw_level_anims(char level[], char upgrades[], unsigned int step)
y + 15 + DRAW_OFFSET_Y, BG_COLOR);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y + buffer, &img_jitem);
}
else level[i] = '.';
break;
case 'c':
{
unsigned int buffer = (step/20)%4 - 1;
if (buffer == 2) buffer = 0;
drect(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, x + 15 + DRAW_OFFSET_X,
y + 15 + DRAW_OFFSET_Y, BG_COLOR);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y + buffer, &img_coin);
}
break;
}
x += 16;
@ -123,7 +137,7 @@ void draw_upgrade_message(char item)
case 'j':
{
extern image_t img_jitem_popup;
dimage(96 + DRAW_OFFSET_X, 160 + DRAW_OFFSET_Y, &img_jitem_popup);
dimage(112 + DRAW_OFFSET_X, 88 + DRAW_OFFSET_Y, &img_jitem_popup);
break;
}
}

@ -16,6 +16,8 @@
#define JUMP_SCALE 12
#define JUMP_REDUCTION -0.41
#define UG_CAN_JUMP upgrades[0]
char coins[1];
#define DRAW_LEVEL() draw_level(level, upgrades, coins[coin_id])
void dupdate(); //gint function
//test if jump pressed
@ -35,9 +37,11 @@ int main(void)
int level_id = 5050;
//START UPGRADES
char upgrades[] = {
0 //can jump
0 //jump
};
//END UPGRADES
unsigned int coin_id = 0;
unsigned int coin_count = 0;
char jump_pressed = 1; //avoid holding jump
char jump_buffer = 0; //jump buffer, last 3 frames
unsigned int jump_hold = 0; //number of consecutive frames jump has been held
@ -53,8 +57,8 @@ int main(void)
int old_x, old_y;
char spawn_buffer = 0;
unsigned int step = 0;
set_level(level_id, level);
draw_level(level, upgrades, step);
set_level(level_id, level, &coin_id);
DRAW_LEVEL();
draw_level_anims(level, upgrades, step);
player_x = start_x;
player_y = start_y;
@ -190,8 +194,8 @@ int main(void)
level_id -= 1;
player_x = 416 + (move * (int) hspd);
set_start_pos(&start_x, &start_y, player_x, player_y);
set_level(level_id, level);
draw_level(level, upgrades, step);
set_level(level_id, level, &coin_id);
DRAW_LEVEL();
reset_old_pos(&old_x, &old_y);
}
else if (player_x >= 416)
@ -199,8 +203,8 @@ int main(void)
level_id += 1;
player_x = 22 + (move * (int) hspd);
set_start_pos(&start_x, &start_y, player_x, player_y);
set_level(level_id, level);
draw_level(level, upgrades, step);
set_level(level_id, level, &coin_id);
DRAW_LEVEL();
reset_old_pos(&old_x, &old_y);
}
else if (player_y <= 8)
@ -208,8 +212,8 @@ int main(void)
level_id -= 100;
player_y = 246;
spawn_buffer = 1;
set_level(level_id, level);
draw_level(level, upgrades, step);
set_level(level_id, level, &coin_id);
DRAW_LEVEL();
reset_old_pos(&old_x, &old_y);
}
else if (player_y >= 248)
@ -217,8 +221,8 @@ int main(void)
level_id += 100;
player_y = 10;
set_start_pos(&start_x, &start_y, player_x, player_y);
set_level(level_id, level);
draw_level(level, upgrades, step);
set_level(level_id, level, &coin_id);
DRAW_LEVEL();
reset_old_pos(&old_x, &old_y);
}
//item get
@ -228,6 +232,13 @@ int main(void)
erase_tile(player_x, player_y, level);
draw_upgrade_message('j');
}
//coin get
if (collide(player_x, player_y, level, 'c'))
{
coins[coin_id] = 1;
coin_count++;
erase_tile(player_x, player_y, level);
}
//exit
if (keydown(KEY_EXIT)) return 0;
}

Loading…
Cancel
Save