Compare commits

..

18 Commits

Author SHA1 Message Date
mibi88 3572e739f1 20220727 - Correction d'une erreur de formatage. 2022-08-27 15:17:02 +02:00
mibi88 0a7883193f 20220727 - Informations utiles. 2022-08-27 14:58:24 +02:00
mibi88 0f125742e5 20220827 - Feu de camp ajouté, cleanup du code. 2022-08-27 13:35:21 +02:00
mibi88 81a7e1113c 20220826 - Correction d'un bug qui empêchait de poser des blocs. 2022-08-26 18:39:39 +02:00
mibi88 1c4c1a11ae 20220826 - La vitesse de destruction varie selon le type et l'outil, pioche ajoutée (premier outil !). 2022-08-26 18:06:27 +02:00
mibi88 8e677b7b59 20220719 - Petite correction des messages. 2022-07-29 12:35:15 +02:00
mibi88 56a21494ac 20220728 - Dernière build. 2022-07-28 17:58:01 +02:00
mibi88 eea76509d6 20220728 - Correction du font. 2022-07-28 17:56:33 +02:00
mibi88 528c63abc8 20220728 - Little font fix. 2022-07-28 17:45:57 +02:00
mibi88 a25ff1878e 20220728 - Crafting fonctionnel. 2022-07-28 13:50:16 +02:00
mibi88 02a36f236c 20220727 - Menu pour le crafting terminé. 2022-07-27 13:41:44 +02:00
mibi88 0db6dd3238 20220724 - Préparation du crafting. amélioration, ajout de quelque sprites. 2022-07-24 12:44:49 +02:00
mibi88 283b3e6248 20220723 - Correction des bugs dans la destruction des blocs, on peut maintenant bouger les blocs dans l'inventaire. 2022-07-23 14:50:50 +02:00
mibi88 6b51915814 20220720 - Nouveau title.png 2022-07-23 12:40:50 +02:00
mibi88 8305603f65 20220720 - Plein de nouveaux sprites ! 2022-07-20 12:16:12 +02:00
mibi88 1e2b91f5ff 20220718 - Destruction des blocs ralentie presque fonctionnelle. 2022-07-18 22:33:05 +02:00
mibi88 6c303bf972 20220718 - Correction du README. 2022-07-18 13:44:28 +02:00
mibi88 069b763156 20220718 - Nouvel inventaire. 2022-07-18 13:39:46 +02:00
70 changed files with 916 additions and 61 deletions

View File

@ -14,21 +14,72 @@ set(SOURCES
)
set(ASSETS_fx
assets-fx/title.png
assets-fx/microfont.png
assets-fx/tiles/blocks/soil.png
assets-fx/tiles/blocks/grass.png
assets-fx/tiles/blocks/stone.png
assets-fx/tiles/blocks/coal.png
assets-fx/tiles/blocks/steel.png
assets-fx/tiles/blocks/wood.png
assets-fx/tiles/blocks/apple.png
assets-fx/tiles/blocks/barrel.png
assets-fx/tiles/blocks/bed.png
assets-fx/tiles/blocks/chain.png
assets-fx/tiles/blocks/cherry.png
assets-fx/tiles/blocks/choco.png
assets-fx/tiles/blocks/cotton.png
assets-fx/tiles/blocks/fire.png
assets-fx/tiles/blocks/furnace.png
assets-fx/tiles/blocks/granit.png
assets-fx/tiles/blocks/ingot.png
assets-fx/tiles/blocks/lantern.png
assets-fx/tiles/blocks/leaves.png
assets-fx/tiles/blocks/orange.png
assets-fx/tiles/blocks/pear.png
assets-fx/tiles/blocks/pumpkin.png
assets-fx/tiles/blocks/starston.png
assets-fx/tiles/blocks/water1.png
assets-fx/tiles/blocks/water2.png
assets-fx/tiles/blocks/wheat.png
assets-fx/tiles/blocks/woodplks.png
assets-fx/tiles/blocks/woodstep1.png
assets-fx/tiles/blocks/woodstep2.png
assets-fx/player/skin1/player0.png
assets-fx/player/skin1/player1.png
assets-fx/player/skin1/player2.png
assets-fx/player/skin1/player3.png
assets-fx/tools/pickaxe.png
assets-fx/tools/axe.png
assets-fx/tools/sword.png
assets-fx/tools/shovel.png
assets-fx/tools/hoe.png
assets-fx/tools/selectcross.png
assets-fx/ui_icons/invnormal.png
assets-fx/ui_icons/invselected.png
assets-fx/ui_icons/craftselect.png
assets-fx/ui_icons/arrow1.png
assets-fx/ui_icons/arrow2.png
assets-fx/tiles/overlays/block_break1.png
assets-fx/tiles/overlays/block_break2.png
assets-fx/tiles/overlays/block_break3.png
assets-fx/tiles/overlays/block_break4.png
assets-fx/tiles/overlays/smoke1.png
assets-fx/tiles/overlays/smoke2.png
assets-fx/living/animals/chicken.png
assets-fx/living/animals/cow.png
assets-fx/living/animals/horse.png
assets-fx/living/animals/pig.png
assets-fx/living/animals/sheep.png
assets-fx/living/ennemies/badbird1.png
assets-fx/living/ennemies/badbird2.png
assets-fx/living/ennemies/caterp1.png
assets-fx/living/ennemies/caterp2.png
assets-fx/living/ennemies/gloup1.png
assets-fx/living/ennemies/gloup2.png
assets-fx/living/ennemies/zombie1.png
assets-fx/living/ennemies/zombie2.png
# ...
)
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
@ -38,4 +89,4 @@ target_link_libraries(myaddin Gint::Gint)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
generate_g1a(TARGET myaddin OUTPUT "Builder.g1a"
NAME "Builder" ICON assets-fx/icon.png)
endif()
endif()

View File

@ -1,3 +1,68 @@
# Builder
A little game like Minecraft or Terraria.
A little game like Minecraft or Terraria.
# Build an install
Install gint if you have not already installed it.
```
$ fxsdk build-fx
$ bash clear.sh
```
Copy `Builder.g1a` that is in `./latest-build/` to the main folder of your calculator.
# Gameplay
## When playing
1 - Break a block.
EXE - Add a block.
MENU - Detailled inventory.
8,4,5,6 - Select blocks.
0 - Select something in the inventory.
Right, Left - Move.
SHIFT - Jump.
## In the detailled inventory
SHIFT - Select a stack.
0 - Move the cursor.
ALPHA - Transfer the blocks from the stack to the cursor.
X² - Transfer a block from the stack to the cursor.
EXE - Quit this menu.
MENU - Go to the crafting menu.
## In the crafting
SHIFT - Build the selected block.
Right, Left - Choose another block to build.
EXE - Quit crafting.
## Incinerator
SHIFT - Burn an item from the selected stack.
DEL - Burn the selected stack.
EXE - Quit this menu.
## Everywhere
EXIT - Quit the game.
# Missing features
- [ ] Survival.
- [ ] Mobs.
- [ ] Save.
- [ ] Included help.
- [ ] Water and lava.
- [ ] Leafs.
- [ ] Many blocks (see `./assets-fx/tiles/blocks/`).
- [ ] Portals ?
- [ ] Boss ?
- [ ] Multiplayer ?
# Issues
See tickets.
# Topic
https://www.planet-casio.com/Fr/forums/topic17108-last-builder-un-jeu-de-construction-comme-minecraft-et-terraria.html#188890
# Testing
You can get the latest build in `./latest-build/`.
If you find an issue, please write a ticket !

View File

@ -1,3 +1,10 @@
title.png:
type: bopti-image
name: title_img
name: title_img
microfont.png:
type: font
charset: print
grid.size: 4x4
grid.padding: 1
proportional: true
name: microfont

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

View File

@ -0,0 +1,15 @@
chicken.png:
type: bopti-image
name: animal_chicken
cow.png:
type: bopti-image
name: animal_cow
horse.png:
type: bopti-image
name: animal_horse
pig.png:
type: bopti-image
name: animal_pig
sheep.png:
type: bopti-image
name: animal_sheep

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

View File

@ -0,0 +1,24 @@
badbird1.png:
type: bopti-image
name: ennemy_badbird_1
badbird2.png:
type: bopti-image
name: ennemy_badbird_2
caterp1.png:
type: bopti-image
name: ennemy_caterp_1
caterp2.png:
type: bopti-image
name: ennemy_caterp_2
gloup1.png:
type: bopti-image
name: ennemy_gloup_1
gloup2.png:
type: bopti-image
name: ennemy_gloup_2
zombie1.png:
type: bopti-image
name: ennemy_zombie_1
zombie2.png:
type: bopti-image
name: ennemy_zombie_2

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

BIN
assets-fx/microfont.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

View File

@ -16,3 +16,75 @@ coal.png:
steel.png:
type: bopti-image
name: steel_tile
apple.png:
type: bopti-image
name: apple_tile
barrel.png:
type: bopti-image
name: barrel_tile
bed.png:
type: bopti-image
name: bed_tile
chain.png:
type: bopti-image
name: chain_tile
cherry.png:
type: bopti-image
name: cherry_tile
choco.png:
type: bopti-image
name: choco_tile
cotton.png:
type: bopti-image
name: cotton_tile
fire.png:
type: bopti-image
name: fire_tile
furnace.png:
type: bopti-image
name: furnace_tile
granit.png:
type: bopti-image
name: granit_tile
ingot.png:
type: bopti-image
name: ingot_tile
lantern.png:
type: bopti-image
name: lantern_tile
leaves.png:
type: bopti-image
name: leaves_tile
orange.png:
type: bopti-image
name: orange_tile
pear.png:
type: bopti-image
name: pear_tile
pumpkin.png:
type: bopti-image
name: pumpkin_tile
starston.png:
type: bopti-image
name: starstone_tile
water1.png:
type: bopti-image
name: water_1_tile
water2.png:
type: bopti-image
name: water_2_tile
wheat.png:
type: bopti-image
name: wheat_tile
woodplks.png:
type: bopti-image
name: woodplanks_tile
woodstep1.png:
type: bopti-image
name: woodsteps_1_tile
woodstep2.png:
type: bopti-image
name: woodsteps_2_tile
woodstick.png:
type: bopti-image
name: woodstick_tile

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 B

View File

@ -0,0 +1,18 @@
block_break1.png:
type: bopti-image
name: overlay_break_1
block_break2.png:
type: bopti-image
name: overlay_break_2
block_break3.png:
type: bopti-image
name: overlay_break_3
block_break4.png:
type: bopti-image
name: overlay_break_4
smoke1.png:
type: bopti-image
name: smoke_1
smoke2.png:
type: bopti-image
name: smoke_2

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 B

After

Width:  |  Height:  |  Size: 221 B

BIN
assets-fx/tools/axe.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B

View File

@ -1,6 +1,18 @@
pickaxe.png:
type: bopti-image
name: pickaxe_tool
axe.png:
type: bopti-image
name: axe_tool
sword.png:
type: bopti-image
name: sword_tool
hoe.png:
type: bopti-image
name: hoe_tool
shovel.png:
type: bopti-image
name: shovel_tool
selectcross.png:
type: bopti-image
name: select_tool

BIN
assets-fx/tools/hoe.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

BIN
assets-fx/tools/shovel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B

BIN
assets-fx/tools/sword.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

View File

@ -0,0 +1,15 @@
invnormal.png:
type: bopti-image
name: invnormal
invselected.png:
type: bopti-image
name: invselected
craftselect.png:
type: bopti-image
name: craftselection
arrow1.png:
type: bopti-image
name: arrow_1
arrow2.png:
type: bopti-image
name: arrow_2

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 B

3
clear.sh Normal file
View File

@ -0,0 +1,3 @@
rm ./build-fx ./latest-build --recursive --force
mkdir latest-build
mv Builder.g1a latest-build/Builder.g1a

BIN
latest-build/Builder.g1a Normal file

Binary file not shown.

View File

@ -1,6 +1,8 @@
# define GAMESNUM 5 // How many games you can save (and play).
# define WORLDGEN_SOIL 8 // Blocks (y) of soil.
# define WORLD_WIDTH 64 // World width.
# define WORLD_WIDTH 256 // World width.
# define WORLD_HEIGHT 64 // World height.
# define INVENTORY_SIZE 5 // Size of the inventory.
# define INVENTORY_SIZE 5 // Size of the inventory.
# define CRAFTSIZE 9 // How many different blocks you can use to craft something.
# define CRAFTINGS 4 // How many things you can craft.

View File

@ -3,13 +3,23 @@
# include <stdlib.h>
# include <time.h>
# include <string.h>
#include <gint/clock.h>
# include <gint/clock.h>
# include "msg_fr.h"
# include "itemsizes.h"
# include "gamesettings.h"
# include "worldgen.h"
# include "itoa.h"
# define ERROR(error, errorcode) dclear(C_WHITE); \
dprint(1, 1, C_BLACK, "ERROR"); \
dprint(1, 6, C_BLACK, "LINE : %d", __LINE__); \
dprint(1, 12, C_BLACK, "FILE : %d", __FILE__); \
dprint(1, 18, C_BLACK, "ERROR NUM : %d", errorcode); \
dprint(1, 24, C_BLACK, "%c", error); \
dupdate(); \
getkey(); \
return errorcode;
extern bopti_image_t title_img;
extern bopti_image_t soil_tile;
extern bopti_image_t grass_tile;
@ -17,18 +27,90 @@ extern bopti_image_t stone_tile;
extern bopti_image_t coal_tile;
extern bopti_image_t steel_tile;
extern bopti_image_t wood_tile;
extern bopti_image_t woodplanks_tile;
extern bopti_image_t woodsteps_1_tile;
extern bopti_image_t woodsteps_2_tile;
extern bopti_image_t woodstick_tile;
extern bopti_image_t fire_tile;
extern bopti_image_t skin1_player_left1;
extern bopti_image_t skin1_player_left2;
extern bopti_image_t skin1_player_right1;
extern bopti_image_t skin1_player_right2;
extern bopti_image_t select_tool;
extern bopti_image_t pickaxe_tool;
extern bopti_image_t invnormal;
extern bopti_image_t invselected;
extern bopti_image_t craftselection;
extern bopti_image_t arrow_1;
extern bopti_image_t arrow_2;
extern bopti_image_t overlay_break_1;
extern bopti_image_t overlay_break_2;
extern bopti_image_t overlay_break_3;
extern bopti_image_t overlay_break_4;
extern font_t microfont;
# include "player.h"
# include "objects.h"
//int x, y, pos, hour, animation, orient, timing, falling, jumping, jumpheight;
int pos, hour;
char tmp_char[2];
Player player;
Crafting crafting;
Tool hand;
Tool wood_pickaxe;
Destroy destroy;
const int canbeplaced_lenght = 7;
const int canbeplaced[7] = {1, 2, 3, 4, 5, 6, 8};
const int hasmenu_lenght = 1;
const int hasmenu[1] = {8};
void drawtile(int x, int y, int tilenum) {
switch(tilenum){
case 1:
dimage(x, y, &soil_tile); break;
case 2:
dimage(x, y, &stone_tile); break;
case 3:
dimage(x, y, &coal_tile); break;
case 4:
dimage(x, y, &steel_tile); break;
case 5:
dimage(x, y, &wood_tile); break;
case 6:
dimage(x, y, &woodplanks_tile); break;
case 7:
dimage(x, y, &pickaxe_tool); break;
case 8:
dimage(x, y, &fire_tile); break;
}
}
void drawoverlay() {
/*
Calculation details :
x = x - 60
y = y - 24
ftx = x>>3
fty = y>>3
sx = ftx*8-x
sy = fty*8-y
rx = sx+(tx-ftx)*8
ry = sy+(ty-fty)*8
*/
int rx = (((player.x-60)>>3)*8-(player.x-60))+(player.select_tx-((player.x-60)>>3))*8;
int ry = (((player.y-24)>>3)*8-(player.y-24))+(player.select_ty-((player.y-24)>>3))*8;
switch(player.overlayframe){
case 1:
dimage(rx, ry, &overlay_break_1);break;
case 2:
dimage(rx, ry, &overlay_break_2);break;
case 3:
dimage(rx, ry, &overlay_break_3);break;
case 4:
dimage(rx, ry, &overlay_break_4);break;
}
}
void drawselectedgame(int selected) {
dclear(C_WHITE);
// dimage(16, 8, &title_img);
@ -41,7 +123,7 @@ void drawselectedgame(int selected) {
void addtree(int pos, unsigned short int * terrain, int n){
int i;
srand(clock());
for(i=pos-rand()%11;i!=pos;i++){
for(i=pos-rand()%6;i!=pos;i++){
terrain[i*WORLD_WIDTH+(n>>3)] = 5;
}
}
@ -55,7 +137,9 @@ void addtrees(unsigned short int * terrain){
break;
}
}
addtree(pos, terrain, n);
if(n != (player.x>>3)){
addtree(pos, terrain, n);
}
}
}
}
@ -83,6 +167,10 @@ void mappartdisplaying(int x, int y, unsigned short int * terrain, int player) {
dimage(px, py, &steel_tile); break;
case 5:
dimage(px, py, &wood_tile); break;
case 6:
dimage(px, py, &woodplanks_tile); break;
case 8:
dimage(px, py, &fire_tile); break;
}
px += 8;
}
@ -139,14 +227,149 @@ int collisiononmap(int x, int y, unsigned short int * terrain, int testx, int te
}
return 0;
}
Player player;
void drawinventory(){
int i;
for(i=0;i!=5;i++){
if(i == player.invselect){
dimage(26+i*15, 49, &invselected);
}else{
dimage(26+i*15, 49, &invnormal);
}
drawtile(26+i*15+3, 52, player.inventoryitems[i]);
}
}
void drawdetailinv(){
int i;
dtext(1, 1, C_BLACK, INV_INFO);
for(i=0;i!=INVENTORY_SIZE;i++){
pos = i*8+16;
drawtile(5, pos, player.inventoryitems[i]);
itoa(player.inventorynum[i], tmp_char);
dtext(20, pos, C_BLACK, tmp_char);
if(i == player.invselect){
dtext(60, pos, C_BLACK, SELECTED);
}
if(i == player.invmoving){
dtext(66, pos, C_BLACK, MOVING);
}
}
}
void drawcrafting(){
int i;
dfont(&microfont);
dimage(32, 0, &craftselection);
dimage(4, 28, &arrow_2);
dimage(116, 28, &arrow_1);
drawtile(36, 28, craftingitem[crafting.selected]);
dtext(36, 38, C_BLACK, MULTIPLY);
itoa(craftingnum[crafting.selected], tmp_char);
dtext(36, 44, C_BLACK, tmp_char);
pos = 4;
for(i=crafting.selected*CRAFTSIZE;i!=(crafting.selected+1)*CRAFTSIZE;i++){
if(craftingsnum[i]!=0){
switch(craftingsitems[i]){
case 1:
dtext(58, pos, C_BLACK, SOIL_TILE); break;
case 2:
dtext(58, pos, C_BLACK, STONE_TILE); break;
case 3:
dtext(58, pos, C_BLACK, COAL_TILE); break;
case 4:
dtext(58, pos, C_BLACK, STEEL_TILE); break;
case 5:
dtext(58, pos, C_BLACK, WOOD_TILE); break;
case 6:
dtext(58, pos, C_BLACK, WOODPLANKS_TILE); break;
case 7:
dtext(58, pos, C_BLACK, WOODPICKAXE_TILE); break;
case 8:
dtext(58, pos, C_BLACK, FIRE_TILE); break;
}
itoa(craftingsnum[i], tmp_char);
dtext(46, pos, C_BLACK, tmp_char);
dtext(52, pos, C_BLACK, MULTIPLY);
pos+=6;
}
}
dfont(dfont_default());
}
void drawdestroy() {
int i;
dtext(1, 1, C_BLACK, DESTROY_INFO);
for(i=0;i!=INVENTORY_SIZE;i++){
pos = i*8+16;
drawtile(5, pos, player.inventoryitems[i]);
itoa(player.inventorynum[i], tmp_char);
dtext(20, pos, C_BLACK, tmp_char);
if(i == destroy.selected){
dtext(60, pos, C_BLACK, SELECTED);
}
}
}
bool is_in(int item, int* array, int len){
for(int i=0;i!=len;i++){
if(array[i] == item){
return 1;
}
}
return 0;
}
int main(void) {
// Tools //
// Hand
hand.easy_lenght = 1;
hand.middle_lenght = 1;
hand.hard_lenght = 1;
hand.very_hard_lenght = 2;
hand.breakable_middle = NULL;
hand.breakable_hard = NULL;
hand.breakable_very_hard = NULL;
hand.breakable_middle = malloc(sizeof(int));
hand.breakable_hard = malloc(sizeof(int));
hand.breakable_very_hard = malloc(hand.very_hard_lenght*sizeof(int));
if(hand.breakable_middle == NULL || hand.breakable_hard == NULL || hand.breakable_very_hard == NULL){
ERROR("Need more ram !", 2)
}
hand.breakable_middle[0] = 1;
hand.breakable_hard[0] = 6;
hand.breakable_very_hard[0] = 5;
hand.breakable_very_hard[1] = 8;
hand.attack = 1;
// Wooden pickaxe
wood_pickaxe.easy_lenght = 1;
wood_pickaxe.middle_lenght = 1;
wood_pickaxe.hard_lenght = 3;
wood_pickaxe.very_hard_lenght = 3;
wood_pickaxe.breakable_middle = NULL;
wood_pickaxe.breakable_hard = NULL;
wood_pickaxe.breakable_very_hard = NULL;
wood_pickaxe.breakable_middle = malloc(sizeof(int));
wood_pickaxe.breakable_hard = malloc(wood_pickaxe.hard_lenght*sizeof(int));
wood_pickaxe.breakable_very_hard = malloc(wood_pickaxe.very_hard_lenght*sizeof(int));
if(wood_pickaxe.breakable_middle == NULL || wood_pickaxe.breakable_hard == NULL || wood_pickaxe.breakable_very_hard == NULL){
ERROR("Need more ram !", 3)
}
wood_pickaxe.breakable_middle[0] = 1;
wood_pickaxe.breakable_hard[0] = 6;
wood_pickaxe.breakable_hard[1] = 2;
wood_pickaxe.breakable_hard[2] = 8;
wood_pickaxe.breakable_very_hard[0] = 5;
wood_pickaxe.breakable_very_hard[1] = 3;
wood_pickaxe.breakable_very_hard[2] = 4;
wood_pickaxe.attack = 2;
///////////
dclear(C_WHITE);
dimage(16, TITLE_IMAGE_MARGIN, &title_img);
dtext(1, TITLE_MARGIN, C_BLACK, TITLE_START);
dupdate();
int key = 0, game = 0, selected = 0, i;
unsigned short terrain[WORLD_WIDTH*WORLD_HEIGHT];
int key = 0, game = 0, selected = 0, i, n;
unsigned short int* terrain = NULL;
terrain = malloc(WORLD_WIDTH*WORLD_HEIGHT*sizeof(unsigned short int));
if(terrain == NULL){
ERROR("Need more ram !", 0)
}
while(keydown(KEY_EXIT) == 0){
////////// TITLE SCREEN //////////
if(game == 0){
@ -185,12 +408,12 @@ int main(void) {
terrain[i] = 0;
}
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 40) - (WORLD_HEIGHT - 50) + 1)) + WORLD_HEIGHT - 50), WORLD_HEIGHT - 50, WORLD_HEIGHT - 40, 0, 1);
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 50) - (WORLD_HEIGHT - 60) + 1)) + WORLD_HEIGHT - 60), WORLD_HEIGHT - 60, WORLD_HEIGHT - 50, 0, 1);
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 30) - (WORLD_HEIGHT - 40) + 1)) + WORLD_HEIGHT - 40), WORLD_HEIGHT - 40, WORLD_HEIGHT - 30, 3, 2);
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 40) - (WORLD_HEIGHT - 50) + 1)) + WORLD_HEIGHT - 50), WORLD_HEIGHT - 50, WORLD_HEIGHT - 40, 3, 2);
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 20) - (WORLD_HEIGHT - 30) + 1)) + WORLD_HEIGHT - 30), WORLD_HEIGHT - 30, WORLD_HEIGHT - 20, 4, 2);
dtext(1, 1, C_BLACK, "Adding trees");
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 30) - (WORLD_HEIGHT - 40) + 1)) + WORLD_HEIGHT - 40), WORLD_HEIGHT - 40, WORLD_HEIGHT - 30, 4, 2);
// dtext(1, 1, C_BLACK, "Adding trees");
///// Add trees /////
addtrees(terrain);
/////////////////////
@ -208,11 +431,29 @@ int main(void) {
player.jumping = 0;
player.jumpheight = 0;
player.falling = 0;
player.overlayframe = 0;
player.overlaytimer = 0;
player.wasdestroyingbefore = 0;
player.destroytime = 3;
player.select_tx = 0;
player.select_ty = 0;
player.invselect = 0;
player.invmoving = 0;
for(i=0;i!=INVENTORY_SIZE;i++){
player.inventoryitems[i] = 0;
player.inventorynum[i] = 0;
}
player.tool = hand;
}else if(game == 3){
clock_t begin = clock();
switch(player.inventoryitems[player.invselect]){
case 7:
player.tool = wood_pickaxe; break;
default:
player.tool = hand; break;
};
player.select_tx = ((player.x+player.selx)>>3);
player.select_ty = ((player.y+player.sely)>>3);
clearevents();
if(keydown(KEY_RIGHT) && (collisiononmap(player.x, player.y, terrain, 67, 35) == 0 && collisiononmap(player.x, player.y, terrain, 67, 25) == 0)){
player.x++;
@ -282,16 +523,49 @@ int main(void) {
}else if (keydown(KEY_6) && player.selx<16){
player.selx++;
}
if(((player.x+player.selx)>>3)!=player.select_tx||((player.y+player.sely)>>3)!=player.select_ty){
player.overlayframe = 0;
player.overlaytimer = 0;
player.wasdestroyingbefore = 0;
}
pos = ((player.y+player.sely)>>3)*WORLD_WIDTH+((player.x+player.selx)>>3);
if(pos<=WORLD_WIDTH*WORLD_HEIGHT && pos>=0){
player.is_breakable = 1;
if(is_in(terrain[pos], player.tool.breakable_easy, player.tool.easy_lenght)){
player.destroytime = 4;
}else if(is_in(terrain[pos], player.tool.breakable_middle, player.tool.middle_lenght)){
player.destroytime = 8;
}else if(is_in(terrain[pos], player.tool.breakable_hard, player.tool.hard_lenght)){
player.destroytime = 16;
}else if(is_in(terrain[pos], player.tool.breakable_very_hard, player.tool.very_hard_lenght)){
player.destroytime = 32;
}else{
player.is_breakable = 0;
}
clearevents();
if (keydown(KEY_EXE) && terrain[pos] == 0 && player.inventorynum[player.invselect] != 0){
terrain[pos] = player.inventoryitems[player.invselect];
player.inventorynum[player.invselect]--;
if(player.inventorynum[player.invselect] == 0) {
player.inventoryitems[player.invselect] = 0;
if (keydown(KEY_EXE)){
int placed = 0;
if(terrain[pos] == 0 && player.inventorynum[player.invselect] != 0 && is_in(player.inventoryitems[player.invselect], (int*)canbeplaced, canbeplaced_lenght)){
placed = player.inventoryitems[player.invselect];
terrain[pos] = player.inventoryitems[player.invselect];
player.inventorynum[player.invselect]--;
if(player.inventorynum[player.invselect] == 0) {
player.inventoryitems[player.invselect] = 0;
}
if(is_in(placed, (int*)hasmenu, hasmenu_lenght)){
clearevents();
while(keydown(KEY_EXE)){
clearevents();
}
}
}else if(terrain[pos] == 8){
game = 6;
clearevents();
while(keydown(KEY_EXE)){
clearevents();
}
}
}else if (keydown(KEY_1) && terrain[pos] != 0){
}else if (keydown(KEY_1) && terrain[pos] != 0 && player.is_breakable && player.overlaytimer == player.destroytime && player.overlayframe == 4 && (player.select_tx == player.old_select_tx && player.select_ty == player.old_select_ty)){
for(i=0;i!=INVENTORY_SIZE;i++){
if((terrain[pos] == player.inventoryitems[i] && player.inventorynum[i] < 64 && terrain[pos] != 0) || (player.inventoryitems[i] == 0 && player.inventorynum[i] == 0 && terrain[pos] != 0)) {
player.inventoryitems[i] = terrain[pos];
@ -300,6 +574,22 @@ int main(void) {
break;
}
}
player.overlayframe = 0;
player.overlaytimer = 0;
player.wasdestroyingbefore = 0;
}else if (keydown(KEY_1) && terrain[pos] != 0 && player.is_breakable && (player.select_tx == player.old_select_tx && player.select_ty == player.old_select_ty)){
if(player.overlaytimer == player.destroytime){
player.overlaytimer = 0;
player.overlayframe++;
}
player.overlaytimer++;
if(player.wasdestroyingbefore == 0){
player.wasdestroyingbefore = 1;
}
}else if(player.wasdestroyingbefore == 1 && keydown(KEY_1) == 0){
player.overlayframe = 0;
player.overlaytimer = 0;
player.wasdestroyingbefore = 0;
}
}
clearevents();
@ -309,41 +599,245 @@ int main(void) {
}else{
player.invselect = 0;
}
clearevents();
while(keydown(KEY_0)){
clearevents();
}
}
clearevents();
if(keydown(KEY_MENU)){
game = 4;
while(keydown(KEY_MENU)){
clearevents();
}
}
// dtext(1, 1, C_BLACK, "test");
mappartdisplaying(player.x, player.y, terrain, player.orient+player.animation);
if(player.wasdestroyingbefore && (player.select_tx == player.old_select_tx && player.select_ty == player.old_select_ty)){
drawoverlay();
}
dimage(player.selx + 56, player.sely + 20, &select_tool);
drawinventory();
player.old_select_tx = player.select_tx;
player.old_select_ty = player.select_ty;
dupdate();
sleep_ms(20);
clock_t end = clock();
double time_spent = (double)(end-begin)/CLOCKS_PER_SEC;
int ms = time_spent*1000;
if(ms < 20){
sleep_ms(20-ms);
}
}else if(game == 4){
dclear(C_WHITE);
for(i=0;i!=INVENTORY_SIZE;i++){
pos = i*8;
switch(player.inventoryitems[i]){
case 1:
dimage(5, pos, &soil_tile); break;
case 2:
dimage(5, pos, &stone_tile); break;
case 3:
dimage(5, pos, &coal_tile); break;
case 4:
dimage(5, pos, &steel_tile); break;
case 5:
dimage(5, pos, &wood_tile); break;
}
itoa(player.inventorynum[i], tmp_char);
dtext(20, pos, C_BLACK, tmp_char);
if(i == player.invselect){
dtext(60, pos, C_BLACK, SELECTED);
}
}
drawdetailinv();
dupdate();
clearevents();
if(keydown(KEY_EXE)){
game = 3;
clearevents();
while(keydown(KEY_EXE)){
clearevents();
}
}else if(keydown(KEY_MENU)){
game = 5;
clearevents();
while(keydown(KEY_MENU)){
clearevents();
}
}
clearevents();
if(keydown(KEY_SHIFT)){
player.invmoving = player.invselect;
clearevents();
while(keydown(KEY_SHIFT)){
clearevents();