Can some buddy help me with 3DS Homebrew coding

BurningDesire

Well-Known Member
OP
Member
Joined
Jan 27, 2015
Messages
4,999
Trophies
1
Location
Behind a screen reading news
XP
4,885
Country
United States
So I am making a random maze game for 3DS I am posting in the EoF so I do not receive a lot of hate. Here is my code for moving the character. It compiles with no errors but the character will not move.

//player move up
if (kDown & KEY_UP)
{
if(playerPos.y > 0 && map[playerPos.x][playerPos.y-1].walkable)
{
playerPos.y--;
}
}

//player move udown
if (kDown & KEY_DOWN)
{
if (playerPos.y < MapHeight -1 && map[playerPos.x][playerPos.y+1].walkable)
{
playerPos.y++;
}
}
//player move right
if (kDown & KEY_RIGHT)
{
if(playerPos.x < MapWidth -1 && map[playerPos.x][playerPos.x+1].walkable)
{
playerPos.y++;
}
}

//player move left
if (kDown & KEY_LEFT)
{
if(kDown & KEY_LEFT && playerPos.x < MapWidth -1 && map[playerPos.x][playerPos.x-1].walkable)
{
playerPos.y--;
}
}
 

GalladeGuy

Cool and Epic
Member
Joined
Oct 28, 2015
Messages
2,686
Trophies
1
XP
3,115
Country
United States
Well, for one thing, the if statements for moving left and right add/subtract to PlayerPos.y instead of PlayerPos.x. I don't understand why it would cause the player to not move at all though. Mind PMing me your whole program?
 

BurningDesire

Well-Known Member
OP
Member
Joined
Jan 27, 2015
Messages
4,999
Trophies
1
Location
Behind a screen reading news
XP
4,885
Country
United States
Well, for one thing, the if statements for moving left and right add/subtract to PlayerPos.y instead of PlayerPos.x. I don't understand why it would cause the player to not move at all though. Mind PMing me your whole program?
I cab PM you the whole thing in the morning
 
  • Like
Reactions: GalladeGuy

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
Aside from the Left/Right using Y instead of X issue that's been pointed out, are you then going on to actually use the player's X/Y coordinates when drawing the sprite?
 

BurningDesire

Well-Known Member
OP
Member
Joined
Jan 27, 2015
Messages
4,999
Trophies
1
Location
Behind a screen reading news
XP
4,885
Country
United States
playerPos.y is used for all the 4 cases, that probably is the problem
This is why I post online! Too stupid to see my own problems. Will try in the morning!

--------------------- MERGED ---------------------------

Aside from the Left/Right using Y instead of X issue that's been pointed out, are you then going on to actually use the player's X/Y coordinates when drawing the sprite?
Well the game is in ASCII so the player is a @ symbole. To draw that I have

if(x== playerPos.x && playerPos.y)
cout << "@"

the player position starts at 0,0 top left with

playerPos.y = 0
playerPos.x = 0

Thats how i draw the character. I do not know if that is the correct response though as I am still learning CPP

--------------------- MERGED ---------------------------

wow realized i spelled somebody wrong. fml
 

BurningDesire

Well-Known Member
OP
Member
Joined
Jan 27, 2015
Messages
4,999
Trophies
1
Location
Behind a screen reading news
XP
4,885
Country
United States
So. That did not get it to work ;( I am going to post the full code here

Code:
#include <string.h>
#include <3ds.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <iostream>

using namespace std;


struct Map_Tile
       {
            char tileCharacter;
            bool walkable;
       };

struct Point
{
     int x, y;
} playerPos;

  int const MapWidth  =  10;
  int const MapHeight =  10;
  Map_Tile map[MapWidth][MapHeight];

void GenMap() {

srand(time(NULL));
for (int y = 0; y < MapHeight; y++)
  {
   for(int x = 0; x < MapWidth; x++)
   {
       int t = rand() % 2;
       if(t == 0)
       {
           map[x][y].tileCharacter = '#';
           map[x][y].walkable = false;
       }
       else
       {
           map[x][y].tileCharacter = '.';
           map[x][y].walkable = true;
       }
  }
}
map[0][0].tileCharacter = '.';
map[0][0].walkable = true;
}

void PrintMap()
{
for (int y = 0; y < MapHeight; y++)
   {
   for(int x = 0; x < MapWidth; x++)
        {
        if(x == playerPos.x && y == playerPos.y)
            cout << "@";
        else
             cout << map[x][y].tileCharacter;
         }
           cout << endl;

  }

}
int main()
{
    gfxInitDefault();
    //gfxSet3D(true); // uncomment if using stereoscopic 3D

        // Let us set up the top and bottom screen
        PrintConsole topConsole;
        PrintConsole bottomConsole;
        consoleInit(GFX_TOP, &topConsole);
        consoleInit(GFX_BOTTOM, &bottomConsole);

        bool update = true;


    // Main loop
    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();

        // Your code goes here

        u32 kDown = hidKeysDown();
        if (kDown & KEY_START)
        break; // break in order to return to hbmenu

     // Start game statements here


            
             // Where you start to print stuff to the screen *__* Important!
                if(update) {
                    consoleSelect(&topConsole);
                    consoleClear();
                    playerPos.x = 0;
                    playerPos.y = 0;
                    GenMap();


             
                    PrintMap();
                    //player move up
                   if (kDown & KEY_UP)
                   {
                    if(playerPos.y > 0 && map[playerPos.x][playerPos.y-1].walkable)
                    {
                      playerPos.y--;
                    }
                }
                   
                       //player move udown
                     if (kDown & KEY_DOWN)
                     {
                    if (playerPos.y < MapHeight -1 && map[playerPos.x][playerPos.y+1].walkable)
                    {
                      playerPos.y++;
                    }
                }
                       //player move right
                   if (kDown & KEY_RIGHT)
                {
                    if(playerPos.x < MapWidth -1 && map[playerPos.x][playerPos.x+1].walkable)
                    {
                      playerPos.x++;
                    }
                }

                           //player move left
                if (kDown & KEY_LEFT)
                {
                    if(kDown & KEY_LEFT && playerPos.x < MapWidth -1 && map[playerPos.x][playerPos.x-1].walkable)
                    {
                      playerPos.x--;
                    }
               }
               

                   
                    update = false;
               }

        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    gfxExit();
    return 0;
}
Whoever can fix this will get a internet cookie
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    AncientBoi @ AncientBoi: :rofl2: