1. HamBone41801

    OP HamBone41801 Vipera’s Alt
    Member

    Joined:
    Jan 16, 2017
    Messages:
    1,083
    Country:
    United States
    Heres my code. It compiles fine but crashes in citra.

    #include <time.h>
    #include <string.h>
    #include <stdio.h>
    #include <sf2d.h>
    #include <3ds.h>

    const int NumRows = 240;
    const int NumColumns = 400;

    void printToConsole(char* msg)
    {
    time_t unixTime = time(NULL);
    struct tm* timeStruct = gmtime((const time_t *)&unixTime);

    int hours = timeStruct->tm_hour;
    int minutes = timeStruct->tm_min;
    int seconds = timeStruct->tm_sec;

    printf("[%02i:%02i:%02i] %s\n", hours, minutes, seconds, msg);
    }

    int checkCollisions(int arr[][NumColumns], int arr2[][NumColumns])
    {
    int i = 0;
    int j = 0;
    for(i = 0; i <= NumRows; i++)
    {
    for(j = 0; j <= NumColumns; j++)
    {
    if(arr[j] == 1 && arr2[j] == 1)
    {
    return 1;
    }
    else
    {
    return 0;
    }
    }
    }
    return 0;
    }

    int main()
    {

    int paddleOneX = 10;
    int paddleOneY = 80;

    int paddleTwoX = 380;
    int paddleTwoY = 80;

    int ballX = 195;
    int ballY = 115;

    int ballCollider[NumRows][NumColumns];
    int paddleOneCollider[NumRows][NumColumns];
    int paddleTwoCollider[NumRows][NumColumns];

    sf2d_init();
    sf2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));

    consoleInit(GFX_BOTTOM, NULL);

    printToConsole("Hi!");

    while (aptMainLoop())
    {
    hidScanInput();
    u32 kUp = hidKeysUp();
    u32 kHeld = hidKeysHeld();

    if (kUp & KEY_START)
    {
    break;
    }

    //GAME_CODE////////////////////////////////////////////////

    // Paddle Movement
    if(kHeld & KEY_UP)
    {
    if(paddleOneY != 0)
    {
    paddleOneY--;
    }
    }
    if(kHeld & KEY_DOWN)
    {
    if(paddleOneY != 160)
    {
    paddleOneY++;
    }
    }

    if(((paddleTwoY + 40) > (ballY + 5)) & (paddleTwoY != 0))
    {
    paddleTwoY--;
    }
    if(((paddleTwoY + 40) < (ballY + 5)) & (paddleTwoY != 160))
    {
    paddleTwoY++;
    }

    // Ball Movement
    ballX--;
    //Collisions

    if(checkCollisions(ballCollider, paddleOneCollider) == 1)
    {
    break;
    }
    else if(checkCollisions(ballCollider, paddleTwoCollider) == 1)
    {

    }

    ///////////////////////////////////////////////////////////

    //DRAW_CODE////////////////////////////////////////////////

    sf2d_start_frame(GFX_TOP, GFX_LEFT);
    sf2d_draw_rectangle(ballX, ballY, 10, 10, RGBA8(0xFF, 0xFF, 0xFF, 0xFF)); // Ball
    sf2d_draw_rectangle(paddleOneX, paddleOneY, 10, 80, RGBA8(0xFF, 0xFF, 0xFF, 0xFF)); // Paddle One
    sf2d_draw_rectangle(paddleTwoX, paddleTwoY, 10, 80, RGBA8(0xFF, 0xFF, 0xFF, 0xFF)); // Paddle Two
    sf2d_end_frame();

    ///////////////////////////////////////////////////////////

    sf2d_swapbuffers();
    }

    sf2d_fini();
    return 0;
    }
     
  2. Kartik

    Kartik GBAtemp Advanced Fan
    Member

    Joined:
    Jun 6, 2015
    Messages:
    616
    Country:
    India
    You cannot use ctrulib 's consoleInit() with sf2d.Use sftd instead.
    https://github.com/xerpi/sftdlib
     
    Last edited by Kartik, Mar 9, 2017
  3. erman1337

    erman1337 GBAtemp Maniac
    Member

    Joined:
    Sep 27, 2015
    Messages:
    1,211
    Country:
    Belgium
    put printf on every line to pinpoint the problematic line
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - crashes,