Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <minix/drivers.h>
- #include "Arkanoid.h"
- #include "Graphics.h"
- #include "Keyboard.h"
- #include "Mouse.h"
- const int FPS = 25;
- const int mouseFPSmult = 3;
- void checkIfStateIsDone(Arkanoid* game);
- void deleteCurrentState(Arkanoid* game);
- Arkanoid* startArkanoid(){
- Arkanoid* arkanoid = (Arkanoid*) malloc(sizeof(Arkanoid));
- //subscribing devices
- arkanoid->IRQ_SET_KB = kbd_subscribe_int();
- arkanoid->IRQ_SET_TIMER = timer_subscribe_int();
- arkanoid->IRQ_SET_MOUSE = mouse_subscribe_int();
- //reseting time freq
- timer_set_square(0, mouseFPSmult*FPS);
- //other variables
- arkanoid->tempRecX = 10;
- arkanoid->scancode = 0;
- arkanoid->currentState = MAIN_MENU_STATE;
- arkanoid->state = newMainMenuState();
- //finishing initialization
- arkanoid->done = 0, arkanoid->draw = 1;
- arkanoid->timer = newTimer();
- return arkanoid;
- }
- void updateArkanoid(Arkanoid* arkanoid){
- int ipc_status, r = 0;
- message msg;
- r = driver_receive(ANY,&msg,&ipc_status);
- if(r != 0) //In case something wrong happened with driver communication report error msg
- return;
- if(is_ipc_notify(ipc_status))
- {
- switch (_ENDPOINT_P(msg.m_source))
- {
- case HARDWARE:
- if(msg.NOTIFY_ARG & arkanoid->IRQ_SET_KB) {
- arkanoid->scancode = kbc_read();
- /*
- switch (arkanoid->currentState) {
- case MAIN_MENU_STATE:
- updateMainMenuState(arkanoid->state, arkanoid->scancode);
- break;
- case GAME_STATE:
- updateGameState(arkanoid->state, arkanoid->scancode);
- break;
- default:
- break;
- }
- arkanoid->scancode = 0;
- //update at 25 FPS
- arkanoid->tempRecX++;
- arkanoid->draw = 1; */
- }
- if(msg.NOTIFY_ARG & arkanoid->IRQ_SET_TIMER)
- timerHandler(arkanoid->timer);
- if(msg.NOTIFY_ARG & arkanoid->IRQ_SET_MOUSE)
- updateMouse();
- break;
- default:
- break;
- }
- }
- if(arkanoid->scancode != 0){
- if (arkanoid->scancode == KEY_ESC)
- arkanoid->done = 1;
- }
- if(arkanoid->timer->ticked){
- getMouse()->draw = 1;
- //...
- if(arkanoid->timer->counter % mouseFPSmult == 0)
- { /*
- switch (arkanoid->currentState) {
- case MAIN_MENU_STATE:
- updateMainMenuState(arkanoid->state, arkanoid->scancode);
- break;
- case GAME_STATE:
- updateGameState(arkanoid->state, arkanoid->scancode);
- break;
- default:
- break;
- } */
- arkanoid->scancode = 0;
- //update at 25 FPS
- arkanoid->tempRecX++;
- arkanoid->draw = 1;
- }
- }
- //checkIfStateIsDone(arkanoid);
- }
- void drawArkanoid(Arkanoid* arkanoid){
- /*
- switch (arkanoid->currentState) {
- case MAIN_MENU_STATE:
- drawMainMenuState(arkanoid->state);
- break;
- case GAME_STATE:
- drawGameState(arkanoid->state);
- default:
- break;
- }*/
- fillDisplay(BLUE);
- }
- void stopArkanoid(Arkanoid* arkanoid){
- deleteCurrentState(arkanoid);
- mouse_unsubscribe_int();
- kbd_unsubscribe_int();
- timer_unsubscribe_int();
- deleteTimer(arkanoid->timer);
- deleteMouse();
- free(arkanoid);
- }
- void changeState(Arkanoid* game, State newState) {
- deleteCurrentState(game);
- game->currentState = newState;
- switch (game->currentState) {
- case MAIN_MENU_STATE:
- game->state = newMainMenuState();
- break;
- case GAME_STATE:
- game->state = newGameState();
- break;
- }
- game->draw = 1;
- }
- void checkIfStateIsDone(Arkanoid* game) {
- switch (game->currentState) {
- case MAIN_MENU_STATE:
- if (((MainMenuState*) (game->state))->done) {
- int action = ((MainMenuState*) (game->state))->action;
- switch (action) {
- case PLAY_CHOSEN:
- changeState(game, GAME_STATE);
- break;
- case EXIT_CHOSEN:
- game->done = 1;
- break;
- }
- }
- break;
- case GAME_STATE:
- if (((GameState*) (game->state))->done) {
- changeState(game, MAIN_MENU_STATE);
- }
- break;
- default:
- break;
- }
- }
- void deleteCurrentState(Arkanoid* game) {
- switch (game->currentState) {
- case MAIN_MENU_STATE:
- deleteMainMenuState(game->state);
- break;
- case GAME_STATE:
- deleteGameState(game->state);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement