Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
pedroBzh | 585c386974 | |
pedroBzh | cea54c4bcb | |
pedroBzh | 4228a7e1b4 | |
pedroBzh | ac059e8217 | |
pedroBzh | c74cb211a6 | |
pedroBzh | ee7958534f | |
pedroBzh | ed2e54bf51 | |
pedroBzh | 997cc6d36a | |
pedroBzh | 3883cde36b | |
pedroBzh | f0fae5d294 | |
pedroBzh | afcc6c58bd | |
pedroBzh | 38bc6bf6d9 |
After Width: | Height: | Size: 118 B |
Before Width: | Height: | Size: 134 B After Width: | Height: | Size: 149 B |
Before Width: | Height: | Size: 355 B After Width: | Height: | Size: 476 B |
BIN
binnword.g1a
865
build-fx/map
|
@ -87,3 +87,4 @@ LDFLAGS_CG += -Wl,-Map=build-cg/map
|
|||
#
|
||||
# FONT.hexa.png = charset:print grid.size:3x5 grid.padding:1
|
||||
IMG.tilemap.png :=
|
||||
IMG.craft.png :=
|
||||
|
|
After Width: | Height: | Size: 399 B |
After Width: | Height: | Size: 429 B |
After Width: | Height: | Size: 437 B |
After Width: | Height: | Size: 406 B |
After Width: | Height: | Size: 209 B |
149
src/main.c
|
@ -1,13 +1,19 @@
|
|||
extern "C"{
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
//#include <gint/std/string.h>
|
||||
}
|
||||
#define MAP_X 50
|
||||
#define MAP_X 250
|
||||
#define BLOCKS_LEN 17
|
||||
#define CRAFTS 2
|
||||
using namespace std;
|
||||
|
||||
int sx = 0;
|
||||
int x = 30;
|
||||
int x = 100;
|
||||
int y = 30;
|
||||
extern bopti_image_t img_tilemap;
|
||||
int game_map[MAP_X+1][7];
|
||||
extern bopti_image_t img_craft;
|
||||
int8_t game_map[MAP_X+1][7] = {0};
|
||||
int opt = GETKEY_DEFAULT | GETKEY_REP_ARROWS | GETKEY_MENU;
|
||||
int optd = GETKEY_DEFAULT | GETKEY_MENU;
|
||||
int timeout = 1;
|
||||
|
@ -16,6 +22,24 @@ int rwalk =0;
|
|||
int can_move = 1;
|
||||
int dir = 1;
|
||||
int vdir;
|
||||
int sele = 2;
|
||||
int vas = 0;
|
||||
int sinv = 3;
|
||||
int inv[BLOCKS_LEN+1] = {0};
|
||||
int btmp = sinv;
|
||||
int selecoll = 0;
|
||||
int rockminer_interval;
|
||||
int craftdata[][6] = {{5,1,4,2,15,1},{3,2,15,4,0,0}};
|
||||
int s = 0;
|
||||
|
||||
int isCollide(int num){
|
||||
if(num==0){return 1;}
|
||||
else if(num==3){return 1;}
|
||||
else if(num==14){return 1;}
|
||||
else if(num==15){return 1;}
|
||||
else if(num==16){return 1;}
|
||||
else{return 0;}
|
||||
}
|
||||
|
||||
int isMultipleof5 (int n)
|
||||
{
|
||||
|
@ -27,29 +51,89 @@ int isMultipleof5 (int n)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PrintSblock(int num,int x,int y){
|
||||
dsubimage(x*10, y*10+4 ,&img_tilemap,num*10,10,10, 10, DIMAGE_NONE);
|
||||
}
|
||||
|
||||
void PrintMap(){
|
||||
int cx = MAP_X;
|
||||
int cy = 6;
|
||||
dsubimage(116, 0 ,&img_tilemap,sinv*10,0,10, 10, DIMAGE_NONE);
|
||||
dhline(12,C_BLACK);
|
||||
dprint(96, 0, C_BLACK, "%d", inv[sinv]);
|
||||
while(cx>0){
|
||||
cy = 6;
|
||||
while(cy>0){
|
||||
dsubimage(cx*10-sx, cy*10+4 ,&img_tilemap,game_map[cx][cy]*10,0,10, 10, DIMAGE_NONE);
|
||||
/*if(game_map[cx][cy]==2&&game_map[cx][cy]>1&&game_map[cx][cy]<MAP_X){
|
||||
if(game_map[cx-1][cy]==2&&game_map[cx+1][cy]==2){PrintSblock(4,cx,cy);}
|
||||
if(game_map[cx-1][cy]!=2&&game_map[cx+1][cy]==2){PrintSblock(3,cx,cy);}
|
||||
if(game_map[cx-1][cy]==2&&game_map[cx+1][cy]!=2){PrintSblock(5,cx,cy);}
|
||||
}*/
|
||||
cy--;
|
||||
}
|
||||
cx--;
|
||||
}
|
||||
if(dir==0){dsubimage(x-sx, y+4 ,&img_tilemap,5*10,0,10, 10, DIMAGE_NONE);}
|
||||
if(dir==1){dsubimage(x-sx, y+4 ,&img_tilemap,4*10,0,10, 10, DIMAGE_NONE);}
|
||||
if(dir==0){dsubimage(x-sx, y+4 ,&img_tilemap,5*10,20,10, 10, DIMAGE_NONE);}
|
||||
if(dir==1){dsubimage(x-sx, y+4 ,&img_tilemap,4*10,20,10, 10, DIMAGE_NONE);}
|
||||
if(vas==0&& (keydown(KEY_VARS) || keydown(KEY_SQUARE))){
|
||||
if(sele==1){dsubimage(x+10-sx, y+4 ,&img_tilemap,0,20,10, 10, DIMAGE_NONE);}
|
||||
if(sele==2){dsubimage(x-sx, y+4+10 ,&img_tilemap,0,20,10, 10, DIMAGE_NONE);}
|
||||
if(sele==3){dsubimage(x-10-sx, y+4 ,&img_tilemap,0,20,10, 10, DIMAGE_NONE);}
|
||||
if(sele==0){dsubimage(x-sx, y+4-10 ,&img_tilemap,0,20,10, 10, DIMAGE_NONE);}
|
||||
}
|
||||
if(vas==1){
|
||||
if(sele==1){dsubimage(x+10-sx, y+4 ,&img_tilemap,10,20,10, 10, DIMAGE_NONE);}
|
||||
if(sele==2){dsubimage(x-sx, y+4+10 ,&img_tilemap,10,20,10, 10, DIMAGE_NONE);}
|
||||
if(sele==3){dsubimage(x-10-sx, y+4 ,&img_tilemap,10,20,10, 10, DIMAGE_NONE);}
|
||||
if(sele==0){dsubimage(x-sx, y+4-10 ,&img_tilemap,10,20,10, 10, DIMAGE_NONE);}
|
||||
}
|
||||
}
|
||||
|
||||
int craft(int item){
|
||||
if(craftdata[item][3]<=inv[craftdata[item][2]] && craftdata[item][5]<=inv[craftdata[item][4]]){
|
||||
inv[craftdata[item][2]] = inv[craftdata[item][2]] - craftdata[item][3];
|
||||
inv[craftdata[item][4]] = inv[craftdata[item][4]] - craftdata[item][5];
|
||||
inv[craftdata[item][0]] = inv[craftdata[item][0]] + craftdata[item][1];
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void craftmenu(){
|
||||
int s = 0;
|
||||
while(1){
|
||||
dclear(C_WHITE);
|
||||
for(int i=0;i<CRAFTS;i++) {
|
||||
dsubimage(0,i*16,&img_craft,0,0,128,16,DIMAGE_NONE); // template
|
||||
if(s==i){dsubimage(1,i*16+3,&img_tilemap,21,21,8,8,DIMAGE_NONE);} //if select
|
||||
dsubimage(13,i*16+3,&img_tilemap,craftdata[i][0]*10,0,10,10,DIMAGE_NONE); //block to craft
|
||||
dprint(25, i*16+4, C_BLACK, "%d",craftdata[i][1]);
|
||||
dsubimage(75,i*16+3,&img_tilemap,craftdata[i][2]*10,0,10,10,DIMAGE_NONE);
|
||||
dprint(88, i*16+4, C_BLACK, "%d",craftdata[i][3]);
|
||||
dsubimage(95,i*16+3,&img_tilemap,craftdata[i][4]*10,0,10,10,DIMAGE_NONE);
|
||||
dprint(108, i*16+4, C_BLACK, "%d",craftdata[i][5]);
|
||||
}
|
||||
key = getkey_opt(opt, &timeout).key;
|
||||
if(key==KEY_EXIT){break;}
|
||||
if(key==KEY_OPTN){if(craft(s)){break;}}
|
||||
if(key==KEY_DOWN&&s<CRAFTS-1){s++;}
|
||||
if(key==KEY_UP&&s>0){s--;}
|
||||
dupdate();
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i = 0;
|
||||
while(i<MAP_X){
|
||||
int i = 10;
|
||||
while(i<MAP_X-10){
|
||||
game_map[i][5] = 1;
|
||||
game_map[i][4] = 2;
|
||||
i++;
|
||||
if(i>5 && i<MAP_X-5 && isMultipleof5(i) == 1){
|
||||
if(i>10 && i<MAP_X-10 && isMultipleof5(i) == 1){
|
||||
game_map[i][3] = 15;
|
||||
game_map[i][2] = 15;
|
||||
game_map[i][1] = 15;
|
||||
|
@ -60,21 +144,61 @@ int main(void)
|
|||
game_map[i+1][1] = 17;
|
||||
game_map[i-2][1] = 17;
|
||||
game_map[i+2][1] = 17;
|
||||
game_map[i+1][3] = 4;
|
||||
}
|
||||
}
|
||||
game_map[5][3] = 9;
|
||||
game_map[6][3] = 10;
|
||||
game_map[7][3] = 11;
|
||||
inv[3] = 15;
|
||||
inv[13] = 10;
|
||||
inv[17] = 5;
|
||||
while(1==1){
|
||||
if(keydown(KEY_OPTN)){vas=1;}else{vas=0;}
|
||||
sx = x-60;
|
||||
dclear(C_WHITE);
|
||||
dtext(1, 1, C_BLACK, "Sample fxSDK add-in.");
|
||||
//dtext(12, 1, C_BLACK, "item");
|
||||
PrintMap();
|
||||
dupdate();
|
||||
key = getkey_opt(opt, &timeout).key;
|
||||
if(can_move == 1 && game_map[x/10][y/10+1] != 0){
|
||||
if(keydown(KEY_RIGHT)){rwalk = 10;can_move=0;dir=1;vdir=1;}
|
||||
if(keydown(KEY_LEFT)){rwalk = 10;can_move=0;dir=0;vdir=3;}
|
||||
if(keydown(KEY_VARS)==0&&can_move == 1 &&( isCollide(game_map[x/10][y/10+1]) == 0 || game_map[x/10][y/10+1]==3)){
|
||||
if(keydown(KEY_RIGHT)&&isCollide(game_map[x/10+1][y/10])){rwalk = 10;can_move=0;dir=1;vdir=1;}
|
||||
if(keydown(KEY_UP)&&game_map[x/10][y/10]==3){rwalk = 10;can_move=0;vdir=0;}
|
||||
if(keydown(KEY_LEFT)&&isCollide(game_map[x/10-1][y/10])){rwalk = 10;can_move=0;dir=0;vdir=3;}
|
||||
if(keydown(KEY_DOWN)&&game_map[x/10][y/10+1]==3){rwalk = 10;can_move=0;vdir=2;}
|
||||
}
|
||||
if(keydown(KEY_VARS)){
|
||||
if(keydown(KEY_RIGHT)){sele=1;}
|
||||
if(keydown(KEY_DOWN)){sele=2;}
|
||||
if(keydown(KEY_LEFT)){sele=3;}
|
||||
if(keydown(KEY_UP)){sele=0;}
|
||||
}
|
||||
if(can_move ==1 && keydown(KEY_OPTN)&& inv[sinv] > 0){
|
||||
|
||||
if(sele==1&&game_map[x/10+1][y/10]==0){game_map[x/10+1][y/10]=sinv;inv[sinv]--;}
|
||||
if(sele==2&&game_map[x/10][y/10+1]==0){game_map[x/10][y/10+1]=sinv;inv[sinv]--;}
|
||||
if(sele==3&&game_map[x/10-1][y/10]==0){game_map[x/10-1][y/10]=sinv;inv[sinv]--;}
|
||||
if(sele==0&&game_map[x/10][y/10-1]==0){game_map[x/10][y/10-1]=sinv;inv[sinv]--;}
|
||||
}
|
||||
if(can_move ==1 && keydown(KEY_SQUARE)){
|
||||
if(sele==1){inv[game_map[x/10+1][y/10]]++;game_map[x/10+1][y/10]=0;}
|
||||
if(sele==2){inv[game_map[x/10][y/10+1]]++;game_map[x/10][y/10+1]=0;}
|
||||
if(sele==3){inv[game_map[x/10-1][y/10]]++;game_map[x/10-1][y/10]=0;}
|
||||
if(sele==0){inv[game_map[x/10][y/10-1]]++;game_map[x/10][y/10-1]=0;}
|
||||
}
|
||||
if(selecoll>0){selecoll--;}
|
||||
if(keydown(KEY_F6)&&selecoll==0){
|
||||
if(sinv==BLOCKS_LEN+1){sinv=1;}
|
||||
sinv++;
|
||||
selecoll = 30;
|
||||
}
|
||||
if(keydown(KEY_F5)&&selecoll==0){
|
||||
if(sinv==1){sinv=BLOCKS_LEN+1;}
|
||||
sinv--;
|
||||
selecoll = 30;
|
||||
}
|
||||
if(keydown(KEY_F1)){
|
||||
craftmenu();
|
||||
}
|
||||
if(can_move == 1 && game_map[x/10][y/10+1] == 0){
|
||||
can_move = 0;
|
||||
|
@ -86,6 +210,7 @@ int main(void)
|
|||
if(vdir==1){x++;}
|
||||
if(vdir==2){y++;}
|
||||
if(vdir==3){x--;}
|
||||
if(vdir==0){y--;}
|
||||
if(rwalk==0){can_move = 1;}
|
||||
}
|
||||
}
|
||||
|
|