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
  • Xdqwerty
    what are you looking at?
  • BakerMan
    I rather enjoy a life of taking it easy. I haven't reached that life yet though.
  • RedColoredStars @ RedColoredStars:
    i used to go out to the recycling center every couple weeks and look at the crts and other electronics people would drop off. Usually screens were broken or severely scratched from being tossed around. Did find a good one here and there, but never anything like a 1080i widescreen crt.
  • RedColoredStars @ RedColoredStars:
    Or a good contition 40" Sony Trini that weighs 300 lbs. lol
  • RedColoredStars @ RedColoredStars:
    Literally 300 lbs. lolol
  • BigOnYa @ BigOnYa:
    I have a few of those boat anchors in my basement I tried giving away but no one wanted them, So anyone close to Columbus, Ohio area that wants them, (26", 2x 19") please come get, for free.
  • RedColoredStars @ RedColoredStars:
    Dont know anyone wants those smaller ones. Most are after larger sizes and the kinda top of the line models
  • RedColoredStars @ RedColoredStars:
    Motion handling and input lag on those things destroy plasmas, led, oled
  • realtimesave @ realtimesave:
    I had some really nice CRTs I should've kept
  • realtimesave @ realtimesave:
    now I have all lcd
  • realtimesave @ realtimesave:
    one in particular I regret getting rid of oh well :|
  • realtimesave @ realtimesave:
    the Sonys and stuff I don't care about
  • realtimesave @ realtimesave:
    and used LCD are hard to sell I can imagine.. not worth much
  • realtimesave @ realtimesave:
    @SylverReZ where do u lurk
  • a_username_that_isnt_cool @ a_username_that_isnt_cool:
    Is it piracy if it was released for free? Not in my opinion, but I also think it's not piracy if buying it isn't owning it, and it's not piracy if you can't buy it from the original creators anymore.
  • K3Nv2 @ K3Nv2:
    Free release can have loopholes where they still make money through ads
    +1
  • Xdqwerty @ Xdqwerty:
    sigh
  • Xdqwerty @ Xdqwerty:
    @a_username_that_isnt_cool, could you change your username?
  • Xdqwerty @ Xdqwerty:
    i guess not...
  • Xdqwerty @ Xdqwerty:
    yawn
  • Xdqwerty @ Xdqwerty:
    anybody here?
  • P @ PKNate:
    nope
  • BakerMan @ BakerMan:
    fun fact: 7 years by lukas graham, supermassive black hole by muse, and megalomania all have the same bpm
  • BakerMan @ BakerMan:
    girls just wanna have fun and renai circulation also share the same tempo as the few i said before
  • Xdqwerty @ Xdqwerty:
    @BakerMan, megalomania the live a live song?
    Xdqwerty @ Xdqwerty: @BakerMan, megalomania the live a live song?