static void update_grid_normal(Grid* grid) { int i, j, x, y; // rotation j = button_down(BUTTON_A) - button_down(BUTTON_B); if(j) { i = grid->rot; grid->rot = (j > 0) ? grid->rot * 2 % 15 : (grid->rot / 2 | grid->rot * 8) & 15; if(collision(grid, 0)) grid->rot = i; } // horizontal movement i = grid->x; grid->x += button_down(BUTTON_RIGHT) - button_down(BUTTON_LEFT); if(i != grid->x && collision(grid, 0)) grid->x = i; // vertical movement grid->tick++; if(button_down(BUTTON_DOWN) || grid->tick >= grid->ticks_per_drop) { grid->tick = 0; grid->y++; if(collision(grid, 0)) { grid->y--; // check for game over if(collision(grid, 1)) { grid->state = STATE_GAMEOVER; return; } // copy stone to grid for(y = 0; y < 4; y++) for(x = 0; x < 4; x++) if(STONES[grid->stone][x * 4 + y] & grid->rot) grid->matrix[y + grid->y][x + grid->x] = grid->stone + 1; // get a new stone new_stone(grid); // check for complete lines int lines = 0; for(y = 0; y < GRID_HEIGHT; y++) { for(x = 0; x < GRID_WIDTH; x++) if(!grid->matrix[y][x]) break; lines += (x == GRID_WIDTH); grid->highlight[y] = (x == GRID_WIDTH); } grid->state = lines ? STATE_CLEARLINES : STATE_WAIT; grid->state_delay = 0; } } }
internal void player_step(Entity *P) { i32 dx = 0; Collision C; world_test_move(&GAME->world, P->collider, 0, 1, CollisionTestMask_TileMap, &C, collision_stop); P->flags = C.B ? (P->flags | EntityFlag_Grounded) : (P->flags & ~EntityFlag_Grounded); if (button_down(Button_Right)) dx = 1; if (button_down(Button_Left)) dx = -1; if (P->flags & EntityFlag_Grounded) { // printf("Grounded"); P->vy = 0; if (button_ended_down(Button_X)) { P->vy = -3; } } else { P->vy += 0.4; } // printf("vy %f\n", P->vy); i32 fx = 0; if (signof(P->vx) != dx) { if (dx == 0) { player_set_state(P, EntityState_Brake); } else { entity_flip(P, (dx < 0)); player_set_state(P, EntityState_Walk); P->dx = dx; } } fx = dx * 2; if (fx > P->vx) { P->vx++; } else if (fx < P->vx) { P->vx--; } if (dx == 0 && P->vx == 0 && P->state == EntityState_Brake) { player_set_state(P, EntityState_Idle); } }
static void get_grid_input(Grid* grid, int* mov, int* rot, int* drop) { if(is_occupied(grid->nr)) { *mov = button_down(grid->nr, BUTTON_RIGHT) - button_down(grid->nr, BUTTON_LEFT); *rot = button_down(grid->nr, BUTTON_A) - button_down(grid->nr, BUTTON_B); *drop = button_down(grid->nr, BUTTON_DOWN); } else { grid_bot(grid, mov, rot, drop); } if(*mov != grid->input_mov) grid->input_rep = 0; grid->input_mov = *mov; if(grid->input_rep <= 0) grid->input_rep = 6; else { grid->input_rep--; *mov = 0; } if(*rot != grid->input_rot) grid->input_rot = *rot; else *rot = 0; }
// Render button. How it draws exactly depends on it's current state. void UI_BUTTON::draw() { int offset, frame_num = -1; if (uses_bmaps) { gr_reset_clip(); // if button is down, draw it that way if (button_down()) { if (bmap_ids[B_PRESSED] >= 0){ frame_num = B_PRESSED; } // otherwise if button is disabled, draw it that way } else if (disabled_flag) { if (bmap_ids[B_DISABLED] >= 0){ frame_num = B_DISABLED; } // otherwise, if button is highlighted (mouse is over it, but mouse buttons not down) draw it that way } else if (m_flags & BF_HIGHLIGHTED) { if (bmap_ids[B_HIGHLIGHT] >= 0){ frame_num = B_HIGHLIGHT; } // otherwise, just draw it normally } else { if (bmap_ids[B_NORMAL] >= 0){ frame_num = B_NORMAL; } } if (frame_num >= 0) { gr_set_bitmap(bmap_ids[frame_num]); gr_bitmap(x, y); } } else { gr_set_font(my_wnd->f_id); gr_set_clip( x, y, w, h ); // draw the button's box if (button_down()) { ui_draw_box_in( 0, 0, w-1, h-1 ); offset = 1; } else { ui_draw_box_out( 0, 0, w-1, h-1 ); offset = 0; } // now draw the button's text if (disabled_flag){ gr_set_color_fast(&CDARK_GRAY); } else if (my_wnd->selected_gadget == this){ gr_set_color_fast(&CBRIGHT_GREEN); } else { gr_set_color_fast(&CBLACK); } if (text){ ui_string_centered( Middle(w) + offset, Middle(h) + offset, text ); } gr_reset_clip(); } }
void callbox(byte my_floor) { byte rxmessage[PAYLOAD_SIZE]; // Received data payload static byte floor, direction; word distance; static byte flag_dist_init = 0; CANframe txframe; // Transmitted CAN frame floor = 0xFF; // Start at false floor direction = DIRECTION_STATIONARY; // Assume starting car direction is stationary if (!flag_dist_init){ dist_init(); flag_dist_init = 1; } if(SW1 && !sw1_pressed) { sw1_pressed = 1; button_up(my_floor); } if(SW2 && !sw2_pressed) { sw2_pressed = 1; button_down(my_floor); } if(!SW1) sw1_pressed = 0; if(!SW2) sw2_pressed = 0; runSerialCAN(MSCAN_NODE_ID); if(data_available()) { CANget(rxmessage); switch(rxmessage[0]) { case CMD_LOCATION: floor = rxmessage[1]; direction = rxmessage[2]; #ifdef USE_LCD LCDclear(); LCDprintf("Floor: %d\nDir: %d", floor, direction); #endif #ifdef USE_LED7 led7_write(led7_table[floor]); #endif break; case CMD_BUTTON_CALL: rxmessage[1] == DIRECTION_UP ? button_up(my_floor) : button_down(my_floor); break; case CMD_ERROR: #ifdef USE_LCD LCDclear(); LCDprintf("Error condition\nreceived!"); #endif break; default: #ifdef USE_LCD LCDclear(); LCDputs("Unknown command"); #endif break; } // Turn off indicator LED once car has reached local floor if(floor == my_floor) { LED1 = 0; LED2 = 0; } } // Sonar sensor currently attached to callbox 1 // Send off distance message to controller node if (my_floor == FLOOR1) { distance = dist_read(); txframe.id = MSCAN_CTL_ID; txframe.priority = 0x01; txframe.length = 3; txframe.payload[0] = CMD_DISTANCE; txframe.payload[1] = (distance & 0xFF00) >> 8; txframe.payload[2] = (distance & 0x00FF); CANsend(&txframe); }