void draw_how_to_play_guide(alt_up_pixel_buffer_dma_dev* pixel_buffer, alt_up_char_buffer_dev* char_buffer) { alt_up_char_buffer_clear(char_buffer); draw_menu_text(char_buffer); alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 31, 320, 240, BLACK, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 70, 10, 140, 30, BLUE, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 0, 10, 70, 30, YELLOW, 0); alt_up_char_buffer_string(char_buffer, "O B J E C T I V E", 3, 12); alt_up_char_buffer_string(char_buffer, "_________________", 3, 13); alt_up_char_buffer_string(char_buffer, "In SHARKS VS. BABIES, players play as babies, trying to protect their", 3, 15); alt_up_char_buffer_string(char_buffer, "base against the enemy sharks. The player can purchase towers using the", 3, 17); alt_up_char_buffer_string(char_buffer, "resources currently avalable to them and place them on a grid in order to", 3, 19); alt_up_char_buffer_string(char_buffer, "fight the enemy sharks. Each tower is unique and has different attributes.", 3, 21); alt_up_char_buffer_string(char_buffer, "However, be wary that each type of shark has different attributes and some", 3, 23); alt_up_char_buffer_string(char_buffer, "towers may be more or less effective against the different types of sharks.", 3, 25); alt_up_char_buffer_string(char_buffer, "The objective of the game is to prevent the sharks from reaching the dock.", 3, 27); alt_up_char_buffer_string(char_buffer, "A C Q U I R I N G R E S O U R C E S", 3, 32); alt_up_char_buffer_string(char_buffer, "____________________________________", 3, 33); alt_up_char_buffer_string(char_buffer, "Resources can be acquired in two ways:", 3, 35); alt_up_char_buffer_string(char_buffer, "1) Resources will periodically fall from the sky. The player can attempt to", 3, 38); alt_up_char_buffer_string(char_buffer, "obtain these resources by navigating a boat at the top of the screen.", 3, 40); alt_up_char_buffer_string(char_buffer, "There are three types of resources, each yielding a different amount.", 3, 42); alt_up_char_buffer_string(char_buffer, "2) The player can place a resource generating tower that slowly generates", 3, 45); alt_up_char_buffer_string(char_buffer, "resources for the player. Note that these towers cannot attack the enemies", 3, 47); alt_up_char_buffer_string(char_buffer, "and have low HP.", 3, 49); }
void promptSDcard(struct Env* p, alt_up_sd_card_dev* device_reference) { /* * Loading Screen if SD card is not presented */ int frame = 25; struct animation* b = initAnimation((int*)pacman01, 1); addImage(b, initAnimation((int*)pacman02, 0)); addImage(b, initAnimation((int*)pacman03, 0)); addImage(b, initAnimation((int*)pacman04, 0)); struct Object *face; face= initObject(80, 120, 10, b, NULL); addToEnv(p, face); alt_alarm_start (&alarm,alt_ticks_per_second(),my_alarm_callback,(void*)p); while(!loadSDCard(device_reference)) { displayString("Please insert the SD card to start", frame, 30); frame++; setXY(face, face->x+4, face->y); if(face->x >245) face->x = 0; if(frame > 61) frame = 0; usleep(300000); }alt_up_char_buffer_clear(char_buffer); killAnimation(b); removeFromEnv(p, face); alt_alarm_stop(&alarm); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); }
void draw_help_menu(alt_up_pixel_buffer_dma_dev* pixel_buffer, alt_up_char_buffer_dev* char_buffer, alt_up_ps2_dev *ps2_kb, KB_CODE_TYPE decode_mode) { int count = 0; int exit_flag = 0; int current_menu = HOW_TO_PLAY_MENU; alt_u8 data; char ascii; alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 10, 319, 30, BLUE, 0); draw_menu_text(char_buffer); draw_how_to_play_guide(pixel_buffer, char_buffer); while(exit_flag == 0) { if (decode_scancode(ps2_kb, &decode_mode, &data, &ascii) == 0) { if(data == LEFT || data == RIGHT || data == ESC) count++; if(data == LEFT && count >= 2) { if(current_menu != HOW_TO_PLAY_MENU) current_menu--; draw_current_menu(pixel_buffer, char_buffer, current_menu); count = 0; } if(data == RIGHT && count >= 2) { if(current_menu != DEVS_MENU) current_menu++; draw_current_menu(pixel_buffer, char_buffer, current_menu); count = 0; } if(data == ESC && count >= 2) { exit_flag = 1; } } } alt_up_char_buffer_clear(char_buffer); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); }
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); }
void game_screen() { alt_up_char_buffer_clear(char_buffer); char str1[50], str2[30], str3[50]; sprintf(str1, "Player 1: $%d", dealer->players[0].total_money); alt_up_char_buffer_string(char_buffer, str1, 5, 5); sprintf(str1, "Player 2: $%d", dealer->players[1].total_money); alt_up_char_buffer_string(char_buffer, str1, 5, 10); Bitmap* flop_card0_bmp = load_bitmap(card_bitmap_name(dealer->cards_on_table[0])); Bitmap* flop_card1_bmp = load_bitmap(card_bitmap_name(dealer->cards_on_table[1])); Bitmap* flop_card2_bmp = load_bitmap(card_bitmap_name(dealer->cards_on_table[2])); Bitmap* turn_card_bmp = load_bitmap(card_bitmap_name(dealer->cards_on_table[3])); Bitmap* river_card_bmp = load_bitmap(card_bitmap_name(dealer->cards_on_table[4])); draw_bitmap(flop_card0_bmp, 25, 60); draw_bitmap(flop_card1_bmp, 55, 60); draw_bitmap(flop_card2_bmp, 85, 60); draw_bitmap(turn_card_bmp, 115, 60); draw_bitmap(river_card_bmp, 145, 60); sprintf(str3, "Pot: $%d", dealer->pot); alt_up_char_buffer_string(char_buffer, str3, 5, 50); sprintf(str3, "Current Bet: $%d", dealer->current_bet); alt_up_char_buffer_string(char_buffer, str3, 5, 51); draw_to_screen(); }
void prepareText(void){ alt_up_char_buffer_clear(char_buffer_dev); //Chars for the vertical line (Vpp) alt_up_char_buffer_string(char_buffer_dev,"2.5",0,0); alt_up_char_buffer_string(char_buffer_dev," V ",0,29); alt_up_char_buffer_string(char_buffer_dev,"0.0",0,56); //Chars for the horizontal line (kHz) (soft, except for kHz) alt_up_char_buffer_string(char_buffer_dev,"kHz",37,58); }
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"); }
void draw_sharks_guide(alt_up_pixel_buffer_dma_dev* pixel_buffer, alt_up_char_buffer_dev* char_buffer){ alt_up_char_buffer_clear(char_buffer); draw_menu_text(char_buffer); alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 31, 320, 240, BLACK, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 70, 10, 140, 30, BLUE, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 195, 10, 260, 30, BLUE, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 140, 10, 190, 30, YELLOW, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 62, 40, 102, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 62, 82, 102, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 16, 22); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 16, 24); alt_up_char_buffer_string(char_buffer, "A.RATE: X", 16, 26); alt_up_char_buffer_string(char_buffer, "SPEED: XX", 16, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 16, 30); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 114, 40, 154, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 114, 82, 154, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 29, 22); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 29, 24); alt_up_char_buffer_string(char_buffer, "A.RATE: X", 29, 26); alt_up_char_buffer_string(char_buffer, "SPEED: XX", 29, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 29, 30); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 166, 40, 204, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 166, 82, 204, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 42, 22); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 42, 24); alt_up_char_buffer_string(char_buffer, "A.RATE: X", 42, 26); alt_up_char_buffer_string(char_buffer, "SPEED: XX", 42, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 42, 30); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 218, 40, 258, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 218, 82, 258, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 55, 22); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 55, 24); alt_up_char_buffer_string(char_buffer, "A.RATE: X", 55, 26); alt_up_char_buffer_string(char_buffer, "SPEED: XX", 55, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 55, 30); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 114, 140, 154, 180, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 114, 182, 154, 232, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 29, 47); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 29, 49); alt_up_char_buffer_string(char_buffer, "A.RATE: X", 29, 51); alt_up_char_buffer_string(char_buffer, "SPEED: XX", 29, 53); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 29, 55); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 166, 140, 204, 180, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 166, 182, 204, 232, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 42, 47); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 42, 49); alt_up_char_buffer_string(char_buffer, "A.RATE: X", 42, 51); alt_up_char_buffer_string(char_buffer, "SPEED: XX", 42, 53); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 42, 55); }
void VGA_task(void* pvParameters){ while(1){ alt_up_char_buffer_string(char_buf, "Hello World", 40, 30); //usleep(1000000); alt_up_char_buffer_draw(char_buf, '!', 51, 30); //usleep(1000000); alt_up_char_buffer_clear(char_buf); //usleep(1000000); } }
void draw_developers_guide(alt_up_pixel_buffer_dma_dev* pixel_buffer, alt_up_char_buffer_dev* char_buffer){ alt_up_char_buffer_clear(char_buffer); draw_menu_text(char_buffer); alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 31, 320, 240, BLACK, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 195, 10, 260, 30, BLUE, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 260, 10, 319, 30, YELLOW, 0); alt_up_char_buffer_string(char_buffer, "D E V E L O P E R S", 31, 12); alt_up_char_buffer_string(char_buffer, "___________________", 31, 13); alt_up_char_buffer_string(char_buffer, "CYRIL CANONIZADO", 33, 19); alt_up_char_buffer_string(char_buffer, "DAVID LU", 37, 23); alt_up_char_buffer_string(char_buffer, "KEVAL SHAH", 36, 27); alt_up_char_buffer_string(char_buffer, "BRYCE TOWNS", 36, 31); }
void draw_nothing() { if(0) // Check if in waiting mode { bluebackground(v.pixel_buffer); alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); if(v.blank_flag == FALSE) { alt_up_char_buffer_clear(v.char_buffer); alt_up_char_buffer_string(v.char_buffer, "Waiting for user input...", 27, 30); v.blank_flag = TRUE; } } }
void display_score() { char* display_score_message[20]; if(m == displayscore) { bluebackground(v.pixel_buffer); // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); alt_up_char_buffer_clear(v.char_buffer); sprintf( display_score_message, "FINAL SCORE: %d", rb.score ); alt_up_char_buffer_string(v.char_buffer, "GAME OVER.", 36, 20); alt_up_char_buffer_string(v.char_buffer, display_score_message, 32, 30); } }
void initVGA(void){ //reset the display pixel_buf = alt_up_pixel_buffer_dma_open_dev(VIDEO_PIXEL_BUFFER_DMA_NAME); if(pixel_buf == NULL){ printf("Cannot find pixel buffer device\n"); } alt_up_pixel_buffer_dma_clear_screen(pixel_buf, 0); //initialize character buffer char_buf = alt_up_char_buffer_open_dev("/dev/video_character_buffer_with_dma"); if(char_buf == NULL){ printf("can't find char buffer device\n"); } alt_up_char_buffer_clear(char_buf); }
void draw_controls_guide(alt_up_pixel_buffer_dma_dev* pixel_buffer, alt_up_char_buffer_dev* char_buffer){ alt_up_char_buffer_clear(char_buffer); draw_menu_text(char_buffer); alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 31, 320, 240, BLACK, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 140, 10, 190, 30, BLUE, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 260, 10, 319, 30, BLUE, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 195, 10, 260, 30, YELLOW, 0); alt_up_char_buffer_string(char_buffer, "C O N T R O L S", 33, 12); alt_up_char_buffer_string(char_buffer, "_______________", 33, 13); alt_up_char_buffer_string(char_buffer, "UP ARROW ----- Move Cursor Up / Navigate Menus", 17, 19); alt_up_char_buffer_string(char_buffer, "DOWN ARROW --- Move Cursor Down / Navigate Menus", 17, 22); alt_up_char_buffer_string(char_buffer, "RIGHT ARROW -- Move Cursor Right / Navigate Menus", 17, 25); alt_up_char_buffer_string(char_buffer, "LEFT ARROW --- Move Cursor Left / Navigate Menus", 17, 28); alt_up_char_buffer_string(char_buffer, "A ------------ Move Resource Collecting Boat Left", 17, 31); alt_up_char_buffer_string(char_buffer, "D ------------ Move Resource Collecting Boat Right", 17, 34); alt_up_char_buffer_string(char_buffer, "(1 to 9) ----- Select Tower To Place", 17, 37); alt_up_char_buffer_string(char_buffer, "SPACEBAR ----- Place Tower On Current Grid ", 17, 40); alt_up_char_buffer_string(char_buffer, "ESC ---------- Pause Menu / Return To Previous Menu", 17, 43); }
/* 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); }
//Audio selection screen and volume control void select_bgm(char ** soundfiles, int numfiles) { int init_y; int i; int y_index = 4; int temp,temp2; char ptr[] = "->"; int cross; int crossptr = 36; if (onetime > 0) { free(bgm); //If called again, clean up original file name for audio file } bgm = (char *)malloc(sizeof(char) * (MAX_NAME_LEN + direct_len)); char vol_display[3]; temp2 = sprintf(vol_display, "%d", ((int)(VOL_SET * 10))); alt_up_char_buffer_string(char_buffer, "Select BGM file",33, y_index); alt_up_char_buffer_string(char_buffer, "Use D-pad to scroll",31, 6); alt_up_char_buffer_string(char_buffer, "Use Left & Right to scroll to volume",25, 7); alt_up_char_buffer_string(char_buffer, "Press 'X' to select",31, 8); alt_up_char_buffer_string(char_buffer, "Volume Control",62, 21); alt_up_char_buffer_string(char_buffer, "+", 68, 26); alt_up_char_buffer_string(char_buffer, vol_display, 68, 30); alt_up_char_buffer_string(char_buffer, "-", 68, 34); y_index = 27; temp = numfiles; while (temp > 0) { y_index -= 2; temp--; } for(i = 0; i < numfiles; i++) { if (soundfiles[i] != NULL) { y_index += 3; //Display soundfiles alt_up_char_buffer_string(char_buffer, soundfiles[i],36, y_index); if (i == 0) { arrow_y = y_index; init_y = arrow_y; if (arrow_x == 0) { alt_up_char_buffer_string(char_buffer, ptr,33, arrow_y); } else if (arrow_x == 1){ arrow_y = 30; alt_up_char_buffer_string(char_buffer,"->",65, arrow_y); } } } } arrow_index = 0; while(1) { if(*keys == 7) { usleep(150000); if (((arrow_index) > 0) && (arrow_x == 0)) { alt_up_char_buffer_string(char_buffer," ",33, arrow_y); arrow_y -= 3; alt_up_char_buffer_string(char_buffer,ptr,33, arrow_y); arrow_index--; } else if (arrow_x == 1) { alt_up_char_buffer_string(char_buffer, " ", 68, 30); VOL_SET = VOL_SET + 0.1; //Volume precision if (VOL_SET >= 2.0) VOL_SET = 2.0; //Max volume temp2 = sprintf(vol_display, "%d", ((int)(VOL_SET * 10))); alt_up_char_buffer_string(char_buffer, vol_display, 68, 30); } } if(*keys == 11) { usleep(150000); if (((arrow_index) < (numfiles - 1)) && (arrow_x == 0)) { alt_up_char_buffer_string(char_buffer," ",33, arrow_y); arrow_y += 3; alt_up_char_buffer_string(char_buffer,ptr,33, arrow_y); arrow_index++; } else if (arrow_x == 1) { alt_up_char_buffer_string(char_buffer, " ", 68, 30); VOL_SET = VOL_SET - 0.1; if (VOL_SET <= 0.0) VOL_SET = 0.0; temp2 = sprintf(vol_display, "%d", ((int)(VOL_SET * 10))); alt_up_char_buffer_string(char_buffer, vol_display, 68, 30); } } //Select button if(*switches == 1) { usleep(150000); if (arrow_x == 0) { cross = strlen(soundfiles[arrow_index]); for (i = 0; i < cross; i++) { alt_up_char_buffer_string(char_buffer,"-",crossptr, arrow_y); crossptr++; } strcpy(bgm, AUD_DIRECT); strcat(bgm, soundfiles[arrow_index]); alt_up_char_buffer_clear(char_buffer); alt_up_char_buffer_string(char_buffer,"Loading, Please Wait",31, 25); init_wav(bgm, VOL_SET, 0); alt_up_audio_enable_write_interrupt(audio); //Resume audio alt_up_char_buffer_clear(char_buffer); return; } } if(*keys == 13) { usleep(150000); if (arrow_x == 0) { arrow_x = 1; alt_up_char_buffer_string(char_buffer," ",33, arrow_y); arrow_y = 30; alt_up_char_buffer_string(char_buffer,"->",65, arrow_y); } } if (arrow_x == 1) { arrow_x = 0; alt_up_char_buffer_string(char_buffer," ",65, arrow_y); arrow_y = init_y; alt_up_char_buffer_string(char_buffer,"->",33, arrow_y); arrow_index = 0; } /* else if (ps.b.sel == 1) { usleep(150000); alt_up_audio_enable_write_interrupt(audio); alt_up_char_buffer_clear(char_buffer); return; } */ usleep(150000); } }
//inputs: a message to be decoded and executed //output: -1 for an error, 0 otherwise //purpose: Take in a raw message from middleman and execute the required functions depending on what the input command is. int executeCmd(msg * currentMsg) { if(currentMsg == NULL) { return -1; } unsigned int nextCmd = currentMsg->cmd; unsigned char byteInfo; msg * rspnsMsg; switch ((command)nextCmd) { case CONNECT: //not implemented break; case DISCONNECT: //not implemented break; case SEND_MAP: //Android sends map to DE2 - needs to be recieved, stored and drawn printf("Entering send SEND_MAP\n"); if(loadedTokenCnt < MAX_TOKENS) { receiveMap(currentMsg->buffer); drawMap(); } else { printf("Error when Android sending map!\n"); return -1; } break; case SEND_TOKEN: //Android sends token to DE2 - needs to be recieved, stored as a token, and drawn // Then others need to be notified of new token printf("Entering send Token\n"); //obtain free address in token array token *newTok = allocateToken(); if(newTok) { newTok->ownerID = currentMsg->androidID; receiveTokenPixArr(currentMsg->buffer, &(newTok->bmp)); drawBmp(&newTok->bmp, newTok->x, newTok->y); } else { printf("Error when Android sending token!\n"); return -1; } // respond with token ID rspnsMsg = createSendTokenResponsesMsg(currentMsg, newTok); sendMessage(rspnsMsg); free(rspnsMsg->buffer); free(rspnsMsg); alertUsersOfTokenInfo(currentMsg, newTok->tokenID); break; case GET_DM: //Android attempts to get DM and new DM information is sent to all Android Users printf("In get_dm\n"); //only allow DM to be taken if it is not already taken if (dmID == 0) { dmID = currentMsg->androidID; printf("New DM: %x\n", dmID); } else { printf("DM not available - player %x currently has it\n", dmID); } sendAllUsersDMID(dmID); printf("DM id %x\n", dmID); break; case RELEASE_DM: //Android attempts to release DM and new DM information is sent to all Androi Users printf("In release_dm\n"); //only the DM can release their status if (dmID == currentMsg->androidID) { dmID = 0; } sendAllUsersDMID(dmID); printf("DM id %x\n", dmID); break; case GET_DM_ID: //All Android users get DM information printf("In test_get_dm\n"); sendAllUsersDMID(dmID); printf("DM id %x\n", dmID); break; case MOVE_TOKEN: //Android moves token on DE2 - needs structure to be updated, and redrawn // Then others need to be notified of new token position printf("In move_token\n"); handleMoveTokenMsg(currentMsg); alertUsersOfTokenInfo(currentMsg, currentMsg->buffer[0]); break; case HANDSHAKE: //return identical message to Android that was recieved printf("In hand_shake command\n"); sendMessage(currentMsg); break; case PASS_MSG: //Pass message between Android users printf("In Pass_msg command statement\n"); passMsg(currentMsg); break; case UPDATE_ALIAS: //Update the user's alias to a new string printf("In Update_Alias\n"); updateConnUserAlias(currentMsg); alertUsersNewUser(currentMsg); break; case OUTPUT_TOKEN_INFO: //This is a java side command - the DE2 will update all connected androids that a token has moved. printf("In Output_Token_Info\n"); break; case DISCONNECT_DEV: //A device disconnected, so cleanup everything it owns and alert all other users that this player, // and their tokens no longer exist printf("In DISCONNECT_DEV\n"); if (dmID == currentMsg->androidID) { dmID = 0; sendAllUsersDMID(dmID); } alertUsersOfUserDC(currentMsg); // removes their alias removeTokensOfOneUser(currentMsg, REMOVEALLVAL); // removes all references to DC'd players tokens from all other users. removeTokenFromUser(currentMsg->androidID); clearUserInfo(currentMsg); alt_up_char_buffer_clear(char_buffer); // refresh buffer. break; case REMOVE_TOKEN: //Android removes token from DE2 - needs to be cleaned up // Then others need to be notified of token removed from game printf("In Remove_Token"); byteInfo = *(currentMsg->buffer); // first byte in buffer is Token_ID; removeTokensOfOneUser(currentMsg, byteInfo); removeToken(byteInfo); break; default: printf("Error, invalid command received on DE2!"); break; } return 0; }
void draw_towers_guide(alt_up_pixel_buffer_dma_dev* pixel_buffer, alt_up_char_buffer_dev* char_buffer){ alt_up_char_buffer_clear(char_buffer); draw_menu_text(char_buffer); alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 31, 320, 240, BLACK, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 0, 10, 70, 30, BLUE, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 140, 10, 190, 30, BLUE, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 70, 10, 140, 30, YELLOW, 0); /* Tower Row 1 Col 1 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 10, 40, 50, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 10, 82, 50, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 3, 22); alt_up_char_buffer_string(char_buffer, "COST: XXX", 3, 24); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 3, 26); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 3, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 3, 30); /* Tower Row 1 Col 2 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 62, 40, 102, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 62, 82, 102, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 16, 22); alt_up_char_buffer_string(char_buffer, "COST: XXX", 16, 24); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 16, 26); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 16, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 16, 30); /* Tower Row 1 Col 3 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 114, 40, 154, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 114, 82, 154, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 29, 22); alt_up_char_buffer_string(char_buffer, "COST: XXX", 29, 24); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 29, 26); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 29, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 29, 30); /* Tower Row 1 Col 4 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 166, 40, 204, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 166, 82, 204, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 42, 22); alt_up_char_buffer_string(char_buffer, "COST: XXX", 42, 24); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 42, 26); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 42, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 42, 30); /* Tower Row 1 Col 5 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 218, 40, 258, 80, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 218, 82, 258, 132, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 55, 22); alt_up_char_buffer_string(char_buffer, "COST: XXX", 55, 24); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 55, 26); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 55, 28); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 55, 30); /* Tower Row 2 Col 1 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 10, 140, 50, 180, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 10, 182, 50, 232, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 3, 47); alt_up_char_buffer_string(char_buffer, "COST: XXX", 3, 49); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 3, 51); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 3, 53); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 3, 55); /* Tower Row 2 Col 2 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 62, 140, 102, 180, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 62, 182, 102, 232, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 16, 47); alt_up_char_buffer_string(char_buffer, "COST: XXX", 16, 49); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 16, 51); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 16, 53); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 16, 55); /* Tower Row 2 Col 3 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 114, 140, 154, 180, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 114, 182, 154, 232, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 29, 47); alt_up_char_buffer_string(char_buffer, "COST: XXX", 29, 49); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 29, 51); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 29, 53); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 29, 55); /* Tower Row 2 Col 4 */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 166, 140, 204, 180, RED, 0); alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer, 166, 182, 204, 232, WHITE, 0); alt_up_char_buffer_string(char_buffer, "HP: XXX", 42, 47); alt_up_char_buffer_string(char_buffer, "COST: XXX", 42, 49); alt_up_char_buffer_string(char_buffer, "DMG: XXX", 42, 51); alt_up_char_buffer_string(char_buffer, "F.RATE: X", 42, 53); alt_up_char_buffer_string(char_buffer, "EFF: XXX", 42, 55); }
int main(void) { alt_up_char_buffer_dev * char_buf_dev; char_buf_dev = alt_up_char_buffer_open_dev("/dev/char_buffer"); // open the Char Buffer port if (char_buf_dev == NULL) alt_printf("Error: could not open char buffer device \n"); else alt_printf("Opened char buffer device \n"); alt_up_char_buffer_clear(char_buf_dev); alt_up_char_buffer_string(char_buf_dev, "ECE4440 Team MSB", 5, 5); alt_up_char_buffer_string(char_buf_dev, "Video Demo", 5, 10); alt_up_char_buffer_string(char_buf_dev, "Blue", 15, 20); alt_up_char_buffer_string(char_buf_dev, "Red", 40, 20); alt_up_char_buffer_string(char_buf_dev, "Green", 40, 40); alt_up_char_buffer_string(char_buf_dev, "Purple", 15, 40); alt_up_pixel_buffer_dma_dev * pixel_buf_dev; // open the Pixel Buffer port pixel_buf_dev = alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer"); if (pixel_buf_dev == NULL) alt_printf("Error: could not open pixel buffer device \n"); else alt_printf("Opened pixel buffer device \n"); //Clear and draw a blue box on the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buf_dev, 0); alt_up_pixel_buffer_dma_swap_buffers(pixel_buf_dev); alt_up_pixel_buffer_dma_draw_box(pixel_buf_dev, 0, 0, 200, 200, 0x3FF, 0); //blue box alt_up_pixel_buffer_dma_draw_box(pixel_buf_dev, 200, 200, 400, 400, 0xFFC00, 1); //green box alt_up_pixel_buffer_dma_draw_box(pixel_buf_dev, 200, 0, 400, 200, 0x3FF00000, 0); //red box alt_up_pixel_buffer_dma_draw_box(pixel_buf_dev, 0, 200, 200, 400, 0x3FF003FF, 1); //light blue box int image[60][60] = {{255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,0,0,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,0,255,255,255,255,255,0,0,255,255,255,255,0,255,255,255,255,0,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,0,255,0,255,255,255,255,0,255,255,255,0,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,0,255,255,0,255,255,255,255,0,0,255,0,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,0,0,0,255,255,255,255,255,255,255,0,255,255,255,255,0,0,255,255,0,0,255,255,255,255,0,0,0,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,0,255,255,255,255,0,255,255,255,255,0,255,255,255,255,255,0,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,0,255,255,255,255,0,0,0,0,0,0,0,255,255,255,255,0,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,0,0,255,255,255,255,0,0,0,255,255,0,255,255,255,255,255,0,255,255,255,255,0,255,255,255,255,255,0,255,255,255,255,0,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,0,255,255,255,255,0,255,255,255,255,255,255,0,255,255,255,0,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,0,255,255,255,255,0,255,255,255,255,255,255,0,255,255,255,0,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,0,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,0,0,255,255,255,255,255,0,255,255,255,255,0,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,0,0,0,0,0,0,0,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,204,0,204,204,204,204,255,204,204,204,204,255,204,204,204,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,0,255,255,255,255,255,255,0,255,255,204,255,204,255,255,255,255,255,255,204,204,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,204,255,255,255,255,255,255,204,255,255,0,255,204,255,255,255,255,255,255,204,204,204,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,255,255,255,0,0,0,0,255,255,255,255,255,255,255,204,204,0,204,204,255,255,0,204,204,204,255,204,255,255,255,255,255,204,255,255,204,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,255,255,255,255,255,255,255,255,255,255,204,255,255,255,255,255,255,204,255,255,255,255,0,255,204,204,255,255,204,255,255,204,204,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,0,255,255,255,255,204,255,255,204,255,255,204,204,0,204,0,255,255}, {255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,204,255,255,255,255,255,255,204,255,255,255,255,204,204,204,0,255,0,204,255,255,255,204,255,255}, {255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,204,255,255,255,255,204,255,255}, {255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,255,255,255,255,0,255,255,255,255,255,255,255,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}}; int i, j; for (i = 0; i < 60; i++){ for (j = 0; j < 60; j++){ if (image[i][j] < 255) alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x0, 100+i, 100+j); else alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0xFFFFFFFF, 100+i, 100+j); } } /*alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 100, 100); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 101, 101); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 102, 102); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 103, 103); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 104, 102); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 105, 101); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 106, 100); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 105, 100); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 104, 100); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 103, 100); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 102, 100); alt_up_pixel_buffer_dma_draw(pixel_buf_dev, 0x3FF003FF, 101, 100);*/ return 0; }
int main(){ printf("NEW GAME!\n\n"); volatile int old_game_state = 0; int doge = 0; //animation counter //buffer init stuff pixel_buffer = alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma"); char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); //phil's stuff master* m = master_init(); printf("NEW GAME!\n\n"); // 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); printf("NEW GAME!\n\n"); // Clear the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_char_buffer_clear(char_buffer); //Write some text alt_up_char_buffer_string(char_buffer, "LOADING...", 0, 0); //load bitmap files title = read_bmp("title.bmp"); alt_up_char_buffer_string(char_buffer, "title.bmp", 0, 2); menu = read_bmp("menu.bmp"); alt_up_char_buffer_string(char_buffer, "MENU.BMP", 0, 3); selA = read_bmp("selA.bmp"); alt_up_char_buffer_string(char_buffer, "selA.bmp", 0, 4); selB = read_bmp("selB.bmp"); alt_up_char_buffer_string(char_buffer, "selB.bmp", 0, 5); selC = read_bmp("selC.bmp"); alt_up_char_buffer_string(char_buffer, "selC.bmp", 0, 6); dead = read_bmp("dead.bmp"); alt_up_char_buffer_string(char_buffer, "dead.bmp", 0, 7); bmp * b = read_bmp("para1.bmp"); alt_up_char_buffer_string(char_buffer, "para.bmp", 0, 8); bmp * doge0 = read_bmp("doge0.bmp"); alt_up_char_buffer_string(char_buffer, "doge0.bmp", 0, 9); bmp * doge1 = read_bmp("doge1.bmp"); alt_up_char_buffer_string(char_buffer, "doge1.bmp", 0, 10); bmp * doge2 = read_bmp("doge2.bmp"); alt_up_char_buffer_string(char_buffer, "doge2.bmp", 0, 11); bmp * doge3 = read_bmp("doge3.bmp"); alt_up_char_buffer_string(char_buffer, "doge3.bmp", 0, 12); bmp * flat = read_bmp("flat.bmp"); alt_up_char_buffer_string(char_buffer, "flat.bmp", 0, 13); bmp * coin = read_bmp("coin.bmp"); alt_up_char_buffer_string(char_buffer, "coin.bmp", 0, 14); bmp * spike = read_bmp("spike.bmp"); alt_up_char_buffer_string(char_buffer, "spike.bmp", 0, 15); bmp * box1 = read_bmp("box1.bmp"); alt_up_char_buffer_string(char_buffer, "box1.bmp", 0, 16); bmp * box3 = read_bmp("box3.bmp"); alt_up_char_buffer_string(char_buffer, "box3.bmp", 0, 17); bmp * low = read_bmp("low.bmp"); alt_up_char_buffer_string(char_buffer, "low.bmp", 0, 18); bmp * flatb = read_bmp("flatb.bmp"); alt_up_char_buffer_string(char_buffer, "flatb.bmp", 0, 19); bmp * flatr = read_bmp("flatr.bmp"); alt_up_char_buffer_string(char_buffer, "flatr.bmp", 0, 20); bmp * blue = read_bmp("bstar.bmp"); alt_up_char_buffer_string(char_buffer, "blue.bmp", 0, 21); bmp * red = read_bmp("rstar.bmp"); alt_up_char_buffer_string(char_buffer, "red.bmp", 0, 22); bmp * flag_img = read_bmp("flag.bmp"); alt_up_char_buffer_string(char_buffer, "flag.bmp", 0, 23); name = read_bmp("name.bmp"); alt_up_char_buffer_string(char_buffer, "name.bmp", 0, 24); instr = read_bmp("instr.bmp"); alt_up_char_buffer_string(char_buffer, "instr.bmp", 0, 25); dcol = read_bmp("dcol.bmp"); alt_up_char_buffer_string(char_buffer, "dcol.bmp", 0, 26); win = read_bmp("win.bmp"); alt_up_char_buffer_string(char_buffer, "win.bmp", 0,27); alt_up_char_buffer_clear(char_buffer); printf("NEW GAME!\n\n"); //interrupt init stuff (for object writing) //TIMERPERIOD int timer_period = 1 * 500000; IOWR_16DIRECT(TIMER_0_BASE, 8, timer_period & 0xFFFF); //writes the period to the hardware timer IOWR_16DIRECT(TIMER_0_BASE, 12, timer_period >> 16); IOWR_16DIRECT(TIMER_0_BASE, 4, 1 << 3); //stop timer alt_irq_register(TIMER_0_IRQ,NULL,(void*)handle_timer_interrupts);//registers function to a specific IRQ //IOWR_16DIRECT(TIMER_0_BASE, 4, 0x5); //start timer //SET UP KEYBOARD INTERRUPT// ps2 = alt_up_ps2_open_dev(KEYBOARD_NAME); alt_up_ps2_init(ps2); alt_up_ps2_clear_fifo(ps2); //void* keyboard_control_register_ptr = (void*) (PS2_0_BASE + 4); alt_irq_register(PS2_0_IRQ, m, keyboard_ISR); alt_up_ps2_enable_read_interrupt(ps2); char sw = 0; char p_sw = 0; ///////////////////////////////////////////////////////////////////////// printf("NEW GAME!\n\n"); //SUPERDUPERLOOP while (1){ printf("old state:%i\nnew state: %i\n\n",old_game_state, game_state); draw_menu(game_state); //update screen while (old_game_state == game_state); printf("old state:%i\nnew state: %i\n\n",old_game_state, game_state); //only when entering a new menu alt_up_char_buffer_clear(char_buffer); //ENTER GAME LOOP if (game_state == 5){ printf("START GAME! LEVEL: %i\n\n", highlighted_level); alt_up_char_buffer_string(char_buffer, playername, 10, 4); if (highlighted_level == 1) { free_bmp(b); b = read_bmp("para1.bmp"); game_start(m,b,"lvl/1.txt","song1.wav"); } else if (highlighted_level == 2) { free_bmp(b); b = read_bmp("bg2.bmp"); game_start(m,b,"lvl/2.txt","a/abcd.wav"); } else{ free_bmp(b); b = read_bmp("bg3.bmp"); game_start(m,b,"lvl/2.txt","a/nyan1.wav"); } //collision loop while(!m->c->collide && !m->c->win){ alt_up_char_buffer_string(char_buffer, "POINTS: ", 50, 4); char str[15]; sprintf(str, "%d", m->c->points); alt_up_char_buffer_string(char_buffer, str, 58, 4); sw = IORD_8DIRECT(SWITCHES_BASE,0); IOWR_8DIRECT(LEDS_BASE,0,sw); if(sw == 1 && p_sw == 0){ //m->ab->sfx_flag = 1; m->c->jump_pressed = 1; } p_sw = sw; //boxes int i; for( i= 0 ; i < OBJECT_SIZE ; i++) { if(m->o->color[i] == -1) draw_object(pixel_buffer, box, flat, i); else if(m->o->color[i] == 0) draw_object(pixel_buffer, box, flatb, i); else if(m->o->color[i] == 1) draw_object(pixel_buffer, box, flatr, i); draw_object(pixel_buffer, co, coin, i ); draw_object(pixel_buffer, spikes, spike, i); draw_object(pixel_buffer, box_3, box3, i); draw_object(pixel_buffer, box_1, box1, i); // if(m->color_gates->color[i] == 1) // draw_object(pixel_buffer,cgates, rgate,i); // else if (m->color_gates->color[i] == 0) // draw_object(pixel_buffer,cgates, bgate,i); } //draws the win flag draw_object(pixel_buffer, flag, flag_img, 0); //Draw Doge if (m->c->ducking) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,low); else{ doge++; if(doge == 37) doge = 0; if( doge <9) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge0); else if (doge <18) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge1); else if (doge <27) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge2); else draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge3); } //Draw Color Indicator if(m->c->color == 0) draw_bmp(pixel_buffer, m->c->x- m->c->width + 5, m->c->y - m->c->height - 10, blue); else draw_bmp(pixel_buffer,m->c->x- m->c->width + 5, m->c->y - m->c->height - 10, red); p_counter++; if(p_counter == 3){ p_shift++; alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer unrolled_parallax_draw(pixel_buffer, b); }else if(p_counter == 4){ //if(p_counter == 1){ alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer unrolled_parallax_draw(pixel_buffer, b); p_counter = 0; }else{ // alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); // while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) // refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer // unrolled_parallax_draw(pixel_buffer, b); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer int j; for( j = 0 ; j < OBJECT_SIZE ; j++) { clear_object(pixel_buffer, box, b, j); clear_object(pixel_buffer, co, b, j); clear_object(pixel_buffer, spikes, b, j); clear_object(pixel_buffer, box_3, b, j); clear_object(pixel_buffer, box_1, b, j); } clear_object(pixel_buffer,flag,b,0); //clear doge clear_doge(pixel_buffer, m->c->x - m->c->width, m->c->y - m->c->height , b); //clear_loc(pixel_buffer,m->c->x- m->c->width + 5, m->c->y - m->c->height - 10,m->c->x- m->c->width + 5 - 10, m->c->y - m->c->height - 20,b); } } alt_up_char_buffer_string(char_buffer, "POINTS: ", 50, 4); char str[15]; sprintf(str, "%d", m->c->points); alt_up_char_buffer_string(char_buffer, str, 58, 4); printf("game exited\n"); if(m->c->win) game_state = 7; else game_state = 6; highlighted_item = 3; game_reset(m); } //exit game mode, restart superduperloop in main menu old_game_state = game_state; } return 0; }
int main() { //SD device initialization up_dev.device_reference = NULL; while(!loadSDCard(up_dev.device_reference)) { printf("SD card is not connected.\n"); } initVGA(); initAudioDeviceController(); initSoundMixer(); struct CmdScheduler* scheduler = initCmdScheduler(); //Serial device initialization com = initRS232(scheduler); initPushKeyController(); initDatabase(); initMemory(); //sync database update(); //Test VGA Output /*struct Image* testImg; while((testImg = loadSDImage("TEST.BMP")) == NULL); draw(35, 35, testImg); killImage(testImg);*/ //alt_up_char_buffer_string(char_buffer, "Initialization Completed", 27, 5); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_char_buffer_clear(char_buffer); //graphicTester(); struct Frame* mainFrame = initMainFrame(); mainFrame->drawFrame(mainFrame); //Test End mouse = initCursor(10, 100, mainFrame); //graphicTester(); //drawAllSongsInList(2); //drawAllSongsInList(2); /*int i; struct Frame* b; for (i = 0; i < 5000; i++){ drawAllSongsInList(2); //b = initSongInListPanel(mainFrame, 2); //killSongInListPanel(&b); printf("Iteration %d\n", i); }*/ initAudioBuffer(); initAnimate(mouse); int i = 2; syncPlay(1, 100, 0); while(1) { cmdProcessing(scheduler); i = soundTester(i); } return 0; }
int update_eq_sinc(int amplitude, int green) // FUNCTION: Updates the equaliser for pretty graphics and swaps the pixel buffer // REQUIRES: Initialised pixel buffer // RETURNS: New green value { // Declare variables int i, j, red, blue, height, y_value, original_top, x_axis, x_value; float period = ((rand() % 200) + 600.0) / 100.0; // Randomly generate period between 6.0 and 8.0 uint16_t colour; int random_amplitude; float random_period; if(/* alt_timestamp()/(float) alt_timestamp_freq() > EQ_TIME_CONSTANT_S && */ m == eq) { v.blank_flag = FALSE; rb.background_flag = FALSE; alt_up_char_buffer_clear(v.char_buffer); random_amplitude = (rand() % 50) + 50; random_period = ((rand() % 200) + 600.0) / 100.0; printf("Random amplitude: %d\n", random_amplitude); if(rand() % 1 == 0) { if(green < 251) green += 5; } else if(green > 5) green -= 5; alt_up_pixel_buffer_dma_clear_screen(v.pixel_buffer, 1); // Clear back buffer x_axis = 190; original_top = x_axis - x_axis*amplitude/MAX_AMPLITUDE; for(x_value=0; x_value < 160; x_value++) // Draw two-sided sinc function, almost to each side of the screen { red = 255*(160-x_value)/160; // red will increase towards the middle of the screen // Calculate value of the sinc function for x-coordinate x_value if(x_value>0) height = (x_axis*amplitude/MAX_AMPLITUDE)*sin(x_value/period) /(x_value/period); else height = x_axis*amplitude/MAX_AMPLITUDE; y_value = x_axis - height; if(height>0) // This means the sinc function is above the x-axis { for(j=y_value; j<=x_axis; j++) // j is the y-coordinate { blue = 255*(j - original_top)/(x_axis*amplitude/MAX_AMPLITUDE); // blue will increase towards the x_axis of the screen colour = drawRGB24toRGB565(red, green, blue); i=160-x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); i=160+x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); } } else // This means the sinc function is on or below the x-axis { for(j=y_value; j>=x_axis; j--) // j is the y-coordinate { blue = 255*(2*x_axis-j - original_top)/(x_axis*amplitude/MAX_AMPLITUDE); // blue will increase towards the x_axis of the screen colour = drawRGB24toRGB565(red, green, blue); i=160-x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); i=160+x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); } } } // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); // alt_timestamp_start(); } return green; }
void draw_sheetmusic() { // Symbolic constants int x_indent = 16; int y_indent = 100; int space_height = (240 - 2*y_indent)/4; // Declare variables int i; if(m == blank) { rb.background_flag = FALSE; if(v.blank_flag == FALSE) { alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 0, 0, 319, 239, 0xFFFF, 1); // White box to fill the back buffer for(i=0; i<5; i++) // Draw 5 horizontal lines of the musical staff to the back buffer alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, x_indent-2, 320-(x_indent-2), y_indent+space_height*i, 0x0000, 1); // Double bar line at the start alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, x_indent-4, y_indent, x_indent-2, 240-y_indent, 0x0000, 1); alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, x_indent, y_indent, 240-y_indent, 0x0000, 1); // Double bar line at the end alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 320-(x_indent-4), y_indent, 320-(x_indent-2), 240-y_indent, 0x0000, 1); alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, 320-x_indent, y_indent, 240-y_indent, 0x0000, 1); // Three bar lines to divide the staff into four measures alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, (160+x_indent)/2, y_indent, 240-y_indent, 0x0000, 1); alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, 160, y_indent, 240-y_indent, 0x0000, 1); alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, (480-x_indent)/2, y_indent, 240-y_indent, 0x0000, 1); // Draw some notes: C major scale draw_qnote_on_sheetmusic(v.pixel_buffer, 0, 0); draw_qnote_on_sheetmusic(v.pixel_buffer, 1, 1); draw_qnote_on_sheetmusic(v.pixel_buffer, 2, 2); draw_qnote_on_sheetmusic(v.pixel_buffer, 3, 3); draw_qnote_on_sheetmusic(v.pixel_buffer, 4, 4); draw_qnote_on_sheetmusic(v.pixel_buffer, 5, 5); draw_qnote_on_sheetmusic(v.pixel_buffer, 6, 6); draw_qnote_on_sheetmusic(v.pixel_buffer, 7, 7); draw_qnote_on_sheetmusic(v.pixel_buffer, 7, 8); draw_qnote_on_sheetmusic(v.pixel_buffer, 6, 9); draw_qnote_on_sheetmusic(v.pixel_buffer, 5, 10); draw_qnote_on_sheetmusic(v.pixel_buffer, 4, 11); draw_qnote_on_sheetmusic(v.pixel_buffer, 3, 12); draw_qnote_on_sheetmusic(v.pixel_buffer, 2, 13); draw_qnote_on_sheetmusic(v.pixel_buffer, 1, 14); draw_qnote_on_sheetmusic(v.pixel_buffer, 0, 15); // Blue box and message near top of the screen alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 100, 26, 220, 40, 0x122B, 1); alt_up_char_buffer_clear(v.char_buffer); alt_up_char_buffer_string(v.char_buffer, "Waiting for user input...", 28, 8); v.blank_flag = TRUE; // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); } } }
void Char_clearScreen(CharBuffer* char_buffer) { alt_up_char_buffer_clear(char_buffer->char_buffer); }
/* * Helper method that will print the string on the display */ void displayString(char* string, int x, int y) { alt_up_char_buffer_clear(char_buffer); alt_up_char_buffer_string(char_buffer, string, x, y); }
void update_rb(int note_pressed) // FUNCTION: Updates the RB_data struct and displays the new data on the moniter. // REQUIRES: if no note has been pressed, note_pressed < 0 // if a note has been pressed, 0 <= note_pressed <= 11 // RETURNS: None { // Declare variables int i, j, difference; char* all_notes[12] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; if(m == notegame) // Check if in rockband mode { v.blank_flag = FALSE; if(rb.background_flag == FALSE) { // Clear char buffer alt_up_char_buffer_clear(v.char_buffer); for(j=0; j<12; j++) alt_up_char_buffer_string(v.char_buffer, all_notes[j], 10 + 5*j, 55 - rb.CORRECT_ZONE_HEIGHT/2); // Print the pitch at its corresponding location rb.background_flag = TRUE; } /* // Draw blue background and correct zone to back buffer bluebackground(v.pixel_buffer); alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, 0, 319, 220-4*rb.CORRECT_ZONE_HEIGHT, 0x0000, 1); // Top of the correct zone alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 0, 221-4*rb.CORRECT_ZONE_HEIGHT, 319, 219, 0xCCCC, 1); alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, 0, 319, 220, 0x0000, 1); // Bottom of the correct zone // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); */ // Draw blue background and correct zone to back buffer bluebackground(v.pixel_buffer); draw_correct_zone(v.pixel_buffer, rb.CORRECT_ZONE_HEIGHT); // Clear char buffer alt_up_char_buffer_clear(v.char_buffer); for(j=0; j<12; j++) alt_up_char_buffer_string(v.char_buffer, all_notes[j], 10 + 5*j, 55 - rb.CORRECT_ZONE_HEIGHT/2); // Print the pitch at its corresponding location // Clear char buffer // alt_up_char_buffer_clear(v.char_buffer); for(j=0; j<12; j++) rb.in_correct_zone[j] = FALSE; // Reset all entries at each update //rb.time = alt_timestamp() / (float) alt_timestamp_freq(); // Time represents the amount of time passed since the game started, in seconds rb.count = rb.time / rb.RB_TIME_CONSTANT_S; // Count represents the number of time constants that have passed since the game started rb.count_difference = rb.count - rb.old_count; // Count_difference represents the number of time constants that have passed since the last time update_rb was called rb.old_count = rb.count; // Old_count represents the number of time constants passed from the start of the game to the last time update_rb was called rb.index = rb.count / 10; // Index represents the number of notes that are active // printf("Index:%d\n", rb.index); if(rb.index > rb.n + 6) { rb.finished = TRUE; m = displayscore; } rb.bottom_index = -1; // Initialise. This will be changed at some point in the for loop below, or after the for loop for(i=0; i<rb.index; i++) { difference = rb.index - i; rb.y_locations[i] = /* 4 + */ difference*10 + rb.count%10; // Check if there exists a note to be displayed and it is within range to be displayed on the screen if(rb.notes[i] != -1 && rb.y_locations[i] < 66) { // alt_up_char_buffer_string(v.char_buffer, rb.notes_char[i], rb.x_locations[i], rb.y_locations[i]); // Print the pitch at its corresponding location // eraser_rb(v.pixel_buffer, rb.y_locations[i] - rb.count_difference - 1, rb.x_locations[i], rb.CORRECT_ZONE_HEIGHT); // Erase the old note draw_rb_note_at(v.pixel_buffer, rb.y_locations[i], rb.x_locations[i]); // Draw new note if(rb.y_locations[i] >= 56 - rb.CORRECT_ZONE_HEIGHT && rb.y_locations[i] <= 55) // Check if the location is within the correct range { rb.in_correct_zone[rb.notes[i]] = TRUE; // Record that the pitch of note i is in the correct zone rb.bottom_index = i; // Since note i is in the correct zone { if(note_pressed == rb.notes[i]) // Check if the note in the correct zone matches the most recent piano key press { if(rb.already_counted[i] == FALSE) { rb.score++; rb.already_counted[i] = TRUE; } draw_rb_correct_note_at(v.pixel_buffer, rb.y_locations[i], rb.x_locations[i]); } } } } } if(rb.bottom_index == -1) // This means there was no note within the correct zone { while(rb.y_locations[i] < 56 - rb.CORRECT_ZONE_HEIGHT) i--; rb.bottom_index = i+1; // Set bottom_index to the index of the note closest to, and on top of, the correct zone } if(note_pressed >= 0) // Check if there has been a note pressed { if(rb.in_correct_zone[note_pressed] == TRUE) // Check if the note pressed is in the correct zone { draw_rb_correct_note_at(v.pixel_buffer, rb.y_locations[rb.bottom_index], rb.x_locations[rb.bottom_index]); rb.score++; } else { draw_rb_incorrect_note_at(v.pixel_buffer, rb.y_locations[rb.bottom_index], rb.x_locations[rb.bottom_index]); rb.score--; } } // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); // Draw blue background and correct zone to back buffer /* bluebackground(v.pixel_buffer); alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, 0, 319, 220-4*rb.CORRECT_ZONE_HEIGHT, 0x0000, 1); // Top of the correct zone alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 0, 221-4*rb.CORRECT_ZONE_HEIGHT, 319, 219, 0xCCCC, 1); alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, 0, 319, 220, 0x0000, 1); // Bottom of the correct zone */ // for(;;); } }
/* * 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; }
/* Clear Character buffer */ void clearCharBuff(void) { alt_up_char_buffer_clear(char_buffer); }
int main() { // INIT COMS cd = (Comm_data*) malloc(sizeof(Comm_data)); uart = init_clear_uart(cd); alt_timestamp_start(); srand(alt_timestamp()); CardCtrl *cardCtrl = (CardCtrl*)malloc(sizeof(CardCtrl)); PlayerCtrl* playerCtrl = (PlayerCtrl*)malloc(sizeof(PlayerCtrl)); initCards(cardCtrl); printf("Waiting for players\n"); while(connected_count < 3) { receivedFromAndroid(); } printf("Got all players\n"); initPlayers(playerCtrl, connected_count); int y; for (y = 0; y < connected_count; y++) { if (pid_connected[y] == 1) { tell_user_pid_role(y, playerCtrl->players[y]); Message message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); } } int i, j; for (i = 0; i < connected_count; i++) { drawCardsForId(i, cardCtrl, 2, playerCtrl); } field = malloc(sizeof(Field)); alt_up_char_buffer_dev *charBuffer = initCharBuffer(); alt_up_pixel_buffer_dma_dev *pixelBuffer = initPixelBuffer(); initField(field, playerCtrl, cardCtrl, charBuffer); *leds = *switches; alt_timestamp_start(); srand(alt_timestamp()); Message message; tell_user_all_opponent_range_role(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_all_opponent_blue_lives(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_their_turn(0); while (1){ int listening = 1; while (listening) { Message message = receivedFromAndroid(); switch (message.type) { case DRAW_CARDS: drawCardsForId(message.fromId, cardCtrl, message.count, playerCtrl); tell_user_ok(message.fromId); break; case UPDATE_HAND: updateHandForId(playerCtrl, message.fromId, message.count, message.cards); break; case UPDATE_BLUE: updateBlueCardsForId(playerCtrl, message.fromId, message.count, message.cards); tell_user_ok(message.fromId); break; case UPDATE_LIVES: updateLivesForId(playerCtrl, message.fromId, message.count); break; case GATLING: startGatling(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case ALIENS: startAliens(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case BEER: { //TODO //updateLivesForId(playerCtrl, message.fromId, message.count); Message message = receivedFromAndroid(); if (message.type == UPDATE_LIVES) updateLivesForId(playerCtrl, message.fromId, message.count); updateHand(message.fromId, playerCtrl); break; } case GENERAL_STORE: startStore(playerCtrl, message.fromId, cardCtrl); break; case SALOON: startSaloon(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case ZAP: { startZap(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; } case PANIC: startPanic(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case CAT_BALOU: startCatBalou(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case DUEL: startDuel(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case JAIL: //TODO tell_user_jail(message.toId, message.cards); break; case END_TURN: listening = 0; break; default: break; } alt_up_char_buffer_clear(charBuffer); runField(field, isGameEnd, winningPlayer); } endTurn(playerCtrl); tell_user_all_opponent_range_role(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_all_opponent_blue_lives(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); int y; for (y = 0; y < MAX_CARDS; y++ ) { if (playerCtrl->players[playerCtrl->turn].blueCards[y] >= 72 && playerCtrl->players[playerCtrl->turn].blueCards[y] <= 74) { drawCardsForId(playerCtrl->turn, cardCtrl, 1, playerCtrl); break; } } tell_user_their_turn(playerCtrl->turn); alt_up_char_buffer_clear(charBuffer); runField(field, isGameEnd, winningPlayer); } return 0; }
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; }