#include <io.h>
#include <system.h>
#include <stdio.h>

#define IOWR_SRAM_DATA(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data)

// 60* 80 player 13 2
// 60 * 80 boss 15 0
// 30 * 14 bullet14 1


int main()
{

    int xPlayerCoordinate;
    int yPlayerCoordinate;
    int xBossCoordinate;
    int yBossCoordinate;
    int xBulletCoordinate;
    int yBulletCoordinate;
    int xSpeed;
    int ySpeed;
    int xLowBound;
    int xHighBound;
    int yLowBound;
    int yHighBound;
    int counter=10000;
    printf("software works \n");
    int i=0;

    //IOWR_VGA_SPEED(VGA_BASE, 0x0040);

    xPlayerCoordinate = 40;
    yPlayerCoordinate = 50;
    xBossCoordinate = 600;
    yBossCoordinate = 200;
    xSpeed = 2;
    ySpeed = 2;
    xLowBound = 0;
    xHighBound = 640;
    yLowBound = 0;
    yHighBound = 480;
    radius = 25;

    for(i=0;i<2500;i++){
    	IOWR_SRAM_DATA(VGA_BASE, i, r[i]);
    	IOWR_SRAM_DATA(VGA_BASE, i+2500, g[i]);
    	IOWR_SRAM_DATA(VGA_BASE, i+5000, b[i]);
    }

    for(;;){
    	counter--;
    	if (counter ==0)
    	{
    		counter=10000;

        if(xCoordinate - xLowBound <= radius){
            ySpeed = - ySpeed;
        }
        if(xHighBound - xCoordinate <= radius){
            ySpeed = - ySpeed;
        }
        if(yCoordinate - yLowBound <= radius){
            xSpeed = - xSpeed;
        }
        if(yHighBound - yCoordinate <= radius){
            xSpeed = - xSpeed;
        }

        xCoordinate = xCoordinate + ySpeed;
        yCoordinate = yCoordinate + xSpeed;

        IOWR_SRAM_DATA(VGA_BASE, 7501, xCoordinate);
        IOWR_SRAM_DATA(VGA_BASE, 7502, yCoordinate);
    	}
    }


    return 0;
}
