// *********************************************************************************** // Programs written by R.Swan - rs108@mdx.ac.uk - www.netyaroze-europe.com/~middex2 // General Screen functions // *********************************************************************************** #include #include "header.h" // **** Global variables and structures u_long BoxX = 0, BoxY = 0; // **** Global variables and structures u_long GameRunning = true; // flag used to quit // **** Function prototypes void UpdateWorld(); void RenderWorld(); void ProcessJoyPad(); // *********************************************************************************** // MAIN FUNCTION // *********************************************************************************** void main() { InitialiseScreen(); InitialiseJoyPad(); while (GameRunning == true) { ProcessJoyPad(); UpdateWorld(); RenderWorld(); } ResetGraph(3); } // *********************************************************************************** // Function Definitions // *********************************************************************************** // **** Update everything in the world before drawing void UpdateWorld() { FntPrint(FntOne, "Speed - %d/280\n", VerticalSync); FntPrint(FntOne, "Joypad - Move the square\n"); FntPrint(FntOne, "Start + Select - quit\n"); } // **** Register everything that needs to be drawn and then draw it void RenderWorld() { RenderPrepare(); DrawColouredBox(20, 20, 150, 110, -1, 2, 128, 128, 64, 255, 255, 255, 64, 64, 128, 64, 64, 128); DrawColouredBox(170, 20, 300, 110, -1, 2, 255, 0, 0, 64, 0, 64, 64, 0, 64, 0, 0, 255); DrawColouredBox(20, 130, 150, 220, -1, 2, 64, 0, 255, 0, 255, 0, 64, 0, 0, 0, 255, 0); DrawColouredBox(170, 130, 300, 220, -1, 2, 0, 32, 0, 0, 32, 0, 196, 32, 255, 0, 32, 0); DrawColouredBox(BoxX, BoxY, BoxX+80, BoxY+80, 1, 1, 255, 0, 0, 0, 0, 255, 0, 255, 0, 128, 128, 128); DrawColouredBox(240-BoxX, 160-BoxY, 320-BoxX, 240-BoxY, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 255, 255, 255); RenderFinish(); } // **** Respond to user input from joypad 1 void ProcessJoyPad() { u_long PAD = ReadJoyPad(); if ((PAD& PADselect) && (PAD& PADstart)) GameRunning = false; if ((PAD& PADup) && (BoxY>0)) BoxY--; if ((PAD& PADdown) && (BoxY<160)) BoxY++; if ((PAD& PADleft) && (BoxX>0)) BoxX--; if ((PAD& PADright) && (BoxX<240)) BoxX++; }