forked from mibi88/Builder
20220718 - Destruction des blocs ralentie presque fonctionnelle.
This commit is contained in:
parent
6c303bf972
commit
1e2b91f5ff
|
@ -28,6 +28,10 @@ set(ASSETS_fx
|
|||
assets-fx/tools/selectcross.png
|
||||
assets-fx/ui_icons/invnormal.png
|
||||
assets-fx/ui_icons/invselected.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
|
||||
# ...
|
||||
)
|
||||
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
|
||||
|
|
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 |
|
@ -0,0 +1,12 @@
|
|||
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
|
Binary file not shown.
72
src/main.c
72
src/main.c
|
@ -3,7 +3,7 @@
|
|||
# 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"
|
||||
|
@ -24,6 +24,10 @@ extern bopti_image_t skin1_player_right2;
|
|||
extern bopti_image_t select_tool;
|
||||
extern bopti_image_t invnormal;
|
||||
extern bopti_image_t invselected;
|
||||
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;
|
||||
|
||||
# include "player.h"
|
||||
|
||||
|
@ -31,6 +35,33 @@ extern bopti_image_t invselected;
|
|||
int pos, hour;
|
||||
char tmp_char[2];
|
||||
|
||||
Player player;
|
||||
|
||||
void drawoverlay() {
|
||||
/*
|
||||
Détails du calcul ci-dessous :
|
||||
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);
|
||||
|
@ -57,7 +88,9 @@ void addtrees(unsigned short int * terrain){
|
|||
break;
|
||||
}
|
||||
}
|
||||
addtree(pos, terrain, n);
|
||||
if(n != (player.x>>3)){
|
||||
addtree(pos, terrain, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +174,6 @@ 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++){
|
||||
|
@ -166,8 +198,9 @@ void drawinventory(){
|
|||
}
|
||||
void drawdetailinv(){
|
||||
int i;
|
||||
dtext(1, 1, C_BLACK, INV_INFO);
|
||||
for(i=0;i!=INVENTORY_SIZE;i++){
|
||||
pos = i*8;
|
||||
pos = i*8+16;
|
||||
switch(player.inventoryitems[i]){
|
||||
case 1:
|
||||
dimage(5, pos, &soil_tile); break;
|
||||
|
@ -255,6 +288,12 @@ 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;
|
||||
for(i=0;i!=INVENTORY_SIZE;i++){
|
||||
player.inventoryitems[i] = 0;
|
||||
player.inventorynum[i] = 0;
|
||||
|
@ -338,7 +377,7 @@ int main(void) {
|
|||
if(player.inventorynum[player.invselect] == 0) {
|
||||
player.inventoryitems[player.invselect] = 0;
|
||||
}
|
||||
}else if (keydown(KEY_1) && terrain[pos] != 0){
|
||||
}else if (keydown(KEY_1) && terrain[pos] != 0 && 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];
|
||||
|
@ -347,8 +386,26 @@ int main(void) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
player.overlayframe = 0;
|
||||
player.overlaytimer = 0;
|
||||
player.wasdestroyingbefore = 0;
|
||||
}else if (keydown(KEY_1) && terrain[pos] != 0 && (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;
|
||||
}
|
||||
}
|
||||
player.select_tx = ((player.x+player.selx)>>3);
|
||||
player.select_ty = ((player.y+player.sely)>>3);
|
||||
clearevents();
|
||||
if (keydown(KEY_0)){
|
||||
if(player.invselect<INVENTORY_SIZE-1){
|
||||
|
@ -367,8 +424,13 @@ int main(void) {
|
|||
}
|
||||
// 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);
|
||||
}else if(game == 4){
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# define TITLE_START "[EXE] pour jouer" // Start screen text.
|
||||
# define WORLDSEL_EMPTY "--- VIDE ---" // Empty slot in the game selection menu.
|
||||
# define WORLDGEN_INFO "Generation ..." // Text when waiting for world generation.
|
||||
# define SELECTED "<" // Selected block info.
|
||||
# define SELECTED "<" // Selected block info.
|
||||
# define INV_INFO "INVENTAIRE & CRAFTING"
|
|
@ -13,4 +13,12 @@ struct Player{
|
|||
int inventoryitems[INVENTORY_SIZE];
|
||||
int inventorynum[INVENTORY_SIZE];
|
||||
int invselect;
|
||||
int overlayframe;
|
||||
int overlaytimer;
|
||||
int select_tx;
|
||||
int select_ty;
|
||||
int old_select_tx;
|
||||
int old_select_ty;
|
||||
int wasdestroyingbefore;
|
||||
int destroytime;
|
||||
};
|
Loading…
Reference in New Issue