#include
#include "Utils.c"
// #defines
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (1)
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define BLUE 0x00FF0000
#define RED 0x000000FF
#define GREEN 0x0000FF00
#define WHITE 0x00FFFFFF
#define BLACK 0x00000000
//////////////////////////////////////////////////////////////////////////////////////////
// Global Variables
//////////////////////////////////////////////////////////////////////////////////////////
u16 *VRAM=(void *)(0x44000000);
int player1X, player1Y;
int player1Radius;
int player1Xold, player1Yold;
int player1dir;
int player2X, player2Y;
int player2Radius;
int player2Xold, player2Yold;
int player2dir;
int collided;
///////////////////////////////////////////////////////////////////////////////////
// Random number generator
///////////////////////////////////////////////////////////////////////////////////
int Random(int high)
{
return (rand() % (high+1));
}
//////////////////////////////////////////////////////////////////////////////////////////
// Sets a pixel on the screen using x,y, and three 0-255 shade color attributes.
//////////////////////////////////////////////////////////////////////////////////////////
void SetPixel(int x,int y,int r,int g,int b)
{
// Tests whether pixel is being drawn off-screen, and returns imediately if so.
if(x479//y271//r255//g255//b255)
{
return;
}
int color=((b>>3)>3)>3) / 0x8000; // Creates and stores color.
u16 *address=VRAM+((((512)*PIXEL_SIZE)*y)+x); // Caculates address of pixel.
if((int)*address!=65535) *address=color; // Writes color code into address of the pixel.
}
//////////////////////////////////////////////////////////////////////////////////////////
// Get a pixels x,y, value
//////////////////////////////////////////////////////////////////////////////////////////
int GetPixel(int x,int y)
{
int color=0;
if(x479//y271)
return -1;
u16 *address=VRAM+((((512)*PIXEL_SIZE)*y)+x); // Caculates address of pixel.
color = *address; // Read pixel color.
return color;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Plots a line according to the given values, startX, startY, endX, endY, and color: R,G,B.
//////////////////////////////////////////////////////////////////////////////////////////
void PlotLine(int x0,int y0,int x1,int y1,int r,int g,int b)
{
int dy = y1 - y0;
int dx = x1 - x0;
float t = (float) 0.5; // offset for rounding
SetPixel(x0,y0,r,g,b);
// If endpoints are the same, then don't draw the line, just return.
if( dy == 0 && dx == 0 ) return;
if (abs(dx) > abs(dy)) // slope = 1
{
float m = (float) dx / (float) dy; // compute slope
t += x0;
dy = (dy 479) player1X=479-player1Radius;
}
if(player1dir==3)
{
player1Y--;
if(player1Y-player1Radius271) player1Y=271-player1Radius;
}
if(player2dir==1)
{
player2X--;
if(player2X-player2Radius479) player2X=479-player2Radius;
}
if(player2dir==3)
{
player2Y--;
if(player2Y-player2Radius271) player2Y=271-player2Radius;
}
check_collisions();
}
void drawScreenBG(void)
{
PlotLine(0,15, 479,15, 255,255,255);
PlotLine(0,271, 479,271, 255,255,255);
PlotLine(0,15, 0,271, 255,255,255);
PlotLine(479,15,479,271, 255,255,255);
}
void EraseCircle(int x, int y, int rad)
{
PlotCircle(x, y, rad, 0, 0, 0);
SetPixel(x, y, 255, 255, 255);
}
void drawPlayers(void)
{
EraseCircle(player1Xold, player1Yold, player1Radius);
SetPixel(player1X, player1Y, 255, 255, 255);
PlotCircle(player1X, player1Y, player1Radius, 0, 255, 0);
EraseCircle(player2Xold, player2Yold, player2Radius);
SetPixel(player2X, player2Y, 255, 255, 255);
PlotCircle(player2X, player2Y, player2Radius, 255, 0, 0);
}
///////////////////////////////////////////////////////////////////////////////////
// Set up screen and controller
///////////////////////////////////////////////////////////////////////////////////
void initPSP(void)
{
// Sets the display mode.
sceDisplaySetMode(1,SCR_WIDTH,SCR_HEIGHT);
sceDisplaySetFrameBuf(VRAM,BUF_WIDTH,1,1);
// Setup the keypad ctrl mode
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(1);
}
void initVariables(void)
{
player1Xold = 0;
player1Yold = 0;
player1X = 230;
player1Y = 135;
player1Radius = 5;
player1dir=1;
player2Xold = 0;
player2Yold = 0;
player2X = 248;
player2Y = 135;
player2Radius = 5;
player2dir=2;
collided=0;
}
void Main(void)
{
// Set up screen and controller
initPSP();
//Init my vars
initVariables();
// Main Program Loop
while(1)
{
drawScreenBG();
if(!collided)
{
movePlayers();
drawPlayers();
}
//print some text
Print(0, 0, RED, "PSPTron");
//char pixelcolor[25];
//_ltoa(pixelcolor, GetPixel(playerX,playerY), 10);
//Print(0, 0, RED, pixelcolor);
//process any key presses
sceCtrlReadBufferPositive(&gpaddata,1);
WriteDwordDummy(0,22,gpaddata.Buttons);
ProcessKeys(gpaddata.Buttons);
}
}