Added kill screen

This commit is contained in:
id101010
2016-01-29 17:37:17 +01:00
parent 6aa75bbcc3
commit 8dd1e35475
3 changed files with 43 additions and 34 deletions

View File

@@ -2,12 +2,25 @@
#include <lcd_lld.h> #include <lcd_lld.h>
#include <color.h> #include <color.h>
#include <stdio.h> #include <stdio.h>
#include <font.h>
#include "game.h" #include "game.h"
#include "io.h" #include "io.h"
#include "draw.h" #include "draw.h"
#include "bitmap.h" //generated by gimp #include "bitmap.h" //generated by gimp
static const char* texts [] = {
"Config Instructions:",
"* Change the player colors using the switches S7-S0",
"* Use the poti to change the game speed",
"* Press T0 to start the game",
"",
"Game Instructions:",
"* Player 1 Keys: T3 and T2",
"* Player 2 Keys: T1 and T0",
"* Stay alive!",
NULL
};
void game_init(game_t* game, uint16_t ticks_per_sec) { void game_init(game_t* game, uint16_t ticks_per_sec) {
@@ -244,7 +257,6 @@ void game_get_color(uint16_t confbits, uint16_t* player1_color, uint16_t* player
} }
} }
bool game_step_init(game_t* game) { bool game_step_init(game_t* game) {
//Draw welcome bitmap //Draw welcome bitmap
@@ -261,21 +273,6 @@ bool game_step_init(game_t* game) {
return true; return true;
} }
static const char* texts [] = {
"Config Instructions:",
"* Change the player colors using the switches S7-S0",
"* Use the poti to change the game speed",
"* Press T0 to start the game",
"",
"Game Instructions:",
"* Player 1 Keys: T3 and T2",
"* Player 2 Keys: T1 and T0",
"* Stay alive!",
NULL
};
bool game_step_prestart(game_t* game) { bool game_step_prestart(game_t* game) {
//Draw "Player x: Color" Strings //Draw "Player x: Color" Strings
@@ -309,9 +306,8 @@ bool game_step_prestart(game_t* game) {
i++; i++;
} }
uint8_t switches_old = 0; uint8_t switches_old = 0;
uint16_t adc_old =0; uint16_t adc_old = 0;
uint16_t player1_color=0, player2_color=0,game_speed=0; uint16_t player1_color=0, player2_color=0,game_speed=0;
bool first = true; bool first = true;
@@ -486,6 +482,31 @@ bool game_step_running(game_t* game, uint64_t delta_time)
} }
bool game_step_ended(game_t* game) { bool game_step_ended(game_t* game) {
// Kill screen
LCD_DrawRect(TG_END_LEFT, // left top x
TG_END_TOP, // left top y
(TFT_WIDTH - TG_END_LEFT - TG_END_RIGHT - 1), // right bottom x
(TFT_HEIGHT - TG_END_TOP - TG_END_BOTTOM - 1), // right bottom y
GUI_COLOR_WHITE); // Color of the boundary
LCD_DrawRectF(TG_END_LEFT + 1, // left top x
TG_END_TOP + 1, // left top y
(TFT_WIDTH - TG_END_LEFT - TG_END_RIGHT - 3), // right bottom x
(TFT_HEIGHT - TG_END_TOP - TG_END_BOTTOM - 3), // right bottom y
GUI_COLOR_DARK_GREY); // Color of the boundary
LCD_SetTextColor(GUI_COLOR_BLACK);
LCD_SetBackColor(GUI_COLOR_DARK_GREY);
LCD_SetFont(&font_9x15B);
LCD_DisplayStringXY(TG_END_LEFT + TG_START_FONT_OFFSET_Y,
TG_END_TOP + TG_START_FONT_OFFSET_Y,
"Game over!");
LCD_DisplayStringXY(TG_END_LEFT + TG_START_FONT_OFFSET_Y,
TG_END_TOP + TG_START_FONT_OFFSET_Y + 20,
"Press S0 to restart.");
LCD_SetBackColor(GUI_COLOR_BLACK);
LCD_SetFont(&font_5x8);
while(!io_button_has_edge(BTN_START)); // Wait for the start button to be pressed again while(!io_button_has_edge(BTN_START)); // Wait for the start button to be pressed again
LCD_Clear(GUI_COLOR_BLACK); // Clear the background LCD_Clear(GUI_COLOR_BLACK); // Clear the background
game->state= prestart; // Set the state to prestart game->state= prestart; // Set the state to prestart

View File

@@ -27,6 +27,10 @@
#define TG_FIELD_LEFT 5 #define TG_FIELD_LEFT 5
#define TG_FIELD_RIGHT 5 #define TG_FIELD_RIGHT 5
#define TG_FIELD_START_OFFSET 10 #define TG_FIELD_START_OFFSET 10
#define TG_END_TOP 50
#define TG_END_BOTTOM 30
#define TG_END_LEFT 30
#define TG_END_RIGHT 30
#define TG_HEADER_TIME_X 5 #define TG_HEADER_TIME_X 5
#define TG_HEADER_TIME_Y 3 #define TG_HEADER_TIME_Y 3
#define TG_HEADER_PLAYER_X 100 #define TG_HEADER_PLAYER_X 100

View File

@@ -30,8 +30,6 @@ static volatile unsigned char* SWITCH = (volatile unsigned char*)0x6C000400;
#define SQR3_SQ_SET ((uint32_t)0x0000001F) #define SQR3_SQ_SET ((uint32_t)0x0000001F)
#define SMPR1_SMP_SET ((uint32_t)0x00000007) #define SMPR1_SMP_SET ((uint32_t)0x00000007)
void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr, bool input) { void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr, bool input) {
GPIO_InitTypeDef gi; // Create gpio init structure GPIO_InitTypeDef gi; // Create gpio init structure
GPIO_StructInit(&gi); // Fill gpio init structure with defaults GPIO_StructInit(&gi); // Fill gpio init structure with defaults
@@ -82,40 +80,28 @@ void io_init(void){
pin_create(&pin_t1, GPIOB, 15, true); // create pin_t1 pin_create(&pin_t1, GPIOB, 15, true); // create pin_t1
pin_create(&pin_t2, GPIOB, 14, true); // create pin_t2 pin_create(&pin_t2, GPIOB, 14, true); // create pin_t2
pin_create(&pin_t3, GPIOI, 0, true); // create pin_t3 pin_create(&pin_t3, GPIOI, 0, true); // create pin_t3
// ADC Init
//Enable the peripheral clock of GPIOB //Enable the peripheral clock of GPIOB
//This has been already done in the startup code
//Page 239/1718 of "RM0090 Reference Reference Manual (October 2014)"
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOB; RCC->AHB1ENR |= RCC_AHB1Periph_GPIOB;
//Choose the working mode of PB0 with the GPIO port mode register //Choose the working mode of PB0 with the GPIO port mode register
//Page 279/1718 of "RM0090 Reference Reference Manual (October 2014)"
GPIOB->MODER &= ~GPIO_MODER_MODER0; GPIOB->MODER &= ~GPIO_MODER_MODER0;
GPIOB->MODER |= GPIO_Mode_AN; GPIOB->MODER |= GPIO_Mode_AN;
//Configure the GPIO port pull-up/pull-down register for PB0 //Configure the GPIO port pull-up/pull-down register for PB0
//Page 282/1718 of "RM0090 Reference Reference Manual (October 2014)" //Page 282/1718 of "RM0090 Reference Reference Manual (October 2014)"
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR0; GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR0;
GPIOB->PUPDR |= GPIO_PuPd_UP; GPIOB->PUPDR |= GPIO_PuPd_UP;
//Initialize the ADC //Initialize the ADC
//Enable the peripheral clock of the ADC //Enable the peripheral clock of the ADC
//Page 245/1718 of "RM0090 Reference Reference Manual (October 2014)"
RCC->APB2ENR |= RCC_APB2Periph_ADC; RCC->APB2ENR |= RCC_APB2Periph_ADC;
//Configure ADC1: scan conversion mode and resolution //Configure ADC1: scan conversion mode and resolution
//Set SCAN bit according to ADC_ScanConvMode value //Set SCAN bit according to ADC_ScanConvMode value
//Set RES bit according to ADC_Resolution value //Set RES bit according to ADC_Resolution value
// Page 416/1718 of "RM0090 Reference Reference Manual (October 2014)"
ADC1->CR1 = ADC_Resolution_10b; ADC1->CR1 = ADC_Resolution_10b;
// Configure ADC1: regular channel sequence length // Configure ADC1: regular channel sequence length
// Set L bits according to ADC_NbrOfConversion value // Set L bits according to ADC_NbrOfConversion value
// Page 422/1718 of "RM0090 Reference Reference Manual (October 2014)"
ADC1->SQR1 = 0; ADC1->SQR1 = 0;
// Set the ADON bit to enable the ADC // Set the ADON bit to enable the ADC
// Page 418/1718 of "RM0090 Reference Reference Manual (October 2014)"
ADC1->CR2 = ADC_CR2_ADON; ADC1->CR2 = ADC_CR2_ADON;
} }
void io_process(void) { void io_process(void) {
@@ -159,8 +145,6 @@ uint16_t read_adc(){
return value; return value;
} }
uint8_t read_switches() { uint8_t read_switches() {
*LED=*SWITCH; *LED=*SWITCH;
return *SWITCH; return *SWITCH;