Can some buddy help me with 3DS Homebrew coding

Discussion in 'The Edge of the Forum' started by BurningDesire, Feb 10, 2016.

  1. BurningDesire
    OP

    BurningDesire GBAtemp Psycho!

    Member
    4,964
    5,822
    Jan 27, 2015
    United States
    Behind a screen reading news
    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 and Tomato Hentai like this.
  2. GalladeGuy

    GalladeGuy Freeze Kirby :3

    Member
    2,588
    2,652
    Oct 28, 2015
    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?
     
  3. VinsCool

    VinsCool Disgusted

    Member
    GBAtemp Patron
    VinsCool is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    12,001
    29,026
    Jan 7, 2014
    Canada
    An Alternate Reality
    playerPos.y is used for all the 4 cases, that probably is the problem
     
    BurningDesire likes this.
  4. GalladeGuy

    GalladeGuy Freeze Kirby :3

    Member
    2,588
    2,652
    Oct 28, 2015
    United States
    You've been ninja'd, fool. :ninja:
     
  5. BurningDesire
    OP

    BurningDesire GBAtemp Psycho!

    Member
    4,964
    5,822
    Jan 27, 2015
    United States
    Behind a screen reading news
    I cab PM you the whole thing in the morning
     
    GalladeGuy likes this.
  6. daxtsu

    daxtsu GBAtemp Guru

    Member
    5,546
    3,955
    Jun 9, 2007
    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?
     
  7. BurningDesire
    OP

    BurningDesire GBAtemp Psycho!

    Member
    4,964
    5,822
    Jan 27, 2015
    United States
    Behind a screen reading news
    This is why I post online! Too stupid to see my own problems. Will try in the morning!

    — Posts automatically merged - Please don't double post! —

    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

    — Posts automatically merged - Please don't double post! —

    wow realized i spelled somebody wrong. fml
     
    GalladeGuy and daxtsu like this.
  8. BurningDesire
    OP

    BurningDesire GBAtemp Psycho!

    Member
    4,964
    5,822
    Jan 27, 2015
    United States
    Behind a screen reading news
    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