/* * this function clear the screen and set up pixel buffers for graphics */ void initVGA() { // Use the name of your pixel buffer DMA core pixel_buffer =alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma_0"); //text on screen initialization char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(char_buffer); // Set the background buffer address � Although we don�t use thebackground, // they only provide a function to change the background buffer address, so // we must set that, and then swap it to the foreground. unsigned int pixel_buffer_addr1 = PIXEL_BUFFER_BASE; unsigned int pixel_buffer_addr2 = PIXEL_BUFFER_BASE + (320*240*2); alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr1); // Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); // Wait for the swap to complete while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr2); // Clear the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); //Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); //Wait for the swap to complete while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); }
void heads_up_display_static(void){ alt_up_char_buffer_dev *char_buffer_score; alt_up_pixel_buffer_dma_dev* pixel_buffer; char_buffer_score = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(char_buffer_score); //initializes character buffer alt_up_char_buffer_clear(char_buffer_score); //clears the character buffer of an previous characters alt_up_char_buffer_string(char_buffer_score,"Score:", 5, 50); //updates score alt_up_char_buffer_string(char_buffer_score,"Milk:", 5, 52); //updates resources alt_up_char_buffer_string(char_buffer_score,"Level:", 5, 54); //updates level alt_up_char_buffer_string(char_buffer_score,"Time:", 5, 56); //updates time pixel_buffer = alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma"); alt_up_pixel_buffer_dma_draw_box(pixel_buffer,1,120,11,130,BLACK,0);//draws black baby's body alt_up_pixel_buffer_dma_draw_box(pixel_buffer,1,130,11,133,WHITE,0);//draws diaper alt_up_pixel_buffer_dma_draw_box(pixel_buffer,1,150,11,160,BEIGE,0);//draws beige baby's body alt_up_pixel_buffer_dma_draw_box(pixel_buffer,1,160,11,163,WHITE,0);//draws diaper alt_up_pixel_buffer_dma_draw_box(pixel_buffer,1,180,11,190,YELLOW,0);//draws yellow baby's body alt_up_pixel_buffer_dma_draw_box(pixel_buffer,1,190,11,193,WHITE,0);//draws diaper //draws rectangle around indicator of tower choice alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer,0,119,12,134,ORANGE,0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer,0,149,12,164,ORANGE,0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer,0,179,12,194,ORANGE,0); }
//alt_up_char_buffer_dev *char_buffer = init_char_stuff("/dev/char_drawer"); alt_up_char_buffer_dev *init_char_stuff(char *location) { //Character Buffer alt_up_char_buffer_dev *char_buffer; char_buffer = alt_up_char_buffer_open_dev(location); alt_up_char_buffer_init(char_buffer); return char_buffer; }
void vga_init() { // Initialise buffers v.pixel_buffer = initialise_pixel(); v.char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(v.char_buffer); alt_up_char_buffer_clear(v.char_buffer); printf("Exiting vga_init\n"); }
/* Initialze the character and pixel buffers for writing */ void initBuffers(void) { // Use the name of your pixel buffer DMA core pixel_buffer = alt_up_pixel_buffer_dma_open_dev(PIXEL_BUFFER_DMA_NAME); unsigned int pixel_buffer_addr1 = PIXEL_BUFFER_BASE; unsigned int pixel_buffer_addr2 = PIXEL_BUFFER_BASE + (320 * 240 * 2); // Set the 1st buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, pixel_buffer_addr1); // Swap buffers – we have to swap because there is only an API function // to set the address of the background buffer. alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); // Set the 2nd buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, pixel_buffer_addr2); // Clear both buffers (this makes all pixels black) alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(char_buffer); alt_up_char_buffer_clear(char_buffer); }
int main() { //Print status message printf("Program Started...\n"); //=================================================================================================== // INITIALIZE HARDWARE //=================================================================================================== initialize_hardware(); // //Print Background // int i,j; // for (i=0; i<240; i++){ // for (j=0; j<320; j++){ // alt_up_pixel_buffer_dma_draw(pixel_buffer, world[i][j], j, i); // } // } //Draws the rectangle for the Game Grid (150 by 150) alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 149, 44, 300, 195, 0x3333, 0); alt_up_char_buffer_clear(char_buffer); alt_up_char_buffer_init(char_buffer); //=================================================================================================== //=================================================================================================== //=================================================================================================== // Game Grid and other initialization //=================================================================================================== int GameGrid[GRID_WIDTH][GRID_HEIGHT] = {0}; int UserHasQuit = 0; int GameStatus = 0; //=========================================================== //Create Player 1 struct and initialize positions struct Player Player1; Player1.CurrentPositionX = 37; Player1.CurrentPositionY = 75; Player1.PreviousPositionX = 37; Player1.PreviousPositionY = 75; Player1.DirectionX = 1; Player1.DirectionY = 0; //=========================================================== //Create Player 2 struct and initialize positions struct Player Player2; Player2.CurrentPositionX = 113; Player2.CurrentPositionY = 75; Player2.PreviousPositionX = 113; Player2.PreviousPositionY = 75; Player2.DirectionX = -1; Player2.DirectionY = 0; //=========================================================== // Sets the starting position as being filled GameGrid[Player1.CurrentPositionX][Player1.CurrentPositionY] = 1; GameGrid[Player2.CurrentPositionX][Player2.CurrentPositionY] = 1; //=================================================================================================== //=================================================================================================== //=================================================================================================== // Controls //=================================================================================================== alt_up_char_buffer_string(char_buffer, "Press Enter to Start!", 4, 40); alt_up_char_buffer_string(char_buffer, "Press 'P' to Pause", 4, 42); alt_up_char_buffer_string(char_buffer, "Player 1: RED", 4, 46); alt_up_char_buffer_string(char_buffer, "W- Up", 8, 47); alt_up_char_buffer_string(char_buffer, "S- Down", 8, 48); alt_up_char_buffer_string(char_buffer, "A- Left", 8, 49); alt_up_char_buffer_string(char_buffer, "D- Right", 8, 50); alt_up_char_buffer_string(char_buffer, "Player 2: BLUE", 4, 53); alt_up_char_buffer_string(char_buffer, "Arrow Up- Up", 8, 54); alt_up_char_buffer_string(char_buffer, "Arrow Down - Down", 8, 55); alt_up_char_buffer_string(char_buffer, "Arrow Left- Left", 8, 56); alt_up_char_buffer_string(char_buffer, "Arrow Right- Right", 8, 57); //=================================================================================================== // START GAME //=================================================================================================== while(UserHasQuit != 1){ // Function to read when user has pressed entered to start the game /* if( UserHasPressedEnter ) GameStatus = 1; */ // This is the beginning of the game while( GameStatus != 1) { //Starts the timer to read keyboard inputs until we update the player positions and collisions UpdatePlayerMovement(&Player1, &Player2); //Updating the collision detection, movement, and screen //UpdateGame(&Player1, &Player2, &GameGrid, GameStatus, pixel_buffer); } } return 0; }
/* * Main Game Loop */ int main() { // Use the name of your pixel buffer DMA core pixel_buffer =alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma_0"); initVGA(); usleep(5000000); ps2 = alt_up_ps2_open_dev("/dev/ps2_0"); ps2->timeout = 2000000; alt_up_ps2_clear_fifo(ps2); alt_up_ps2_init(ps2); unsigned char byte1; while(alt_up_ps2_read_data_byte(ps2, &byte1)!=0); char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/character_lcd_0"); alt_up_character_lcd_init (char_lcd_dev); char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(char_buffer); alt_up_sd_card_dev *device_reference = NULL; struct Env* p = initEnv(); initGameInfo(); struct Collidable* collisionChecker = initCollidable(); addCollisionToEnv(p, collisionChecker); promptSDcard(p, device_reference); usleep(1000); alt_up_char_buffer_string(char_buffer, "Loading ", 40, 30); unsigned end_time, start_time; int count = 0; lock = 0; struct animation* starAnimation = loadSDImageSeq("ST0.BMP", 2, 8); struct animation* star2Animation = loadSDImageSeq("ST00.BMP", 3, 7); struct animation* alien0 = loadSDImageSeq("A100.BMP", 2, 2); //2 images where first 2 characters are prefix struct animation* alien1 = loadSDImageSeq("A000.BMP", 2, 15); struct animation* ship0 = loadSDImageSeq("S00.BMP", 2, 16); struct animation* ship1 = loadSDImageSeq("S10.BMP", 2, 27); struct animation* bossAnimate = loadSDImageSeq("BO00.BMP", 2, 28); struct animation* ship2 = loadSDImageSeq("S20.BMP", 2, 35); struct animation* ship3 = loadSDImageSeq("S30.BMP", 2, 30); struct animation* ship4 = loadSDImageSeq("S40.BMP", 2, 10); struct animation* explode1 = initAnimation((int*)explode01, 1); addImage(explode1, initAnimation((int*)explode02, 0)); addImage(explode1, initAnimation((int*)explode03, 0)); addImage(explode1, initAnimation((int*)explode04, 0)); addImage(explode1, initAnimation((int*)explode05, 0)); struct animation** shipAnimationCollection = (struct animation**)malloc(sizeof(struct animation*)*5); shipAnimationCollection[0] = ship0; shipAnimationCollection[1] = ship1; shipAnimationCollection[2] = ship2; shipAnimationCollection[3] = ship3; shipAnimationCollection[4] = ship4; initWeapon(collisionChecker, p); struct Cursor* mouse = initCursor(p, collisionChecker); addToEnv(p, mouse->super); addObjToCollide(collisionChecker, mouse->super); setCursor(p, mouse); struct KeyController* keyController = initKeyController(); struct SwitchController* switchController = initSwitchController(); struct CursorController* ctrl = initCursorController(mouse->super, switchController, keyController); alt_up_char_buffer_string(char_buffer, "Loading Sounds ", 30, 30); audioController = initAudioController(); loadSound( audioController, LOOP_ONE ); loadSound( audioController, LASER_SOUND ); alt_irq_register(AUDIO_IRQ, audioController, (void*) audio_ISR); alt_irq_enable(AUDIO_IRQ); play_background_loop( audioController, LOOP_ONE ); enableAudioController( audioController ); printhex(info.score); mainMenu(mouse, ctrl, p); disableAudioController(audioController); stop_background_loop(audioController); unloadSoundById(audioController, LASER_SOUND); unloadSoundById(audioController, LOOP_ONE); alt_up_char_buffer_string(char_buffer, "Loading Sounds ", 30, 30); //loadSound(audioController, WIN_SOUND); //loadSound(audioController, LOSE_SOUND); loadSound( audioController, TOWER_UPGRADE_SOUND ); loadSound( audioController, LOOP_TWO ); play_background_loop(audioController, LOOP_TWO); enableAudioController( audioController ); alt_up_char_buffer_clear(char_buffer); //usleep(1000); struct Alien* testAlienCollection[60]; gameSetup(p, shipAnimationCollection, mouse, starAnimation, star2Animation); usleep(500000); //time delay for panel to be drawn // char LPS[50]; float lps_; int n = 0; for(n = 0; n < 20; n++) { testAlienCollection[n] =initAlien(n, 10*n, 10, alien0, explode1, "IdontKnow", 1.4, 150, 500, collisionChecker); addToEnvNR(p, testAlienCollection[n]->super); } for(n = 0; n < 20; n++) { testAlienCollection[n+20] =initAlien(10*n, n, 10, alien1, explode1, "whatName", 1.4, 190, 850, collisionChecker); addToEnvNR(p, testAlienCollection[n+20]->super); } for(n = 0; n < 20; n++) { testAlienCollection[n+40] =initAlien(10*n, n, 20, bossAnimate, explode1, "IamBoss", 1.6, 800, 1500, collisionChecker); testAlienCollection[n+40]->score = 300; addToEnvNR(p, testAlienCollection[n+40]->super); } int stage = 0; /* * Game Starts!!!!!! */ alt_alarm_start (&alarm,alt_ticks_per_second(),my_alarm_callback,(void*)p); int startTimer = 0; char second_row1[15]; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); sprintf(second_row1, "wave# %d ", stage); alt_up_character_lcd_string(char_lcd_dev, second_row1); while(1) { alt_timestamp_start(); start_time = (unsigned)alt_timestamp(); /*-----------------------------------------------------------------------------------------------*/ checkCollision(collisionChecker); //a major function that check each collision happen between each object updateCursorController(ctrl, 1); count++; if (startTimer > count) info.startButton = false; else { if(stage == 7) info.isWin = true; else if(startTimer == count){ //play_background_loop(audioController, LOOP_TWO); enableAudioController( audioController ); } } if (info.startButton){ disableAudioController(audioController); //stop_background_loop(audioController); startTimer = count + 15000; checkStages(testAlienCollection, stage%7, collisionChecker); stage++; //if(stage > 6) stage = 0; info.startButton = false; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); sprintf(second_row1, "wave# %d ", stage); alt_up_character_lcd_string(char_lcd_dev, second_row1); } if(info.isEnd || info.isWin) { disableAudioController(audioController); stop_background_loop(audioController); endGame(testAlienCollection, collisionChecker, p, mouse, ctrl, keyController); } /*-----------------------------------------------------------------------------------------------*/ end_time = (unsigned)alt_timestamp(); lps_ = (float)alt_timestamp_freq()/(float)(end_time - start_time); sprintf(LPS, "The current LPS is %.2f", lps_); alt_up_char_buffer_string(char_buffer, LPS, 3, 2); } return 0; }
/* * @brief Initialize the name of the alt_up_char_buffer_dev structure * * @param char_buffer -- struct for the character buffer device * */ void Char_init(CharBuffer *char_buffer) { alt_up_char_buffer_init(char_buffer -> char_buffer); }