Thread: MSP432 + BoosterPack; paddle and ball game

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2019
    Posts
    1

    MSP432 + BoosterPack; paddle and ball game

    I need assistance on a part of a project in working on in which a ball bounces around a led screen and you have to hit it with a paddle and have it collide. There are two buttons that have been programmed to move the paddle up and down(since the paddle is on the right side of the screen), i need help on making the paddle a tangible thing. here is my code so far. any and all help is appreciated.
    Code:
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>#include<ti/grlib/grlib.h>
    #include"LcdDriver/Crystalfontz128x128_ST7735.h"
    #include <stdint.h>
    #include <stdbool.h>
    Graphics_Context g_sContext;
    volatile uint32_t radius;
    volatile uint32_t timerflag;
    volatile uint32_t timerflag2;
    volatile uint32_t timerflag3;
    volatile uint32_t x;
    volatile uint32_t y;
    volatile int32_t Vx;
    volatile int32_t Vy;
    volatile uint32_t window_height;
    volatile uint32_t window_width;
    volatile uint32_t paddleY;
    const int32_t paddle_width= 16;
    volatile uint32_t hits;
    void draw(int32_t x,int32_t y,int32_t radius)
    {
        Graphics_fillCircle(&g_sContext,x,y,radius);
    }
    void erase(int32_t x,int32_t y,int32_t radius)
    {
        Graphics_setForegroundColor(&g_sContext,GRAPHICS_COLOR_WHITE);
        Graphics_fillCircle(&g_sContext,x,y,radius);
        Graphics_setForegroundColor(&g_sContext,GRAPHICS_COLOR_RED);
    }
    void erase_paddle(int32_t x, int32_t y)
    {
        Graphics_setForegroundColor(&g_sContext, GRAPHICS_COLOR_WHITE);
        Graphics_drawLineV(&g_sContext, x, y, y + paddle_width -1);
        Graphics_setForegroundColor(&g_sContext, GRAPHICS_COLOR_RED);
    }
    void draw_paddle(int32_t x, int32_t y)
    {
        Graphics_drawLineV(&g_sContext, x, y, y + paddle_width -1);
    }
    int main(void)
    {
    
    
    SysTick_enableModule();
    
    
    GPIO_setAsInputPin(GPIO_PORT_P5, GPIO_PIN1);
    GPIO_setAsInputPin(GPIO_PORT_P3, GPIO_PIN5);
    GPIO_clearInterruptFlag(GPIO_PORT_P5, GPIO_PIN1);
    GPIO_clearInterruptFlag(GPIO_PORT_P3, GPIO_PIN5);
    GPIO_interruptEdgeSelect(GPIO_PORT_P5, GPIO_PIN1,GPIO_HIGH_TO_LOW_TRANSITION);
    GPIO_interruptEdgeSelect(GPIO_PORT_P3, GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION);
    GPIO_enableInterrupt(GPIO_PORT_P5, GPIO_PIN1);
    GPIO_enableInterrupt(GPIO_PORT_P3, GPIO_PIN5);
    Interrupt_enableInterrupt(INT_PORT5);
    Interrupt_enableInterrupt(INT_PORT3);
    Interrupt_enableMaster();
    
    
    
    
    Crystalfontz128x128_Init();
    Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP);
    Graphics_initContext(&g_sContext,&g_sCrystalfontz128x128,&g_sCrystalfontz128x128_funcs);
    Graphics_setForegroundColor(&g_sContext,GRAPHICS_COLOR_RED);
    Graphics_setBackgroundColor(&g_sContext,GRAPHICS_COLOR_WHITE);
    GrContextFontSet(&g_sContext,&g_sFontFixed6x8);
    Graphics_clearDisplay(&g_sContext);
    
    
    
    
    MAP_WDT_A_holdTimer();
    
    
    y = 64;
    x = 64;
    Vx = 1;
    Vy =-1;
    radius = 3;
    window_height = 127;
    window_width = 127;
    paddleY = 64;
     draw_paddle(120,paddleY);
    SysTick_setPeriod(90000);
    SysTick_enableInterrupt();
    while(1)
            {
              if(x <= 0 || x >= window_width-5)
                      Vx*= -1;
          if(y <= 0 || y >= window_height -5)
              Vy*= -1;
    
    
    if(timerflag==1)
    {
        draw(x,y,radius);
        erase(x,y,radius);
    
    
        timerflag = 0;
    }
    if(timerflag2==1)
    {
            erase_paddle(120,paddleY+paddle_width+1);
            draw_paddle(120,paddleY);
            timerflag2 = 0;
    }
    if(timerflag3==1)
    {
        erase_paddle(120,paddleY-paddle_width+1);
               draw_paddle(120,paddleY);
               timerflag3 = 0;
    }
    
    
    
    
    
    
            }
    
    
    
    
    
    
    
    
    }
    void SysTick_Handler(void)
    {
        timerflag = 1;
        if(x+radius <127 || x-radius>0)
        {
            if(y+radius <127 || y-radius>0)
            {
                x+=Vx;
                       y+=Vy;
            }
    
    
    }
        if(x+radius==127 || x-radius==0)
        {
            Vx*= -1;
        }
        if(y+radius ==127 || y-radius==0)
        {
            Vy*= -1;
        }
    }
    
    
    void PORT5_IRQHandler(void)
    {
        uint32_t status;
        status= GPIO_getEnabledInterruptStatus(GPIO_PORT_P5);
        GPIO_clearInterruptFlag(GPIO_PORT_P5, status);
        timerflag2=1;
        if(status & GPIO_PIN1)
        {
            timerflag2=1;
            paddleY-= paddle_width-1;
    
    
        }
    }
        void PORT3_IRQHandler(void)
        {
        uint32_t status;
           status= GPIO_getEnabledInterruptStatus(GPIO_PORT_P3);
           GPIO_clearInterruptFlag(GPIO_PORT_P3, status);
    
    
           if(status & GPIO_PIN5)
           {
               timerflag3=1;
                      paddleY+= paddle_width-1;
           }
         }
    Last edited by Solnoid; 06-05-2019 at 07:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ball keeps bouncing off paddle in same direction
    By arortell in forum C Programming
    Replies: 7
    Last Post: 04-30-2014, 02:51 PM
  2. Ball bouncing in Breakout-like game
    By redbull2020 in forum Game Programming
    Replies: 7
    Last Post: 05-18-2011, 12:57 PM
  3. 3D ball problem
    By software tester in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2011, 03:54 PM
  4. The Old Bouncing Ball
    By bartybasher in forum Game Programming
    Replies: 3
    Last Post: 08-19-2003, 03:06 AM

Tags for this Thread