ledHeadWii/source/platform/Platform_football.c
2020-03-03 18:49:42 +01:00

573 lines
12 KiB
C

/*
LEDhead
Copyright 2001, Peter Hirschberg
Author: Peter Hirschberg
The current version of this SOURCE CODE as well as the official
versions of the LEDHEAD APPLICATION are available from my website
at: http://www.peterhirschberg.com
Based on the handheld electronic games by Mattel Electronics.
All trademarks copyrighted by their respective owners. This
program is not affiliated or endorsed by Mattel Electronics.
License agreement:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (license.txt); if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Email : peter@peterhirschberg.com
Website : http://www.peterhirschberg.com
*/
#include "football.h"
#include "football_screen_png.h"
#include "football_poweroff_png.h"
#include "football_pro1_png.h"
#include "football_pro2_png.h"
#include "football_tick_raw.h"
#include "football_endplay_raw.h"
#include "football_endpossession_raw.h"
#include "football_score_raw.h"
// images
static GRRLIB_texImg *bmpScreen;
static GRRLIB_texImg *bmpPowerOff;
static GRRLIB_texImg *bmpPro1;
static GRRLIB_texImg *bmpPro2;
static Sound_t tcWaveRes[4];
static Blip_t blip[FOOTBALL_BLIP_COLUMNS][FOOTBALL_BLIP_ROWS];
static Digit_t digit[7] = {
{football_digit_x, football_digit_y, -1},
{football_digit_x + football_digit_spacing, football_digit_y, -1, -1},
{football_digit_x + (4 * football_digit_spacing), football_digit_y, -1, -1},
{football_digit_x + (5 * football_digit_spacing), football_digit_y, -1, -1},
{football_digit_x + (6 * football_digit_spacing), football_digit_y, -1, -1},
{football_digit_x + (9 * football_digit_spacing), football_digit_y, -1, -1},
{football_digit_x + (10 * football_digit_spacing), football_digit_y, -1, -1}
};
static Help_t help[] = {
{ WK_2, { 74, 205} },
{ WK_MINUS, { 30, 230} },
{ WK_PLUS, { 30, 184} },
{ WK_BLR, { 92, 285 } },
{ WK_UD, { 187, 201 } },
{ WK_LR, { 140, 201 } }
};
//----------------------------------------------------------------------------
//
//
void Football_Help()
{
Platform_Help(help, sizeof(help)/sizeof(*help));
}
static BOOL bInited = FALSE;
void Football_Init()
{
int x, y;
if (bInited) return;
// Init sounds
Sound_set(&tcWaveRes[0], football_tick_raw, football_tick_raw_size, 25);
Sound_set(&tcWaveRes[1], football_endplay_raw, football_endplay_raw_size, 489);
Sound_set(&tcWaveRes[2], football_endpossession_raw, football_endpossession_raw_size, 984);
Sound_set(&tcWaveRes[3], football_score_raw, football_score_raw_size, 1335);
// load images
bmpScreen = GRRLIB_LoadTexture(football_screen_png);
// set up the power switch images
bmpPowerOff = GRRLIB_LoadTexture(football_poweroff_png);
bmpPro1 = GRRLIB_LoadTexture(football_pro1_png);
bmpPro2 = GRRLIB_LoadTexture(football_pro2_png);
// init blips positions
for (y = 0; y < FOOTBALL_BLIP_ROWS; y++){
for (x = 0; x < FOOTBALL_BLIP_COLUMNS; x++){
Blip_t *pblip = &blip[x][y];
pblip->x = (int)((x * ((float)football_blip_xspacing/100)) + football_blip_x);
pblip->y = (int)((y * ((float)football_blip_yspacing/100)) + football_blip_y);
pblip->status = -1;
}
}
// clean digit
for (x=0; x<7; x++) {
digit[x].val = -1;
digit[x].type = DIGIT_TYPE_NORMAL;
}
PlatformSetInput(0);
// turn on the game
Football_SetSkill(0);
Football_PowerOn();
bInited = TRUE;
}
void Football_DeInit()
{
// stop all sounds...
Platform_StopSound();
GRRLIB_FreeTexture(bmpScreen);
GRRLIB_FreeTexture(bmpPowerOff);
GRRLIB_FreeTexture(bmpPro1);
GRRLIB_FreeTexture(bmpPro2);
bInited = FALSE;
}
void Football_Paint()
{
int x, y;
BOOL power = Football_GetPower();
BOOL skill = Football_GetSkill();
int p_switch;
p_switch = Platform_GetPowerSwitch(ONOFF_OFF12);
if(power) {
if(p_switch == -1) {
if(skill == 0)
Football_PowerOff();
if(skill == 1) {
Football_PowerOn();
Football_SetSkill(0);
}
}
if(p_switch == 1) {
if(skill == 0) {
Football_PowerOn();
Football_SetSkill(1);
}
}
}
else {
if(p_switch == 1) {
Football_PowerOn();
Football_SetSkill(0);
}
}
// paint the backdrop
GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xffffffff);
// visualize the control states
if (power){
if (skill == 0){
GRRLIB_DrawImg(realx(football_pro_1_x), realy(football_pro_1_y), bmpPro1, 0, 1, 1, 0xffffffff);
} else {
GRRLIB_DrawImg(realx(football_pro_2_x), realy(football_pro_2_y), bmpPro2, 0, 1, 1, 0xffffffff);
}
for (y = 0; y < FOOTBALL_BLIP_ROWS; y++){
for (x = 0; x < FOOTBALL_BLIP_COLUMNS; x++){
if(blip[x][y].status != -1)
draw_oblip(blip[x][y].x, blip[x][y].y, blip[x][y].status);
}
}
for(x = 0; x < 7; x++) {
draw_digit_f(digit[x].x, digit[x].y, digit[x].val, digit[x].type);
}
}
else {
GRRLIB_DrawImg(realx(football_power_off_x), realy(football_power_off_y), bmpPowerOff, 0, 1, 1, 0xffffffff);
}
}
void Football_ClearScreen()
{
int x, y;
Platform_StartDraw();
// erase the blips
for (y = 0; y < FOOTBALL_BLIP_ROWS; y++){
for (x = 0; x < FOOTBALL_BLIP_COLUMNS; x++){
Football_DrawBlip(BLIP_OFF, x, y);
}
}
// erase the stat display
Football_DrawScores(-1, -1);
Football_DrawTime(-1);
Platform_EndDraw();
}
void Football_PlaySound(int nSound, unsigned int nFlags)
{
Platform_PlaySound(&tcWaveRes[nSound], nFlags);
}
void Football_StopSound()
{
// stop all sounds...
Platform_StopSound();
}
//----------------------------------------------------------------------------
// local fcn's
//
void Football_DrawBlip(int nBright, int x, int y)
{
Blip_t *pblip = &blip[x][y];
switch(nBright){
case BLIP_OFF:
pblip->status = -1;
break;
case BLIP_DIM:
pblip->status = BLIP_TYPE_NORMAL;
break;
case BLIP_BRIGHT:
pblip->status = BLIP_TYPE_BRIGHT;
break;
}
}
void Football_DrawScores(int nHScore, int nVScore)
{
// draw home team score
if (nHScore == -1){
// erase the time
digit[0].val = -1;
digit[0].type = DIGIT_TYPE_NORMAL;
digit[1].val = -1;
digit[1].type = DIGIT_TYPE_NORMAL;
} else {
// draw 10s place
if ((nHScore/10) != 0){
digit[0].val = nHScore/10;
} else {
digit[0].val = -1;
}
digit[0].type = DIGIT_TYPE_NORMAL;
// draw 1s place
digit[1].val = nHScore%10;
digit[1].type = DIGIT_TYPE_NORMAL;
}
// draw visitor team score
if (nVScore == -1){
// erase the time
digit[5].val = -1;
digit[5].type = DIGIT_TYPE_NORMAL;
digit[6].val = -1;
digit[6].type = DIGIT_TYPE_NORMAL;
} else {
// draw 10s place
if ((nVScore/10) != 0){
digit[5].val = nVScore/10;
} else {
digit[5].val = -1;
}
digit[5].type = DIGIT_TYPE_NORMAL;
// draw 1s place
digit[6].val = nVScore%10;
digit[6].type = DIGIT_TYPE_NORMAL;
}
}
void Football_DrawDown(int nDown, int nYards)
{
// draw downs
if (nDown == -1){
// erase the down
digit[0].val = -1;
digit[0].type = DIGIT_TYPE_NORMAL;
digit[1].val = -1;
digit[1].type = DIGIT_TYPE_NORMAL;
} else {
++nDown;
// draw 10s place
if (nDown >= 10){
digit[0].val = nDown/10;
} else {
digit[0].val = -1;
}
digit[0].type = DIGIT_TYPE_NORMAL;
// draw 1s place
digit[1].val = nDown%10;
digit[1].type = DIGIT_TYPE_NORMAL;
}
// draw yards
if (nYards <= 0){
// erase the yards
digit[5].val = -1;
digit[5].type = DIGIT_TYPE_NORMAL;
digit[6].val = -1;
digit[6].type = DIGIT_TYPE_NORMAL;
} else {
// draw 10s place
if (nYards >= 10){
digit[5].val = nYards/10;
} else {
digit[5].val = -1;
}
digit[5].type = DIGIT_TYPE_NORMAL;
// draw 1s place
digit[6].val = nYards%10;
digit[6].type = DIGIT_TYPE_NORMAL;
}
}
void Football_DrawTime(float fTime)
{
int i;
// erase the time
for(i=2; i<5; i++) {
digit[i].val = -1;
digit[i].type = DIGIT_TYPE_NORMAL;
}
// draw time display
if (fTime == 0.0) {
// zero time is displayed as '00'
digit[2].val = -1;
digit[3].val = 0;
digit[4].val = 0;
}
else if (fTime > 0.0) {
int nTime = (int)(fTime + .1); // add .1 for rounding error
// draw 10s place
if ((nTime/10) != 0){
digit[2].val = nTime/10;
}
else {
digit[2].val = -1;
}
// draw 1s place (and decimal)
digit[3].val = nTime%10;
digit[3].type = DIGIT_TYPE_FLOAT;
// draw fractional portion
char lpszTime[16];
sprintf(lpszTime, "%.01f", fTime);
for (int i=0; lpszTime[i]; i++){
if (lpszTime[i] == '.'){
digit[4].val = lpszTime[i+1] - '0';
break;
}
}
}
}
void Football_DrawYard(int nYard)
{
int sign;
int val, idx;
// convert display to proper format
if (nYard >= 50){
sign = 1;
val = 100 - nYard;
} else {
sign = -1;
val = nYard;
}
// draw yard
idx = 2;
if (sign == 1){
// draw direction on left
digit[idx].val = 1;
digit[idx].type = DIGIT_TYPE_SPECIAL;
idx++;
}
// draw 10s place
digit[idx].val = val/10;
digit[idx].type = DIGIT_TYPE_NORMAL;
idx++;
digit[idx].val = val%10;
digit[idx].type = DIGIT_TYPE_NORMAL;
idx++;
if (sign == -1){
// draw direction on right
digit[idx].val = 0;
digit[idx].type = DIGIT_TYPE_SPECIAL;
}
}
BOOL Football_GetInputKICK(BOOL *pChange)
{
static BOOL bLast = FALSE;
if (pChange){ *pChange = FALSE; }
// check the keys
if (Platform_GetInput2())
{
if (!bLast && pChange)
{
*pChange = TRUE;
}
bLast = TRUE;
return TRUE;
}
bLast = FALSE;
return FALSE;
}
BOOL Football_GetInputSTATUS(BOOL *pChange)
{
static BOOL bLast = FALSE;
if (pChange){ *pChange = FALSE; }
// check the keys
if (Platform_GetInputPLUS())
{
if (!bLast && pChange)
{
*pChange = TRUE;
}
bLast = TRUE;
return TRUE;
}
bLast = FALSE;
return FALSE;
}
BOOL Football_GetInputSCORE(BOOL *pChange)
{
static BOOL bLast = FALSE;
if (pChange){ *pChange = FALSE; }
// check the keys
if (Platform_GetInputMINUS())
{
if (!bLast && pChange)
{
*pChange = TRUE;
}
bLast = TRUE;
return TRUE;
}
bLast = FALSE;
return FALSE;
}
BOOL Football_GetInputUP(BOOL *pChange)
{
static BOOL bLast = FALSE;
if (pChange){ *pChange = FALSE; }
// check the keys
if (Platform_GetInputUP())
{
if (!bLast && pChange)
{
*pChange = TRUE;
}
bLast = TRUE;
return TRUE;
}
bLast = FALSE;
return FALSE;
}
BOOL Football_GetInputRUN(BOOL *pChange)
{
static BOOL bLast = FALSE;
if (pChange){ *pChange = FALSE; }
// check the keys
if (Platform_GetInputRIGHT()
|| Platform_GetInputLEFT())
{
if (!bLast && pChange)
{
*pChange = TRUE;
}
bLast = TRUE;
return TRUE;
}
bLast = FALSE;
return FALSE;
}
BOOL Football_GetInputDOWN(BOOL *pChange)
{
static BOOL bLast = FALSE;
if (pChange){ *pChange = FALSE; }
// check the keys
if (Platform_GetInputDOWN())
{
if (!bLast && pChange)
{
*pChange = TRUE;
}
bLast = TRUE;
return TRUE;
}
bLast = FALSE;
return FALSE;
}
BOOL Football_TestForMovement()
{
// check the keys
if (Platform_GetInputRIGHT()
|| Platform_GetInputLEFT()
|| Platform_GetInputUP()
|| Platform_GetInputDOWN())
{
return TRUE;
}
return FALSE;
}
void Football_GetSize(int *w, int *h)
{
*w = bmpScreen->w;
*h = bmpScreen->h;
}