diff --git a/README.md b/README.md index fdbea22..e2e990f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ledHeadWii -Porting on Wii of Peter Hirschberg's LedHEAD (classic electronic LED handled game simulator) +Based on Peter Hirschberg's LedHEAD (classic electronic LED handled game simulator) source code. ## OVERVIEW LEDhead is a program that simulates the classic electronic LED (light emitting diode) based handheld @@ -8,4 +8,12 @@ All games feature fully authentic sound-effects, and faithfully replicate the ga Rather than using proprietary code or "ROM images", as is the case with emulators, LEDhead uses simple but extremely clever imitation to ensure excruciating faithfulness to the games you grew up with. -Endless hours of painstaking effort have gone into ensuring the accuracy of each of these games. +Endless hours of painstaking effort have gone into ensuring the accuracy of each of these games. + +## NOTE +Wii version have some games not present in original version. These games was developed from scratch. + +## CREDITS +Thanks to Peter Hirschberg for the original source code. +Thanks to ArcadeUSA and Rick.R for playing real hardware games and telling me how they work. +And then for playing with the simulator to find the differences. diff --git a/data/images/autorace_aimcenter.png b/data/images/autorace_aimcenter.png deleted file mode 100644 index a9069ba..0000000 Binary files a/data/images/autorace_aimcenter.png and /dev/null differ diff --git a/data/images/autorace_aimleft.png b/data/images/autorace_aimleft.png deleted file mode 100644 index 561e9a9..0000000 Binary files a/data/images/autorace_aimleft.png and /dev/null differ diff --git a/data/images/autorace_aimright.png b/data/images/autorace_aimright.png deleted file mode 100644 index 836fe99..0000000 Binary files a/data/images/autorace_aimright.png and /dev/null differ diff --git a/data/images/autorace_gear1.png b/data/images/autorace_gear1.png deleted file mode 100644 index b925ee2..0000000 Binary files a/data/images/autorace_gear1.png and /dev/null differ diff --git a/data/images/autorace_gear2.png b/data/images/autorace_gear2.png deleted file mode 100644 index 8a28ae8..0000000 Binary files a/data/images/autorace_gear2.png and /dev/null differ diff --git a/data/images/autorace_gear3.png b/data/images/autorace_gear3.png deleted file mode 100644 index f97172e..0000000 Binary files a/data/images/autorace_gear3.png and /dev/null differ diff --git a/data/images/autorace_gear4.png b/data/images/autorace_gear4.png deleted file mode 100644 index b606cf5..0000000 Binary files a/data/images/autorace_gear4.png and /dev/null differ diff --git a/data/images/autorace_poweroff.png b/data/images/autorace_poweroff.png deleted file mode 100644 index 31429c5..0000000 Binary files a/data/images/autorace_poweroff.png and /dev/null differ diff --git a/data/images/autorace_poweron.png b/data/images/autorace_poweron.png deleted file mode 100644 index b7ce3a7..0000000 Binary files a/data/images/autorace_poweron.png and /dev/null differ diff --git a/data/images/autorace_slide.png b/data/images/autorace_slide.png new file mode 100644 index 0000000..ca23eee Binary files /dev/null and b/data/images/autorace_slide.png differ diff --git a/data/images/baseball_blip.png b/data/images/baseball_blip.png index 1ac3510..d6b37ec 100644 Binary files a/data/images/baseball_blip.png and b/data/images/baseball_blip.png differ diff --git a/data/images/baseball_brightdigits.png b/data/images/baseball_brightdigits.png index 5d9e1db..1108392 100644 Binary files a/data/images/baseball_brightdigits.png and b/data/images/baseball_brightdigits.png differ diff --git a/data/images/baseball_dimdigits.png b/data/images/baseball_dimdigits.png index 290c073..4bae23d 100644 Binary files a/data/images/baseball_dimdigits.png and b/data/images/baseball_dimdigits.png differ diff --git a/data/images/baseball_poweroff.png b/data/images/baseball_poweroff.png deleted file mode 100644 index b6a6a79..0000000 Binary files a/data/images/baseball_poweroff.png and /dev/null differ diff --git a/data/images/baseball_pro1.png b/data/images/baseball_pro1.png deleted file mode 100644 index 8313a80..0000000 Binary files a/data/images/baseball_pro1.png and /dev/null differ diff --git a/data/images/baseball_pro2.png b/data/images/baseball_pro2.png deleted file mode 100644 index 6c6e7b6..0000000 Binary files a/data/images/baseball_pro2.png and /dev/null differ diff --git a/data/images/basketball2_screen.png b/data/images/basketball2_screen.png new file mode 100644 index 0000000..c001b3a Binary files /dev/null and b/data/images/basketball2_screen.png differ diff --git a/data/images/digits_f.png b/data/images/digits_f.png index 32da834..4f37478 100644 Binary files a/data/images/digits_f.png and b/data/images/digits_f.png differ diff --git a/data/images/football2_poweroff.png b/data/images/football2_poweroff.png deleted file mode 100644 index 78c4455..0000000 Binary files a/data/images/football2_poweroff.png and /dev/null differ diff --git a/data/images/football2_pro1.png b/data/images/football2_pro1.png deleted file mode 100644 index c3aed24..0000000 Binary files a/data/images/football2_pro1.png and /dev/null differ diff --git a/data/images/football2_pro2.png b/data/images/football2_pro2.png deleted file mode 100644 index b199d2d..0000000 Binary files a/data/images/football2_pro2.png and /dev/null differ diff --git a/data/images/football_poweroff.png b/data/images/football_poweroff.png deleted file mode 100644 index 9bd2ec8..0000000 Binary files a/data/images/football_poweroff.png and /dev/null differ diff --git a/data/images/football_pro1.png b/data/images/football_pro1.png deleted file mode 100644 index d7a9335..0000000 Binary files a/data/images/football_pro1.png and /dev/null differ diff --git a/data/images/football_pro2.png b/data/images/football_pro2.png deleted file mode 100644 index 75947cf..0000000 Binary files a/data/images/football_pro2.png and /dev/null differ diff --git a/data/images/missileattack_screen.png b/data/images/missileattack_screen.png new file mode 100644 index 0000000..8aaf720 Binary files /dev/null and b/data/images/missileattack_screen.png differ diff --git a/data/images/nodisp_screen.png b/data/images/nodisp_screen.png deleted file mode 100644 index 69e5009..0000000 Binary files a/data/images/nodisp_screen.png and /dev/null differ diff --git a/data/images/poweroff_a.png b/data/images/poweroff_a.png deleted file mode 100644 index 3163d06..0000000 Binary files a/data/images/poweroff_a.png and /dev/null differ diff --git a/data/images/skislalom_aimcenter.png b/data/images/skislalom_aimcenter.png deleted file mode 100644 index f39f19b..0000000 Binary files a/data/images/skislalom_aimcenter.png and /dev/null differ diff --git a/data/images/skislalom_aimleft.png b/data/images/skislalom_aimleft.png deleted file mode 100644 index ccb4fd3..0000000 Binary files a/data/images/skislalom_aimleft.png and /dev/null differ diff --git a/data/images/skislalom_aimright.png b/data/images/skislalom_aimright.png deleted file mode 100644 index 7c09444..0000000 Binary files a/data/images/skislalom_aimright.png and /dev/null differ diff --git a/data/images/skislalom_gear1.png b/data/images/skislalom_gear1.png deleted file mode 100644 index 6ab0464..0000000 Binary files a/data/images/skislalom_gear1.png and /dev/null differ diff --git a/data/images/skislalom_gear2.png b/data/images/skislalom_gear2.png deleted file mode 100644 index 72c4aa4..0000000 Binary files a/data/images/skislalom_gear2.png and /dev/null differ diff --git a/data/images/skislalom_gear3.png b/data/images/skislalom_gear3.png deleted file mode 100644 index 75a4eaa..0000000 Binary files a/data/images/skislalom_gear3.png and /dev/null differ diff --git a/data/images/skislalom_gear4.png b/data/images/skislalom_gear4.png deleted file mode 100644 index b606cf5..0000000 Binary files a/data/images/skislalom_gear4.png and /dev/null differ diff --git a/data/images/skislalom_gearknob.png b/data/images/skislalom_gearknob.png deleted file mode 100644 index 8da6bb9..0000000 Binary files a/data/images/skislalom_gearknob.png and /dev/null differ diff --git a/data/images/skislalom_powerknob.png b/data/images/skislalom_powerknob.png deleted file mode 100644 index 8da6bb9..0000000 Binary files a/data/images/skislalom_powerknob.png and /dev/null differ diff --git a/data/images/skislalom_poweroff.png b/data/images/skislalom_poweroff.png deleted file mode 100644 index 818c2ce..0000000 Binary files a/data/images/skislalom_poweroff.png and /dev/null differ diff --git a/data/images/skislalom_poweron.png b/data/images/skislalom_poweron.png deleted file mode 100644 index 18c5944..0000000 Binary files a/data/images/skislalom_poweron.png and /dev/null differ diff --git a/data/images/skislalom_slide.png b/data/images/skislalom_slide.png new file mode 100644 index 0000000..9c9f968 Binary files /dev/null and b/data/images/skislalom_slide.png differ diff --git a/data/images/skislalom_slide2.png b/data/images/skislalom_slide2.png new file mode 100644 index 0000000..0daf279 Binary files /dev/null and b/data/images/skislalom_slide2.png differ diff --git a/data/images/slide1.png b/data/images/slide1.png new file mode 100644 index 0000000..a1e456e Binary files /dev/null and b/data/images/slide1.png differ diff --git a/data/images/slide2.png b/data/images/slide2.png new file mode 100644 index 0000000..72227b9 Binary files /dev/null and b/data/images/slide2.png differ diff --git a/data/images/slide3.png b/data/images/slide3.png new file mode 100644 index 0000000..fce423d Binary files /dev/null and b/data/images/slide3.png differ diff --git a/data/images/soccer2_screen.png b/data/images/soccer2_screen.png new file mode 100644 index 0000000..bfa9aee Binary files /dev/null and b/data/images/soccer2_screen.png differ diff --git a/data/images/spacealert_aimcenter.png b/data/images/spacealert_aimcenter.png deleted file mode 100644 index 28c374f..0000000 Binary files a/data/images/spacealert_aimcenter.png and /dev/null differ diff --git a/data/images/spacealert_aimleft.png b/data/images/spacealert_aimleft.png deleted file mode 100644 index 3b75e16..0000000 Binary files a/data/images/spacealert_aimleft.png and /dev/null differ diff --git a/data/images/spacealert_aimright.png b/data/images/spacealert_aimright.png deleted file mode 100644 index 0db9a63..0000000 Binary files a/data/images/spacealert_aimright.png and /dev/null differ diff --git a/data/images/spacealert_poweroff.png b/data/images/spacealert_poweroff.png deleted file mode 100644 index fde9685..0000000 Binary files a/data/images/spacealert_poweroff.png and /dev/null differ diff --git a/data/images/spacealert_poweron.png b/data/images/spacealert_poweron.png deleted file mode 100644 index a85aa65..0000000 Binary files a/data/images/spacealert_poweron.png and /dev/null differ diff --git a/data/images/switch1.png b/data/images/switch1.png new file mode 100644 index 0000000..c7ffd16 Binary files /dev/null and b/data/images/switch1.png differ diff --git a/data/images/switch2.png b/data/images/switch2.png new file mode 100644 index 0000000..deac3ed Binary files /dev/null and b/data/images/switch2.png differ diff --git a/data/images/switch3.png b/data/images/switch3.png new file mode 100644 index 0000000..3679d03 Binary files /dev/null and b/data/images/switch3.png differ diff --git a/data/images/switch4.png b/data/images/switch4.png new file mode 100644 index 0000000..c092b26 Binary files /dev/null and b/data/images/switch4.png differ diff --git a/data/sounds/basketball2_3secs.raw b/data/sounds/basketball2_3secs.raw new file mode 100644 index 0000000..9e2301f Binary files /dev/null and b/data/sounds/basketball2_3secs.raw differ diff --git a/data/sounds/basketball2_bounce.raw b/data/sounds/basketball2_bounce.raw new file mode 100644 index 0000000..b747d92 Binary files /dev/null and b/data/sounds/basketball2_bounce.raw differ diff --git a/data/sounds/basketball2_endgame.raw b/data/sounds/basketball2_endgame.raw new file mode 100644 index 0000000..de5c169 Binary files /dev/null and b/data/sounds/basketball2_endgame.raw differ diff --git a/data/sounds/basketball2_endplay.raw b/data/sounds/basketball2_endplay.raw new file mode 100644 index 0000000..b3c137f Binary files /dev/null and b/data/sounds/basketball2_endplay.raw differ diff --git a/data/sounds/basketball2_endquarter.raw b/data/sounds/basketball2_endquarter.raw new file mode 100644 index 0000000..66a24f0 Binary files /dev/null and b/data/sounds/basketball2_endquarter.raw differ diff --git a/data/sounds/basketball2_foul.raw b/data/sounds/basketball2_foul.raw new file mode 100644 index 0000000..26f4bd6 Binary files /dev/null and b/data/sounds/basketball2_foul.raw differ diff --git a/data/sounds/basketball2_freethrow.raw b/data/sounds/basketball2_freethrow.raw new file mode 100644 index 0000000..7069772 Binary files /dev/null and b/data/sounds/basketball2_freethrow.raw differ diff --git a/data/sounds/basketball2_overtime.raw b/data/sounds/basketball2_overtime.raw new file mode 100644 index 0000000..ef8740e Binary files /dev/null and b/data/sounds/basketball2_overtime.raw differ diff --git a/data/sounds/basketball2_score.raw b/data/sounds/basketball2_score.raw new file mode 100644 index 0000000..6376b78 Binary files /dev/null and b/data/sounds/basketball2_score.raw differ diff --git a/data/sounds/basketball2_score3.raw b/data/sounds/basketball2_score3.raw new file mode 100644 index 0000000..af3e05a Binary files /dev/null and b/data/sounds/basketball2_score3.raw differ diff --git a/data/sounds/basketball2_tick.raw b/data/sounds/basketball2_tick.raw new file mode 100644 index 0000000..292ed9d --- /dev/null +++ b/data/sounds/basketball2_tick.raw @@ -0,0 +1 @@ +üüûþööã6ë…täº &æ¼ÿ'ë×5ÞÛ3ôÏÿ&åî âõþìèôô&öõ÷úóõÿøù \ No newline at end of file diff --git a/data/sounds/soccer2_ballout.raw b/data/sounds/soccer2_ballout.raw new file mode 100644 index 0000000..09466b1 Binary files /dev/null and b/data/sounds/soccer2_ballout.raw differ diff --git a/data/sounds/soccer2_beep.raw b/data/sounds/soccer2_beep.raw new file mode 100644 index 0000000..3dd944d Binary files /dev/null and b/data/sounds/soccer2_beep.raw differ diff --git a/data/sounds/soccer2_bounce.raw b/data/sounds/soccer2_bounce.raw new file mode 100644 index 0000000..fa2f5e2 Binary files /dev/null and b/data/sounds/soccer2_bounce.raw differ diff --git a/data/sounds/soccer2_endgame.raw b/data/sounds/soccer2_endgame.raw new file mode 100644 index 0000000..f27fa1c Binary files /dev/null and b/data/sounds/soccer2_endgame.raw differ diff --git a/data/sounds/soccer2_endhalf.raw b/data/sounds/soccer2_endhalf.raw new file mode 100644 index 0000000..b980e75 Binary files /dev/null and b/data/sounds/soccer2_endhalf.raw differ diff --git a/data/sounds/soccer2_goal.raw b/data/sounds/soccer2_goal.raw new file mode 100644 index 0000000..20da26d Binary files /dev/null and b/data/sounds/soccer2_goal.raw differ diff --git a/data/sounds/soccer2_highkick.raw b/data/sounds/soccer2_highkick.raw new file mode 100644 index 0000000..452462e Binary files /dev/null and b/data/sounds/soccer2_highkick.raw differ diff --git a/data/sounds/soccer2_looseball.raw b/data/sounds/soccer2_looseball.raw new file mode 100644 index 0000000..1652b69 Binary files /dev/null and b/data/sounds/soccer2_looseball.raw differ diff --git a/data/sounds/soccer2_lowkick.raw b/data/sounds/soccer2_lowkick.raw new file mode 100644 index 0000000..288e3e0 Binary files /dev/null and b/data/sounds/soccer2_lowkick.raw differ diff --git a/data/sounds/soccer2_tick.raw b/data/sounds/soccer2_tick.raw new file mode 100644 index 0000000..740df1a Binary files /dev/null and b/data/sounds/soccer2_tick.raw differ diff --git a/data/wiimote/WKBLR1.png b/data/wiimote/WKBLR1.png new file mode 100644 index 0000000..478f0bd Binary files /dev/null and b/data/wiimote/WKBLR1.png differ diff --git a/data/wiimote/WKD.png b/data/wiimote/WKD.png new file mode 100644 index 0000000..c9356a5 Binary files /dev/null and b/data/wiimote/WKD.png differ diff --git a/data/wiimote/WKL.png b/data/wiimote/WKL.png new file mode 100644 index 0000000..98b55dd Binary files /dev/null and b/data/wiimote/WKL.png differ diff --git a/data/wiimote/WKR.png b/data/wiimote/WKR.png new file mode 100644 index 0000000..0908e9d Binary files /dev/null and b/data/wiimote/WKR.png differ diff --git a/data/wiimote/WKU.png b/data/wiimote/WKU.png new file mode 100644 index 0000000..c322117 Binary files /dev/null and b/data/wiimote/WKU.png differ diff --git a/source/Games.c b/source/Games.c index b8f0b2f..c28ea96 100644 --- a/source/Games.c +++ b/source/Games.c @@ -39,11 +39,13 @@ Website : http://www.peterhirschberg.com #include "autorace.h" #include "spacealert.h" #include "basketball.h" +#include "basketball2.h" #include "football.h" #include "football2.h" #include "hockey.h" #include "hockeyca.h" #include "soccer.h" +#include "soccer2.h" #include "armorbattle.h" #include "baseball.h" #include "subchase.h" @@ -51,15 +53,19 @@ Website : http://www.peterhirschberg.com #include "autorace_screen_png.h" #include "baseball_screen_png.h" #include "basketball_screen_png.h" +#include "basketball2_screen_png.h" #include "football_screen_png.h" #include "football2_screen_png.h" #include "hockey_screen_png.h" #include "hockeyca_screen_png.h" #include "skislalom_screen_png.h" #include "soccer_screen_png.h" +#include "soccer2_screen_png.h" #include "spacealert_screen_png.h" +#include "missileattack_screen_png.h" #include "subchase_screen_png.h" -#include "nodisp_screen_png.h" + +//#define DEEP_DEBUG 1 GAMECONTEXT gGameContext[NUM_GAMES] = { @@ -67,8 +73,7 @@ GAMECONTEXT gGameContext[NUM_GAMES] = { GAME_ARMORBATTLE, 150, - "Armor Battle", - "armorbattle", + "Armor Battle (1978)", ArmorBattle_Init, ArmorBattle_DeInit, ArmorBattle_Run, @@ -81,13 +86,13 @@ GAMECONTEXT gGameContext[NUM_GAMES] = ArmorBattle_GetSize, armorbattle_screen_png, ArmorBattle_Help, + NULL }, // auto race { GAME_AUTORACE, 100,//65 - "Auto Race", - "autorace", + "Auto Race (1976)", AutoRace_Init, AutoRace_DeInit, AutoRace_Run, @@ -99,14 +104,14 @@ GAMECONTEXT gGameContext[NUM_GAMES] = AutoRace_Paint, AutoRace_GetSize, autorace_screen_png, - AutoRace_Help + AutoRace_Help, + NULL }, // baseball { GAME_BASEBALL, - 10, - "Baseball", - "baseball", + 1, + "Baseball (1978)", Baseball_Init, Baseball_DeInit, Baseball_Run, @@ -118,14 +123,18 @@ GAMECONTEXT gGameContext[NUM_GAMES] = Baseball_Paint, Baseball_GetSize, baseball_screen_png, - Baseball_Help + Baseball_Help, +#ifdef DEEP_DEBUG + Baseball_Debug +#else + NULL +#endif }, // basketball { GAME_BASKETBALL, 60, - "Basketball", - "basketball", + "Basketball (1978)", Basketball_Init, Basketball_DeInit, Basketball_Run, @@ -137,33 +146,37 @@ GAMECONTEXT gGameContext[NUM_GAMES] = Basketball_Paint, Basketball_GetSize, basketball_screen_png, - Basketball_Help + Basketball_Help, + NULL }, // basketball 2 { GAME_BASKETBALL2, - 0, - "Basketball II", - "basketball2", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - nodisp_screen_png, + 60, + "Basketball 2 (1979)", + Basketball2_Init, + Basketball2_DeInit, + Basketball2_Run, + Basketball2_SetSkill, + Basketball2_GetSkill, + Basketball2_PowerOn, + Basketball2_PowerOff, + Basketball2_GetPower, + Basketball2_Paint, + Basketball2_GetSize, + basketball2_screen_png, + Basketball2_Help, +#ifdef DEEP_DEBUG + Basketball2_Debug +#else NULL +#endif }, // football { GAME_FOOTBALL, 55, - "Football", - "football", + "Football (1977)", Football_Init, Football_DeInit, Football_Run, @@ -176,13 +189,13 @@ GAMECONTEXT gGameContext[NUM_GAMES] = Football_GetSize, football_screen_png, Football_Help, + NULL }, // football 2 { GAME_FOOTBALL2, 50, - "Football II", - "football2", + "Football II (1978)", Football2_Init, Football2_DeInit, Football2_Run, @@ -195,13 +208,17 @@ GAMECONTEXT gGameContext[NUM_GAMES] = Football2_GetSize, football2_screen_png, Football2_Help, +#ifdef DEEP_DEBUG + Football2_Debug +#else + NULL +#endif }, // hockey { GAME_HOCKEY, 60, - "Hockey", - "hockey", + "Hockey (1978)", Hockey_Init, Hockey_DeInit, Hockey_Run, @@ -213,14 +230,14 @@ GAMECONTEXT gGameContext[NUM_GAMES] = Hockey_Paint, Hockey_GetSize, hockey_screen_png, - Hockey_Help + Hockey_Help, + NULL }, // hockey (canadian) { GAME_HOCKEYCA, 60, - "Hockey (Canadian)", - "hockeyca", + "Hockey (Canadian) (1978)", HockeyCa_Init, HockeyCa_DeInit, HockeyCa_Run, @@ -232,14 +249,14 @@ GAMECONTEXT gGameContext[NUM_GAMES] = HockeyCa_Paint, HockeyCa_GetSize, hockeyca_screen_png, - HockeyCa_Help + HockeyCa_Help, + NULL }, // ski slalom { GAME_SKISLALOM, 65, - "Ski Slalom", - "skislalom", + "Ski Slalom (1980)", SkiSlalom_Init, AutoRace_DeInit, AutoRace_Run, @@ -251,14 +268,14 @@ GAMECONTEXT gGameContext[NUM_GAMES] = AutoRace_Paint, AutoRace_GetSize, skislalom_screen_png, - SkiSlalom_Help + SkiSlalom_Help, + NULL }, // soccer { GAME_SOCCER, 60, - "Soccer", - "soccer", + "Soccer (1978)", Soccer_Init, Soccer_DeInit, Soccer_Run, @@ -270,33 +287,37 @@ GAMECONTEXT gGameContext[NUM_GAMES] = Soccer_Paint, Soccer_GetSize, soccer_screen_png, - Soccer_Help + Soccer_Help, + NULL }, // soccer 2 { GAME_SOCCER2, - 0, - "Soccer II", - "soccer2", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - nodisp_screen_png, + 60, + "Soccer 2 (1979)", + Soccer2_Init, + Soccer2_DeInit, + Soccer2_Run, + Soccer2_SetSkill, + Soccer2_GetSkill, + Soccer2_PowerOn, + Soccer2_PowerOff, + Soccer2_GetPower, + Soccer2_Paint, + Soccer2_GetSize, + soccer2_screen_png, + Soccer2_Help, +#ifdef DEEP_DEBUG + Soccer2_Debug +#else NULL +#endif }, // space alert { GAME_SPACEALERT, 110, - "Space Alert", - "spacealert", + "Space Alert (1978)", SpaceAlert_Init, SpaceAlert_DeInit, SpaceAlert_Run, @@ -308,14 +329,41 @@ GAMECONTEXT gGameContext[NUM_GAMES] = SpaceAlert_Paint, SpaceAlert_GetSize, spacealert_screen_png, - SpaceAlert_Help + SpaceAlert_Help, +#ifdef DEEP_DEBUG + SpaceAlert_Debug +#else + NULL +#endif + }, + // missile attack + { + GAME_MISSILEATTACK, + 110, + "Missile Attack (1977)", + MissileAttack_Init, + SpaceAlert_DeInit, + SpaceAlert_Run, + NULL, + NULL, + SpaceAlert_PowerOn, + SpaceAlert_PowerOff, + SpaceAlert_GetPower, + SpaceAlert_Paint, + SpaceAlert_GetSize, + missileattack_screen_png, + MissileAttack_Help, +#ifdef DEEP_DEBUG + SpaceAlert_Debug +#else + NULL +#endif }, // subchase { GAME_SUBCHASE, 60, - "Sub Chase", - "subchase", + "Sub Chase (1978)", SubChase_Init, SubChase_DeInit, SubChase_Run, @@ -327,7 +375,8 @@ GAMECONTEXT gGameContext[NUM_GAMES] = SubChase_Paint, SubChase_GetSize, subchase_screen_png, - SubChase_Help + SubChase_Help, + NULL } }; diff --git a/source/Games.h b/source/Games.h index 0d3aed3..2af5f2a 100644 --- a/source/Games.h +++ b/source/Games.h @@ -33,7 +33,6 @@ Website : http://www.peterhirschberg.com */ - #ifndef __GAMES_H__ #define __GAMES_H__ @@ -51,9 +50,11 @@ Website : http://www.peterhirschberg.com #define GAME_SOCCER 10 #define GAME_SOCCER2 11 #define GAME_SPACEALERT 12 -#define GAME_SUBCHASE 13 +#define GAME_MISSILEATTACK 13 +#define GAME_SUBCHASE 14 -#define NUM_GAMES 14 + +#define NUM_GAMES 15 typedef struct GAMECONTEXT { @@ -64,7 +65,6 @@ typedef struct GAMECONTEXT int tu; char *szName; - char *szDir; void (*Init)(void); void (*DeInit)(void); @@ -78,6 +78,7 @@ typedef struct GAMECONTEXT void (*GetSize)(int *w, int *h); const u8 *screen; void (*Help)(void); + void (*Debug)(int f); }GAMECONTEXT; extern GAMECONTEXT gGameContext[NUM_GAMES]; diff --git a/source/LED_Handled.h b/source/LED_Handled.h index dc372e3..8ec0834 100644 --- a/source/LED_Handled.h +++ b/source/LED_Handled.h @@ -2,6 +2,10 @@ * LEDhead for Wii * Copyright (C) 2017-2020 Nebiun * + * 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. + * * 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 3 of the License, or @@ -30,13 +34,18 @@ #define IR_X_CORRECTION 64 #define IR_Y_CORRECTION 20 -#define realx(x) ((x) + (rmode->viWidth - 240)/2) -#define realy(y) ((y) + 20) +#define SCALE_X _scale_x +#define SCALE_Y _scale_y +#define realx(x) (((x)*SCALE_X) + (rmode->viWidth - 240*SCALE_X)/2) +#define realy(y) (((y)*SCALE_Y) + 20) // draw_poweroff_a modes -#define POWER_POS_OFF 0 -#define POWER_POS_MODE1 1 -#define POWER_POS_MODE2 2 +#define SWITCH_POS_OFF 0 +#define SWITCH_POS_ON 1 +#define SWITCH_POS_MODE1 2 +#define SWITCH_POS_MODE2 3 +#define SWITCH_POS_PRO1 4 +#define SWITCH_POS_PRO2 5 // draw_vblip/draw_oblip modes #define BLIP_TYPE_NORMAL 0 @@ -48,17 +57,29 @@ #define DIGIT_TYPE_FLOAT 1 #define DIGIT_TYPE_SPECIAL 2 -extern int trace; +// Switch types +#define SWITCH_TYPE_1 0 /* like baseball, football2 */ +#define SWITCH_TYPE_2 1 /* like basketball, hockey, soccer */ +#define SWITCH_TYPE_3 3 /* like football */ +#define SWITCH_TYPE_4 4 /* like basketball2, soccer2 */ + +extern f32 _scale_x, _scale_y; + extern void print_text(int x, int y, u32 rgba, const char *fmt, ...); extern int draw_digit(int x, int y, int val); extern int print_digit(int x, int y, int pass, int val, int max); extern int draw_digit_f(int x, int y, int val, int flag); -extern int draw_poweroff_a(int x, int y, int val); extern int draw_vblip(int x, int y, int type); extern int draw_oblip(int x, int y, int type); +extern int draw_gear(int x, int y, int pos); +extern void destroy_gear(void); + +extern int draw_switch(int type, int x, int y, int pos); +extern void destroy_switch(void); + extern void debugPrintf(int x, int y, u32 rgba, const char *fmt, ...); extern void debugDestroy(void); #endif \ No newline at end of file diff --git a/source/blip.c b/source/blip.c index 31b2e47..3833395 100644 --- a/source/blip.c +++ b/source/blip.c @@ -2,6 +2,10 @@ * LEDhead for Wii * Copyright (C) 2017-2020 Nebiun * + * 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. + * * 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 3 of the License, or @@ -15,7 +19,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #include "LED_Handled.h" #include "v_blip_png.h" #include "o_blip_png.h" @@ -41,7 +45,7 @@ static inline int _drawBlip(int x, int y, int type, GRRLIB_texImg *blip) idx = 0; break; } - GRRLIB_DrawTile(realx(x), realy(y), blip, 0, 1, 1, 0xFFFFFFFF, idx); + GRRLIB_DrawTile(realx(x), realy(y), blip, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF, idx); return idx; } diff --git a/source/digit.c b/source/digit.c index d46dfe8..85dbcd5 100644 --- a/source/digit.c +++ b/source/digit.c @@ -2,6 +2,10 @@ * LEDhead for Wii * Copyright (C) 2017-2020 Nebiun * + * 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. + * * 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 3 of the License, or @@ -15,7 +19,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + #include "LED_Handled.h" #include "digits_f_png.h" @@ -48,13 +52,13 @@ int draw_digit_f(int x, int y, int val, int flag) idx = 12 + val%10; break; case DIGIT_TYPE_SPECIAL: - idx = 23 + val%2; + idx = 22 + val%4; break; } if(idx < 0) return -1; - GRRLIB_DrawTile(realx(x), realy(y), digit, 0, 1, 1, 0xFFFFFFFF, idx); + GRRLIB_DrawTile(realx(x), realy(y), digit, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF, idx); return 0; } diff --git a/source/font.c b/source/font.c index f63ecba..e3d7328 100644 --- a/source/font.c +++ b/source/font.c @@ -2,6 +2,10 @@ * LEDhead for Wii * Copyright (C) 2017-2020 Nebiun * + * 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. + * * 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 3 of the License, or diff --git a/source/game/ArmorBattle.h b/source/game/ArmorBattle.h index abdc178..411c71b 100644 --- a/source/game/ArmorBattle.h +++ b/source/game/ArmorBattle.h @@ -50,8 +50,9 @@ Website : http://www.peterhirschberg.com #define ARMORBATTLE_SOUND_HIT 4 #define ARMORBATTLE_SOUND_SCORE 5 #define ARMORBATTLE_SOUND_ENDGAME 6 +#define ARMORBATTLE_SOUND_NSOUNDS 7 -void ArmorBattle_Run(); +void ArmorBattle_Run(int tu); void ArmorBattle_SetSkill(int i); int ArmorBattle_GetSkill(); void ArmorBattle_PowerOn(); diff --git a/source/game/AutoRace.h b/source/game/AutoRace.h index d0e6396..67db7f3 100644 --- a/source/game/AutoRace.h +++ b/source/game/AutoRace.h @@ -50,8 +50,9 @@ Website : http://www.peterhirschberg.com #define AUTORACE_SOUND_HIT 4 #define AUTORACE_SOUND_TIME 5 #define AUTORACE_SOUND_WIN 6 +#define AUTORACE_SOUND_NSOUNDS 7 -void AutoRace_Run(); +void AutoRace_Run(int tu); void AutoRace_SetSkill(int i); int AutoRace_GetSkill(); void AutoRace_PowerOn(); diff --git a/source/game/Baseball.c b/source/game/Baseball.c index 8ee85a9..92cdf16 100644 --- a/source/game/Baseball.c +++ b/source/game/Baseball.c @@ -28,10 +28,13 @@ 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.comWebsite : http://www.peterhirschberg.com +Email : peter@peterhirschberg.com +Website : http://www.peterhirschberg.com */ +#include +#include #include "Baseball.h" #include "Games.h" @@ -41,12 +44,16 @@ Email : peter@peterhirschberg.comWebsite : http://www.peterhirschberg.com #define THIRDBASE 9 #define HOMEPLATE 12 +#define MAGIC_NUMBER 64 // emperically derived magic number +#define SPEED_BASE (1 + (MAGIC_NUMBER/16)) + +#define CENTER_FIELD 0 +#define LEFT_FIELD 1 +#define RIGHT_FIELD 2 // game variables static BOOL bHomeTeam; static BOOL bInFrame = FALSE; -static BOOL bPower; -static BOOL bPro2 = FALSE; static int nHRuns; static int nVRuns; @@ -59,7 +66,7 @@ static int nTimerPitchWait; static int nPitchSpeed; static BOOL bCurveball; -static int nEraseIndex; +static BOOL bStrike = FALSE; static int nPitchIndex; static int nPendingRuns; @@ -68,13 +75,15 @@ static int nTimerEndPlayWait; static int nTimerRunnerMove; static int nRunnerSpeed; static int nTimerFielding; - static int nCurrentRunnerIndex; static int nDefenseBlip; +static int nBallBlip; static BOOL bCaught; +static BOOL bDisplayOff; static int fireWorks; +static int nSwingSlot; // finite state machine stuff @@ -88,8 +97,9 @@ static void fsmOut(int tu); static void fsmHomeRun(int tu); static void fsmEndPossession(int tu); static void fsmGameOver(int tu); +static void fsmGoOut(int tu); -static enum FSM { +enum FSM { FSM_IDLE, FSM_PITCHWAIT, FSM_PITCHING, @@ -99,8 +109,10 @@ static enum FSM { FSM_OUT, FSM_HOMERUN, FSM_ENDPOSSESSION, - FSM_GAMEOVER -}fsm; + FSM_GAMEOVER, + FSM_GOOUT +}; +static enum FSM fsm; typedef void (*FSMFCN)(int); @@ -114,66 +126,125 @@ static FSMFCN fsmfcn[] = { fsmOut, fsmHomeRun, fsmEndPossession, - fsmGameOver + fsmGameOver, + fsmGoOut }; -typedef struct RUNNER +typedef struct { int baseindex; BOOL enabled; -}RUNNER; +} RUNNER; #define MAX_RUNNERS 4 RUNNER runners[MAX_RUNNERS]; +typedef struct { + int seq[3]; + int n; +} fireworks_t; -// proto's -static void InitGame(); -static void ClearAllDisplay(); -static void RestoreAllDisplay(); -static void InsertRunner(); -static BOOL MoveRunners(); -static void ResetOffBaseRunners(); -static void DrawDefenseBlip(int index); -static void DrawBaseBlips(BOOL bState); -static void ErasePitchBlips(); -static void HitBall(int nPosition); -static void DoOut(); +static fireworks_t fw_frames[] = { + { {DIAMOND(1)}, 1}, + { {DIAMOND(1), DIAMOND(2)}, 2}, + { {DIAMOND(1), DIAMOND(2), DEEP_1ST}, 3}, + { {DIAMOND(2), DEEP_1ST, DIAMOND(4)}, 3}, + { {DEEP_1ST, DIAMOND(4), DIAMOND(5)}, 3}, + { {DIAMOND(4), DIAMOND(5), DEEP_3RD}, 3}, + { {DIAMOND(5), DEEP_3RD, DIAMOND(8)}, 3}, + { {DEEP_3RD, DIAMOND(8), DIAMOND(7)}, 3}, + { {DIAMOND(8), DIAMOND(7), OUT_LEFT}, 3}, + { {DIAMOND(7), OUT_LEFT, OUT_CENTER}, 3}, + { {OUT_LEFT, OUT_CENTER, -1}, 3}, + { {OUT_CENTER, -1, DIAMOND(10)}, 3}, + { {-1, DIAMOND(10), DIAMOND(11)}, 3}, + { {DIAMOND(10), DIAMOND(11), NORMAL_BALL(8)}, 3}, + { {NORMAL_BALL(8), NORMAL_BALL(7)}, 2}, + { {NORMAL_BALL(8), NORMAL_BALL(7), NORMAL_BALL(6)}, 3}, + { {NORMAL_BALL(7), NORMAL_BALL(6), NORMAL_BALL(5)}, 3}, + { {NORMAL_BALL(6), NORMAL_BALL(5), CURVE_BALL(4)}, 3}, + { {NORMAL_BALL(5), CURVE_BALL(3), CURVE_BALL(2)}, 3}, + { {CURVE_BALL(3), CURVE_BALL(2), CURVE_BALL(1)}, 3}, + { {CURVE_BALL(2), CURVE_BALL(1), NORMAL_BALL(1)}, 3}, + { {CURVE_BALL(1), NORMAL_BALL(1), NORMAL_BALL(2)}, 3}, + { {NORMAL_BALL(1), NORMAL_BALL(2), NORMAL_BALL(3)}, 3}, + { {NORMAL_BALL(2), NORMAL_BALL(3), NORMAL_BALL(4)}, 3}, + { {NORMAL_BALL(3), NORMAL_BALL(4)}, 2}, + { {}, 0} +}; -BOOL Baseball_GetPower() +static void ClearBlips() { - return (bPower ? TRUE : FALSE); -} - -void Baseball_PowerOn() -{ - InitGame(); - bPower = TRUE; -} - -void Baseball_PowerOff() -{ - bPower = FALSE; - Baseball_StopSound(); -} - -void Baseball_SetSkill(int i) -{ - if (i == 0) - { - bPro2 = FALSE; - } + int i; + + if(fireWorks) { + fireworks_t *fw=&fw_frames[fireWorks-1]; + + for(i=0; in; i++) { + if(fw->seq[i] != -1) + Baseball_DrawBlip(FALSE,fw->seq[i]); + } + } else { - bPro2 = TRUE; + if(nBallBlip != -1) { + Baseball_DrawBlip(FALSE, nBallBlip); + } + for (i=0; i 0) { + fireworks_t *fw=&fw_frames[fireWorks-1]; + + Baseball_DrawScore(-1, -1); // Clean fireworks + for(i=0; in; i++) { + if(fw->seq[i] == -1) + Baseball_DrawFireWorks(); + else + Baseball_DrawBlip(TRUE,fw->seq[i]); + } + } + else { + if(nBallBlip != -1) { + Baseball_DrawBlip(TRUE, nBallBlip); + } + for (i=0; i 0) - { - Baseball_DrawPitchBlip(TRUE, nEraseIndex, bCurveball); - } - DrawBaseBlips(TRUE); - if (nDefenseBlip != -1) - { - DrawDefenseBlip(nDefenseBlip); - } -} - -static void DrawDefenseBlip(int index) -{ - Baseball_DrawDeepBlip((index == 0) ? TRUE:FALSE, 0); - Baseball_DrawOutfieldBlip((index == 1) ? TRUE:FALSE, 0); - Baseball_DrawOutfieldBlip((index == 2) ? TRUE:FALSE, 1); - Baseball_DrawOutfieldBlip((index == 3) ? TRUE:FALSE, 2); - Baseball_DrawDeepBlip((index == 4) ? TRUE:FALSE, 1); -} - -static void DrawBaseBlips(BOOL bState) -{ - if (bState) - { - for (int i=0; i= 0) && (runners[i].baseindex < HOMEPLATE)) - { - // erase previous blip position - Baseball_DrawBaseBlip(FALSE, runners[i].baseindex); - } + for (int i=0; i= HOMEPLATE) - { + if (runners[i].baseindex >= HOMEPLATE) { // got a run - runners[i].baseindex=-1; - runners[i].enabled=FALSE; - if (i == nCurrentRunnerIndex) - { + runners[i].baseindex = -1; + runners[i].enabled = FALSE; + if (i == nCurrentRunnerIndex) { nCurrentRunnerIndex = -1; } bRun=TRUE; @@ -331,23 +340,19 @@ static BOOL MoveRunners() static void ResetOffBaseRunners() { BOOL bOffBase = FALSE; - for (int i=0; i runners[nRunnerOut].baseindex) - { + else { + if (runners[i].baseindex > runners[nRunnerOut].baseindex) { nRunnerOut = i; } } } } // mark the lead runner out - if (nRunnerOut != -1) - { + if (nRunnerOut != -1) { runners[nRunnerOut].enabled = FALSE; } // figure out if the remaining runners should go to the previous or next base - for (i=0; i 0) { + Baseball_PlaySound(BASEBALL_SOUND_RUN, PLAYSOUNDFLAGS_PRIORITY); + Platform_Pause(200); + --nPendingRuns; + } + bDisplayOff = (nPendingRuns > 0) ? TRUE : FALSE; +} + +// FINITE STATE MACHINE STUFF +static void fsmGoOut(int tu) +{ + static int delay = 0; + + if(delay == 0) { + delay = 1000 * 600; + bDisplayOff = TRUE; + Baseball_PlaySound(BASEBALL_SOUND_OUT, PLAYSOUNDFLAGS_ASYNC|PLAYSOUNDFLAGS_PRIORITY); + Baseball_Clock(1); + } + else if(Baseball_Clock(0) >= delay) { + delay = 0; + bDisplayOff = FALSE; + fsm = FSM_OUT; + } } static void fsmOut(int tu) { ++nOuts; - if (nOuts == 3) - { + if (nOuts == 3) { // end of possession // but first play any pending run sounds - while(nPendingRuns > 0) - { - Baseball_PlaySound(BASEBALL_SOUND_RUN, PLAYSOUNDFLAGS_ASYNC|PLAYSOUNDFLAGS_PRIORITY); - Platform_Pause(600); - --nPendingRuns; - } + if(nPendingRuns > 0) + pendigRunNotify(); nOuts = 0; bHomeTeam = !bHomeTeam; - if (!bHomeTeam) - { + if (!bHomeTeam) { ++nInnings; - if (nInnings == 5) - { + if (nInnings == 5) { // ************************ // ****** GAME OVER ******* // ************************ Baseball_PlaySound(BASEBALL_SOUND_ENDGAME, PLAYSOUNDFLAGS_ASYNC|PLAYSOUNDFLAGS_PRIORITY); - Platform_Pause(200); fsm = FSM_GAMEOVER; return; } } PlatformSetInput(bHomeTeam); - Baseball_PlaySound(BASEBALL_SOUND_ENDPOSSESSION, PLAYSOUNDFLAGS_PRIORITY); - RestoreAllDisplay(); + Baseball_PlaySound(BASEBALL_SOUND_ENDPOSSESSION, PLAYSOUNDFLAGS_PRIORITY|PLAYSOUNDFLAGS_ASYNC); Baseball_DrawStats(-1, -1, nBalls, nStrikes, bHomeTeam); fsm = FSM_ENDPOSSESSION; } - else - { - RestoreAllDisplay(); + else { Baseball_DrawStats(-1, -1, nBalls, nStrikes, bHomeTeam); - nTimerEndPlayWait = (nDefenseBlip == -1) ? (1500/50) : (3000/50); + nStrikes = 0; + nBalls = 0; + nTimerEndPlayWait = (nDefenseBlip == -1) ? 1500 : 3000; + Baseball_Clock(1); fsm = FSM_ENDPLAYWAIT; } - nStrikes = 0; - nBalls = 0; } - -// FINITE STATE MACHINE STUFF - static void fsmIdle(int tu) { // play the run sounds - while(nPendingRuns > 0) - { - Baseball_PlaySound(BASEBALL_SOUND_RUN, PLAYSOUNDFLAGS_ASYNC|PLAYSOUNDFLAGS_PRIORITY); - Platform_Pause(600); - --nPendingRuns; - } + if(nPendingRuns > 0) + pendigRunNotify(); nCurrentRunnerIndex = -1; nDefenseBlip = -1; bCaught = FALSE; - - if (Baseball_GetInputSCORE(NULL)) - { + nBallBlip = -1; + + if (Baseball_GetInputSCORE(NULL)) { Baseball_DrawScore(nVRuns, nHRuns); } - else - { + else { Baseball_DrawStats(nInnings+1, nOuts, nBalls, nStrikes, bHomeTeam); } // wait for pitch button - if (Baseball_GetInputPITCH(NULL)) - { + if (Baseball_GetInputPITCH(NULL)) { // delay from 1.5 to 2.5 seconds (according to manual) // before pitching the ball - - // access of game context info from here is probably not too cool - nTimerPitchWait = (Platform_Random(1000) + 1500) / gGameContext[GAME_BASEBALL].tu; + nTimerPitchWait = 1000 * (1500 + Platform_Random(1000)); // Microsecs + Baseball_Clock(1); fsm = FSM_PITCHWAIT; } - Baseball_DrawBaseBlip(FALSE, 0); - DrawBaseBlips(TRUE); } static void fsmPitchWait(int tu) { Baseball_DrawScore(-1, -1); - - if (nTimerPitchWait > 0) - { - --nTimerPitchWait; - } - - if (nTimerPitchWait <= 0) - { + + if (Baseball_Clock(0) >= nTimerPitchWait) { + int level = Baseball_GetSkill(); + // pick a ball speed and throw style // and pitch the ball - bCurveball = (Platform_Random(3) == 0) ? TRUE : FALSE; - if (bCurveball) - { - nPitchSpeed = Platform_Random(2)+1; // curve balls are a little slower + bCurveball = (Platform_Random(3 - level) == 0) ? TRUE : FALSE; + if (bCurveball) { + nPitchSpeed = (3 - level) + Platform_Random(2 - level); // curve balls are a little slower } - else - { - nPitchSpeed = Platform_Random(3); + else { + nPitchSpeed = (2 - level) + Platform_Random(3 - level); } + + nSwingSlot = nPitchSpeed; + nPitchIndex = 0; + nBallBlip = (bCurveball) ? CURVE_BALL(nPitchIndex) : NORMAL_BALL(nPitchIndex); -#ifdef __PALMOS__ - nPitchSpeed += 7; // PALMOS ONLY -#endif - - nPitchIndex = -1; + bStrike = FALSE; fsm = FSM_PITCHING; } } static void fsmPitching(int tu) { - BOOL bStrike = FALSE; - static int nswing; // swing early=0, center=1, late=2 - int nMissChance = 5; - - if(nPitchIndex == -1) { - Baseball_DrawScore(-1, -1); - nEraseIndex = -1; - nPitchIndex = 0; - nswing = 0; - } + const int nMissChance = 5; - if(nPitchIndex <= 8) - { - if (nEraseIndex != -1) - { - Baseball_DrawPitchBlip(FALSE, nEraseIndex, bCurveball); - } - - Baseball_DrawPitchBlip(TRUE, nPitchIndex, bCurveball); - nEraseIndex = nPitchIndex; - - // check for swing at 3 different points - // we really only need to check 3 times - // when the ball is in the strike zone, but - // we'll do it anyway to keep the timing consistant - - // see HitBall() function for detailed description - // of what it does and what the parameter means - - if (Baseball_GetInputHIT(NULL)) - { - // swing early - switch (nPitchIndex) - { - case 5: - if (Platform_Random(nMissChance)==0) - { - // missed - bStrike = TRUE; - break; - } - else - { - HitBall(0+nswing); - return; - } - case 6: - if (Platform_Random(nMissChance)==0) - { - // missed - bStrike = TRUE; - break; - } - else - { - HitBall(3+nswing); - return; - } - case 7: - if (Platform_Random(nMissChance)==0) - { - // missed - bStrike = TRUE; - break; - } - else - { - HitBall(6+nswing); - return; - } - default: - // strike - bStrike = TRUE; - break; + if(nPitchIndex <= 8) { + if(Baseball_GetInputHIT(NULL)) { + if((nPitchIndex >= 5) && (nPitchIndex <= 7) && (Platform_Random(nMissChance) != 0)) { + fsm = HitBall(); } - } - - if (!bStrike) { - int nDelay = ((nPitchSpeed * 4) / 3) - tu; - - if(nDelay > 0) - Platform_Pause(nDelay); - nswing++; - if(nswing == 3) { - nPitchIndex++; - nswing = 0; + else { + bStrike = TRUE; + nPitchIndex = 9; } } else { - nPitchIndex = 9; + if(--nSwingSlot <= 0) { + nSwingSlot = nPitchSpeed; + ++nPitchIndex; + } } } - - if(nPitchIndex >= 9) { - Platform_Pause(200); - + else { // if player didn't swing, randomly pick strike or ball - if (Platform_Random(2) && !bStrike) - { + if (Platform_Random(2) && !bStrike) { ++nBalls; } - else - { + else { ++nStrikes; } - if (nBalls == 4) - { + if (nBalls == 4) { // walk Baseball_DrawStats(-1, -1, nBalls, nStrikes, bHomeTeam); - Baseball_PlaySound(BASEBALL_SOUND_STRIKE, PLAYSOUNDFLAGS_PRIORITY); - nTimerEndPlayWait = 1500/50; - nTimerRunnerMove = nRunnerSpeed = 10; // walk is always a set speed + Baseball_PlaySound(BASEBALL_SOUND_STRIKE, PLAYSOUNDFLAGS_PRIORITY|PLAYSOUNDFLAGS_ASYNC); + nTimerRunnerMove = nRunnerSpeed = 2 * SPEED_BASE; // walk is always a fixed speed InsertRunner(); fsm = FSM_WALK; } - else if (nStrikes == 3) - { + else if (nStrikes == 3) { // struck out - DoOut(); + fsm = FSM_GOOUT; } - else - { + else { Baseball_DrawStats(-1, -1, nBalls, nStrikes, bHomeTeam); - Baseball_PlaySound(BASEBALL_SOUND_STRIKE, PLAYSOUNDFLAGS_PRIORITY); - nTimerEndPlayWait = 1500/50; + Baseball_PlaySound(BASEBALL_SOUND_STRIKE, PLAYSOUNDFLAGS_PRIORITY|PLAYSOUNDFLAGS_ASYNC); + nTimerEndPlayWait = 1500; fsm = FSM_ENDPLAYWAIT; } } + + if(nPitchIndex <= 8) + nBallBlip = (bCurveball) ? CURVE_BALL(nPitchIndex) : NORMAL_BALL(nPitchIndex); } static void fsmEndPlayWait(int tu) { - if (nTimerEndPlayWait > 0) - { - --nTimerEndPlayWait; - if (nDefenseBlip != -1) - { - // blink fielder if one caught a ball - if (bCaught) - { - static BOOL blink=FALSE; - static int blinkcnt=0; - --blinkcnt; - if (blinkcnt<0) - { - blinkcnt=2; - blink=!blink; - } - if (blink) - { - DrawDefenseBlip(nDefenseBlip); - } - else - { - DrawDefenseBlip(-1); - } - } - else - { - DrawDefenseBlip(nDefenseBlip); - } - } + static int delay = 0; + + if(delay == 0) { + delay = 1000 * nTimerEndPlayWait; + Baseball_Clock(1); } - else - { - // erase the old blips - Baseball_DrawPitchBlip(FALSE, nEraseIndex, bCurveball); - DrawDefenseBlip(-1); - ErasePitchBlips(); - + else if(Baseball_Clock(0) >= delay) { + delay = 0; // reset the runners ResetOffBaseRunners(); - DrawBaseBlips(FALSE); - fsm = FSM_IDLE; } } static void fsmRun(int tu) { - DrawBaseBlips(TRUE); - // RUN does not take effect until you release HIT - if (Baseball_GetInputRUN(NULL) && !Baseball_GetInputHIT(NULL)) - { - if (nTimerRunnerMove > 0) - { - --nTimerRunnerMove; - } - if (nTimerRunnerMove == 0) - { - nTimerRunnerMove = nRunnerSpeed; - if (MoveRunners()) - { - // record runs - if (bHomeTeam) - { - ++nHRuns; - } - else - { - ++nVRuns; - } - // also note the run for later (for the sounds) - ++nPendingRuns; - } - } + if (Baseball_GetInputRUN(NULL) && !Baseball_GetInputHIT(NULL)) { + run(); } - if (nTimerFielding > 0) - { - --nTimerFielding; - } - if (nTimerFielding == 0) - { + if (--nTimerFielding <= 0) { // ball is finished being fielded - // erase the fielder's blip -// nDefenseBlip = -1; -// DrawDefenseBlip(-1); - // ball has been fielded - see if any runners are off base BOOL bOffBase = FALSE; - for (int i=0; i 0) - { - --nTimerRunnerMove; - } - if (nTimerRunnerMove == 0) - { - nTimerRunnerMove = nRunnerSpeed; - if (MoveRunners()) - { - // record runs - if (bHomeTeam) - { - ++nHRuns; - } - else - { - ++nVRuns; - } - // also note the run for later (for the sounds) - ++nPendingRuns; - } - + if (Baseball_GetInputRUN(NULL)) { + if(run() == TRUE) { // when the current runner gets on first, we're done - if (runners[nCurrentRunnerIndex].baseindex == FIRSTBASE) - { + if (runners[nCurrentRunnerIndex].baseindex == FIRSTBASE) { // got someone on first - all done nStrikes = 0; nBalls = 0; - Baseball_DrawPitchBlip(FALSE, 8, FALSE); - DrawDefenseBlip(-1); - ErasePitchBlips(); - fsm = FSM_IDLE; + nTimerEndPlayWait = 1500; + fsm = FSM_ENDPLAYWAIT; } } } @@ -1061,139 +829,14 @@ static void fsmHomeRun(int tu) { static int loop = 0; - trace = fireWorks; if(fireWorks > 0) { // // do fireworks display - // - Platform_Pause(40); - ClearAllDisplay(); + // - switch(fireWorks) { - case 1: // base and fielder blips + if(fireWorks == 1) Baseball_PlaySound(BASEBALL_SOUND_RUN, PLAYSOUNDFLAGS_PRIORITY|PLAYSOUNDFLAGS_ASYNC); - Baseball_DrawBaseBlip(TRUE,1); - break; - case 2: - Baseball_DrawBaseBlip(TRUE,1); - Baseball_DrawBaseBlip(TRUE,2); - break; - case 3: - Baseball_DrawBaseBlip(TRUE,1); - Baseball_DrawBaseBlip(TRUE,2); - Baseball_DrawDeepBlip(TRUE,0); - break; - case 4: - Baseball_DrawBaseBlip(TRUE,2); - Baseball_DrawDeepBlip(TRUE,0); - Baseball_DrawBaseBlip(TRUE,4); - break; - case 5: - Baseball_DrawDeepBlip(TRUE,0); - Baseball_DrawBaseBlip(TRUE,4); - Baseball_DrawBaseBlip(TRUE,5); - break; - case 6: - Baseball_DrawBaseBlip(TRUE,4); - Baseball_DrawBaseBlip(TRUE,5); - Baseball_DrawDeepBlip(TRUE,1); - break; - case 7: - Baseball_DrawBaseBlip(TRUE,5); - Baseball_DrawDeepBlip(TRUE,1); - Baseball_DrawBaseBlip(TRUE,8); - break; - case 8: - Baseball_DrawDeepBlip(TRUE,1); - Baseball_DrawBaseBlip(TRUE,8); - Baseball_DrawBaseBlip(TRUE,7); - break; - case 9: - Baseball_DrawBaseBlip(TRUE,8); - Baseball_DrawBaseBlip(TRUE,7); - Baseball_DrawOutfieldBlip(TRUE,0); - break; - case 10: - Baseball_DrawBaseBlip(TRUE,7); - Baseball_DrawOutfieldBlip(TRUE,0); - Baseball_DrawOutfieldBlip(TRUE,1); - break; - case 11: - Baseball_DrawOutfieldBlip(TRUE,0); - Baseball_DrawOutfieldBlip(TRUE,1); - Baseball_DrawFireWorks(); - break; - case 12: - Baseball_DrawOutfieldBlip(TRUE,1); - Baseball_DrawFireWorks(); - Baseball_DrawBaseBlip(TRUE,10); - break; - case 13: - Baseball_DrawFireWorks(); - Baseball_DrawBaseBlip(TRUE,10); - Baseball_DrawBaseBlip(TRUE,11); - break; - case 14: - Baseball_DrawBaseBlip(TRUE,10); - Baseball_DrawBaseBlip(TRUE,11); - Baseball_DrawPitchBlip(TRUE, 8, FALSE); - break; - case 15: - Baseball_DrawPitchBlip(TRUE, 8, FALSE); - Baseball_DrawPitchBlip(TRUE, 7, FALSE); - break; - case 16: - Baseball_DrawPitchBlip(TRUE, 8, FALSE); - Baseball_DrawPitchBlip(TRUE, 7, FALSE); - Baseball_DrawPitchBlip(TRUE, 6, FALSE); - break; - case 17: - Baseball_DrawPitchBlip(TRUE, 7, FALSE); - Baseball_DrawPitchBlip(TRUE, 6, FALSE); - Baseball_DrawPitchBlip(TRUE, 5, FALSE); - break; - case 18: - Baseball_DrawPitchBlip(TRUE, 6, FALSE); - Baseball_DrawPitchBlip(TRUE, 5, FALSE); - Baseball_DrawPitchBlip(TRUE, 4, TRUE); - break; - case 19: - Baseball_DrawPitchBlip(TRUE, 5, FALSE); - Baseball_DrawPitchBlip(TRUE, 3, TRUE); - Baseball_DrawPitchBlip(TRUE, 2, TRUE); - break; - case 20: - Baseball_DrawPitchBlip(TRUE, 3, TRUE); - Baseball_DrawPitchBlip(TRUE, 2, TRUE); - Baseball_DrawPitchBlip(TRUE, 1, TRUE); - break; - case 21: - Baseball_DrawPitchBlip(TRUE, 2, TRUE); - Baseball_DrawPitchBlip(TRUE, 1, TRUE); - Baseball_DrawPitchBlip(TRUE, 1, FALSE); - break; - case 22: - Baseball_DrawPitchBlip(TRUE, 1, TRUE); - Baseball_DrawPitchBlip(TRUE, 1, FALSE); - Baseball_DrawPitchBlip(TRUE, 2, FALSE); - break; - case 23: - Baseball_DrawPitchBlip(TRUE, 1, FALSE); - Baseball_DrawPitchBlip(TRUE, 2, FALSE); - Baseball_DrawPitchBlip(TRUE, 3, FALSE); - break; - case 24: - Baseball_DrawPitchBlip(TRUE, 2, FALSE); - Baseball_DrawPitchBlip(TRUE, 3, FALSE); - Baseball_DrawPitchBlip(TRUE, 4, FALSE); - break; - case 25: - Baseball_DrawPitchBlip(TRUE, 3, FALSE); - Baseball_DrawPitchBlip(TRUE, 4, FALSE); - break; - case 26: - break; - } + Platform_Pause(40); fireWorks++; if(fireWorks > 26) { @@ -1203,7 +846,7 @@ static void fsmHomeRun(int tu) fireWorks = 0; // insert a runner InsertRunner(); - nTimerRunnerMove = nRunnerSpeed = 10; // fixed run speed + nTimerRunnerMove = nRunnerSpeed = 2 * SPEED_BASE; // fixed run speed } else { fireWorks = 1; @@ -1212,55 +855,22 @@ static void fsmHomeRun(int tu) return; } - DrawBaseBlips(TRUE); - - Baseball_DrawBaseBlip(TRUE, 0); - - if (Baseball_GetInputRUN(NULL)) - { - if (nTimerRunnerMove > 0) - { - --nTimerRunnerMove; - } - if (nTimerRunnerMove == 0) - { - nTimerRunnerMove = nRunnerSpeed; - if (MoveRunners()) - { - // record runs - if (bHomeTeam) - { - ++nHRuns; - } - else - { - ++nVRuns; - } - // also note the run for later (for the sounds) - ++nPendingRuns; - - // see if anyone is still running the bases - BOOL bManOnBase = FALSE; - for (int i=0; i #include "Platform.h" #include "Platform_Baseball.h" @@ -47,15 +47,10 @@ Website : http://www.peterhirschberg.com #define BASEBALL_SOUND_STRIKE 3 #define BASEBALL_SOUND_ENDPOSSESSION 4 #define BASEBALL_SOUND_ENDGAME 5 +#define BASEBALL_SOUND_NSOUNDS 6 - -void Baseball_Run(); -void Baseball_SetSkill(int i); -int Baseball_GetSkill(); -void Baseball_PowerOn(); -void Baseball_PowerOff(); -int Baseball_GetPower(); - +void Baseball_Run(int tu); +void Baseball_Debug(int f); #endif diff --git a/source/game/Basketball.c b/source/game/Basketball.c index 115623d..3f9cf02 100644 --- a/source/game/Basketball.c +++ b/source/game/Basketball.c @@ -131,7 +131,6 @@ static PLAYER defense[NUM_DEFENSEPLAYERS]; p.nColumn++; \ } -static BOOL ISBALL(int x, int y); static BOOL ISBALL(int x, int y) { if ((ball.nColumn == x) @@ -142,7 +141,6 @@ static BOOL ISBALL(int x, int y) return FALSE; } -static BOOL ISPLAYER(int x, int y); static BOOL ISPLAYER(int x, int y) { if ((player.nColumn == x) @@ -153,7 +151,6 @@ static BOOL ISPLAYER(int x, int y) return FALSE; } -static BOOL ISDEFENSE(int x, int y); static BOOL ISDEFENSE(int x, int y) { for (int i=0; i. + */ + +#include "Basketball2.h" +#include "Games.h" + +// constants + +#define GAMETIME 12.0 +#define OVERTIME 5.0 +#define PLAYTIME 24 +#define PLAYTIME2 14 +#define NUM_DEFENSEPLAYERS 5 + +#define TIME_TICKTIMER 10 + +#define TIME_STATSDISPLAY 5 +#define TIME_BALLMOVE 5 +#define TIME_WAITPASSAGE (10 * (4 - nLevel + 1)) +#define TIME_DEFLECT 2 + +#define DMODE_MAN 0 +#define DMODE_ZONE 1 +#define DMODE_PRESS 2 + +typedef struct { + int state; + const int value; +} BLIP; + +static BLIP Blips[BASKETBALL2_BLIP_COLUMNS][BASKETBALL2_BLIP_ROWS] = { + { {0, 3}, {0, 0}, {0, 0}, {0, 3}, {0, 0} }, + { {0, 2}, {0, 0}, {0, 2}, {0, 0}, {0, 0} }, + { {0, 2}, {0, 2}, {0, 0}, {0, 0}, {0, 0} }, + { {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 3} }, + { {0, 2}, {0, 2}, {0, 0}, {0, 0}, {0, 0} }, + { {0, 2}, {0, 0}, {0, 2}, {0, 0}, {0, 0} }, + { {0, 3}, {0, 0}, {0, 0}, {0, 3}, {0, 0} } +}; + +// game variables +static BOOL bGameOver; +static BOOL bHomeTeam; +static BOOL bInFrame = FALSE; +static BOOL bPower; +static int nLevel = -1; +static int nPoints; + +static int nHScore; +static int nVScore; +static float fGameTime; +static int nPlayTime; +static int nQuarter; +static int nTimerTickTimer; +static int n3secTime; +static int nFreeShoot; + +static BOOL bShoot; +static BOOL bPass; +static BOOL bPassed; +static BOOL bInPass; +static BOOL bFoul; +static int nBallDirectionX; +static int nBallDirectionY; +static int nTimerBallMove; +static int nDefenseMode = -1; + +static BOOL bDeflect; +static BOOL nTimerDeflect; + +static int nStatsIndex; +static int nTimerStatsDisplay; + +typedef struct { + int nColumn; + int nRow; + int nBright; + int nColumnOld; + int nRowOld; + int nMoveNow; +}PLAYER; + +static PLAYER ball; +static PLAYER player; +static PLAYER receiver; +static PLAYER defense[NUM_DEFENSEPLAYERS]; + +typedef struct { + int min_x; + int min_y; + int max_x; + int max_y; +} ZONE; + +// macros for dealing with the players + +#define SETPLAYERBRIGHTNESS(p,b) { \ + p.nBright = b; \ +} + +#define NOTECURRENTPLAYERPOSITION(p) { \ + p.nColumnOld = p.nColumn; \ + p.nRowOld = p.nRow; \ +} + +#define SETPLAYER(p,x,y,b) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nColumn = x; \ + p.nRow = y; \ + p.nBright = b; \ +} + +#define UNSETPLAYER(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nBright = BLIP_OFF; \ +} + +#define MOVEPLAYERUP(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nRow--; \ +} +#define MOVEPLAYERDOWN(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nRow++; \ +} +#define MOVEPLAYERLEFT(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nColumn--; \ +} +#define MOVEPLAYERLEFTUP(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nColumn--; \ + p.nRow--;\ +} +#define MOVEPLAYERLEFTDOWN(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nColumn--; \ + p.nRow++; \ +} +#define MOVEPLAYERRIGHT(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nColumn++; \ +} +#define MOVEPLAYERRIGHTUP(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nColumn++; \ + p.nRow--; \ +} +#define MOVEPLAYERRIGHTDOWN(p) { \ + NOTECURRENTPLAYERPOSITION(p); \ + p.nColumn++; \ + p.nRow++; \ +} + +#define IN_ZONE(x, y, z) \ + ((x >= z->min_x && x <= z->max_x) && (y >= z->min_y && ny <= z->max_y)) + +#define IS_SHOOT_POSITION(x,y) ((Blips[x][y].value >= 2) ? 1 : 0) + +#define IS_3SEC_ZONE(x,y) ((x >= 2 && x <= 4) && (y >= 0 && y <= 2)) + +static BOOL ISPLAYER(int x, int y) +{ + if ((player.nColumn == x) + && (player.nRow == y) + && (player.nBright)){ + return TRUE; + } + return FALSE; +} + +static BOOL ISRECEIVER(int x, int y) +{ + if ((receiver.nColumn == x) + && (receiver.nRow == y) + && (receiver.nBright)){ + return TRUE; + } + return FALSE; +} + +static BOOL ISDEFENSE(int x, int y) +{ + for (int i=0; i dx && sx > 0) + x--; + else if(sx < dx && sx < BASKETBALL2_BLIP_COLUMNS-1) + x++; + } + + if(sy != dy) { + if(sy > dy && sy > 0) + y--; + else if(sy < dy && sy < BASKETBALL2_BLIP_ROWS-1) + y++; + } + + if(x != 0 || y != 0) { + if (ISPLAYER(sx+x,sy+y) && IS_SHOOT_POSITION(sx+x,sx+y)){ + if(y > 0) + y = 0; + } + if(ISOCCUPIED(sx+x,sy+y)) { + if(!ISOCCUPIED(sx,sy+y)) + x = 0; + else if (!ISOCCUPIED(sx+x,sy)) + y = 0; + else { + x = 0; + y = 0; + } + } + *nx = sx + x; + *ny = sy + y; + if(x == 0 && y == 0) + return FALSE; + return TRUE; + } + + *nx = sx; + *ny = sy; + return FALSE; +} + +static BOOL ISAGOODPASS() +{ + int x, y; + + x = player.nColumn + nBallDirectionX; + y = player.nRow + nBallDirectionY; + + if(nBallDirectionX == 0) { + while(y != receiver.nRow) { + y += nBallDirectionY; + if(ISDEFENSE(x,y)) { + return 0; + } + } + return 1; + } + if(nBallDirectionY == 0) { + while(x != receiver.nColumn) { + x += nBallDirectionX; + if(ISDEFENSE(x,y)) { + return 0; + } + } + return 1; + } + + while(x != receiver.nColumn && y != receiver.nRow) { + x += nBallDirectionX; + y += nBallDirectionY; + if(ISDEFENSE(x,y)) { + return 0; + } + } + + return 1; +} + +static BOOL probability(int value) +{ + int rtn; + + rtn = (Platform_Random(100) <= ((value/4 * (nLevel + 1)) - Platform_Random(4 - nLevel))) ? TRUE : FALSE; + + return rtn; +} + +static BOOL ISFOUL() +{ + int v = 0; + int d = 0; + + if(ISDEFENSE(player.nColumn,player.nRow-1)) + d++; + else if(ISDEFENSE(player.nColumn,player.nRow+1)) + d++; + else if(ISDEFENSE(player.nColumn-1,player.nRow)) + d++; + else if(ISDEFENSE(player.nColumn+1,player.nRow)) + d++; + + if(d == 0) + return FALSE; + + if((player.nRow == 0) && (player.nColumn == 3)) + v = 80; + else if((player.nRow >= 0 && player.nRow <= 1) && (player.nColumn >= 2 && player.nColumn <= 4)) + v = 40; + else if((player.nRow >= 0 && player.nRow <= 2) && (player.nColumn >= 1 && player.nColumn <= 5)) + v = 20; + else if(player.nRow >= 0 && player.nRow <= 3) + v = 10; + + if(v == 0) + return FALSE; + + if(probability(v)) + return TRUE; + + return FALSE; +} + +static void freethrow_scheme() +{ + SETPLAYER(receiver, ((bHomeTeam) ? 1 : 5), 1, BLIP_DIMBLINK); + SETPLAYER(player, 3, 3, BLIP_BRIGHT); + UNSETPLAYER(ball); + SETPLAYER(defense[0], 1, 0, BLIP_DIM); + SETPLAYER(defense[1], ((bHomeTeam) ? 5 : 1), 1, BLIP_DIM); + SETPLAYER(defense[2], 5, 0, BLIP_DIM); + SETPLAYER(defense[3], 1, 2, BLIP_DIM); + SETPLAYER(defense[4], 5, 2, BLIP_DIM); +} + +static void show_formation() +{ + int i; + + SETPLAYER(receiver, ((bHomeTeam) ? 6 : 0), 4, BLIP_DIMBLINK); + SETPLAYER(player, 3, 4, BLIP_BRIGHT); + UNSETPLAYER(ball); + SETPLAYER(defense[0], 2, 0, BLIP_DIM); + SETPLAYER(defense[1], 4, 0, BLIP_DIM); + SETPLAYER(defense[2], 1, 2, BLIP_DIM); + SETPLAYER(defense[3], 5, 2, BLIP_DIM); + SETPLAYER(defense[4], 3, 3, BLIP_DIM); + + for (i=0; i BASKETBALL2_BLIP_COLUMNS-1) \ + || (p.nColumn < 0) \ + || (p.nRow > BASKETBALL2_BLIP_ROWS-1) \ + || (p.nRow < 0)) + + +#define ISPLAYERENABLED(p) \ + (p.nBright) + +// finite state machine stuff + +static void fsmPlayStartWait(); +static void fsmShowStats(); +static void fsmDefenseWait(); +static void fsmInPlay(); +static void fsmDunk(); +static void fsmGameOver(); +static void fsmFreeThrow(); +static void fsmFoul(); + +static enum FSM { + FSM_PLAYSTARTWAIT=0, + FSM_SHOWSTATS, + FSM_DEFENSEWAIT, + FSM_INPLAY, + FSM_DUNK, + FSM_GAMEOVER, + FSM_FREETHROW, + FSM_FOUL +}fsm; + +typedef void (*FSMFCN)(); + +static FSMFCN fsmfcn[] = { + fsmPlayStartWait, + fsmShowStats, + fsmDefenseWait, + fsmInPlay, + fsmDunk, + fsmGameOver, + fsmFreeThrow, + fsmFoul +}; + +static void InitGame() +{ + bHomeTeam = FALSE; + PlatformSetInput(bHomeTeam); + + nHScore = 0; + nVScore = 0; + fGameTime = GAMETIME; + nQuarter = 0; + bGameOver = FALSE; + bDeflect = FALSE; + + fsm = FSM_DEFENSEWAIT; +} + +static void DrawBlips() +{ + int x, y, nBright; + static BOOL bBlink = FALSE; + + if(fsm != FSM_DUNK) { + for (int i=0; i 0) && (player.nRow > 0) + && (!ISOCCUPIED(player.nColumn-1, player.nRow-1))){ + MOVEPLAYERLEFTUP(player); + } + } + } + else if (Basketball2_GetInputLEFTDOWN(&bChange)) { + if (bChange) + { + if ((player.nColumn > 0) && (player.nRow < (BASKETBALL2_BLIP_ROWS-1)) + && (!ISOCCUPIED(player.nColumn-1, player.nRow+1))){ + MOVEPLAYERLEFTDOWN(player); + } + } + } + else if (Basketball2_GetInputRIGHTUP(&bChange)) { + if (bChange) + { + if ((player.nColumn < (BASKETBALL2_BLIP_COLUMNS-1)) && (player.nRow > 0) + && (!ISOCCUPIED(player.nColumn+1, player.nRow-1))){ + MOVEPLAYERRIGHTUP(player); + } + } + } + else if (Basketball2_GetInputRIGHTDOWN(&bChange)) { + if (bChange) + { + if ((player.nColumn < (BASKETBALL2_BLIP_COLUMNS-1)) && (player.nRow < (BASKETBALL2_BLIP_ROWS-1)) + && (!ISOCCUPIED(player.nColumn+1, player.nRow+1))){ + MOVEPLAYERRIGHTDOWN(player); + } + } + } + else if (Basketball2_GetInputLEFT(&bChange)) + { + if (bChange) + { + if ((player.nColumn > 0) + && (!ISOCCUPIED(player.nColumn-1, player.nRow))){ + MOVEPLAYERLEFT(player); + } + } + } + else if (Basketball2_GetInputRIGHT(&bChange)) + { + if (bChange) + { + if ((player.nColumn < (BASKETBALL2_BLIP_COLUMNS-1)) + && (!ISOCCUPIED(player.nColumn+1, player.nRow))){ + MOVEPLAYERRIGHT(player); + } + } + } + else if (Basketball2_GetInputUP(&bChange)) + { + if (bChange) + { + if ((player.nRow > 0) + && (!ISOCCUPIED(player.nColumn, player.nRow-1))){ + MOVEPLAYERUP(player); + } + } + } + else if (Basketball2_GetInputDOWN(&bChange)) + { + if (bChange) + { + if ((player.nRow < (BASKETBALL2_BLIP_ROWS-1)) + && (!ISOCCUPIED(player.nColumn, player.nRow+1))){ + MOVEPLAYERDOWN(player); + } + } + } + + if (nTimerDeflect) + { + // still in deflect + --nTimerDeflect; + return; + } + + if (Basketball2_GetInputSHOOT(&bChange)) + { + if (bChange) + { + if (!ISPLAYERENABLED(ball)) + { + // shoot! + bShoot = TRUE; + bPassed = FALSE; + bInPass = FALSE; + nTimerBallMove = TIME_BALLMOVE; + SETPLAYERBRIGHTNESS(player, BLIP_DIMBLINK); + SETPLAYER(ball, player.nColumn, player.nRow, BLIP_BRIGHT); + nPoints = Blips[player.nColumn][player.nRow].value; + + if (player.nRow > 0) + nBallDirectionY = -1; + else + nBallDirectionY = 0; + + if (player.nColumn < 3) + nBallDirectionX = 1; + else if(player.nColumn > 3) + nBallDirectionX = -1; + else // player.nColumn == 3 + nBallDirectionX = 0; + + bFoul = ISFOUL(); + } + } + } + + if (Basketball2_GetInputPASS(&bChange)) + { + if (bChange) + { + if (!ISPLAYERENABLED(ball)) + { + int x, y; + + // Pass! + bPass = TRUE; + bInPass = TRUE; + nTimerBallMove = TIME_BALLMOVE; + SETPLAYERBRIGHTNESS(player, BLIP_DIMBLINK); + SETPLAYER(ball, player.nColumn, player.nRow, BLIP_BRIGHT); + + y = player.nRow - receiver.nRow; + x = player.nColumn - receiver.nColumn; + + if(x > 0) + nBallDirectionX = -1; + else if(x < 0) + nBallDirectionX = 1; + else + nBallDirectionX = 0; + + if(y > 0) + nBallDirectionY = -1; + else if(y < 0) + nBallDirectionY = 1; + else + nBallDirectionY = 0; + + bPassed = ISAGOODPASS(); + } + } + } + // move the receiver + moveReceiver(); + + // move defenders + switch(nDefenseMode) { + case DMODE_MAN: + manDefense(); + break; + case DMODE_ZONE: + zoneDefense(); + break; + case DMODE_PRESS: + pressDefense(); + break; + } + + // move the ball + if (ISPLAYERENABLED(ball)) + { + n3secTime = -1; + + // the puck hit a defender last frame - play the sound + if (ISDEFENSE(ball.nColumn, ball.nRow) && !bDeflect && !bPassed) + { + bDeflect = TRUE; + Basketball2_PlaySound(BASKETBALL2_SOUND_BOUNCE, PLAYSOUNDFLAGS_PRIORITY); + nTimerDeflect = TIME_DEFLECT; + return; + } + + if (--nTimerBallMove <= 0) + { + nTimerBallMove = TIME_BALLMOVE; + if (bFoul) { + Basketball2_PlaySound(BASKETBALL2_SOUND_FOUL, PLAYSOUNDFLAGS_PRIORITY); + } + + // check for a basket + if ((ball.nColumn == 3) && (ball.nRow == 0) && !bInPass + && !ISDEFENSE(ball.nColumn, ball.nRow)) // <-- is this right? + { + // basket! + nFreeShoot = (bFoul) ? 1 : 0; + ball.nRow = -1; + Basketball2_DrawBasket(TRUE); + fsm = FSM_DUNK; + return; + } + + // check the foul + if (bFoul) { + nFreeShoot = nPoints; + fsm = FSM_FOUL; + return; + } + + // bounce the ball off the far wall + if (!ISDEFENSE(ball.nColumn, ball.nRow) && !ISRECEIVER(ball.nColumn, ball.nRow)) + { + if ((ball.nRow <= 0) && (ball.nColumn >= 2 && ball.nColumn <= 4) && (nBallDirectionY == -1)) + { + ball.nRow = 0; + nBallDirectionY = 1; + Basketball2_PlaySound(BASKETBALL2_SOUND_BOUNCE, PLAYSOUNDFLAGS_PRIORITY); + nTimerDeflect = TIME_DEFLECT; + bDeflect = FALSE; + return; + } + } + + // bounce the ball off the defenders + if (bDeflect) + { + nBallDirectionX = Platform_Random(3) - 1; + nBallDirectionY = 1; + bDeflect = FALSE; + } + + // see if player has regained possession + if (ISPLAYER(ball.nColumn, ball.nRow) && !bShoot && !bPass) + { + UNSETPLAYER(ball); + SETPLAYERBRIGHTNESS(player, BLIP_BRIGHT); + } + else if (ISRECEIVER(ball.nColumn, ball.nRow)) { + PLAYER tmp; + + bPassed = FALSE; + UNSETPLAYER(ball); + tmp = player; + player = receiver; + receiver = tmp; + SETPLAYERBRIGHTNESS(player, BLIP_BRIGHT); + } + else + { + // move the ball + ball.nColumn += nBallDirectionX; + ball.nRow += nBallDirectionY; + bShoot = FALSE; + bPass = FALSE; + + // see if the ball bounced off the screen + if (ISPLAYEROFFSCREEN(ball) && ISPLAYERENABLED(ball)) + { + // off the screen - get rid of it and end the play + UNSETPLAYER(ball); + SETPLAYERBRIGHTNESS(player, BLIP_BRIGHT); + Basketball2_ClearScreen(); + Basketball2_PlaySound(BASKETBALL2_SOUND_ENDPLAY, PLAYSOUNDFLAGS_PRIORITY); + bHomeTeam = !bHomeTeam; + PlatformSetInput(bHomeTeam); + nStatsIndex = 0; + nTimerStatsDisplay = TIME_STATSDISPLAY; + fsm = FSM_SHOWSTATS; + return; + } + } + } + } + + // 3sec time rule + if(IS_3SEC_ZONE(player.nColumn, player.nRow) && !ISPLAYERENABLED(ball)) { + if(n3secTime == -1) + n3secTime = 3; + } + else + n3secTime = -1; + + // count down the clock + if (Platform_IsNewSecond()){ + // check for end of quarter + if (fGameTime > 0.0){ + fGameTime -= (float).1; + if (fGameTime < 0.1){ + + // end of quarter + ++nQuarter; + + // Overtime needed if nHScore == nVScore + if ((nQuarter >= 4) && (nHScore != nVScore)) + { + // game over + bGameOver = TRUE; + + show_formation(); + + Basketball2_ClearScreen(); + Basketball2_PlaySound(BASKETBALL2_SOUND_ENDGAME, PLAYSOUNDFLAGS_PRIORITY); + nStatsIndex = 0; + nTimerStatsDisplay = TIME_STATSDISPLAY; + fsm = FSM_SHOWSTATS; + return; + } + + bHomeTeam = (nQuarter % 2) ? FALSE : TRUE; + PlatformSetInput(bHomeTeam); + + fGameTime = (nQuarter < 4) ? GAMETIME : OVERTIME; + Basketball2_ClearScreen(); + if(fGameTime == GAMETIME) + Basketball2_PlaySound(BASKETBALL2_SOUND_ENDQUARTER, PLAYSOUNDFLAGS_PRIORITY); + else + Basketball2_PlaySound(BASKETBALL2_SOUND_OVERTIME, PLAYSOUNDFLAGS_PRIORITY); + nStatsIndex = 0; + nTimerStatsDisplay = TIME_STATSDISPLAY; + fsm = FSM_SHOWSTATS; + return; + } + } + // check for 3sec time + if(n3secTime != -1) { + n3secTime--; + if(n3secTime == 0) { + Basketball2_ClearScreen(); + Basketball2_PlaySound(BASKETBALL2_SOUND_3SECS, PLAYSOUNDFLAGS_PRIORITY); + bHomeTeam = !bHomeTeam; + PlatformSetInput(bHomeTeam); + nStatsIndex = 0; + nTimerStatsDisplay = TIME_STATSDISPLAY; + fsm = FSM_SHOWSTATS; + return; + } + } + + // check for end of play timer + if (--nPlayTime < 0){ + Basketball2_ClearScreen(); + Basketball2_PlaySound(BASKETBALL2_SOUND_ENDPLAY, PLAYSOUNDFLAGS_PRIORITY); + bHomeTeam = !bHomeTeam; + PlatformSetInput(bHomeTeam); + nStatsIndex = 0; + nTimerStatsDisplay = TIME_STATSDISPLAY; + fsm = FSM_SHOWSTATS; + return; + } + } + + Basketball2_DrawStat(nPlayTime); + + // make tick sounds + if (fGameTime >= .1){ + if (--nTimerTickTimer <= 0){ + Basketball2_PlaySound(BASKETBALL2_SOUND_TICK, PLAYSOUNDFLAGS_ASYNC); + nTimerTickTimer = TIME_TICKTIMER; + } + } +} + +static void fsmDunk() +{ + switch(nPoints) { + case 1: + Basketball2_PlaySound(BASKETBALL2_SOUND_FREETHROW, PLAYSOUNDFLAGS_PRIORITY); + break; + case 3: + Basketball2_PlaySound(BASKETBALL2_SOUND_SCORE3, PLAYSOUNDFLAGS_PRIORITY); + break; + default: + Basketball2_PlaySound(BASKETBALL2_SOUND_SCORE, PLAYSOUNDFLAGS_PRIORITY); + break; + } + Basketball2_DrawBasket(FALSE); + if (bHomeTeam) + nHScore += nPoints; + else + nVScore += nPoints; + + if(!bFoul) { + show_formation(); + Platform_IsNewSecond(); + fsm = FSM_INPLAY; + } + else { + fsm = FSM_FOUL; + } +} + +static void fsmFoul() +{ + Basketball2_ClearScreen(); + freethrow_scheme(); + fsm = FSM_FREETHROW; +} + +static void fsmFreeThrow() +{ + BOOL bChange; + if (Basketball2_GetInputSHOOT(&bChange)) { + if (bChange) { + nFreeShoot--; + nTimerBallMove = TIME_BALLMOVE; + SETPLAYERBRIGHTNESS(player, BLIP_DIMBLINK); + SETPLAYER(ball, player.nColumn, player.nRow, BLIP_BRIGHT); + } + } + + if (--nTimerBallMove <= 0) { + nTimerBallMove = TIME_BALLMOVE; + + // check for a basket + if (ball.nRow == 0) { + if(nFreeShoot == 0) + bFoul = 0; + // basket! + if(probability(100)) { + nPoints = 1; + ball.nRow = -1; + Basketball2_DrawBasket(TRUE); + fsm = FSM_DUNK; + } + else { + ball.nRow = 1; + nBallDirectionY = 1; + nBallDirectionX = Platform_Random(3) - 1; + Basketball2_PlaySound(BASKETBALL2_SOUND_BOUNCE, PLAYSOUNDFLAGS_PRIORITY); + nTimerDeflect = TIME_DEFLECT; + bDeflect = FALSE; + nPlayTime = PLAYTIME2; + Platform_IsNewSecond(); + fsm = FSM_INPLAY; + } + return; + } + // move the ball + ball.nRow -= 1; + } +} + +static void fsmGameOver() +{ + // show stats if pressed 'down' + BOOL bChange; + if (Basketball2_GetInputDOWN(&bChange)) + { + if (bChange) + { + nStatsIndex = 0; + nTimerStatsDisplay = TIME_STATSDISPLAY; + fsm = FSM_SHOWSTATS; + fsmShowStats(); + return; + } + } + + Basketball2_DrawStat(0); +} + +void Basketball2_Debug(int f) +{ + +} diff --git a/source/game/Basketball2.h b/source/game/Basketball2.h new file mode 100644 index 0000000..9fde46d --- /dev/null +++ b/source/game/Basketball2.h @@ -0,0 +1,55 @@ +/* + * LEDhead for Wii + * Copyright (C) 2017-2020 Nebiun + * + * 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. + * + * 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 3 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. If not, see . + */ + +#ifndef __BASKETBALL2_H__ +#define __BASKETBALL2_H__ + +#include "Platform.h" +#include "Platform_Basketball2.h" + +#define BASKETBALL2_BLIP_ROWS 5 +#define BASKETBALL2_BLIP_COLUMNS 7 + +#define BASKETBALL2_SOUND_TICK 0 +#define BASKETBALL2_SOUND_BOUNCE 1 +#define BASKETBALL2_SOUND_SCORE 2 // Four-note fanfare +#define BASKETBALL2_SOUND_ENDPLAY 3 // Two whistles +#define BASKETBALL2_SOUND_ENDQUARTER 4 // Buzzer +#define BASKETBALL2_SOUND_ENDGAME 5 // Long buzzer +#define BASKETBALL2_SOUND_SCORE3 6 // Double fanfare +#define BASKETBALL2_SOUND_FOUL 7 // One whistle +#define BASKETBALL2_SOUND_3SECS 8 // Three whistles +#define BASKETBALL2_SOUND_FREETHROW 9 // Two-note fanfare +#define BASKETBALL2_SOUND_OVERTIME 10 // Two buzzers +#define BASKETBALL2_SOUND_NSOUNDS 11 + + +void Basketball2_Run(int tu); +void Basketball2_SetSkill(int i); +int Basketball2_GetSkill(); +void Basketball2_PowerOn(); +void Basketball2_PowerOff(); +BOOL Basketball2_GetPower(); +void Basketball2_Debug(int f); + +#endif + diff --git a/source/game/Football.c b/source/game/Football.c index 7892d9a..d8badfd 100644 --- a/source/game/Football.c +++ b/source/game/Football.c @@ -181,18 +181,6 @@ static PLAYER player[NUM_DEFENSEPLAYERS]; } \ } -static BOOL ISBALL(int x, int y); -static BOOL ISBALL(int x, int y) -{ - if ((ball.nColumn == x) - && (ball.nLane == y) - && (ball.nBright)){ - return TRUE; - } - return FALSE; -} - -static BOOL ISDEFENSE(int x, int y); static BOOL ISDEFENSE(int x, int y) { for (int i=0; i FOOTBALL_BLIP_COLUMNS-1) || (p.nColumn < 0)) - - // finite state machine stuff static void fsmFormation(); @@ -263,12 +236,93 @@ static FSMFCN fsmfcn[] = { fsmGameOver }; +static void InitGame() +{ + bHomeTeam = TRUE; + PlatformSetInput(bHomeTeam); + + nHScore = 0; + nVScore = 0; + fGameTime = 15.0; + nDown = 0; + nQuarter = 0; + nCurrentYardline = 100 - 20; + nFirstDownYard = nCurrentYardline - 10; -// proto's -static void InitGame(); -static void DrawBlips(); -static void EraseBlips(); + bDisplayScore = FALSE; + bDisplayTime = FALSE; + bDisplayYard = FALSE; + bDisplayDown = FALSE; + bDisplayBlips = TRUE; + + fsm = FSM_FORMATION; +} +static void DrawBlips() +{ + int x, y, nBright; + static int nBlinkTimer = 0; + static BOOL bBlink = FALSE; + + for (int i=0; i FOOTBALL2_BLIP_COLUMNS-1) || (p.nColumn < 0)) - // finite state machine stuff static void fsmKickoffWait(); @@ -277,8 +270,11 @@ static void fsmPassing(); static void fsmSafety(); static void fsmPlayEnded(); static void fsmGameOver(); +static void fsmTurnover(); +static void fsmOutPlay(); -static enum FSM { +enum FSM { + FSM_INVALID=-1, FSM_KICKOFFWAIT=0, FSM_KICKOFFCHARGE, FSM_KICKOFFMIDAIR, @@ -290,8 +286,12 @@ static enum FSM { FSM_PASSING, FSM_SAFETY, FSM_PLAYENDED, - FSM_GAMEOVER -}fsm; + FSM_GAMEOVER, + FSM_TURNOVER, + FSM_OUTPLAY +}; + +static enum FSM fsm, nextFsm; typedef void (*FSMFCN)(); @@ -307,16 +307,99 @@ static FSMFCN fsmfcn[] = { fsmPassing, fsmSafety, fsmPlayEnded, - fsmGameOver + fsmGameOver, + fsmTurnover, + fsmOutPlay }; +static void InitGame() +{ + bHomeTeam = FALSE; + PlatformSetInput(bHomeTeam); + + nHScore = 0; + nVScore = 0; + fGameTime = 15.0; + nDown = -1; + nQuarter = 0; + nCurrentYardline = 35; -// proto's -static void InitGame(); -static void DrawBlips(); -static void EraseBlips(); + bDisplayScore = FALSE; + bDisplayTime = TRUE; + bDisplayYard = FALSE; + bDisplayDown = FALSE; + bDisplayBlips = TRUE; + + fsm = FSM_KICKOFFWAIT; +} +static void DrawBlips() +{ + int x, y, nBright; + static BOOL blink = FALSE; + for (int i=0; i= 4) && (!bGotFirstDown)){ - + } + if ((++nDown >= 4) && (!bGotFirstDown)){ // give the ball to the other team - bHomeTeam = !bHomeTeam; - PlatformSetInput(bHomeTeam); nDown = 0; ball.nYard = MAX_YARD - ball.nYard; nFirstDownYard = ball.nYard - 10; - - Football2_PlaySound(FOOTBALL2_SOUND_ENDPOSSESSION, PLAYSOUNDFLAGS_PRIORITY); - fsm = FSM_PLAYENDED; + Football2_PlaySound(FOOTBALL2_SOUND_ENDPOSSESSION, PLAYSOUNDFLAGS_PRIORITY); + nextFsm = FSM_PLAYENDED; + fsm = FSM_TURNOVER; return; - - } else { - Football2_PlaySound(FOOTBALL2_SOUND_ENDPLAY, PLAYSOUNDFLAGS_PRIORITY); - fsm = FSM_PLAYENDED; - return; - } - + } + fsm = FSM_OUTPLAY; return; } // move the defense randomly towards the ball - if (Platform_Random(100) < ((bPro2) ? 25 : 15)){ + if (Platform_Random(100) < ((nLevel%2) ? 25 : 15)){ int i = Platform_Random(NUM_DEFENSEPLAYERS); if (player[i].nBright){ // pick horizontal or vertical movement toward the ball @@ -1235,9 +1221,8 @@ static void fsmInPlay() } } - // move the receiver randomly - if (Platform_Random(100) < ((bPro2) ? 15 : 5)){ + if (Platform_Random(100) < ((nLevel%2) ? 15 : 5)){ if (receiver.nBright){ // pick horizontal or vertical movement toward the ball if (Platform_Random(4) == 0){ @@ -1268,7 +1253,6 @@ static void fsmInPlay() } } - // check for collisions again if (ISDEFENSE(ball.nColumn, ball.nLane)){ // tackled! @@ -1291,28 +1275,21 @@ static void fsmInPlay() fsm = FSM_SAFETY; return; - } else if ((++nDown >= 4) && (!bGotFirstDown)){ - + } + if ((++nDown >= 4) && (!bGotFirstDown)){ // give the ball to the other team - bHomeTeam = !bHomeTeam; - PlatformSetInput(bHomeTeam); nDown = 0; ball.nYard = MAX_YARD - ball.nYard; nFirstDownYard = ball.nYard - 10; - Football2_PlaySound(FOOTBALL2_SOUND_ENDPOSSESSION, PLAYSOUNDFLAGS_PRIORITY); - fsm = FSM_PLAYENDED; + nextFsm = FSM_PLAYENDED; + fsm = FSM_TURNOVER; return; - } else { - Football2_PlaySound(FOOTBALL2_SOUND_ENDPLAY, PLAYSOUNDFLAGS_PRIORITY); - fsm = FSM_PLAYENDED; - return; - } - + } + fsm = FSM_OUTPLAY; return; } - // count down the clock if (Platform_IsNewSecond()){ if (fGameTime > 0.0){ @@ -1330,8 +1307,7 @@ static void fsmInPlay() static void fsmPassing() { -static int i = 0; -BOOL bIntercepted = FALSE; + static int i = 0; bDisplayTime = TRUE; bDisplayScore = FALSE; @@ -1361,20 +1337,18 @@ BOOL bIntercepted = FALSE; if ((++nDown >= 4) && (!bGotFirstDown)){ // give the ball to the other team - bHomeTeam = !bHomeTeam; - PlatformSetInput(bHomeTeam); nDown = 0; ball.nYard = MAX_YARD - ball.nYard; nFirstDownYard = ball.nYard - 10; Football2_PlaySound(FOOTBALL2_SOUND_ENDPOSSESSION, PLAYSOUNDFLAGS_PRIORITY); - - } else { - Football2_PlaySound(FOOTBALL2_SOUND_ENDPLAY, PLAYSOUNDFLAGS_PRIORITY); + nextFsm = FSM_PLAYENDED; + fsm = FSM_TURNOVER; + } + else { + fsm = FSM_OUTPLAY; } - Platform_IsNewSecond(); - fsm = FSM_PLAYENDED; } else if (ISDEFENSE(ball.nColumn, ball.nLane)){ @@ -1399,14 +1373,13 @@ BOOL bIntercepted = FALSE; UNMOVEPLAYER(ball); // give the ball to the other team - bHomeTeam = !bHomeTeam; - PlatformSetInput(bHomeTeam); nDown = 0; ball.nYard = MAX_YARD - ball.nYard; nFirstDownYard = ball.nYard - 10; Platform_IsNewSecond(); - fsm = FSM_PLAYENDED; + nextFsm = FSM_PLAYENDED; + fsm = FSM_TURNOVER; } } } @@ -1459,8 +1432,6 @@ static void fsmSafety() ++nQuarter; if (nQuarter == 2){ // halftime - force kickoff - bHomeTeam = !bHomeTeam; - PlatformSetInput(bHomeTeam); ball.nYard = 35; nCurrentYardline = ball.nYard; nFirstDownYard = nCurrentYardline - 35; @@ -1473,11 +1444,11 @@ static void fsmSafety() } fGameTime = 15.0; - fsm = FSM_KICKOFFWAIT; + nextFsm = FSM_KICKOFFWAIT; + fsm = FSM_TURNOVER; return; - } else { - fGameTime = 15.0; - } + } + fGameTime = 15.0; } // add 2 points and set up kickoff from 20 yardline @@ -1486,17 +1457,15 @@ static void fsmSafety() } else { nHScore += 2; } - bHomeTeam = !bHomeTeam; - PlatformSetInput(bHomeTeam); ball.nYard = 20; nCurrentYardline = ball.nYard; nFirstDownYard = nCurrentYardline - 10; - fsm = FSM_KICKOFFWAIT; - fsmKickoffWait(); + nextFsm = FSM_KICKOFFWAIT; + fsm = FSM_TURNOVER; + // fsmKickoffWait(); return; } - } static void fsmPlayEnded() @@ -1554,7 +1523,15 @@ static void fsmGameOver() } - - - - +#define LINE_STEP 20 +void Football2_Debug(int f) +{ + int w, h; + int y = 0; + Football2_GetSize(&w, &h); + + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "level =%d", nLevel); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "fsm =%d", fsm); + y += LINE_STEP; +} diff --git a/source/game/Football2.h b/source/game/Football2.h index aea8d10..7714f9e 100644 --- a/source/game/Football2.h +++ b/source/game/Football2.h @@ -45,23 +45,24 @@ Website : http://www.peterhirschberg.com #define FOOTBALL2_BLIP_ROWS 3 #define FOOTBALL2_BLIP_COLUMNS 10 -#define FOOTBALL2_SOUND_CHARGESTART 0 -#define FOOTBALL2_SOUND_CHARGE 1 +#define FOOTBALL2_SOUND_CHARGESTART 0 +#define FOOTBALL2_SOUND_CHARGE 1 #define FOOTBALL2_SOUND_TICK 2 -#define FOOTBALL2_SOUND_RUNBACK 3 +#define FOOTBALL2_SOUND_RUNBACK 3 #define FOOTBALL2_SOUND_FIRSTDOWN 4 -#define FOOTBALL2_SOUND_ENDPLAY 5 +#define FOOTBALL2_SOUND_ENDPLAY 5 #define FOOTBALL2_SOUND_ENDPOSSESSION 6 -#define FOOTBALL2_SOUND_ENDQUARTER 7 +#define FOOTBALL2_SOUND_ENDQUARTER 7 #define FOOTBALL2_SOUND_TOUCHDOWN 8 -#define FOOTBALL2_SOUND_SAFETY 9 +#define FOOTBALL2_SOUND_SAFETY 9 +#define FOOTBALL2_SOUND_NSOUNDS 10 -void Football2_Run(); +void Football2_Run(int tu); void Football2_SetSkill(int i); int Football2_GetSkill(); void Football2_PowerOn(); void Football2_PowerOff(); int Football2_GetPower(); - +void Football2_Debug(); #endif diff --git a/source/game/Hockey.c b/source/game/Hockey.c index b2f3a01..14f604f 100644 --- a/source/game/Hockey.c +++ b/source/game/Hockey.c @@ -138,18 +138,6 @@ static PLAYER defense[NUM_DEFENSEPLAYERS]; p.nColumn++; \ } -static BOOL ISPUCK(int x, int y); -static BOOL ISPUCK(int x, int y) -{ - if ((puck.nColumn == x) - && (puck.nRow == y) - && (puck.nBright)){ - return TRUE; - } - return FALSE; -} - -static BOOL ISPLAYER(int x, int y); static BOOL ISPLAYER(int x, int y) { if ((player.nColumn == x) @@ -160,7 +148,6 @@ static BOOL ISPLAYER(int x, int y) return FALSE; } -static BOOL ISDEFENSE(int x, int y); static BOOL ISDEFENSE(int x, int y) { for (int i=0; inColumn; int dy = pDefender->nRow; diff --git a/source/game/HockeyCa.h b/source/game/HockeyCa.h index b100945..0b08006 100644 --- a/source/game/HockeyCa.h +++ b/source/game/HockeyCa.h @@ -50,8 +50,9 @@ Website : http://www.peterhirschberg.com #define HOCKEYCA_SOUND_ENDPLAY 3 #define HOCKEYCA_SOUND_ENDQUARTER 4 #define HOCKEYCA_SOUND_ENDGAME 5 +#define HOCKEYCA_SOUND_NSOUNDS 6 -void HockeyCa_Run(); +void HockeyCa_Run(int tu); void HockeyCa_SetSkill(int i); int HockeyCa_GetSkill(); void HockeyCa_PowerOn(); diff --git a/source/game/Soccer.c b/source/game/Soccer.c index 4841a5c..4b3e4f2 100644 --- a/source/game/Soccer.c +++ b/source/game/Soccer.c @@ -33,12 +33,9 @@ Website : http://www.peterhirschberg.com */ - - #include "Soccer.h" #include "Games.h" - // constants #define NUM_DEFENSEPLAYERS 6 @@ -133,18 +130,6 @@ static PLAYER defense[NUM_DEFENSEPLAYERS]; p.nColumn++; \ } -static BOOL ISBALL(int x, int y); -static BOOL ISBALL(int x, int y) -{ - if ((ball.nColumn == x) - && (ball.nRow == y) - && (ball.nBright)){ - return TRUE; - } - return FALSE; -} - -static BOOL ISPLAYER(int x, int y); static BOOL ISPLAYER(int x, int y) { if ((player.nColumn == x) @@ -155,7 +140,6 @@ static BOOL ISPLAYER(int x, int y) return FALSE; } -static BOOL ISDEFENSE(int x, int y); static BOOL ISDEFENSE(int x, int y) { for (int i=0; inColumn; int dy = pDefender->nRow; diff --git a/source/game/Soccer.h b/source/game/Soccer.h index eb3742b..b9571fc 100644 --- a/source/game/Soccer.h +++ b/source/game/Soccer.h @@ -40,7 +40,6 @@ Website : http://www.peterhirschberg.com #include "Platform.h" #include "Platform_Soccer.h" - #define SOCCER_BLIP_ROWS 4 #define SOCCER_BLIP_COLUMNS 5 @@ -50,8 +49,9 @@ Website : http://www.peterhirschberg.com #define SOCCER_SOUND_ENDPLAY 3 #define SOCCER_SOUND_ENDQUARTER 4 #define SOCCER_SOUND_ENDGAME 5 +#define SOCCER_SOUND_NSOUNDS 6 -void Soccer_Run(); +void Soccer_Run(int tu); void Soccer_SetSkill(int i); int Soccer_GetSkill(); void Soccer_PowerOn(); diff --git a/source/game/Soccer2.c b/source/game/Soccer2.c new file mode 100644 index 0000000..d9d4bd3 --- /dev/null +++ b/source/game/Soccer2.c @@ -0,0 +1,1805 @@ +/* + * LEDhead for Wii + * Copyright (C) 2017-2020 Nebiun + * + * 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. + * + * 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 3 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. If not, see . + */ + +#include "Soccer2.h" +#include "Games.h" + +// constants + +#define NUM_DEFENSEPLAYERS 5 +#define TIME_STATSDISPLAY 5 +#define TIME_BALLMOVE 5 +#define GAMETIME 45.9 +#define TIME_TICKTIMER 10 +#define BALL_LOWKICK (3 + Platform_Random(2)) +#define BALL_HIGHKICK (5 + Platform_Random(4)) + +#define IS_GOALAREA() ((nSector == 1) || (nSector == 9)) +#define IS_ATTACKAREA() ((nSector == 1 && bHomeTeam) || (nSector == 9 && !bHomeTeam)) + +typedef struct { + int state; +} BLIP; + +typedef struct { + Coord_t player; + Coord_t receiver; + Coord_t defense[NUM_DEFENSEPLAYERS]; +} SCHEME_t; + +static BLIP Blips[SOCCER2_BLIP_COLUMNS][SOCCER2_BLIP_ROWS]; + +// debug +static int trc_debug; + +// game variables +static BOOL bGameOver; +static BOOL bHomeTeam; +static BOOL bInFrame = FALSE; +static BOOL bPower; +static BOOL bBounce = FALSE; +static BOOL bTeamMate = FALSE; +static BOOL bTeamMateSet = FALSE; +static BOOL bKickKey = FALSE; + +static int nLevel = -1; +static int nHScore; +static int nVScore; +static int fGameTime; +static int nHalf; +static int nTimerTickTimer; +static int nSector; +static int nBallDirectionX; +static int nBallDirectionY; +static int nTimerBallMove; +static int nStatsIndex; +static int nTimerStatsDisplay; +static int nBallStep; +static int nBallMax; + +typedef struct { + int x; + int y; + int side; +}BALL_OUT; +static BALL_OUT ball_out; + +typedef struct { + int nColumn; + int nRow; + int nBright; + int nColumnOld; + int nRowOld; + int nMoveNow; +}PLAYER; + +static PLAYER ball; +static PLAYER player; +static PLAYER receiver; +static PLAYER goalkeeper; +static PLAYER defense[NUM_DEFENSEPLAYERS]; + +// macros for dealing with the players + +#define SETPLAYERBRIGHTNESS(p,b) { \ + (p)->nBright = b; \ +} + +#define NOTECURRENTPLAYERPOSITION(p) { \ + (p)->nColumnOld = (p)->nColumn; \ + (p)->nRowOld = (p)->nRow; \ +} + +#define SETPLAYER(p,x,y,b) { \ + NOTECURRENTPLAYERPOSITION(p); \ + if (x >= 0) { (p)->nColumn = (x) % SOCCER2_BLIP_COLUMNS; } \ + if (y >= 0) { (p)->nRow = (y) % SOCCER2_BLIP_ROWS; } \ + if (b >= 0) { (p)->nBright = b; }\ +} + +#define UNSETPLAYER(p) { \ + (p)->nBright = BLIP_OFF; \ +} + +#define ISPLAYERMOVED(p) (((p)->nColumn != (p)->nColumnOld) || ((p)->nRow != (p)->nRowOld)) + +#define UNMOVEPLAYER(p) { \ + (p)->nRow = (p)->nRowOld; \ + (p)->nColumn = (p)->nColumnOld; \ +} + +#define ISPLAYEROFFSCREEN(p) (!VALID_COLUMN((p)->nColumn) || !VALID_ROW((p)->nRow)) + +#define ISPLAYERENABLED(p) \ + ((p)->nBright) + +#define ISBALL(x,y) generic_check(&ball, x, y) +#define ISPLAYER(x,y) generic_check(&player, x, y) +#define ISRECEIVER(x,y) generic_check(&receiver, x, y) +#define ISGOALKEEPER(x,y) generic_check(&goalkeeper, x, y) + +#define SET_BALLOUT(p) { ball_out.x = (p)->nColumnOld; ball_out.y = (p)->nRowOld; ball_out.side = Platform_Random(2); } + +static BOOL generic_check(PLAYER *p, int x, int y) +{ + if ((p->nColumn == x) + && (p->nRow == y) + && (p->nBright)){ + return TRUE; + } + return FALSE; +} + +static BOOL ISDEFENSE(int x, int y) +{ + for (int i=0; inRow + 1)) { + v = 1; + } + else if(row == (p->nRow - 1)) { + v = -1; + } + else { + v = 0; + } + + c = (flag) ? -1 : 1; + + if(v != 0 && !ISOCCUPIED(p->nColumn,p->nRow+v)) { + rtn = p->nColumn; + } + else if(VALID_COLUMN(p->nColumn+c) && !ISOCCUPIED(p->nColumn+c,p->nRow+v)) { + rtn = p->nColumn+c; + } + else if(VALID_COLUMN(p->nColumn-c) && !ISOCCUPIED(p->nColumn-c,p->nRow+v)) { + rtn = p->nColumn-c; + } + else { + rtn = -1; + } + + return rtn; +} +*/ +static int move_tocol(PLAYER *p, int col, int flag) +{ + int v = 0; + int r, rtn; + + if(col == (p->nColumn + 1)) { + v = 1; + } + else if(col == (p->nColumn - 1)) { + v = -1; + } + else { + v = 0; + } + + r = (flag) ? -1 : 1; + + if(v != 0 && !ISOCCUPIED(p->nColumn+v,p->nRow)) { + rtn = p->nRow; + } + else if(VALID_ROW(p->nRow+r) && !ISOCCUPIED(p->nColumn+v,p->nRow+r)) { + rtn = p->nRow+r; + } + else if(VALID_ROW(p->nRow-r) && !ISOCCUPIED(p->nColumn+v,p->nRow-r)) { + rtn = p->nRow-r; + } + else { + rtn = -1; + } + return rtn; +} + +static BOOL move_around(PLAYER *p) +{ + int x, y; + int x1, y1; + + for(x=0; xnColumn) % SOCCER2_BLIP_COLUMNS; + for(y=0; ynRow) % SOCCER2_BLIP_ROWS; + if(!ISOCCUPIED(x1,y1)) { + SETPLAYER(p, x1, y1, -1); + return TRUE; + } + } + } + + return FALSE; +} + +static BOOL set_goalkeeper() +{ + PLAYER *p; + int x; + + if(nSector == 1 && bHomeTeam) + x = 0; + else if(nSector == 9 && !bHomeTeam) + x = 6; + else { + UNSETPLAYER(&goalkeeper); + return FALSE; + } + if( (p = GETPLAYERAT(x, 2)) != NULL ) { + move_around(p); + } + SETPLAYER(&goalkeeper,x, 2, BLIP_DIM); + return TRUE; +} + +// finite state machine stuff +#define FSM_RUNNING(x) ((x == FSM_INPLAY) || (x == FSM_SHOOTING) || (x == FSM_GOAL) || (x == FSM_PASSING)) +#define next_fsm(x) { if(FSM_RUNNING(x)) {fsm = x; nextFsm = FSM_INVALID; } else { fsm = FSM_WAITSCOREPRESS; nextFsm = x; } } + +static void fsmKickoff(); +static void fsmTurnover(); +static void fsmThrowin(); +static void fsmGoalKick(); +static void fsmCornerKick(); +static void fsmInPlay(); +static void fsmPassing(); +static void fsmShooting(); +static void fsmGameOver(); +static void fsmWaitScorePress(); +static void fsmGoal(); + +enum FSM { + FSM_INVALID = -1, + FSM_KICKOFF = 0, + FSM_TURNOVER, + FSM_THROWIN, + FSM_GOALKICK, + FSM_CORNERKICK, + FSM_INPLAY, + FSM_PASSING, + FSM_SHOOTING, + FSM_GAMEOVER, + FSM_WAITSCOREPRESS, + FSM_GOAL +}; + +static enum FSM fsm, nextFsm; + +typedef void (*FSMFCN)(); + +static FSMFCN fsmfcn[] = { + fsmKickoff, + fsmTurnover, + fsmThrowin, + fsmGoalKick, + fsmCornerKick, + fsmInPlay, + fsmPassing, + fsmShooting, + fsmGameOver, + fsmWaitScorePress, + fsmGoal +}; + +static int probability(int value) +{ + int rtn; + + rtn = (Platform_Random(100) <= ((value/4 * (nLevel + 1)) - Platform_Random(4 - nLevel))) ? 1 : 0; + + return rtn; +} + +static void lost_possession() +{ + bHomeTeam = !bHomeTeam; + PlatformSetInput(bHomeTeam); +} + +static void InitGame() +{ + bHomeTeam = FALSE; + PlatformSetInput(bHomeTeam); + nHScore = 0; + nVScore = 0; + fGameTime = GAMETIME; + nHalf = 0; + bGameOver = FALSE; + nSector = 5; + bTeamMate = FALSE; + bTeamMateSet = FALSE; + bKickKey = FALSE; + + next_fsm(FSM_INVALID); +} + +static void DrawBlips() +{ + static BOOL bBlink = FALSE; + int x, y, nBright; + + for (int i=0; iplayer.x, ps->player.y, BLIP_BRIGHT); + SETPLAYER(&receiver, ps->receiver.x, ps->receiver.y, BLIP_DIMBLINK); + for(i=0; idefense[i].x, ps->defense[i].y, BLIP_DIM); +} + +static void corner_scheme() +{ + static SCHEME_t cl[2] = { + { {6,0}, {6,1}, {{4,0}, {4,1}, {3,2}, {4,3}, {4,4}} }, + { {0,4}, {0,3}, {{2,0}, {2,1}, {3,2}, {2,3}, {2,4}} } + }; + static SCHEME_t cr[2] = { + { {6,4}, {6,3}, {{4,0}, {4,1}, {3,2}, {4,3}, {4,4}} }, + { {0,0}, {0,1}, {{2,0}, {2,1}, {3,2}, {2,3}, {2,4}} } + + }; + SCHEME_t *ps; + int i; + + if(ball_out.x != 0 && ball_out.x != 6) + return; + + if(ball_out.x == 0) { + if(ball_out.y < 3) + ps = &cr[1]; + else if(ball_out.y > 3) + ps = &cl[1]; + else + ps = ball_out.side ? &cr[1] : &cl[1]; + } + else { /* x == 6 */ + if(ball_out.y < 3) + ps = &cl[0]; + else if(ball_out.y < 3) + ps = &cr[0]; + else + ps = ball_out.side ? &cr[0] : &cl[0]; + } + + UNSETPLAYER(&ball); + + SETPLAYER(&player, ps->player.x, ps->player.y, BLIP_BRIGHT); + SETPLAYER(&receiver, ps->receiver.x, ps->receiver.y, BLIP_DIMBLINK); + for(i=0; idefense[i].x, ps->defense[i].y, BLIP_DIM); + + set_goalkeeper(); +} + +static void throwin_scheme() +{ + static SCHEME_t p[] = { + /* player receiver 0 1 2 3 4 */ + { {3,4}, {3,3}, {{1,3}, {2,2}, {3,2}, {4,2}, {5,3}} }, + { {2,4}, {2,3}, {{0,3}, {1,2}, {2,2}, {3,2}, {4,3}} }, + { {1,4}, {1,3}, {{0,2}, {1,2}, {2,2}, {3,3}, {3,4}} }, + { {0,4}, {0,3}, {{0,2}, {1,2}, {2,2}, {2,3}, {2,4}} }, + { {3,0}, {3,1}, {{1,1}, {2,2}, {3,2}, {4,2}, {5,1}} }, + { {2,0}, {2,1}, {{0,1}, {1,2}, {2,2}, {3,2}, {4,1}} }, + { {1,0}, {1,1}, {{0,2}, {1,2}, {2,2}, {3,1}, {3,0}} }, + { {0,0}, {0,1}, {{0,2}, {1,2}, {2,2}, {2,1}, {2,0}} }, + { {6,4}, {6,3}, {{6,2}, {5,2}, {4,2}, {4,3}, {4,4}} }, + { {5,4}, {5,3}, {{6,2}, {5,2}, {4,2}, {3,3}, {3,4}} }, + { {4,4}, {4,3}, {{6,3}, {5,2}, {4,2}, {3,2}, {2,3}} }, + { {6,0}, {6,1}, {{6,2}, {5,2}, {4,2}, {4,1}, {4,0}} }, + { {5,0}, {5,1}, {{6,2}, {5,2}, {4,2}, {3,1}, {3,0}} }, + { {4,0}, {4,1}, {{6,1}, {5,2}, {4,2}, {3,2}, {2,1}} }, + }; + int i; + + UNSETPLAYER(&ball); + + for(i=0; iplayer.x, ps->player.y, BLIP_BRIGHT); + SETPLAYER(&receiver, ps->receiver.x, ps->receiver.y, BLIP_DIMBLINK); + for(i=0; idefense[i].x, ps->defense[i].y, BLIP_DIM); +} + +static void turnover_scheme() +{ + int i; + + UNSETPLAYER(&ball); + + /* Swap blips specularly to middle line */ + SETPLAYER(&player, SOCCER2_BLIP_COLUMNS - 1 - player.nColumn, player.nRow, BLIP_BRIGHT); + SETPLAYER(&receiver, SOCCER2_BLIP_COLUMNS - 1 - receiver.nColumn, receiver.nRow, BLIP_DIMBLINK); + for(i=0; inColumn != dx) { + if(p->nColumn > dx && p->nColumn > 0) + x--; + else if(p->nColumn < dx && p->nColumn < SOCCER2_BLIP_COLUMNS-1) + x++; + } + + if(p->nRow != dy) { + if(p->nRow > dy && p->nRow > 0) + y--; + else if(p->nRow < dy && p->nRow < SOCCER2_BLIP_ROWS-1) + y++; + } + + *nx = p->nColumn + x; + *ny = p->nRow + y; + + return TRUE; +} + +static BOOL IS_ALIGNED(const PLAYER *p1, const PLAYER *p2, int *dx, int *dy) +{ + int x, y; + + x = p2->nColumn - p1->nColumn; + y = p2->nRow - p1->nRow; + + if(dx != NULL) + *dx = x; + if(dy != NULL) + *dy = y; + + if((x == 0) || (y == 0) || (x == y)) + return TRUE; + + return FALSE; +} + +static int moveCounterInit() +{ + int rtn; + + switch(nLevel) { + case LVL_ROOKIEFAST: + rtn = 8 + Platform_Random(12); + break; + case LVL_PROSLOW: + rtn = 4 + Platform_Random(8); + break; + case LVL_PROFAST: + rtn = Platform_Random(4); + break; + case LVL_ROOKIESLOW: + default: + rtn = 12 + Platform_Random(16); + break; + } + return rtn; +} + +static enum FSM move_player(enum FSM curFsm) +{ + enum FSM newFsm = FSM_INVALID; + BOOL bChange; + BOOL moved = FALSE; + BOOL newsect = FALSE; + int col, row; + PLAYER *p; + + p = (bTeamMate || curFsm == FSM_PASSING) ? &receiver : &player; + + NOTECURRENTPLAYERPOSITION(p); + col = p->nColumn; + row = p->nRow; + + if (Soccer2_GetInputLEFTUP(&bChange)) { + if (bChange) { + col -= 1; + row -= 1; + moved = TRUE; + } + } + else if (Soccer2_GetInputLEFTDOWN(&bChange)) { + if (bChange) { + col -= 1; + row += 1; + moved = TRUE; + } + } + else if (Soccer2_GetInputRIGHTUP(&bChange)) { + if (bChange) { + col += 1; + row -= 1; + moved = TRUE; + } + } + else if (Soccer2_GetInputRIGHTDOWN(&bChange)) { + if (bChange) { + col += 1; + row += 1; + moved = TRUE; + } + } + else if (Soccer2_GetInputLEFT(&bChange)) { + if (bChange) { + col -= 1; + moved = TRUE; + } + } + else if (Soccer2_GetInputRIGHT(&bChange)) { + if (bChange) { + col += 1; + moved = TRUE; + } + } + else if (Soccer2_GetInputUP(&bChange)) { + if (bChange) { + row -= 1; + moved = TRUE; + } + } + else if (Soccer2_GetInputDOWN(&bChange)) { + if (bChange) { + row += 1; + moved = TRUE; + } + } + + if(moved == FALSE) + return newFsm; + + if(!VALID_COLUMN(col)) { + moved = FALSE; + + /* Moves between sectors only if 'p' is the player and has the ball */ + if (!ISPLAYERENABLED(&ball) && (p == &player)) { + if(col < 0) { + if(nSector == 1) { + SET_BALLOUT(p); + newFsm = (!bHomeTeam) ? FSM_CORNERKICK : FSM_GOALKICK; + lost_possession(); + } + else if(nSector > 1) { + nSector--; + newsect = TRUE; + col = SOCCER2_BLIP_COLUMNS - 1; + moved = TRUE; + } + } + else if(col >= SOCCER2_BLIP_COLUMNS) { + if(nSector == 9) { + SET_BALLOUT(p); + newFsm = (!bHomeTeam) ? FSM_GOALKICK : FSM_CORNERKICK; + lost_possession(); + } + else if(nSector < 9) { + nSector++; + newsect = TRUE; + col = 0; + moved = TRUE; + } + } + } + } + if (!VALID_ROW(row)) { + moved = FALSE; /* Invalid move */ + } + + if(moved) { + if(newsect) + build_newsector(p, col, row); + else if(!ISOCCUPIED(col, row) || + ISPLAYER(col,row) || ISRECEIVER(col,row)) { + SETPLAYER(p, col, row, -1); + if(bTeamMate) { + bTeamMateSet = TRUE; + } + } + else if(ISBALL(col,row)) { + UNSETPLAYER(&ball); + Soccer2_PlaySound(SOCCER2_SOUND_BOUNCE, PLAYSOUNDFLAGS_PRIORITY); + if(p == &receiver) { + swap_player(&player, &receiver); + } + SETPLAYER(&player, col, row, BLIP_BRIGHT); + SETPLAYERBRIGHTNESS(&receiver, BLIP_DIMBLINK); + } + newFsm = curFsm; + } + + return newFsm; +} + +static BOOL count_down() +{ + // count down the clock + if (Platform_IsNewSecond()){ + // check for end of quarter + if (fGameTime > 0.0){ + fGameTime -= (int).1; + if (fGameTime < 0.1){ + + // end of quarter + ++nHalf; + if (nHalf >= 2) + { + // game over + bGameOver = TRUE; + Soccer2_ClearScreen(); + Soccer2_PlaySound(SOCCER2_SOUND_ENDGAME, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(FSM_GAMEOVER); + return FALSE; + } + + bHomeTeam = (nHalf % 2) ? FALSE : TRUE; + PlatformSetInput(bHomeTeam); + + fGameTime = GAMETIME; + Soccer2_ClearScreen(); + Soccer2_PlaySound(SOCCER2_SOUND_ENDHALF, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(FSM_KICKOFF); + return FALSE; + } + } + } + + Soccer2_DrawSect(nSector, bHomeTeam); + + // make tick sounds + if (fGameTime >= .1){ + if (--nTimerTickTimer <= 0){ + Soccer2_PlaySound(SOCCER2_SOUND_TICK, PLAYSOUNDFLAGS_ASYNC); + nTimerTickTimer = TIME_TICKTIMER; + } + } + return TRUE; +} + +static BOOL move_receiver() +{ + int x, y; + int dx, dy; + + if(!ISPLAYERENABLED(&receiver)) { + return FALSE; + } + + if(bTeamMate || bTeamMateSet) { + return FALSE; + } + + if(IS_ALIGNED(&receiver, &player, &dx, &dy)) { + return FALSE; + } + + if(receiver.nMoveNow-- > 0) { + return FALSE; + } + + x = receiver.nColumn; + y = receiver.nRow; + if(!bHomeTeam) { + if(dx < 0 && x < (SOCCER2_BLIP_COLUMNS - 1)) + x++; + else if(x < (SOCCER2_BLIP_COLUMNS - 1)) + x++; + } + else { + if(dx > 0 && x > 0) + x--; + else if(x > 0) + x--; + } + + if(ISOCCUPIED(x, y)) { + int newy; + + newy = move_tocol(&receiver, x, Platform_Random(2)); + if(newy >= 0) { + y = newy; + } + else { /* Try move only on y axis */ + x = receiver.nColumn; + newy = move_tocol(&receiver, x, Platform_Random(2)); + if(newy >= 0) { + y = newy; + } + } + } + + if(!ISOCCUPIED(x, y)) { + SETPLAYER(&receiver, x, y, BLIP_DIMBLINK); + receiver.nMoveNow = moveCounterInit(); + return TRUE; + } + + receiver.nMoveNow = 0; /* Try to move next time */ + return FALSE; +} + +static void initDefense() +{ + int i; + + for(i=0; i < NUM_DEFENSEPLAYERS; i++) { + defense[i].nMoveNow = moveCounterInit(); + } +} + +static BOOL passing() +{ + int x, y; + + if (ISPLAYERENABLED(&ball)) + return FALSE; + + Soccer2_PlaySound((bKickKey) ? SOCCER2_SOUND_LOWKICK : SOCCER2_SOUND_HIGHKICK, PLAYSOUNDFLAGS_PRIORITY); + + y = player.nRow - receiver.nRow; + x = player.nColumn - receiver.nColumn; + + if(abs(x) == abs(y)) { + if(y > 0) + nBallDirectionY = -1; + else if(y < 0) + nBallDirectionY = 1; + else + nBallDirectionY = 0; + + if(x > 0) + nBallDirectionX = -1; + else if(x < 0) + nBallDirectionX = 1; + else + nBallDirectionX = 0; + } + else if(abs(x) > abs(y)) { + nBallDirectionY = 0; + if(x > 0) + nBallDirectionX = -1; + else if(x < 0) + nBallDirectionX = 1; + } + else { + nBallDirectionX = 0; + if(y > 0) + nBallDirectionY = -1; + else if(y < 0) + nBallDirectionY = 1; + } + + SETPLAYER(&ball, player.nColumn, player.nRow, BLIP_BRIGHT); + UNSETPLAYER(&player); + + nBallStep = 0; + nBallMax = (bKickKey) ? BALL_HIGHKICK : BALL_LOWKICK; + nTimerBallMove = TIME_BALLMOVE; + return TRUE; +} + +static BOOL shooting() +{ + if (ISPLAYERENABLED(&ball)) + return FALSE; + + Soccer2_PlaySound((bKickKey) ? SOCCER2_SOUND_LOWKICK : SOCCER2_SOUND_HIGHKICK, PLAYSOUNDFLAGS_PRIORITY); + + nBallDirectionX = (!bHomeTeam) ? 1 : -1; + if(IS_ATTACKAREA()) { + if(player.nRow > 2) + nBallDirectionY = -1; + else if(player.nRow < 2) + nBallDirectionY = 1; + else + nBallDirectionY = 0; + } + else { + nBallDirectionY = 0; + } + + SETPLAYER(&ball, player.nColumn, player.nRow, BLIP_BRIGHT); + + UNSETPLAYER(&receiver); + SETPLAYERBRIGHTNESS(&player, BLIP_DIMBLINK); + + nBallStep = 0; + nBallMax = (bKickKey) ? BALL_HIGHKICK : BALL_LOWKICK; + nTimerBallMove = TIME_BALLMOVE; + return TRUE; +} + +static int bounce(enum FSM curFsm) +{ + bBounce = TRUE; + + /* On sector 1 or 9, on shoot or passage it can be corner kick */ + if( IS_ATTACKAREA() ) { + if( (curFsm == FSM_SHOOTING) && probability(50) ) { + nBallDirectionX = (bHomeTeam) ? -1 : 1; + } + else if((curFsm == FSM_PASSING) && probability(25)) { + nBallDirectionX = (bHomeTeam) ? -1 : 1; + } + else { + nBallDirectionX = (bHomeTeam) ? 1 : -1; + } + } + else { + if((curFsm == FSM_PASSING) && probability(15)) + nBallDirectionX = (bHomeTeam) ? -1 : 1; + else + nBallDirectionX = (bHomeTeam) ? 1 : -1; + } + + if(probability(20)) + nBallDirectionY = 0; + else if(probability(40)) + nBallDirectionY = -1; + else if(probability(40)) + nBallDirectionY = 1; + + nBallStep = 0; + nBallMax = (Platform_Random(2)) ? BALL_HIGHKICK : BALL_LOWKICK; + Soccer2_PlaySound(SOCCER2_SOUND_BOUNCE, PLAYSOUNDFLAGS_PRIORITY); + + SETPLAYERBRIGHTNESS(&player, BLIP_DIMBLINK); + SETPLAYERBRIGHTNESS(&receiver, BLIP_DIMBLINK); + nTimerBallMove = TIME_BALLMOVE; + return 0; +} + +static enum FSM move_defense(enum FSM curFsm) +{ + Coord_t gk = {0, 0}; + Coord_t df[NUM_DEFENSEPLAYERS]; + enum FSM newFsm = curFsm; + int i, nx, ny; + + gk.x = goalkeeper.nColumn; + gk.y = goalkeeper.nRow; + for(i=0; i 0 && ball.nRow < 4)) { + gk.y = ball.nRow; + } + } + for(i=0; i gk.y) + gk.y++; + } + else if(player.nRow > 0 && player.nRow < 4) { + if((!bHomeTeam && player.nColumn == 5) || (bHomeTeam && player.nColumn == 1)) { + gk.x = player.nColumn; + gk.y = player.nRow; + } + else { + gk.x = goalkeeper.nColumn; + gk.y = player.nRow; + } + } + else { + if(player.nRow == 2) + gk.y = 2; + else + gk.y = 2 + (player.nRow < 2) ? -1 : 1; + } + } + } + for(i=0; i= nBallMax)) { + SETPLAYERBRIGHTNESS(&player, BLIP_DIMBLINK); + SETPLAYERBRIGHTNESS(&receiver, BLIP_OFF); + bBounce = FALSE; + return FSM_INPLAY; + } + + // move the ball + NOTECURRENTPLAYERPOSITION(&ball); + ball.nColumn += nBallDirectionX; + ball.nRow += nBallDirectionY; + nBallStep++; + + /* Check if is off-screen */ + if (ISPLAYEROFFSCREEN(&ball)) { + /* Choose throwin or goalkick */ + if(!VALID_COLUMN(ball.nColumn)) { + if(nSector > 1 && nBallDirectionX < 0) { + if(nBallDirectionY == 0) { + nSector--; + build_newsector(&ball, SOCCER2_BLIP_COLUMNS - 1, ball.nRow); + } + else { + nBallStep = nBallMax; + ball.nColumn = 0; + ball.nRow = ball.nRowOld; + } + } + else if(nSector < 9 && nBallDirectionX > 0) { + if(nBallDirectionY == 0) { + nSector++; + build_newsector(&ball, 0, ball.nRow); + } + else { + nBallStep = nBallMax; + ball.nColumn = 6; + ball.nRow = ball.nRowOld; + } + } + else { + SET_BALLOUT(&ball); + UNSETPLAYER(&ball); + if(!bBounce) { + lost_possession(); + return FSM_GOALKICK; + } + bBounce = FALSE; + return FSM_CORNERKICK; + } + } + if(!VALID_ROW(ball.nRow)) { + SET_BALLOUT(&ball); + UNSETPLAYER(&ball); + if(!bBounce) { + lost_possession(); + } + else { + bBounce = FALSE; + } + return FSM_THROWIN; + } + } + /* Check if goal */ + if(((fsm == FSM_SHOOTING) || (fsm == FSM_PASSING)) && + ((nSector == 1 && ball.nColumn == 0 && ball.nRow == 2) || + (nSector == 9 && ball.nColumn == 6 && ball.nRow == 2))) { + bBounce = FALSE; + if(bKickKey == TRUE) { + if(ISGOALKEEPER(ball.nColumn,ball.nRow)) { + if(probability(70)) { + SET_BALLOUT(&ball); + lost_possession(); + return FSM_GOALKICK; + } + } + else if(ISDEFENSE(ball.nColumn,ball.nRow)) { + if(probability(20)) { + bounce(curFsm); + return FSM_INPLAY; + } + return FSM_GOAL; + } + else if(probability(30)) { + SET_BALLOUT(&ball); + bBounce = FALSE; + lost_possession(); + return FSM_GOALKICK; + } + return FSM_GOAL; + } + if (ISGOALKEEPER(ball.nColumn, ball.nRow)) { + lost_possession(); + return FSM_GOALKICK; + } + return FSM_GOAL; + } + + /* non goal */ + if( (bKickKey == FALSE) || + (bKickKey == TRUE && (nBallStep == 1 || nBallStep == nBallMax)) ) { + /* Check if bounced by defender or goalkeeper */ + if (ISGOALKEEPER(ball.nColumn, ball.nRow)) { + if(curFsm == FSM_PASSING || probability(50)) { + SET_BALLOUT(&ball); + bBounce = FALSE; + lost_possession(); + return FSM_GOALKICK; + } + bounce(curFsm); + return FSM_INPLAY; + } + if (ISDEFENSE(ball.nColumn, ball.nRow)) { + if(curFsm == FSM_PASSING) { + bounce(curFsm); + return FSM_INPLAY; + } + if(probability(50)) { + lost_possession(); + return FSM_TURNOVER; + } + bounce(curFsm); + return FSM_INPLAY; + } + /* Check if receiver has gained possession */ + if (ISRECEIVER(ball.nColumn, ball.nRow)) { + UNSETPLAYER(&ball); + bBounce = FALSE; + Soccer2_PlaySound(SOCCER2_SOUND_BOUNCE, PLAYSOUNDFLAGS_PRIORITY); + /* Swap player and receiver */ + swap_player(&player, &receiver); + + SETPLAYERBRIGHTNESS(&player, BLIP_BRIGHT); + SETPLAYERBRIGHTNESS(&receiver, BLIP_DIMBLINK); + return FSM_INPLAY; + } + } + + /* Check if player has regained possession */ + if (ISPLAYER(ball.nColumn, ball.nRow)) { + UNSETPLAYER(&ball); + bBounce = FALSE; + Soccer2_PlaySound(SOCCER2_SOUND_BOUNCE, PLAYSOUNDFLAGS_PRIORITY); + SETPLAYERBRIGHTNESS(&player, BLIP_BRIGHT); + SETPLAYERBRIGHTNESS(&receiver, BLIP_DIMBLINK); + return FSM_INPLAY; + } + } + } + else { + bBounce = FALSE; + } + return curFsm; +} + +int Soccer2_GetPower() +{ + return (bPower ? TRUE : FALSE); +} + +void Soccer2_PowerOn() +{ + if (!bPower) + { + InitGame(); + bPower = TRUE; + } +} + +void Soccer2_PowerOff() +{ + bPower = FALSE; + Soccer2_StopSound(); +} + +void Soccer2_SetSkill(int i) +{ + nLevel = i; +} + +int Soccer2_GetSkill() +{ + return nLevel; +} + +void Soccer2_Run(int tu) +{ + int x, y; + + // prevent reentrancy + if (bInFrame){ + return; + } + bInFrame = TRUE; + + // turn off all blips + for (y = 0; y < SOCCER2_BLIP_ROWS; y++){ + for (x = 0; x < SOCCER2_BLIP_COLUMNS; x++){ + Blips[x][y].state = BLIP_OFF; + } + } + + if (!bPower){ + Soccer2_ClearScreen(); + bInFrame = FALSE; + return; + } + + Platform_StartDraw(); + + // run the game + (fsmfcn[fsm])(); + + DrawBlips(); + + Platform_EndDraw(); + + bInFrame = FALSE; +} + +// FINITE STATE MACHINE STUFF +static void fsmWaitScorePress() +{ + static BOOL pressed = FALSE; + BOOL bChange; + + if(nextFsm == FSM_INVALID) { + kickoff_scheme(); + nextFsm = FSM_KICKOFF; + } + + if(pressed == FALSE) { + Soccer2_DrawSect(nSector, bHomeTeam); + if (Soccer2_GetInputSCORE(&bChange)) { + if (bChange) { + pressed = TRUE; + nStatsIndex = 0; + nTimerStatsDisplay = TIME_STATSDISPLAY; + if(nextFsm != FSM_KICKOFF) + EraseBlips(); + } + } + } + else { + if (--nTimerStatsDisplay <= 0) + { + ++nStatsIndex; + nTimerStatsDisplay = TIME_STATSDISPLAY; + } + switch(nStatsIndex) { + case 0: + Soccer2_DrawStat(-1); + break; + case 1: + Soccer2_DrawStat(nVScore); + break; + case 2: + Soccer2_DrawStat(-1); + break; + case 3: + Soccer2_DrawStat(nHScore); + break; + case 4: + Soccer2_DrawStat(-1); + break; + case 5: + Soccer2_DrawStat((int)fGameTime); + break; + case 6: + Soccer2_DrawStat(-1); + break; + case 7: + Soccer2_DrawSect(nSector, bHomeTeam); + break; + default: + initDefense(); + receiver.nMoveNow = moveCounterInit(); + pressed = FALSE; + bTeamMate = FALSE; + bTeamMateSet = FALSE; + bKickKey = FALSE; + bBounce = FALSE; + fsm = nextFsm; + nextFsm = FSM_INVALID; + switch(fsm) { + case FSM_KICKOFF: + kickoff_scheme(); + break; + case FSM_CORNERKICK: + corner_scheme(); + break; + case FSM_GOALKICK: + goalkick_scheme(); + break; + case FSM_THROWIN: + throwin_scheme(); + break; + case FSM_TURNOVER: + turnover_scheme(); + default: + break; + } + break; + } + } +} + +static void fsmKickoff() +{ + BOOL bChange; + + kickoff_scheme(); + + if(Soccer2_GetInputPASS(&bChange)) { + if (bChange) { + Platform_IsNewSecond(); + if(passing() == TRUE) { + next_fsm(FSM_PASSING); + } + } + } + + Soccer2_DrawSect(nSector, bHomeTeam); +} + +static void fsmTurnover() +{ + enum FSM newFsm; + + newFsm = move_player(fsm); + if(newFsm != FSM_INVALID) { + Platform_IsNewSecond(); + next_fsm(FSM_INPLAY); + } +} + +static void fsmThrowin() +{ + BOOL bChange; + + if(Soccer2_GetInputPASS(&bChange)) { + if (bChange) { + Platform_IsNewSecond(); + if(passing() == TRUE) { + next_fsm(FSM_PASSING); + } + } + } + if(IS_LVLPRO(nLevel)) { + if (Soccer2_GetInputTEAM(&bChange)) { + if (bChange) { + bTeamMate = !bTeamMate; + if(bTeamMate == TRUE) + Soccer2_PlaySound(SOCCER2_SOUND_BEEP, PLAYSOUNDFLAGS_PRIORITY); + } + } + if (Soccer2_GetInputSCORE(&bChange)) { + if (bChange) { + bTeamMateSet = FALSE; + } + } + /* Can move the receiver */ + if(bTeamMate == TRUE) { + move_player(FSM_THROWIN); + } + } + Soccer2_DrawSect(nSector, bHomeTeam); +} + +static void fsmGoalKick() +{ + BOOL bChange; + + if(Soccer2_GetInputPASS(&bChange)) { + if (bChange) { + Platform_IsNewSecond(); + if(passing() == TRUE) { + next_fsm(FSM_PASSING); + } + } + } + + Soccer2_DrawSect(nSector, bHomeTeam); +} + +static void fsmCornerKick() +{ + BOOL bChange; + + if(Soccer2_GetInputPASS(&bChange)) { + if (bChange) { + Platform_IsNewSecond(); + if(passing() == TRUE) { + next_fsm(FSM_PASSING); + } + } + } + if(IS_LVLPRO(nLevel)) { + if (Soccer2_GetInputTEAM(&bChange)) { + if (bChange) { + bTeamMate = !bTeamMate; + if(bTeamMate == TRUE) + Soccer2_PlaySound(SOCCER2_SOUND_BEEP, PLAYSOUNDFLAGS_PRIORITY); + } + } + if (Soccer2_GetInputSCORE(&bChange)) { + if (bChange) { + bTeamMateSet = FALSE; + } + } + /* Can move the receiver */ + if(bTeamMate == TRUE) { + move_player(FSM_CORNERKICK); + } + } + + Soccer2_DrawSect(nSector, bHomeTeam); +} + +static void fsmInPlay() +{ + enum FSM newFsm; + BOOL bChange; + + newFsm = move_player(fsm); + if(newFsm == FSM_INVALID) { + if (Soccer2_GetInputSHOOT(&bChange)) { + if (bChange) { + if(shooting() == TRUE) { + next_fsm(FSM_SHOOTING); + return; + } + } + } + + if (Soccer2_GetInputPASS(&bChange)) { + if (bChange) { + if(passing() == TRUE) { + next_fsm(FSM_PASSING); + return; + } + } + } + + if(IS_LVLPRO(nLevel)) { + if (Soccer2_GetInputTEAM(&bChange)) { + if (bChange) { + bTeamMate = !bTeamMate; + if(bTeamMate == TRUE) + Soccer2_PlaySound(SOCCER2_SOUND_BEEP, PLAYSOUNDFLAGS_PRIORITY); + } + } + if (Soccer2_GetInputSCORE(&bChange)) { + if (bChange) { + bTeamMateSet = FALSE; + } + } + if (Soccer2_GetInputKICK(&bChange)) { + if (bChange) { + bKickKey = !bKickKey; + Soccer2_PlaySound((bKickKey) ? SOCCER2_SOUND_LOWKICK : SOCCER2_SOUND_HIGHKICK, PLAYSOUNDFLAGS_PRIORITY); + } + } + } + } + else if(newFsm != FSM_INPLAY) { + if(!FSM_RUNNING(newFsm)) + Soccer2_PlaySound(SOCCER2_SOUND_BALLOUT, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(newFsm); + return; + } + + // move the receiver + move_receiver(); + + // move defenders + newFsm = move_defense(fsm); + if(!FSM_RUNNING(newFsm)) + Soccer2_PlaySound(SOCCER2_SOUND_BALLOUT, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(newFsm); + + // count down the clock + count_down(); +} + +static void fsmPassing() +{ + enum FSM newFsm; + BOOL bChange; + + newFsm = move_player(fsm); + if(newFsm == FSM_INVALID) { + if (Soccer2_GetInputKICK(&bChange) && IS_LVLPRO(nLevel)) { + if (bChange) { + bKickKey = !bKickKey; + Soccer2_PlaySound((bKickKey) ? SOCCER2_SOUND_LOWKICK : SOCCER2_SOUND_HIGHKICK, PLAYSOUNDFLAGS_PRIORITY); + } + } + } + else if(newFsm != FSM_PASSING) { + if(!FSM_RUNNING(newFsm)) + Soccer2_PlaySound(SOCCER2_SOUND_BALLOUT, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(newFsm); + return; + } + // move defenders + if(bKickKey) { + newFsm = move_defense(fsm); + if(!FSM_RUNNING(newFsm)) + Soccer2_PlaySound(SOCCER2_SOUND_BALLOUT, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(newFsm); + } + // move the ball + if(fsm == FSM_PASSING) { + newFsm = move_ball(fsm); + if(!FSM_RUNNING(newFsm)) + Soccer2_PlaySound(SOCCER2_SOUND_BALLOUT, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(newFsm); + } + + // count down the clock + count_down(); +} + +static void fsmShooting() +{ + enum FSM newFsm; + BOOL bChange; + + newFsm = move_player(fsm); + if(newFsm == FSM_INVALID) { + if (Soccer2_GetInputKICK(&bChange) && IS_LVLPRO(nLevel)) { + if (bChange) { + bKickKey = !bKickKey; + Soccer2_PlaySound((bKickKey) ? SOCCER2_SOUND_LOWKICK : SOCCER2_SOUND_HIGHKICK, PLAYSOUNDFLAGS_PRIORITY); + } + } + } + else if(newFsm != FSM_SHOOTING) { + if(!FSM_RUNNING(newFsm)) + Soccer2_PlaySound(SOCCER2_SOUND_BALLOUT, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(newFsm); + return; + } + + // move defenders + if(bKickKey) { + newFsm = move_defense(fsm); + if(!FSM_RUNNING(newFsm)) + Soccer2_PlaySound(SOCCER2_SOUND_BALLOUT, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(newFsm); + } + // move the ball + if(fsm == FSM_SHOOTING) { + newFsm = move_ball(fsm); + if(!FSM_RUNNING(newFsm)) + Soccer2_PlaySound(SOCCER2_SOUND_BALLOUT, PLAYSOUNDFLAGS_PRIORITY); + next_fsm(newFsm); + } + + // count down the clock + count_down(); +} + +static void fsmGameOver() +{ + next_fsm(FSM_GAMEOVER); +} + +static void fsmGoal() +{ + Soccer2_PlaySound(SOCCER2_SOUND_GOAL, PLAYSOUNDFLAGS_PRIORITY); + if(!bHomeTeam) + nVScore++; + else + nHScore++; + nSector = 5; + lost_possession(); + + next_fsm(FSM_KICKOFF); +} + +#define LINE_STEP 20 +void Soccer2_Debug(int f) +{ + int w, h; + int y = 0; + Soccer2_GetSize(&w, &h); + + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "level =%d", nLevel); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "fsm =%d (%d)", fsm, FSM_RUNNING(fsm)); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "nx fsm =%d (%d)", nextFsm, FSM_RUNNING(nextFsm)); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "bnc=%d kk=%d", + bBounce, bKickKey); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "tm=%d tms=%d", + bTeamMate, bTeamMateSet); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "trc =%d", trc_debug); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "ball =%d (%d,%d)(%d,%d)", + ball.nBright, ball.nColumn, ball.nRow, ball.nColumnOld, ball.nRowOld); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "play =%d (%d,%d)(%d,%d)", + player.nBright, player.nColumn, player.nRow, player.nColumnOld, player.nRowOld); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "recv =%d (%d,%d)(%d,%d)", + receiver.nBright, receiver.nColumn, receiver.nRow, receiver.nColumnOld, receiver.nRowOld); + y += LINE_STEP; +} diff --git a/source/game/Soccer2.h b/source/game/Soccer2.h new file mode 100644 index 0000000..7245545 --- /dev/null +++ b/source/game/Soccer2.h @@ -0,0 +1,54 @@ +/* + * LEDhead for Wii + * Copyright (C) 2017-2020 Nebiun + * + * 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. + * + * 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 3 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. If not, see . + */ + +#ifndef __SOCCER2_H__ +#define __SOCCER2_H__ + +#include "Platform.h" +#include "Platform_Soccer2.h" + +#define SOCCER2_BLIP_ROWS 5 +#define SOCCER2_BLIP_COLUMNS 7 +#define VALID_COLUMN(x) ( ((x)>=0) && ((x) < SOCCER2_BLIP_COLUMNS) ) +#define VALID_ROW(y) ( ((y)>=0) && ((y) < SOCCER2_BLIP_ROWS) ) + +#define SOCCER2_SOUND_TICK 0 // Time +#define SOCCER2_SOUND_LOOSEBALL 1 // Loose ball +#define SOCCER2_SOUND_BALLOUT 2 // Defense stole ball or ball out +#define SOCCER2_SOUND_GOAL 3 // Goal Scored +#define SOCCER2_SOUND_BEEP 4 // Offense in sec.1 ore Teammate controlled +#define SOCCER2_SOUND_HIGHKICK 5 // High shot & high pass +#define SOCCER2_SOUND_LOWKICK 6 // Low shot & low pass or defense kick +#define SOCCER2_SOUND_ENDHALF 7 // End of the half +#define SOCCER2_SOUND_ENDGAME 8 // End of the game +#define SOCCER2_SOUND_BOUNCE 9 // Bounce (or ball is caught or bounced by anyone) +#define SOCCER2_SOUND_NSOUNDS 10 // Total sounds + +void Soccer2_Run(int tu); +void Soccer2_SetSkill(int i); +int Soccer2_GetSkill(); +void Soccer2_PowerOn(); +void Soccer2_PowerOff(); +int Soccer2_GetPower(); +void Soccer2_Debug(int f); + +#endif diff --git a/source/game/SpaceAlert.c b/source/game/SpaceAlert.c index c10388c..8ba334c 100644 --- a/source/game/SpaceAlert.c +++ b/source/game/SpaceAlert.c @@ -33,12 +33,9 @@ Website : http://www.peterhirschberg.com */ - - #include "SpaceAlert.h" #include "Games.h" - // constants #define TIME_ATTACKWAVE 20 @@ -55,11 +52,8 @@ static BLIP Blips[SPACEALERT_BLIP_COLUMNS][SPACEALERT_BLIP_ROWS]; typedef struct tagRaider { int nColumn; int nRow; - int nSlow; - BOOL bAttacking; - BOOL bLeftColumn; BOOL bMidColumn; BOOL bRightColumn; @@ -67,7 +61,6 @@ typedef struct tagRaider { static RAIDER sRaiderA, sRaiderB; - // game variables static int nColumnSelector; static int nCurrentMissileRow; @@ -77,7 +70,6 @@ static int nTimerAttackWave; static int nRaiderCount; static int nPoints; static BOOL bGameOver; -static BOOL bWin; static BOOL bInFrame = FALSE; static BOOL bPower; @@ -85,10 +77,36 @@ static void InitGame(); static void InitAttack(); static void DoMissileUpdate(); static void DoRaidersUpdate(); -static void DoHitTest(); +static BOOL DoHitTest(); static void UpdateBlips(); static void PaintGame(); +static void fsmPlayStartWait(); +static void fsmInPlay(); +static void fsmHit(); +static void fsmScore(); +static void fsmWin(); +static void fsmLose(); + +static enum FSM { + FSM_PLAYSTARTWAIT=0, + FSM_INPLAY, + FSM_HIT, + FSM_SCORE, + FSM_WIN, + FSM_LOSE +}fsm; + +typedef void (*FSMFCN)(); + +static FSMFCN fsmfcn[] = { + fsmPlayStartWait, + fsmInPlay, + fsmHit, + fsmScore, + fsmWin, + fsmLose +}; BOOL SpaceAlert_GetPower() { @@ -110,7 +128,6 @@ void SpaceAlert_PowerOff() void InitGame() { - nColumnSelector = 1; nCurrentMissileRow = SPACEALERT_BLIP_ROWS - 1; @@ -121,21 +138,35 @@ void InitGame() nTimerAttackWave = 1; nPoints = 0; - + bGameOver = FALSE; - bWin = TRUE; - sRaiderA.bAttacking = FALSE; - + fsm = FSM_PLAYSTARTWAIT; } +static void PaintGame() +{ + if (bPower){ + // draw the blips field + for (int y = 0; y < SPACEALERT_BLIP_ROWS; y++){ + for (int x = 0; x < SPACEALERT_BLIP_COLUMNS; x++){ + SpaceAlert_DrawBlip(Blips[x][y], x, y); + } + } + + // draw the score + SpaceAlert_DrawScore(nPoints); + } +} void SpaceAlert_Run(int tu) { int x, y; // prevent reentrancy - if (bInFrame){ return; } + if (bInFrame) + return; + bInFrame = TRUE; // init the blips field @@ -144,74 +175,37 @@ void SpaceAlert_Run(int tu) Blips[x][y] = BLIP_OFF; } } - if (bPower){ - if (bGameOver){ - // handle game over - static BOOL bFlash = 0; - if (bWin){ - // win - Blips[0][SPACEALERT_BLIP_ROWS-2] = BLIP_BRIGHT; - Blips[1][SPACEALERT_BLIP_ROWS-2] = BLIP_BRIGHT; - Blips[2][SPACEALERT_BLIP_ROWS-2] = BLIP_BRIGHT; - } else { - // lose - if (bFlash){ - bFlash = FALSE; - Blips[1][SPACEALERT_BLIP_ROWS-1] = BLIP_BRIGHT; - } else { - bFlash = TRUE; - } - } - - // allow stick and fire button to be moved - SpaceAlert_GetInputFIRE(NULL); - SpaceAlert_GetInputSTICK(); - - // draw the frame - PaintGame(); - bInFrame = FALSE; - return; - } - } else { - - // allow stick and fire button to be moved - SpaceAlert_GetInputFIRE(NULL); - SpaceAlert_GetInputSTICK(); - - SpaceAlert_ClearScreen(); - bInFrame = FALSE; - return; + if (!bPower){ + fsm = FSM_PLAYSTARTWAIT; } + Platform_StartDraw(); - // get the current stick position - nColumnSelector = SpaceAlert_GetInputSTICK(); + (fsmfcn[fsm])(); - { - DoHitTest(); + UpdateBlips(); - DoRaidersUpdate(); + PaintGame(); - UpdateBlips(); - PaintGame(); - - DoHitTest(); - - DoMissileUpdate(); - } - - bInFrame = FALSE; + Platform_EndDraw(); + bInFrame = FALSE; } +static void cleanall() +{ + sRaiderA.bAttacking = FALSE; + sRaiderB.bAttacking = FALSE; + nCurrentMissileRow = -1; + SpaceAlert_ClearScreen(); + SpaceAlert_StopRaiderSound(); +} -void DoMissileUpdate() +static void DoMissileUpdate() { // update the missiles - if (SpaceAlert_GetInputFIRE(NULL)) - { + if (SpaceAlert_GetInputFIRE(NULL)) { // fire - if (nCurrentMissileRow == (SPACEALERT_BLIP_ROWS - 1)) - { + if (nCurrentMissileRow == (SPACEALERT_BLIP_ROWS - 1)) { SpaceAlert_PlaySound(SPACEALERT_SOUND_FIRE, PLAYSOUNDFLAGS_ASYNC | PLAYSOUNDFLAGS_PRIORITY); --nCurrentMissileRow; return; @@ -219,30 +213,29 @@ void DoMissileUpdate() } // move any active missiles - if (nCurrentMissileRow < (SPACEALERT_BLIP_ROWS - 1)) - { + if (nCurrentMissileRow < (SPACEALERT_BLIP_ROWS - 1)) { if (nCurrentMissileRow >= MISSILE_LIMIT){ // move missile up the screen --nCurrentMissileRow; - } else { + } + else { // missile has hit its limit offscreen -- show new missile nCurrentMissileRow = SPACEALERT_BLIP_ROWS - 1; } } } -void DoRaidersUpdate() +static void DoRaidersUpdate() { - // update the attack if (nTimerAttackWave > 0){ --nTimerAttackWave; if (nTimerAttackWave == 0){ // start a new attack wave - nIndexAttackWave = 0; InitAttack(); } - } else { + } + else { nTimerAttackWave = 0; } @@ -260,7 +253,8 @@ void DoRaidersUpdate() // handle the slow raiders if (sRaiderP->nSlow == 1){ sRaiderP->nSlow = 2; - } else { + } + else { sRaiderP->nSlow = 1; } } @@ -277,83 +271,67 @@ void DoRaidersUpdate() --nRaiderCount; if (sRaiderP->nColumn == 1){ - // battlestart hit -- lose // draw a blank screen during the tune - sRaiderA.bAttacking = FALSE; - sRaiderB.bAttacking = FALSE; - nCurrentMissileRow = -1; - SpaceAlert_ClearScreen(); - SpaceAlert_StopRaiderSound(); - SpaceAlert_PlaySound(SPACEALERT_SOUND_LOSE, PLAYSOUNDFLAGS_PRIORITY); - bGameOver = TRUE; - bWin = FALSE; + cleanall(); + fsm = FSM_LOSE; return; } - else if (nRaiderCount <= 0){ - + if (nRaiderCount <= 0){ // no more raiders -- win // draw a blank screen during the tune - sRaiderA.bAttacking = FALSE; - sRaiderB.bAttacking = FALSE; - nCurrentMissileRow = -1; - SpaceAlert_ClearScreen(); - SpaceAlert_StopRaiderSound(); - SpaceAlert_PlaySound(SPACEALERT_SOUND_WIN, PLAYSOUNDFLAGS_PRIORITY); - bGameOver = TRUE; - bWin = TRUE; + cleanall(); + fsm = FSM_WIN; return; - - } else { - // set up next wave - nTimerAttackWave = TIME_ATTACKWAVE; } - + // set up next wave + nTimerAttackWave = TIME_ATTACKWAVE; } // change lanes randomly (don't change on last rows) - if (sRaiderP->nRow < SPACEALERT_BLIP_ROWS - 2){ + // but not in the first wave + if ((nIndexAttackWave > 1) && (sRaiderP->nRow < SPACEALERT_BLIP_ROWS - 2)) { if (Platform_Random(7) == 0){ // can only be in each column once per attack switch(sRaiderP->nColumn){ - case 0: - sRaiderP->bLeftColumn = TRUE; - if ((!sRaiderP->bMidColumn) - && (sOtherRaiderP->nColumn != 1) + case 0: + sRaiderP->bLeftColumn = TRUE; + if ((!sRaiderP->bMidColumn) + && (sOtherRaiderP->nColumn != 1) + && (sRaiderP->nRow != sOtherRaiderP->nRow)) + { + sRaiderP->nColumn = 1; + } + break; + case 1: + sRaiderP->bMidColumn = TRUE; + if (Platform_Random(2)) + { + if ((!sRaiderP->bLeftColumn) + && (sOtherRaiderP->nColumn != 0) && (sRaiderP->nRow != sOtherRaiderP->nRow)) { - sRaiderP->nColumn = 1; + sRaiderP->nColumn = 0; } - break; - case 1: - sRaiderP->bMidColumn = TRUE; - if (Platform_Random(2)) - { - if ((!sRaiderP->bLeftColumn) - && (sOtherRaiderP->nColumn != 0) - && (sRaiderP->nRow != sOtherRaiderP->nRow)) - { - sRaiderP->nColumn = 0; - } - } else { - if ((!sRaiderP->bRightColumn) - && (sOtherRaiderP->nColumn != 2) - && (sRaiderP->nRow != sOtherRaiderP->nRow)) - { - sRaiderP->nColumn = 2; - } - } - break; - case 2: - sRaiderP->bRightColumn = TRUE; - if ((!sRaiderP->bMidColumn) - && (sOtherRaiderP->nColumn != 1) + } else { + if ((!sRaiderP->bRightColumn) + && (sOtherRaiderP->nColumn != 2) && (sRaiderP->nRow != sOtherRaiderP->nRow)) { - sRaiderP->nColumn = 1; + sRaiderP->nColumn = 2; } - break; + } + break; + case 2: + sRaiderP->bRightColumn = TRUE; + if ((!sRaiderP->bMidColumn) + && (sOtherRaiderP->nColumn != 1) + && (sRaiderP->nRow != sOtherRaiderP->nRow)) + { + sRaiderP->nColumn = 1; + } + break; } } } @@ -368,15 +346,14 @@ void DoRaidersUpdate() } else { SpaceAlert_StopRaiderSound(); } - } -void DoHitTest() +static BOOL DoHitTest() { if (nCurrentMissileRow < 0) { // missile is off screen - return; + return FALSE; } for (int i=0; i<2; i++){ @@ -389,63 +366,18 @@ void DoHitTest() && (nColumnSelector == 1)){ // don't count 0 point hits to center column if not fired } else { - // hit a raider sRaiderP->bAttacking = FALSE; - UpdateBlips(); - - // draw the blips field (minus the score) - { - SpaceAlert_ClearScreen(); - Platform_StartDraw(); - - for (int y = 0; y < SPACEALERT_BLIP_ROWS; y++){ - for (int x = 0; x < SPACEALERT_BLIP_COLUMNS; x++){ - SpaceAlert_DrawBlip(Blips[x][y], x, y); - } - } - - Platform_EndDraw(); - } - - - SpaceAlert_PlaySound(SPACEALERT_SOUND_HIT, PLAYSOUNDFLAGS_PRIORITY); - - // add the score - nPoints += (SPACEALERT_BLIP_ROWS-1) - nCurrentMissileRow; - - // recharge the missile - nCurrentMissileRow = SPACEALERT_BLIP_ROWS - 1; - - --nRaiderCount; - - if (nRaiderCount <= 0){ - // no more raiders -- win - // draw a blank screen during the tune - sRaiderA.bAttacking = FALSE; - sRaiderB.bAttacking = FALSE; - nCurrentMissileRow = -1; - SpaceAlert_ClearScreen(); - SpaceAlert_StopRaiderSound(); - SpaceAlert_PlaySound(SPACEALERT_SOUND_WIN, PLAYSOUNDFLAGS_PRIORITY); - bGameOver = TRUE; - bWin = TRUE; - return; - } else { - // set up next wave - nTimerAttackWave = TIME_ATTACKWAVE - ((Platform_Random(4) == 0) ? (TIME_ATTACKWAVE / 2) : 0); - } - - + fsm = FSM_HIT; + return TRUE; } - } } } + return FALSE; } - -void UpdateBlips() +static void UpdateBlips() { // draw the raider blips for (int i=0; i<2; i++){ @@ -463,40 +395,21 @@ void UpdateBlips() && (nCurrentMissileRow >= 0)){ Blips[nColumnSelector][nCurrentMissileRow] = BLIP_BRIGHT; } - } -void PaintGame() -{ - Platform_StartDraw(); - - // draw the blips field - for (int y = 0; y < SPACEALERT_BLIP_ROWS; y++){ - for (int x = 0; x < SPACEALERT_BLIP_COLUMNS; x++){ - SpaceAlert_DrawBlip(Blips[x][y], x, y); - } - } - - // draw the score - if (bPower){ - SpaceAlert_DrawScore(nPoints); - } - - Platform_EndDraw(); -} - - void InitAttack() { + nIndexAttackWave++; + sRaiderA.nRow = -2; sRaiderA.nSlow = Platform_Random(3); - sRaiderA.nColumn = Platform_Random(3); + sRaiderA.nColumn = (nIndexAttackWave > 1) ? Platform_Random(3) : 1; sRaiderA.bAttacking = TRUE; sRaiderA.bLeftColumn = FALSE; sRaiderA.bMidColumn = FALSE; sRaiderA.bRightColumn = FALSE; - if ((Platform_Random(2) == 0) && (nRaiderCount > 1)){ + if((nIndexAttackWave > 1) && (Platform_Random(2) == 0) && (nRaiderCount > 1)){ // dual attack @@ -522,3 +435,100 @@ void InitAttack() } } +static void fsmPlayStartWait() +{ + // allow stick and fire button to be moved + SpaceAlert_GetInputFIRE(NULL); + SpaceAlert_GetInputSTICK(); + + if (bPower){ + fsm = FSM_INPLAY; + } +} + +static void fsmInPlay() +{ + // get the current stick position + nColumnSelector = SpaceAlert_GetInputSTICK(); + + if(DoHitTest() == TRUE) + return; + DoMissileUpdate(); + if(DoHitTest() == TRUE) + return; + DoRaidersUpdate(); +} + +static void fsmHit() +{ + SpaceAlert_PlaySound(SPACEALERT_SOUND_HIT, PLAYSOUNDFLAGS_PRIORITY); + SpaceAlert_ClearScreen(); + fsm = FSM_SCORE; +} + +static void fsmScore() +{ + + // add the score + nPoints += (SPACEALERT_BLIP_ROWS-1) - nCurrentMissileRow; + + // recharge the missile + nCurrentMissileRow = SPACEALERT_BLIP_ROWS - 1; + + --nRaiderCount; + + if (nRaiderCount <= 0){ + // no more raiders -- win + // draw a blank screen during the tune + cleanall(); + fsm = FSM_WIN; + return; + } + + // set up next wave + nTimerAttackWave = TIME_ATTACKWAVE - ((Platform_Random(4) == 0) ? (TIME_ATTACKWAVE / 2) : 0); + + fsm = FSM_INPLAY; +} + +static void fsmWin() +{ + + if(bGameOver == FALSE) { + bGameOver = TRUE; + SpaceAlert_PlaySound(SPACEALERT_SOUND_WIN, PLAYSOUNDFLAGS_PRIORITY); + } + else { + Blips[0][SPACEALERT_BLIP_ROWS-2] = BLIP_BRIGHT; + Blips[1][SPACEALERT_BLIP_ROWS-2] = BLIP_BRIGHT; + Blips[2][SPACEALERT_BLIP_ROWS-2] = BLIP_BRIGHT; + } +} + +static void fsmLose() +{ + static BOOL bFlash = FALSE; + + if(bGameOver == FALSE) { + bGameOver = TRUE; + SpaceAlert_PlaySound(SPACEALERT_SOUND_LOSE, PLAYSOUNDFLAGS_PRIORITY); + } + else { + if (bFlash) + Blips[1][SPACEALERT_BLIP_ROWS-1] = BLIP_BRIGHT; + bFlash = !bFlash; + } +} + +#define LINE_STEP 20 +void SpaceAlert_Debug(int f) +{ + int w, h; + int y = 0; + SpaceAlert_GetSize(&w, &h); + + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "wave =%d", nTimerAttackWave); + y += LINE_STEP; + debugPrintf(realx(w)+10, realy(y), 0xFFFFFFFF, "index =%d", nIndexAttackWave); + y += LINE_STEP; +} \ No newline at end of file diff --git a/source/game/SpaceAlert.h b/source/game/SpaceAlert.h index 2d27cb7..5eb9502 100644 --- a/source/game/SpaceAlert.h +++ b/source/game/SpaceAlert.h @@ -49,12 +49,13 @@ Website : http://www.peterhirschberg.com #define SPACEALERT_SOUND_LOSE 2 #define SPACEALERT_SOUND_WIN 3 #define SPACEALERT_SOUND_RAIDER 4 +#define SPACEALERT_SOUND_NSOUNDS 5 -void SpaceAlert_Run(); +void SpaceAlert_Run(int tu); void SpaceAlert_PowerOn(); void SpaceAlert_PowerOff(); BOOL SpaceAlert_GetPower(); - +void SpaceAlert_Debug(int f); #endif diff --git a/source/game/SubChase.c b/source/game/SubChase.c index c88c5a1..cce16dd 100644 --- a/source/game/SubChase.c +++ b/source/game/SubChase.c @@ -177,9 +177,6 @@ void SubChase_Run(int tu) } // run the game - - BOOL bHit = FALSE; - BOOL bChange; if (SubChase_GetInputLEFT(&bChange)) { diff --git a/source/game/SubChase.h b/source/game/SubChase.h index 66ceaf0..2737b60 100644 --- a/source/game/SubChase.h +++ b/source/game/SubChase.h @@ -47,8 +47,9 @@ Website : http://www.peterhirschberg.com #define SUBCHASE_SOUND_CHARGE 1 #define SUBCHASE_SOUND_HIT 2 #define SUBCHASE_SOUND_SINK 3 +#define SUBCHASE_SOUND_NSOUNDS 4 -void SubChase_Run(); +void SubChase_Run(int tu); void SubChase_SetSkill(int i); int SubChase_GetSkill(); void SubChase_PowerOn(); diff --git a/source/gear.c b/source/gear.c new file mode 100644 index 0000000..cd164e1 --- /dev/null +++ b/source/gear.c @@ -0,0 +1,68 @@ +/* + * LEDhead for Wii + * Copyright (C) 2017-2020 Nebiun + * + * 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. + * + * 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 3 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. If not, see . + */ + +#include "LED_Handled.h" +#include "slide1_png.h" +static GRRLIB_texImg *_gear_slide = NULL; + +void destroy_gear(void) +{ + if(_gear_slide != NULL) { + GRRLIB_FreeTexture(_gear_slide); + _gear_slide = NULL; + } +} + +int draw_gear(int x, int y, int pos) +{ + + int yy; + + if(_gear_slide == NULL) { + _gear_slide = GRRLIB_LoadTexture(slide1_png); + if(_gear_slide == NULL) { + return -1; + } + } + switch(pos) { + case 1: + yy = 3; + break; + case 2: + yy = 19; + break; + case 3: + yy = 37; + break; + case 4: + yy = 53; + break; + default: + yy = -1; + break; + } + + if(yy != -1) + GRRLIB_DrawImg(realx(x), realy(y+yy), _gear_slide, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); + + return 0; +} diff --git a/source/main.c b/source/main.c index e451d8c..30c93d1 100644 --- a/source/main.c +++ b/source/main.c @@ -2,6 +2,10 @@ * LEDhead for Wii * Copyright (C) 2017-2020 Nebiun * + * 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. + * * 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 3 of the License, or @@ -15,6 +19,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include #include "LED_Handled.h" #include "Games.h" @@ -24,15 +29,19 @@ #include "WKRD_png.h" #include "WKLU_png.h" -//#define CHECK_PAINTTIME 1 -//#define PRINT_TRACE 1 +f32 _scale_x = 1; +f32 _scale_y = 1; -#ifdef CHECK_PAINTTIME -struct timeval tv1, tv2; -long delta_usec, max_delta; +//#define CHECK_PAINTTIME 1 +//#define PRINT_COUNTER 1 + +#ifdef CHECK_PAINTTIME +static struct timeval tv1, tv2; +static long delta_usec, max_delta; +#endif +#ifdef PRINT_COUNTER +unsigned int counter; #endif - -int trace = 0; static int elapsed = 0; static void timerProc(syswd_t alarm, void *arg) @@ -57,7 +66,7 @@ int main(int argc, char **argv) GRRLIB_texImg *post_screen = NULL; GRRLIB_texImg *next, *prev; GRRLIB_texImg *logo; - u16 btn, last_btn = -1; + u32 btn, last_btn = -1; int help_on = 0; GRRLIB_Init(); @@ -95,9 +104,9 @@ int main(int argc, char **argv) WPAD_ScanPads(); changed = 0; - btn = WPAD_ButtonsHeld(0); + btn = WPAD_ButtonsDown(0); - if(last_btn == -1 || btn != last_btn) { + if((last_btn == -1) || (btn != last_btn)) { last_btn = btn; if(btn & WPAD_BUTTON_A) { @@ -137,10 +146,7 @@ int main(int argc, char **argv) if(delta_usec > max_delta) max_delta = delta_usec; - debugPrintf(300, 60, 0xFFFFFFFF, "run us=%d (max %d)", delta_usec, max_delta); -#endif -#ifdef PRINT_TRACE - debugPrintf(300, 30, 0xFFFFFFFF, "trc=%d", trace); + debugPrintf(realx(game_screen->w)+10, realy(400), 0xFFFFFFFF, "run us=%d (max %d)", delta_usec, max_delta); #endif } #ifdef CHECK_PAINTTIME @@ -152,7 +158,7 @@ int main(int argc, char **argv) delta_usec = tv2.tv_sec - tv1.tv_sec; delta_usec = 1000000 * delta_usec + tv2.tv_usec - tv1.tv_usec; - debugPrintf(300, 90, 0xFFFFFFFF, "paint us=%d", delta_usec); + debugPrintf(realx(game_screen->w)+10, realy(420), 0xFFFFFFFF, "paint us=%d", delta_usec); #endif if(Platform_SoundIsOff()) print_text(realx(0), realy(game_screen->h + 30), 0xFFFFFFFF, "(mute)"); @@ -162,6 +168,9 @@ int main(int argc, char **argv) } Platform_KeyShow(realx(0), realy(game_screen->h + 60), WK_HOME); print_text(realx(0 + 30), realy(game_screen->h + 60), 0xFFFFFFFF, "exit game"); + + if(gCurrentGame->Debug != NULL) + gCurrentGame->Debug(0); GRRLIB_Render(); } gCurrentGame->DeInit(); @@ -231,10 +240,10 @@ int main(int argc, char **argv) print_text(realx(0 + 30), realy(game_screen->h + 90), 0xFFFFFFFF, "for keys map"); if(help_on == 1 && gCurrentGame->Help != NULL) gCurrentGame->Help(); -#ifdef PRINT_TRACE - debugPrintf(300, 30, 0xFFFFFFFF, "trc=%d",trace); -#endif } +#ifdef PRINT_COUNTER + debugPrintf(realx(240)+10, realy(340), 0xFFFFFFFF, "%08d %d",counter++,btn); +#endif GRRLIB_Render(); } diff --git a/source/platform/Platform.c b/source/platform/Platform.c index 89dd6a0..5b62fa9 100644 --- a/source/platform/Platform.c +++ b/source/platform/Platform.c @@ -132,6 +132,9 @@ void Platform_StopSound() ASND_StopVoice(0); } +// Wii input code +#define WPAD_BUTTON_DIRECTION_MASK (WPAD_BUTTON_UP|WPAD_BUTTON_DOWN|WPAD_BUTTON_LEFT|WPAD_BUTTON_RIGHT) + static u32 btn; static int wpad = 0; @@ -169,37 +172,60 @@ int PlatformSetInput(int pad) return -1; } -int PlatformGetInput() -{ - return wpad; -} - BOOL Platform_GetInputUP() { if(btn & WPAD_BUTTON_B) return 0; - return (btn & WPAD_BUTTON_RIGHT); + return ((btn & WPAD_BUTTON_DIRECTION_MASK) == WPAD_BUTTON_RIGHT); } BOOL Platform_GetInputDOWN() { if(btn & WPAD_BUTTON_B) return 0; - return (btn & WPAD_BUTTON_LEFT); + return ((btn & WPAD_BUTTON_DIRECTION_MASK) == WPAD_BUTTON_LEFT); } BOOL Platform_GetInputLEFT() { if(btn & WPAD_BUTTON_B) return 0; - return (btn & WPAD_BUTTON_UP); + return ((btn & WPAD_BUTTON_DIRECTION_MASK) == WPAD_BUTTON_UP); +} + +BOOL Platform_GetInputLEFTUP() +{ + if(btn & WPAD_BUTTON_B) + return 0; + return ((btn & WPAD_BUTTON_DIRECTION_MASK) == (WPAD_BUTTON_UP|WPAD_BUTTON_RIGHT)); +} + +BOOL Platform_GetInputLEFTDOWN() +{ + if(btn & WPAD_BUTTON_B) + return 0; + return ((btn & WPAD_BUTTON_DIRECTION_MASK) == (WPAD_BUTTON_UP|WPAD_BUTTON_LEFT)); } BOOL Platform_GetInputRIGHT() { if(btn & WPAD_BUTTON_B) return 0; - return (btn & WPAD_BUTTON_DOWN); + return ((btn & WPAD_BUTTON_DIRECTION_MASK) == WPAD_BUTTON_DOWN); +} + +BOOL Platform_GetInputRIGHTUP() +{ + if(btn & WPAD_BUTTON_B) + return 0; + return ((btn & WPAD_BUTTON_DIRECTION_MASK) == (WPAD_BUTTON_DOWN|WPAD_BUTTON_RIGHT)); +} + +BOOL Platform_GetInputRIGHTDOWN() +{ + if(btn & WPAD_BUTTON_B) + return 0; + return ((btn & WPAD_BUTTON_DIRECTION_MASK) == (WPAD_BUTTON_DOWN|WPAD_BUTTON_LEFT)); } BOOL Platform_GetInput2() @@ -230,14 +256,7 @@ BOOL Platform_GetInputMINUS() return (btn & WPAD_BUTTON_MINUS); } -BOOL Platform_GetInputMouseDown() -{ - if(btn & WPAD_BUTTON_B) - return 0; - return (btn & WPAD_BUTTON_A); -} - -int Platform_GetPowerSwitch(int type) +int Platform_GetPowerSwitchPlus(int type, int *extra) { static u32 last_btn = 0; @@ -253,10 +272,16 @@ int Platform_GetPowerSwitch(int type) case ONOFF_OFF12: if(btn & WPAD_BUTTON_UP) { btn &= ~WPAD_BUTTON_UP; + if(extra != NULL) { + *extra = (btn & WPAD_BUTTON_1) ? 1 : 0; + } return -1; } if(btn & WPAD_BUTTON_DOWN) { btn &= ~WPAD_BUTTON_DOWN; + if(extra != NULL) { + *extra = (btn & WPAD_BUTTON_1) ? 1 : 0; + } return 1; } break; @@ -277,6 +302,11 @@ int Platform_GetPowerSwitch(int type) return 0; } +int Platform_GetPowerSwitch(int type) +{ + return Platform_GetPowerSwitchPlus(type, NULL); +} + BOOL Platform_CloseGame() { return (btn & WPAD_BUTTON_HOME); diff --git a/source/platform/Platform.h b/source/platform/Platform.h index 0748c55..ac2a2fc 100644 --- a/source/platform/Platform.h +++ b/source/platform/Platform.h @@ -72,10 +72,15 @@ typedef enum { WK_B, WK_BUD, WK_BLR, + WK_BLR1, WK_PLUS, WK_MINUS, WK_HOME, WK_DPAD, + WK_U, + WK_D, + WK_L, + WK_R, WK_LR, WK_UD, WK_NUMKEY @@ -143,7 +148,11 @@ int PlatformGetInput(); BOOL Platform_GetInputUP(); BOOL Platform_GetInputDOWN(); BOOL Platform_GetInputLEFT(); +BOOL Platform_GetInputLEFTUP(); +BOOL Platform_GetInputLEFTDOWN(); BOOL Platform_GetInputRIGHT(); +BOOL Platform_GetInputRIGHTUP(); +BOOL Platform_GetInputRIGHTDOWN(); BOOL Platform_GetInput1(); BOOL Platform_GetInput2(); BOOL Platform_GetInputPLUS(); @@ -155,6 +164,7 @@ BOOL Platform_GetRealTimeInputPLUS(); BOOL Platform_GetRealTimeInputMINUS(); int Platform_GetPowerSwitch(int type); +int Platform_GetPowerSwitchPlus(int type, int *extra); BOOL Platform_CloseGame(); #endif diff --git a/source/platform/Platform_armorbattle.c b/source/platform/Platform_armorbattle.c index 3b512c3..7bce20a 100644 --- a/source/platform/Platform_armorbattle.c +++ b/source/platform/Platform_armorbattle.c @@ -62,7 +62,7 @@ static GRRLIB_texImg *bmpPowerOn; static BOOL bMineSound = FALSE; static BOOL bMineSoundPlaying = FALSE; -static Sound_t tcWaveRes[7]; +static Sound_t tcWaveRes[ARMORBATTLE_SOUND_NSOUNDS]; static Blip_t blip[ARMORBATTLE_BLIP_COLUMNS][ARMORBATTLE_BLIP_ROWS]; static Stat_t digit[2]; static Help_t help[] = { @@ -85,13 +85,13 @@ void ArmorBattle_Init() int x, y; // Init sounds - Sound_set(&tcWaveRes[0], armorbattle_tick_raw, armorbattle_tick_raw_size, 17 ); - Sound_set(&tcWaveRes[1], armorbattle_near_raw, armorbattle_near_raw_size, 165 ); - Sound_set(&tcWaveRes[2], armorbattle_enemy_raw, armorbattle_enemy_raw_size, 124 ); - Sound_set(&tcWaveRes[3], armorbattle_fire_raw, armorbattle_fire_raw_size, 660 ); - Sound_set(&tcWaveRes[4], armorbattle_hit_raw, armorbattle_hit_raw_size, 524 ); - Sound_set(&tcWaveRes[5], armorbattle_score_raw, armorbattle_score_raw_size, 1542 ); - Sound_set(&tcWaveRes[6], armorbattle_endgame_raw, armorbattle_endgame_raw_size, 5244 ); + Sound_set(&tcWaveRes[ARMORBATTLE_SOUND_TICK], armorbattle_tick_raw, armorbattle_tick_raw_size, 17 ); + Sound_set(&tcWaveRes[ARMORBATTLE_SOUND_NEAR], armorbattle_near_raw, armorbattle_near_raw_size, 165 ); + Sound_set(&tcWaveRes[ARMORBATTLE_SOUND_ENEMY], armorbattle_enemy_raw, armorbattle_enemy_raw_size, 124 ); + Sound_set(&tcWaveRes[ARMORBATTLE_SOUND_FIRE], armorbattle_fire_raw, armorbattle_fire_raw_size, 660 ); + Sound_set(&tcWaveRes[ARMORBATTLE_SOUND_HIT], armorbattle_hit_raw, armorbattle_hit_raw_size, 524 ); + Sound_set(&tcWaveRes[ARMORBATTLE_SOUND_SCORE], armorbattle_score_raw, armorbattle_score_raw_size, 1542 ); + Sound_set(&tcWaveRes[ARMORBATTLE_SOUND_ENDGAME], armorbattle_endgame_raw, armorbattle_endgame_raw_size, 5244 ); // load images bmpScreen = GRRLIB_LoadTexture(armorbattle_screen_png); @@ -129,12 +129,20 @@ void ArmorBattle_Init() } } +void ArmorBattle_StopSound() +{ + bMineSoundPlaying = FALSE; + bMineSound = FALSE; + + // stop all sounds... + Platform_StopSound(); +} + void ArmorBattle_DeInit() { // stop all sounds... - Platform_StopSound(); - bMineSoundPlaying = FALSE; - + ArmorBattle_StopSound(); + ArmorBattle_PowerOff(); GRRLIB_FreeTexture(bmpScreen); GRRLIB_FreeTexture(bmpBlipDim); GRRLIB_FreeTexture(bmpBlipBright); @@ -159,12 +167,12 @@ void ArmorBattle_Paint() ArmorBattle_PowerOn(); } - GRRLIB_DrawImg (realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg (realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // visualize the control states if (power) { - GRRLIB_DrawImg(realx(armorbattle_power_x), realy(armorbattle_power_y), bmpPowerOn, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(armorbattle_power_x), realy(armorbattle_power_y), bmpPowerOn, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // show blips for (y = 0; y < ARMORBATTLE_BLIP_ROWS; y++){ @@ -174,10 +182,10 @@ void ArmorBattle_Paint() case BLIP_OFF: break; case BLIP_DIM: - GRRLIB_DrawImg (realx(pblip->x), realy(pblip->y), bmpBlipDim, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg (realx(pblip->x), realy(pblip->y), bmpBlipDim, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); break; case BLIP_BRIGHT: - GRRLIB_DrawImg (realx(pblip->x), realy(pblip->y), bmpBlipBright, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg (realx(pblip->x), realy(pblip->y), bmpBlipBright, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); break; } } @@ -186,9 +194,9 @@ void ArmorBattle_Paint() // Show time for(x = 0; x < sizeof(digit)/sizeof(*digit); x++) { if(digit[x].val == -1) - GRRLIB_DrawTile(realx(digit[x].x), realy(digit[x].y), bmpDigits, 0, 1, 1, 0xFFFFFFFF, 0); + GRRLIB_DrawTile(realx(digit[x].x), realy(digit[x].y), bmpDigits, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF, 0); else - GRRLIB_DrawTile(realx(digit[x].x), realy(digit[x].y), bmpDigits, 0, 1, 1, 0xFFFFFFFF, digit[x].val); + GRRLIB_DrawTile(realx(digit[x].x), realy(digit[x].y), bmpDigits, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF, digit[x].val); } } else @@ -237,16 +245,6 @@ void ArmorBattle_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void ArmorBattle_StopSound() -{ - bMineSoundPlaying = FALSE; - bMineSound = FALSE; - - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // diff --git a/source/platform/Platform_armorbattle.h b/source/platform/Platform_armorbattle.h index 008d289..18fccf4 100644 --- a/source/platform/Platform_armorbattle.h +++ b/source/platform/Platform_armorbattle.h @@ -51,12 +51,6 @@ Website : http://www.peterhirschberg.com // interface that the platform must provide for this game -// Input remapping -#define ARMORBATTLE_KEY_UP -#define ARMORBATTLE_KEY_DOWN -#define ARMORBATTLE_KEY_UP -#define ARMORBATTLE_KEY_UP - // functions exported to the game context void ArmorBattle_Init(); void ArmorBattle_Help(); diff --git a/source/platform/Platform_autorace.c b/source/platform/Platform_autorace.c index 82689d3..de1f33a 100644 --- a/source/platform/Platform_autorace.c +++ b/source/platform/Platform_autorace.c @@ -34,26 +34,11 @@ Website : http://www.peterhirschberg.com */ #include "autorace.h" +#include "slide1_png.h" #include "skislalom_screen_png.h" -#include "skislalom_poweroff_png.h" -#include "skislalom_poweron_png.h" -#include "skislalom_gear1_png.h" -#include "skislalom_gear2_png.h" -#include "skislalom_gear3_png.h" -#include "skislalom_gear4_png.h" -#include "skislalom_aimleft_png.h" -#include "skislalom_aimcenter_png.h" -#include "skislalom_aimright_png.h" +#include "skislalom_slide_png.h" #include "autorace_screen_png.h" -#include "autorace_poweroff_png.h" -#include "autorace_poweron_png.h" -#include "autorace_gear1_png.h" -#include "autorace_gear2_png.h" -#include "autorace_gear3_png.h" -#include "autorace_gear4_png.h" -#include "autorace_aimleft_png.h" -#include "autorace_aimcenter_png.h" -#include "autorace_aimright_png.h" +#include "autorace_slide_png.h" #include "autorace_gear1_raw.h" #include "autorace_gear2_raw.h" #include "autorace_gear3_raw.h" @@ -70,15 +55,8 @@ Website : http://www.peterhirschberg.com #include "skislalom_win_raw.h" // images static GRRLIB_texImg *bmpScreen; -static GRRLIB_texImg *bmpPowerOff; -static GRRLIB_texImg *bmpPowerOn; -static GRRLIB_texImg *bmpGear1; -static GRRLIB_texImg *bmpGear2; -static GRRLIB_texImg *bmpGear3; -static GRRLIB_texImg *bmpGear4; -static GRRLIB_texImg *bmpAimLeft; -static GRRLIB_texImg *bmpAimCenter; -static GRRLIB_texImg *bmpAimRight; +static GRRLIB_texImg *bmpPowerSlide; +static GRRLIB_texImg *bmpSlide; static int nStick = 1; @@ -96,7 +74,7 @@ static BOOL bSkiSlalom = FALSE; static void StartEngineSound(); static void StopEngineSound(); -static Sound_t tcWaveRes[7]; +static Sound_t tcWaveRes[AUTORACE_SOUND_NSOUNDS]; static Blip_t blip[AUTORACE_BLIP_COLUMNS][AUTORACE_BLIP_ROWS]; static Stat_t digit[2]; static Coord_t i_slider, i_power, i_gear; @@ -135,25 +113,18 @@ void SkiSlalom_Init() bSkiSlalom = TRUE; // Init sounds - Sound_set(&tcWaveRes[0], skislalom_gear1_raw, skislalom_gear1_raw_size, 1324); - Sound_set(&tcWaveRes[1], skislalom_gear2_raw, skislalom_gear2_raw_size, 1051); - Sound_set(&tcWaveRes[2], skislalom_gear3_raw, skislalom_gear3_raw_size, 1045); - Sound_set(&tcWaveRes[3], skislalom_gear4_raw, skislalom_gear4_raw_size, 852); - Sound_set(&tcWaveRes[4], skislalom_hit_raw, skislalom_hit_raw_size, 137); - Sound_set(&tcWaveRes[5], skislalom_time_raw, skislalom_time_raw_size, 937); - Sound_set(&tcWaveRes[6], skislalom_win_raw, skislalom_win_raw_size, 1275); + Sound_set(&tcWaveRes[AUTORACE_SOUND_GEAR0], skislalom_gear1_raw, skislalom_gear1_raw_size, 1324); + Sound_set(&tcWaveRes[AUTORACE_SOUND_GEAR1], skislalom_gear2_raw, skislalom_gear2_raw_size, 1051); + Sound_set(&tcWaveRes[AUTORACE_SOUND_GEAR2], skislalom_gear3_raw, skislalom_gear3_raw_size, 1045); + Sound_set(&tcWaveRes[AUTORACE_SOUND_GEAR3], skislalom_gear4_raw, skislalom_gear4_raw_size, 852); + Sound_set(&tcWaveRes[AUTORACE_SOUND_HIT], skislalom_hit_raw, skislalom_hit_raw_size, 137); + Sound_set(&tcWaveRes[AUTORACE_SOUND_TIME], skislalom_time_raw, skislalom_time_raw_size, 937); + Sound_set(&tcWaveRes[AUTORACE_SOUND_WIN], skislalom_win_raw, skislalom_win_raw_size, 1275); // load images bmpScreen = GRRLIB_LoadTexture(skislalom_screen_png); - bmpPowerOff = GRRLIB_LoadTexture(skislalom_poweroff_png); - bmpPowerOn = GRRLIB_LoadTexture(skislalom_poweron_png); - bmpGear1 = GRRLIB_LoadTexture(skislalom_gear1_png); - bmpGear2 = GRRLIB_LoadTexture(skislalom_gear2_png); - bmpGear3 = GRRLIB_LoadTexture(skislalom_gear3_png); - bmpGear4 = GRRLIB_LoadTexture(skislalom_gear4_png); - bmpAimLeft = GRRLIB_LoadTexture(skislalom_aimleft_png); - bmpAimCenter = GRRLIB_LoadTexture(skislalom_aimcenter_png); - bmpAimRight = GRRLIB_LoadTexture(skislalom_aimright_png); + bmpPowerSlide = GRRLIB_LoadTexture(slide1_png); + bmpSlide = GRRLIB_LoadTexture(skislalom_slide_png); // images position i_slider.x = skislalom_slider_x; @@ -211,15 +182,8 @@ void AutoRace_Init() // load images bmpScreen = GRRLIB_LoadTexture(autorace_screen_png); - bmpPowerOff = GRRLIB_LoadTexture(autorace_poweroff_png); - bmpPowerOn = GRRLIB_LoadTexture(autorace_poweron_png); - bmpGear1 = GRRLIB_LoadTexture(autorace_gear1_png); - bmpGear2 = GRRLIB_LoadTexture(autorace_gear2_png); - bmpGear3 = GRRLIB_LoadTexture(autorace_gear3_png); - bmpGear4 = GRRLIB_LoadTexture(autorace_gear4_png); - bmpAimLeft = GRRLIB_LoadTexture(autorace_aimleft_png); - bmpAimCenter = GRRLIB_LoadTexture(autorace_aimcenter_png); - bmpAimRight = GRRLIB_LoadTexture(autorace_aimright_png); + bmpPowerSlide = GRRLIB_LoadTexture(slide1_png); + bmpSlide = GRRLIB_LoadTexture(autorace_slide_png); // images position i_slider.x = autorace_slider_x; @@ -260,22 +224,24 @@ void AutoRace_Init() } } +void AutoRace_StopSound() +{ + bEngineSoundPlaying = FALSE; + bEngineSound = FALSE; + + // stop all sounds... + Platform_StopSound(); +} + void AutoRace_DeInit() { // stop all sounds... - Platform_StopSound(); - - bEngineSoundPlaying = FALSE; + AutoRace_StopSound(); + AutoRace_PowerOff(); GRRLIB_FreeTexture(bmpScreen); - GRRLIB_FreeTexture(bmpPowerOff); - GRRLIB_FreeTexture(bmpPowerOn); - GRRLIB_FreeTexture(bmpGear1); - GRRLIB_FreeTexture(bmpGear2); - GRRLIB_FreeTexture(bmpGear3); - GRRLIB_FreeTexture(bmpGear4); - GRRLIB_FreeTexture(bmpAimLeft); - GRRLIB_FreeTexture(bmpAimCenter); - GRRLIB_FreeTexture(bmpAimRight); + GRRLIB_FreeTexture(bmpPowerSlide); + GRRLIB_FreeTexture(bmpSlide); + destroy_gear(); bInited = FALSE; } @@ -292,42 +258,29 @@ void AutoRace_Paint() AutoRace_PowerOn(); } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // draw gear - switch (AutoRace_GetSkill()) - { - case 0: - GRRLIB_DrawImg(realx(i_gear.x), realy(i_gear.y), bmpGear1, 0, 1, 1, 0xFFFFFFFF); - break; - case 1: - GRRLIB_DrawImg(realx(i_gear.x), realy(i_gear.y), bmpGear2, 0, 1, 1, 0xFFFFFFFF); - break; - case 2: - GRRLIB_DrawImg(realx(i_gear.x), realy(i_gear.y), bmpGear3, 0, 1, 1, 0xFFFFFFFF); - break; - case 3: - GRRLIB_DrawImg(realx(i_gear.x), realy(i_gear.y), bmpGear4, 0, 1, 1, 0xFFFFFFFF); - break; - } + draw_gear(i_gear.x, i_gear.y, 4 - AutoRace_GetSkill()); // Draw stick - switch (nStick) - { + switch (nStick) { case 0: - GRRLIB_DrawImg(realx(i_slider.x), realy(i_slider.y), bmpAimLeft, 0, 1, 1, 0xFFFFFFFF); - break; - case 1: - GRRLIB_DrawImg(realx(i_slider.x), realy(i_slider.y), bmpAimCenter, 0, 1, 1, 0xFFFFFFFF); + x = 2; break; case 2: - GRRLIB_DrawImg(realx(i_slider.x), realy(i_slider.y), bmpAimRight, 0, 1, 1, 0xFFFFFFFF); + x = 27; + break; + case 1: + default: + x = 15; break; } + GRRLIB_DrawImg(realx(i_slider.x+x), realy(i_slider.y), bmpSlide, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // Draw power if (power) { - GRRLIB_DrawImg(realx(i_power.x), realy(i_power.y), bmpPowerOn, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(i_power.x), realy(i_power.y+3), bmpPowerSlide, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); for (y = 0; y < AUTORACE_BLIP_ROWS; y++){ for (x = 0; x < AUTORACE_BLIP_COLUMNS; x++){ if(blip[x][y].status != -1) @@ -338,7 +291,7 @@ void AutoRace_Paint() draw_digit(digit[x].x, digit[x].y, digit[x].val); } else { - GRRLIB_DrawImg(realx(i_power.x), realy(i_power.y), bmpPowerOff, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(i_power.x), realy(i_power.y+16), bmpPowerSlide, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); } } @@ -375,16 +328,6 @@ void AutoRace_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void AutoRace_StopSound() -{ - bEngineSoundPlaying = FALSE; - bEngineSound = FALSE; - - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // diff --git a/source/platform/Platform_baseball.c b/source/platform/Platform_baseball.c index 59ba5b8..6a161c4 100644 --- a/source/platform/Platform_baseball.c +++ b/source/platform/Platform_baseball.c @@ -38,9 +38,6 @@ Website : http://www.peterhirschberg.com #include "baseball_blip_png.h" #include "baseball_dimdigits_png.h" #include "baseball_brightdigits_png.h" -#include "baseball_poweroff_png.h" -#include "baseball_pro1_png.h" -#include "baseball_pro2_png.h" #include "baseball_hit_raw.h" #include "baseball_out_raw.h" #include "baseball_run_raw.h" @@ -54,17 +51,19 @@ Website : http://www.peterhirschberg.com #define DIGIT_TYPE_OFF 0 #define DIGIT_TYPE_DIM 1 #define DIGIT_TYPE_BRIGHT 2 +int Baseball_errno; + +static BOOL bPower = FALSE; +static BOOL bPro2 = FALSE; +static BOOL bInited = FALSE; // images static GRRLIB_texImg *bmpScreen; static GRRLIB_texImg *bmpBlip; static GRRLIB_texImg *bmpDimDigits; static GRRLIB_texImg *bmpBrightDigits; -static GRRLIB_texImg *bmpPowerOff; -static GRRLIB_texImg *bmpPro1; -static GRRLIB_texImg *bmpPro2; -static Sound_t tcWaveRes[6]; +static Sound_t tcWaveRes[BASEBALL_SOUND_NSOUNDS]; static Digit_t digit[4] = { { baseball_digit1_x, baseball_digit_y, 0, DIGIT_TYPE_OFF}, @@ -73,9 +72,9 @@ static Digit_t digit[4] = { { baseball_digit4_x, baseball_digit_y, 0, DIGIT_TYPE_OFF} }; -// blips for normal pitches -static Blip_t blip_pitch[9] = { - { baseball_blip_pitch_1_x, baseball_blip_pitch_1_y, BLIP_OFF }, +#define N_BLIPS (sizeof(blips)/sizeof(*blips)) +static Blip_t blips[BASEBALL_NBLIPS] = { + { baseball_blip_pitch_1_x, baseball_blip_pitch_1_y, BLIP_OFF }, // 0 blips for normal pitches { baseball_blip_pitch_2_x, baseball_blip_pitch_2_y, BLIP_OFF }, { baseball_blip_pitch_3_x, baseball_blip_pitch_3_y, BLIP_OFF }, { baseball_blip_pitch_4_x, baseball_blip_pitch_4_y, BLIP_OFF }, @@ -83,46 +82,28 @@ static Blip_t blip_pitch[9] = { { baseball_blip_pitch_6_x, baseball_blip_pitch_6_y, BLIP_OFF }, { baseball_blip_pitch_7_x, baseball_blip_pitch_7_y, BLIP_OFF }, { baseball_blip_pitch_8_x, baseball_blip_pitch_8_y, BLIP_OFF }, - { baseball_blip_pitch_9_x, baseball_blip_pitch_9_y, BLIP_OFF } -}; -// blips for curve balls -static Blip_t blip_pitchcurve[4] = { - { baseball_blip_pitchcurve_2_x, baseball_blip_pitchcurve_2_y, BLIP_OFF }, + { baseball_blip_pitch_9_x, baseball_blip_pitch_9_y, BLIP_OFF }, + { baseball_blip_pitchcurve_2_x, baseball_blip_pitchcurve_2_y, BLIP_OFF }, // 9 blips for curve balls { baseball_blip_pitchcurve_3_x, baseball_blip_pitchcurve_3_y, BLIP_OFF }, { baseball_blip_pitchcurve_4_x, baseball_blip_pitchcurve_4_y, BLIP_OFF }, - { baseball_blip_pitchcurve_5_x, baseball_blip_pitchcurve_5_y, BLIP_OFF } -}; -// blips bases -static Blip_t blip_base[4][3] = { - // blips for home plate -> 1st base - {{ baseball_blip_base_0_x,baseball_blip_base_0_y, BLIP_OFF }, - { baseball_blip_base_0A_x,baseball_blip_base_0A_y, BLIP_OFF }, - { baseball_blip_base_0B_x,baseball_blip_base_0B_y, BLIP_OFF }}, - // blips for 1st base -> 2nd base - {{ baseball_blip_base_1_x,baseball_blip_base_1_y, BLIP_OFF }, - { baseball_blip_base_1A_x,baseball_blip_base_1A_y, BLIP_OFF }, - { baseball_blip_base_1B_x,baseball_blip_base_1B_y, BLIP_OFF }}, - {{ baseball_blip_base_2_x,baseball_blip_base_2_y, BLIP_OFF }, - // blips for 2nd base -> 3rd base - { baseball_blip_base_2A_x,baseball_blip_base_2A_y, BLIP_OFF }, - { baseball_blip_base_2B_x,baseball_blip_base_2B_y, BLIP_OFF }}, - // blips for 3rd base -> home plate - {{ baseball_blip_base_3_x,baseball_blip_base_3_y, BLIP_OFF }, - { baseball_blip_base_3A_x,baseball_blip_base_3A_y, BLIP_OFF }, - { baseball_blip_base_3B_x,baseball_blip_base_3B_y, BLIP_OFF }} -}; -// blips deep -static Blip_t blip_deep[2] = { - // blip for deep 1st - { baseball_blip_deep1st_x,baseball_blip_deep1st_y, BLIP_OFF }, - // blip for deep 3rd - { baseball_blip_deep3rd_x,baseball_blip_deep3rd_y, BLIP_OFF } -}; -// blips for outfield -static Blip_t blip_outfield[3] = { - { baseball_blip_outfield_left_x,baseball_blip_outfield_left_y, BLIP_OFF }, + { baseball_blip_pitchcurve_5_x, baseball_blip_pitchcurve_5_y, BLIP_OFF }, + { baseball_blip_base_0_x,baseball_blip_base_0_y, BLIP_OFF }, // 13 blips for home plate -> 1st base + { baseball_blip_base_0A_x,baseball_blip_base_0A_y, BLIP_OFF }, + { baseball_blip_base_0B_x,baseball_blip_base_0B_y, BLIP_OFF }, + { baseball_blip_base_1_x,baseball_blip_base_1_y, BLIP_OFF }, // 16 blips for 1st base -> 2nd base + { baseball_blip_base_1A_x,baseball_blip_base_1A_y, BLIP_OFF }, + { baseball_blip_base_1B_x,baseball_blip_base_1B_y, BLIP_OFF }, + { baseball_blip_base_2_x,baseball_blip_base_2_y, BLIP_OFF }, // 19 blips for 2nd base -> 3rd base + { baseball_blip_base_2A_x,baseball_blip_base_2A_y, BLIP_OFF }, + { baseball_blip_base_2B_x,baseball_blip_base_2B_y, BLIP_OFF }, + { baseball_blip_base_3_x,baseball_blip_base_3_y, BLIP_OFF }, // 22 blips for 3rd base -> home plate + { baseball_blip_base_3A_x,baseball_blip_base_3A_y, BLIP_OFF }, + { baseball_blip_base_3B_x,baseball_blip_base_3B_y, BLIP_OFF }, + { baseball_blip_deep1st_x,baseball_blip_deep1st_y, BLIP_OFF }, // 25 blip for deep 1st + { baseball_blip_deep3rd_x,baseball_blip_deep3rd_y, BLIP_OFF }, // 26 blip for deep 3rd + { baseball_blip_outfield_left_x,baseball_blip_outfield_left_y, BLIP_OFF }, // 27 blips for outfield left { baseball_blip_outfield_center_x,baseball_blip_outfield_center_y, BLIP_OFF }, - { baseball_blip_outfield_right_x,baseball_blip_outfield_right_y, BLIP_OFF } + { baseball_blip_outfield_right_x,baseball_blip_outfield_right_y, BLIP_OFF } // 29 blips for outfield right }; static Help_t help[] = { @@ -135,24 +116,55 @@ static Help_t help[] = { //---------------------------------------------------------------------------- // // +static void Baseball_StopSound() +{ + // stop all sounds... + Platform_StopSound(); +} + void Baseball_Help() { Platform_Help(help, sizeof(help)/sizeof(*help)); } -static BOOL bInited = FALSE; +BOOL Baseball_GetPower() +{ + return bPower; +} + +void Baseball_PowerOn() +{ + bPower = TRUE; +} + +void Baseball_PowerOff() +{ + bPower = FALSE; + Baseball_StopSound(); +} + +void Baseball_SetSkill(int v) +{ + bPro2 = (v == 0) ? FALSE : TRUE; +} + +int Baseball_GetSkill() +{ + return (bPro2 == TRUE) ? 1 : 0; +} void Baseball_Init() { - if (bInited) return; + if (bInited) + return; // Init sounds - Sound_set(&tcWaveRes[0], baseball_hit_raw, baseball_hit_raw_size, 82 ); - Sound_set(&tcWaveRes[1], baseball_out_raw, baseball_out_raw_size, 392 ); - Sound_set(&tcWaveRes[2], baseball_run_raw, baseball_run_raw_size, 423 ); - Sound_set(&tcWaveRes[3], baseball_strike_raw, baseball_strike_raw_size, 22 ); - Sound_set(&tcWaveRes[4], baseball_endpossession_raw, baseball_endpossession_raw_size, 560 ); - Sound_set(&tcWaveRes[5], baseball_endgame_raw, baseball_endgame_raw_size, 712 ); + Sound_set(&tcWaveRes[BASEBALL_SOUND_HIT], baseball_hit_raw, baseball_hit_raw_size, 82 ); + Sound_set(&tcWaveRes[BASEBALL_SOUND_OUT], baseball_out_raw, baseball_out_raw_size, 392 ); + Sound_set(&tcWaveRes[BASEBALL_SOUND_RUN], baseball_run_raw, baseball_run_raw_size, 423 ); + Sound_set(&tcWaveRes[BASEBALL_SOUND_STRIKE], baseball_strike_raw, baseball_strike_raw_size, 22 ); + Sound_set(&tcWaveRes[BASEBALL_SOUND_ENDPOSSESSION], baseball_endpossession_raw, baseball_endpossession_raw_size, 560 ); + Sound_set(&tcWaveRes[BASEBALL_SOUND_ENDGAME], baseball_endgame_raw, baseball_endgame_raw_size, 712 ); // load images bmpScreen = GRRLIB_LoadTexture(baseball_screen_png); @@ -162,15 +174,10 @@ void Baseball_Init() bmpBrightDigits = GRRLIB_LoadTexture(baseball_brightdigits_png); GRRLIB_InitTileSet(bmpBrightDigits, DIGIT_W, DIGIT_H, 0); - // set up the power switch images - bmpPowerOff = GRRLIB_LoadTexture(baseball_poweroff_png); - bmpPro1 = GRRLIB_LoadTexture(baseball_pro1_png); - bmpPro2 = GRRLIB_LoadTexture(baseball_pro2_png); - PlatformSetInput(0); // turn on the game - Baseball_SetSkill(0); - Baseball_PowerOn(); + bPro2 = FALSE; + bPower = FALSE; bInited = TRUE; } @@ -178,100 +185,70 @@ void Baseball_Init() void Baseball_DeInit() { // stop all sounds... - Platform_StopSound(); + Baseball_StopSound(); + bPower = FALSE; GRRLIB_FreeTexture(bmpScreen); GRRLIB_FreeTexture(bmpBlip); GRRLIB_FreeTexture(bmpDimDigits); GRRLIB_FreeTexture(bmpBrightDigits); - GRRLIB_FreeTexture(bmpPowerOff); - GRRLIB_FreeTexture(bmpPro1); - GRRLIB_FreeTexture(bmpPro2); - bInited = FALSE; } void Baseball_Paint() { - int i; - BOOL power = Baseball_GetPower(); - BOOL skill = Baseball_GetSkill(); int p_switch; p_switch = Platform_GetPowerSwitch(ONOFF_OFF12); - if(power) { + if(bPower) { if(p_switch == -1) { - if(skill == 0) - Baseball_PowerOff(); - if(skill == 1) { - Baseball_PowerOn(); - Baseball_SetSkill(0); + if(bPro2 == FALSE) + bPower = FALSE; + if(bPro2 == TRUE) { + bPower = TRUE; + bPro2 = FALSE; } } if(p_switch == 1) { - if(skill == 0) { - Baseball_PowerOn(); - Baseball_SetSkill(1); + if(bPro2 == 0) { + bPower = TRUE; + bPro2 = TRUE; } } } else { if(p_switch == 1) { - Baseball_PowerOn(); - Baseball_SetSkill(0); + bPower = TRUE; + bPro2 = FALSE; } } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); - if (power) - { - if (skill == 0) - { - GRRLIB_DrawImg(realx(baseball_pro_1_x), realy(baseball_pro_1_y), bmpPro1, 0, 1, 1, 0xFFFFFFFF); + if (bPower == TRUE) { + int i; + if (bPro2 == FALSE) { + draw_switch(SWITCH_TYPE_1, baseball_pro_1_x, baseball_pro_1_y, SWITCH_POS_PRO1); } else { - GRRLIB_DrawImg(realx(baseball_pro_2_x), realy(baseball_pro_2_y), bmpPro2, 0, 1, 1, 0xFFFFFFFF); + draw_switch(SWITCH_TYPE_1, baseball_pro_1_x, baseball_pro_1_y, SWITCH_POS_PRO2); } // show blips - for(i=0; i<9; i++) { - Blip_t *pblip = &blip_pitch[i]; + for(i=0; i< BASEBALL_NBLIPS; i++) { + Blip_t *pblip = &blips[i]; if(pblip->status != BLIP_OFF) - GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlip, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlip, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); } - for(i=0; i<4; i++) { - Blip_t *pblip = &blip_pitchcurve[i]; - if(pblip->status != BLIP_OFF) - GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlip, 0, 1, 1, 0xFFFFFFFF); - } - for(i=0; i<4; i++) { - int j; - for(j=0; j<3; j++) { - Blip_t *pblip = &blip_base[i][j]; - if(pblip->status != BLIP_OFF) - GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlip, 0, 1, 1, 0xFFFFFFFF); - } - } - for(i=0; i<2; i++) { - Blip_t *pblip = &blip_deep[i]; - if(pblip->status != BLIP_OFF) - GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlip, 0, 1, 1, 0xFFFFFFFF); - } - for(i=0; i<3; i++) { - Blip_t *pblip = &blip_outfield[i]; - if(pblip->status != BLIP_OFF) - GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlip, 0, 1, 1, 0xFFFFFFFF); - } - + // show digits for(i=0; i<4; i++) { Digit_t *pdigit = &digit[i]; switch(pdigit->type) { case DIGIT_TYPE_DIM: - GRRLIB_DrawTile(realx(pdigit->x), realy(pdigit->y), bmpDimDigits, 0, 1, 1, 0xFFFFFFFF, pdigit->val + 1); + GRRLIB_DrawTile(realx(pdigit->x), realy(pdigit->y), bmpDimDigits, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF, pdigit->val + 1); break; case DIGIT_TYPE_BRIGHT: - GRRLIB_DrawTile(realx(pdigit->x), realy(pdigit->y), bmpBrightDigits, 0, 1, 1, 0xFFFFFFFF, pdigit->val + 1); + GRRLIB_DrawTile(realx(pdigit->x), realy(pdigit->y), bmpBrightDigits, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF, pdigit->val + 1); break; case DIGIT_TYPE_OFF: default: @@ -279,9 +256,9 @@ void Baseball_Paint() } } } - else - { - GRRLIB_DrawImg(realx(baseball_power_off_x), realy(baseball_power_off_y), bmpPowerOff, 0, 1, 1, 0xFFFFFFFF); + else { + Baseball_StopSound(); + draw_switch(SWITCH_TYPE_1, baseball_pro_1_x, baseball_pro_1_y, SWITCH_POS_OFF); } } @@ -290,131 +267,12 @@ void Baseball_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void Baseball_StopSound() -{ - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // - -void Baseball_DrawPitchBlip(BOOL state, int index, BOOL curve) +void Baseball_DrawBlip(BOOL state, int index) { - Blip_t *pblip = NULL; - - switch(index) - { - case 0: - default: - pblip = &blip_pitch[0]; - break; - case 1: - if (curve) - pblip = &blip_pitchcurve[0]; - else - pblip = &blip_pitch[1]; - break; - case 2: - if (curve) - pblip = &blip_pitchcurve[1]; - else - pblip = &blip_pitch[2]; - break; - case 3: - if (curve) - pblip = &blip_pitchcurve[2]; - else - pblip = &blip_pitch[3]; - break; - case 4: - if (curve) - pblip = &blip_pitchcurve[3]; - else - pblip = &blip_pitch[4]; - break; - case 5: - pblip = &blip_pitch[5]; - break; - case 6: - pblip = &blip_pitch[6]; - break; - case 7: - pblip = &blip_pitch[7]; - break; - case 8: - pblip = &blip_pitch[8]; - break; - } - - if (pblip != NULL ) - { - pblip->status = (state) ? BLIP_DIM : BLIP_OFF; - } -} - -void Baseball_DrawBaseBlip(BOOL state, int index) -{ - Blip_t *pblip = NULL; - - switch(index) - { - case 12: - case 0: // home plate - pblip = &blip_base[0][0]; - break; - case 1: - pblip = &blip_base[0][1]; - break; - case 2: - pblip = &blip_base[0][2]; - break; - case 3: // 1st base - pblip = &blip_base[1][0]; - break; - case 4: - pblip = &blip_base[1][1]; - break; - case 5: - pblip = &blip_base[1][2]; - break; - case 6: // 2nd base - pblip = &blip_base[2][0]; - break; - case 7: - pblip = &blip_base[2][1]; - break; - case 8: - pblip = &blip_base[2][2]; - break; - case 9: // 3rd - pblip = &blip_base[3][0]; - break; - case 10: - pblip = &blip_base[3][1]; - break; - case 11: - pblip = &blip_base[3][2]; - break; - } - if (pblip != NULL ) - { - pblip->status = (state) ? BLIP_DIM : BLIP_OFF; - } -} - -void Baseball_DrawOutfieldBlip(BOOL state, int index) -{ - Blip_t *pblip = &blip_outfield[index]; - - pblip->status = (state) ? BLIP_DIM : BLIP_OFF; -} - -void Baseball_DrawDeepBlip(BOOL state, int index) -{ - Blip_t *pblip = &blip_deep[index]; + Blip_t *pblip = &blips[index]; pblip->status = (state) ? BLIP_DIM : BLIP_OFF; } @@ -513,8 +371,8 @@ void Baseball_DrawFireWorks(void) int i; for(i=0; i <4; i++) { - digit[i].val = -1; - digit[i].type = (i == 1) ? DIGIT_TYPE_BRIGHT : DIGIT_TYPE_DIM; + digit[i].val = (i == 1) ? 10 : -1; + digit[i].type = DIGIT_TYPE_DIM; } } @@ -591,7 +449,7 @@ BOOL Baseball_GetInputRUN(BOOL *pChange) if (pChange){ *pChange = FALSE; } // check the keys - if (Platform_GetInput1()) + if (Platform_GetRealTimeInput1()) // NOTE: gets realtime key state { if (!bLast && pChange) { diff --git a/source/platform/Platform_baseball.h b/source/platform/Platform_baseball.h index 7104d35..b07edb5 100644 --- a/source/platform/Platform_baseball.h +++ b/source/platform/Platform_baseball.h @@ -53,37 +53,37 @@ Website : http://www.peterhirschberg.com #define baseball_digit_h 9 // blips for normal pitches -#define baseball_blip_pitch_1_x 118 +#define baseball_blip_pitch_1_x 117 #define baseball_blip_pitch_1_y 151 -#define baseball_blip_pitch_2_x 118 +#define baseball_blip_pitch_2_x baseball_blip_pitch_1_x #define baseball_blip_pitch_2_y 167 -#define baseball_blip_pitch_3_x 118 +#define baseball_blip_pitch_3_x baseball_blip_pitch_1_x #define baseball_blip_pitch_3_y 182 -#define baseball_blip_pitch_4_x 118 +#define baseball_blip_pitch_4_x baseball_blip_pitch_1_x #define baseball_blip_pitch_4_y 197 -#define baseball_blip_pitch_5_x 118 +#define baseball_blip_pitch_5_x baseball_blip_pitch_1_x #define baseball_blip_pitch_5_y 211 -#define baseball_blip_pitch_6_x 118 +#define baseball_blip_pitch_6_x baseball_blip_pitch_1_x #define baseball_blip_pitch_6_y 225 -#define baseball_blip_pitch_7_x 118 +#define baseball_blip_pitch_7_x baseball_blip_pitch_1_x #define baseball_blip_pitch_7_y 236 -#define baseball_blip_pitch_8_x 118 +#define baseball_blip_pitch_8_x baseball_blip_pitch_1_x #define baseball_blip_pitch_8_y 248 -#define baseball_blip_pitch_9_x 118 +#define baseball_blip_pitch_9_x baseball_blip_pitch_1_x #define baseball_blip_pitch_9_y 256 // blips for curve balls #define baseball_blip_pitchcurve_2_x 123 -#define baseball_blip_pitchcurve_2_y 166 +#define baseball_blip_pitchcurve_2_y 167 #define baseball_blip_pitchcurve_3_x 125 -#define baseball_blip_pitchcurve_3_y 181 +#define baseball_blip_pitchcurve_3_y 182 #define baseball_blip_pitchcurve_4_x 125 -#define baseball_blip_pitchcurve_4_y 196 +#define baseball_blip_pitchcurve_4_y 197 #define baseball_blip_pitchcurve_5_x 123 -#define baseball_blip_pitchcurve_5_y 210 +#define baseball_blip_pitchcurve_5_y 211 // home plate -> 1st base -#define baseball_blip_base_0_x 118 +#define baseball_blip_base_0_x baseball_blip_pitch_1_x #define baseball_blip_base_0_y 236 #define baseball_blip_base_0A_x 138 #define baseball_blip_base_0A_y 215 @@ -130,22 +130,36 @@ Website : http://www.peterhirschberg.com #define baseball_blip_outfield_right_x 184 #define baseball_blip_outfield_right_y 85 -// interface that the platform must provide for this game +#define NORMAL_BALL(x) (x) +#define CURVE_BALL(x) (((x)>=1 && (x)<=4) ? ((x)-1+9) : NORMAL_BALL(x)) +#define HOME_PLATE 13 +#define BASE(x) (HOME_PLATE+(3*(x))) +#define DIAMOND(x) (HOME_PLATE+(x)) +#define DEEP_1ST 25 +#define DEEP_3RD 26 +#define OUT_LEFT 27 +#define OUT_CENTER 28 +#define OUT_RIGHT 29 -// functions exported to the game context +#define BASEBALL_NBLIPS (OUT_RIGHT+1) + +// interface that the platform must provide for this game void Baseball_Init(); void Baseball_Help(); void Baseball_DeInit(); void Baseball_Paint(); -void Baseball_PlaySound(int nSound, unsigned int nFlags); -void Baseball_StopSound(); void Baseball_GetSize(int *w, int *h); +void Baseball_SetSkill(int i); +int Baseball_GetSkill(); +void Baseball_PowerOn(); +void Baseball_PowerOff(); +int Baseball_GetPower(); + +// functions exported to the game context +void Baseball_PlaySound(int nSound, unsigned int nFlags); // "private" functions not exported to game context -void Baseball_DrawPitchBlip(BOOL state, int index, BOOL curve); -void Baseball_DrawBaseBlip(BOOL state, int index); -void Baseball_DrawOutfieldBlip(BOOL state, int index); -void Baseball_DrawDeepBlip(BOOL state, int index); +void Baseball_DrawBlip(BOOL state, int index); void Baseball_DrawStats(int innings, int outs, int balls, int strikes, BOOL bHomeTeam); void Baseball_DrawScore(int vruns, int hruns); diff --git a/source/platform/Platform_basketball.c b/source/platform/Platform_basketball.c index 57dc873..89cbe39 100644 --- a/source/platform/Platform_basketball.c +++ b/source/platform/Platform_basketball.c @@ -45,7 +45,7 @@ Website : http://www.peterhirschberg.com // images static GRRLIB_texImg *bmpScreen; -static Sound_t tcWaveRes[6]; +static Sound_t tcWaveRes[BASKETBALL_SOUND_NSOUNDS]; static Blip_t blip[BASKETBALL_BLIP_COLUMNS][BASKETBALL_BLIP_ROWS]; static Blip_t basket; static Stat_t digit[2]; @@ -68,15 +68,16 @@ void Basketball_Init() { int x, y; - if (bInited) return; + if (bInited) + return; // Init sounds - Sound_set(&tcWaveRes[0], basketball_tick_raw, basketball_tick_raw_size, 27); - Sound_set(&tcWaveRes[1], basketball_bounce_raw, basketball_bounce_raw_size, 50); - Sound_set(&tcWaveRes[2], basketball_score_raw, basketball_score_raw_size, 799); - Sound_set(&tcWaveRes[3], basketball_endplay_raw, basketball_endplay_raw_size, 721); - Sound_set(&tcWaveRes[4], basketball_endquarter_raw, basketball_endquarter_raw_size, 1878); - Sound_set(&tcWaveRes[5], basketball_endgame_raw, basketball_endgame_raw_size, 3753); + Sound_set(&tcWaveRes[BASKETBALL_SOUND_TICK], basketball_tick_raw, basketball_tick_raw_size, 27); + Sound_set(&tcWaveRes[BASKETBALL_SOUND_BOUNCE], basketball_bounce_raw, basketball_bounce_raw_size, 50); + Sound_set(&tcWaveRes[BASKETBALL_SOUND_SCORE], basketball_score_raw, basketball_score_raw_size, 799); + Sound_set(&tcWaveRes[BASKETBALL_SOUND_ENDPLAY], basketball_endplay_raw, basketball_endplay_raw_size, 721); + Sound_set(&tcWaveRes[BASKETBALL_SOUND_ENDQUARTER], basketball_endquarter_raw, basketball_endquarter_raw_size, 1878); + Sound_set(&tcWaveRes[BASKETBALL_SOUND_ENDGAME], basketball_endgame_raw, basketball_endgame_raw_size, 3753); // load images bmpScreen = GRRLIB_LoadTexture(basketball_screen_png); @@ -109,10 +110,17 @@ void Basketball_Init() bInited = TRUE; } -void Basketball_DeInit() +void Basketball_StopSound() { // stop all sounds... Platform_StopSound(); +} + +void Basketball_DeInit() +{ + // stop all sounds... + Basketball_StopSound(); + Basketball_PowerOff(); GRRLIB_FreeTexture(bmpScreen); bInited = FALSE; } @@ -144,14 +152,14 @@ void Basketball_Paint() } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // visualize the control states if (power){ if (skill == 0){ - draw_poweroff_a(basketball_pro_1_x, basketball_pro_1_y, POWER_POS_MODE1); + draw_switch(SWITCH_TYPE_2,basketball_pro_1_x, basketball_pro_1_y, SWITCH_POS_MODE1); } else { - draw_poweroff_a(basketball_pro_2_x, basketball_pro_2_y, POWER_POS_MODE2); + draw_switch(SWITCH_TYPE_2,basketball_pro_1_x, basketball_pro_1_y, SWITCH_POS_MODE2); } for (y = 0; y < BASKETBALL_BLIP_ROWS; y++){ @@ -168,7 +176,7 @@ void Basketball_Paint() draw_digit(digit[x].x, digit[x].y, digit[x].val); } else { - draw_poweroff_a(basketball_power_off_x, basketball_power_off_y, POWER_POS_OFF); + draw_switch(SWITCH_TYPE_2,basketball_pro_1_x, basketball_pro_1_y, SWITCH_POS_OFF); } } @@ -196,13 +204,6 @@ void Basketball_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void Basketball_StopSound() -{ - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // diff --git a/source/platform/Platform_basketball2.c b/source/platform/Platform_basketball2.c new file mode 100644 index 0000000..b0af075 --- /dev/null +++ b/source/platform/Platform_basketball2.c @@ -0,0 +1,507 @@ +/* + * LEDhead for Wii + * Copyright (C) 2017-2020 Nebiun + * + * 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. + * + * 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 3 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. If not, see . + */ + +#include "Basketball2.h" +#include "Basketball2_screen_png.h" +#include "Basketball2_3secs_raw.h" +#include "Basketball2_bounce_raw.h" +#include "Basketball2_endgame_raw.h" +#include "Basketball2_endplay_raw.h" +#include "Basketball2_endquarter_raw.h" +#include "Basketball2_foul_raw.h" +#include "Basketball2_freethrow_raw.h" +#include "Basketball2_overtime_raw.h" +#include "Basketball2_score_raw.h" +#include "Basketball2_score3_raw.h" +#include "Basketball2_tick_raw.h" + +// images +static GRRLIB_texImg *bmpScreen; + +static Sound_t tcWaveRes[BASKETBALL2_SOUND_NSOUNDS]; +static Blip_t blip[BASKETBALL2_BLIP_COLUMNS][BASKETBALL2_BLIP_ROWS]; +static Blip_t basket; +static Stat_t digit[2]; +static Help_t help[] = { + { WK_U, { 33, 179} }, + { WK_L, { 33, 205} }, + { WK_R, { 33, 232} }, + { WK_1, { 87, 175} }, + { WK_2, { 175, 175} }, + { WK_BLR1, {10, 268} }, + { WK_DPAD, { 128, 231} } +}; +//---------------------------------------------------------------------------- +// +// +void Basketball2_Help() +{ + Platform_Help(help, sizeof(help)/sizeof(*help)); +} + +static BOOL bInited = FALSE; + +void Basketball2_Init() +{ + int x, y; + + if (bInited) + return; + + // Init sounds + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_TICK], basketball2_tick_raw, basketball2_tick_raw_size, 8); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_BOUNCE], basketball2_bounce_raw, basketball2_bounce_raw_size, 37); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_SCORE], basketball2_score_raw, basketball2_score_raw_size, 1153); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_ENDPLAY], basketball2_endplay_raw, basketball2_endplay_raw_size, 1061); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_ENDQUARTER], basketball2_endquarter_raw, basketball2_endquarter_raw_size, 1400); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_ENDGAME], basketball2_endgame_raw, basketball2_endgame_raw_size, 2823); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_SCORE3], basketball2_score3_raw, basketball2_score3_raw_size, 2003); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_FOUL], basketball2_foul_raw, basketball2_foul_raw_size, 0); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_3SECS], basketball2_3secs_raw, basketball2_3secs_raw_size, 687); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_FREETHROW], basketball2_freethrow_raw, basketball2_freethrow_raw_size, 608); + Sound_set(&tcWaveRes[BASKETBALL2_SOUND_OVERTIME], basketball2_overtime_raw, basketball2_overtime_raw_size, 3007); + + // load images + bmpScreen = GRRLIB_LoadTexture(basketball2_screen_png); + + // set blips + for (y = 0; y < BASKETBALL2_BLIP_ROWS; y++){ + for (x = 0; x < BASKETBALL2_BLIP_COLUMNS; x++){ + Blip_t *pblip = &blip[x][y]; + + pblip->x = (x * basketball2_blip_xspacing) + basketball2_blip_x; + pblip->y = (y * basketball2_blip_yspacing) + basketball2_blip_y; + pblip->status = -1; + } + } + basket.x = basketball2_basket_x; + basket.y = basketball2_basket_y; + basket.status = -1; + + // set digits + for(x = 0; x < 2; x++) { + digit[x].x = basketball2_digit_x + x * basketball2_digit_spacing; + digit[x].y = basketball2_digit_y; + } + + PlatformSetInput(0); + // turn on the game + Basketball2_SetSkill(LVL_HIGHSCHOOL); + Basketball2_PowerOn(); + + bInited = TRUE; +} + +void Basketball2_StopSound() +{ + // stop all sounds... + Platform_StopSound(); +} + +void Basketball2_DeInit() +{ + // stop all sounds... + Basketball2_StopSound(); + Basketball2_PowerOff(); + GRRLIB_FreeTexture(bmpScreen); + bInited = FALSE; +} + +void Basketball2_Paint() +{ + int x, y, extra; + BOOL power = Basketball2_GetPower(); + int skill = Basketball2_GetSkill(); + int p_switch; + p_switch = Platform_GetPowerSwitchPlus(ONOFF_OFF12, &extra); + if(power) { + if(p_switch == -1) { + if(skill%2 == 0) + Basketball2_PowerOff(); + if(skill%2 == 1) { + Basketball2_PowerOn(); + Basketball2_SetSkill((extra == 0) ? LVL_HIGHSCHOOL : LVL_ALLSTAR); + } + } + if(p_switch == 1) { + if(skill%2 == 0) { + Basketball2_PowerOn(); + Basketball2_SetSkill((extra == 0) ? LVL_COLLAGE : LVL_PROFESSIONAL); + } + } + } + else { + if(p_switch == 1) { + Basketball2_PowerOn(); + Basketball2_SetSkill((extra == 0) ? LVL_HIGHSCHOOL : LVL_ALLSTAR); + } + } + + // paint the backdrop + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); + + // visualize the control states + if (power){ + if (skill%2 == 0){ + draw_switch(SWITCH_TYPE_4, basketball2_power_off_x, basketball2_power_off_y, SWITCH_POS_PRO1); + } else { + draw_switch(SWITCH_TYPE_4, basketball2_power_off_x, basketball2_power_off_y, SWITCH_POS_PRO2); + } + + for (y = 0; y < BASKETBALL2_BLIP_ROWS; y++){ + for (x = 0; x < BASKETBALL2_BLIP_COLUMNS; x++){ + Blip_t *pblip = &blip[x][y]; + + if(pblip->status != -1) + draw_oblip(pblip->x, pblip->y, pblip->status); + } + } + if(basket.status != -1) + draw_oblip(basket.x, basket.y, basket.status); + for(x = 0; x < 2; x++) + draw_digit(digit[x].x, digit[x].y, digit[x].val); + } + else { + draw_switch(SWITCH_TYPE_4, basketball2_power_off_x, basketball2_power_off_y, SWITCH_POS_OFF); + } +} + +void Basketball2_ClearScreen() +{ + Platform_StartDraw(); + + // erase the blips + for (int y = 0; y < BASKETBALL2_BLIP_ROWS; y++){ + for (int x = 0; x < BASKETBALL2_BLIP_COLUMNS; x++){ + Basketball2_DrawBlip(BLIP_OFF, x, y); + } + } + + Basketball2_DrawBasket(FALSE); + + // erase the stat display + Basketball2_DrawStat(-1); + + Platform_EndDraw(); +} + +void Basketball2_PlaySound(int nSound, unsigned int nFlags) +{ + Platform_PlaySound(&tcWaveRes[nSound], nFlags); +} + +//---------------------------------------------------------------------------- +// local fcn's +// + +void Basketball2_DrawBlip(int nBright, int x, int y) +{ + switch(nBright){ + case BLIP_DIM: + blip[x][y].status = BLIP_TYPE_NORMAL; + break; + case BLIP_BRIGHT: + blip[x][y].status = BLIP_TYPE_BRIGHT; + break; + case BLIP_OFF: + default: + blip[x][y].status = -1; + break; + } +} + +void Basketball2_DrawStat(int nStat) +{ + if (nStat == -1){ + // erase the display + digit[0].val = -1; + digit[1].val = -1; + } else { + // draw 10s place + digit[0].val = nStat/10; + // draw 1s place + digit[1].val = nStat%10; + } +} + +void Basketball2_DrawBasket(BOOL bBasket) +{ + Platform_StartDraw(); + + if (bBasket) + { + int x, y; + + // erase the blips + for (y = 0; y < BASKETBALL2_BLIP_ROWS; y++){ + for (x = 0; x < BASKETBALL2_BLIP_COLUMNS; x++){ + Basketball2_DrawBlip(BLIP_OFF, x, y); + } + } + // draw the basket + basket.status = BLIP_TYPE_BRIGHT; + } + else + { + // erase the basket + basket.status = -1; + } + + Platform_EndDraw(); +} + +BOOL Basketball2_GetInputLEFTUP(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputLEFTUP()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Basketball2_GetInputLEFTDOWN(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputLEFTDOWN()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Basketball2_GetInputLEFT(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputLEFT()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Basketball2_GetInputRIGHTUP(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputRIGHTUP()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Basketball2_GetInputRIGHTDOWN(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputRIGHTDOWN()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Basketball2_GetInputRIGHT(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputRIGHT()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Basketball2_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 Basketball2_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 Basketball2_GetInputSHOOT(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 Basketball2_GetInputPASS(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInput1()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Basketball2_TestForMovement() +{ + // check the keys + if ( + /* Platform_GetInputLEFTUP() || + Platform_GetInputLEFTDOWN() || + Platform_GetInputRIGHTUP() || + Platform_GetInputRIGHTDOWN() || */ + Platform_GetInputLEFT() || + Platform_GetInputUP() || + Platform_GetInputRIGHT() || + Platform_GetInputDOWN() || + Platform_GetInput2() || + Platform_GetInput1()) + { + return TRUE; + } + + return FALSE; +} + +void Basketball2_GetSize(int *w, int *h) +{ + *w = bmpScreen->w; + *h = bmpScreen->h; +} diff --git a/source/platform/Platform_basketball2.h b/source/platform/Platform_basketball2.h new file mode 100644 index 0000000..e9eb47f --- /dev/null +++ b/source/platform/Platform_basketball2.h @@ -0,0 +1,76 @@ +/* + * LEDhead for Wii + * Copyright (C) 2017-2020 Nebiun + * + * 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. + * + * 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 3 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. If not, see . + */ + +#ifndef __PLATFORM_BASKETBALL2_H__ +#define __PLATFORM_BASKETBALL2_H__ + +// [general] +#define basketball2_digit_spacing 12 +#define basketball2_digit_x 112 +#define basketball2_digit_y 7 +#define basketball2_digit_w 8 +#define basketball2_digit_h 9 +#define basketball2_blip_xspacing 22 +#define basketball2_blip_yspacing 21 +#define basketball2_blip_x 52 +#define basketball2_blip_y 42 +#define basketball2_power_off_x 29 +#define basketball2_power_off_y 269 +#define basketball2_basket_x 118 +#define basketball2_basket_y 24 + +// Skills +#define LVL_HIGHSCHOOL 0 // Pro1 +#define LVL_COLLAGE 1 // Pro2 +#define LVL_ALLSTAR 2 // Pro1 + Man button +#define LVL_PROFESSIONAL 3 // Pro2 + Man button + +// interface that the platform must provide for this game + +// functions exported to the game context +void Basketball2_Init(); +void Basketball2_Help(); +void Basketball2_DeInit(); +void Basketball2_Paint(); +void Basketball2_ClearScreen(); +void Basketball2_PlaySound(int nSound, unsigned int nFlags); +void Basketball2_StopSound(); +void Basketball2_GetSize(int *w, int *h); + +// "private" functions not exported to game context +void Basketball2_DrawBlip(int nBright, int x, int y); +void Basketball2_DrawStat(int nStat); +void Basketball2_DrawBasket(BOOL bBasket); + +BOOL Basketball2_GetInputLEFT(BOOL *pChange); +BOOL Basketball2_GetInputLEFTUP(BOOL *pChange); +BOOL Basketball2_GetInputLEFTDOWN(BOOL *pChange); +BOOL Basketball2_GetInputRIGHT(BOOL *pChange); +BOOL Basketball2_GetInputRIGHTUP(BOOL *pChange); +BOOL Basketball2_GetInputRIGHTDOWN(BOOL *pChange); +BOOL Basketball2_GetInputUP(BOOL *pChange); +BOOL Basketball2_GetInputDOWN(BOOL *pChange); +BOOL Basketball2_GetInputSHOOT(BOOL *pChange); +BOOL Basketball2_GetInputPASS(BOOL *pChange); +BOOL Basketball2_TestForMovement(); + +#endif diff --git a/source/platform/Platform_football.c b/source/platform/Platform_football.c index b338802..c93e687 100644 --- a/source/platform/Platform_football.c +++ b/source/platform/Platform_football.c @@ -35,9 +35,6 @@ 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" @@ -45,11 +42,8 @@ Website : http://www.peterhirschberg.com // images static GRRLIB_texImg *bmpScreen; -static GRRLIB_texImg *bmpPowerOff; -static GRRLIB_texImg *bmpPro1; -static GRRLIB_texImg *bmpPro2; -static Sound_t tcWaveRes[4]; +static Sound_t tcWaveRes[FOOTBALL_SOUND_NSOUDS]; static Blip_t blip[FOOTBALL_BLIP_COLUMNS][FOOTBALL_BLIP_ROWS]; static Digit_t digit[7] = { {football_digit_x, football_digit_y, -1}, @@ -82,22 +76,18 @@ void Football_Init() { int x, y; - if (bInited) return; + 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); + Sound_set(&tcWaveRes[FOOTBALL_SOUND_TICK], football_tick_raw, football_tick_raw_size, 25); + Sound_set(&tcWaveRes[FOOTBALL_SOUND_ENDPLAY], football_endplay_raw, football_endplay_raw_size, 489); + Sound_set(&tcWaveRes[FOOTBALL_SOUND_ENDPOSSESSION], football_endpossession_raw, football_endpossession_raw_size, 984); + Sound_set(&tcWaveRes[FOOTBALL_SOUND_SCORE], 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++){ @@ -122,14 +112,18 @@ void Football_Init() bInited = TRUE; } -void Football_DeInit() +void Football_StopSound() { // stop all sounds... Platform_StopSound(); +} + +void Football_DeInit() +{ + // stop all sounds... + Football_StopSound(); + Football_PowerOff(); GRRLIB_FreeTexture(bmpScreen); - GRRLIB_FreeTexture(bmpPowerOff); - GRRLIB_FreeTexture(bmpPro1); - GRRLIB_FreeTexture(bmpPro2); bInited = FALSE; } @@ -139,38 +133,34 @@ void Football_Paint() 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) { + p_switch = Platform_GetPowerSwitch(ONOFF_1OFF2); + if(p_switch == -1) { + if(!power) { Football_PowerOn(); Football_SetSkill(0); - } + } + else if(power && skill == 1) { + Football_PowerOff(); + } + } + else if(p_switch == 1) { + if(!power) { + Football_PowerOn(); + Football_SetSkill(1); + } + else if(power && skill == 0) { + Football_PowerOff(); + } } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xffffffff); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 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); + draw_switch(SWITCH_TYPE_3, football_pro_1_x, football_pro_1_y, SWITCH_POS_PRO1); } else { - GRRLIB_DrawImg(realx(football_pro_2_x), realy(football_pro_2_y), bmpPro2, 0, 1, 1, 0xffffffff); + draw_switch(SWITCH_TYPE_3, football_pro_1_x, football_pro_1_y, SWITCH_POS_PRO2); } for (y = 0; y < FOOTBALL_BLIP_ROWS; y++){ @@ -184,7 +174,7 @@ void Football_Paint() } } else { - GRRLIB_DrawImg(realx(football_power_off_x), realy(football_power_off_y), bmpPowerOff, 0, 1, 1, 0xffffffff); + draw_switch(SWITCH_TYPE_3, football_pro_1_x, football_pro_1_y, SWITCH_POS_OFF); } } @@ -213,13 +203,6 @@ void Football_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void Football_StopSound() -{ - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // diff --git a/source/platform/Platform_football2.c b/source/platform/Platform_football2.c index bc4626e..6e8c8fe 100644 --- a/source/platform/Platform_football2.c +++ b/source/platform/Platform_football2.c @@ -35,9 +35,6 @@ Website : http://www.peterhirschberg.com #include "football2.h" #include "football2_screen_png.h" -#include "football2_poweroff_png.h" -#include "football2_pro1_png.h" -#include "football2_pro2_png.h" #include "football2_chargestart_raw.h" #include "football2_charge_raw.h" #include "football2_tick_raw.h" @@ -51,11 +48,8 @@ Website : http://www.peterhirschberg.com // images static GRRLIB_texImg *bmpScreen; -static GRRLIB_texImg *bmpPowerOff; -static GRRLIB_texImg *bmpPro1; -static GRRLIB_texImg *bmpPro2; -static Sound_t tcWaveRes[10]; +static Sound_t tcWaveRes[FOOTBALL2_SOUND_NSOUNDS]; static Blip_t blip[FOOTBALL2_BLIP_COLUMNS][FOOTBALL2_BLIP_ROWS]; static Digit_t digit[7] = { {football2_digit_x, football2_digit_y, -1}, @@ -89,27 +83,23 @@ void Football2_Init() { int x, y; - if (bInited) return; + if (bInited) + return; // Init sounds - Sound_set(&tcWaveRes[0], football2_chargestart_raw, football2_chargestart_raw_size, 865 ); - Sound_set(&tcWaveRes[1], football2_charge_raw, football2_charge_raw_size, 946 ); - Sound_set(&tcWaveRes[2], football2_tick_raw, football2_tick_raw_size, 12 ); - Sound_set(&tcWaveRes[3], football2_runback_raw, football2_runback_raw_size, 260 ); - Sound_set(&tcWaveRes[4], football2_firstdown_raw, football2_firstdown_raw_size, 138 ); - Sound_set(&tcWaveRes[5], football2_endplay_raw, football2_endplay_raw_size, 334 ); - Sound_set(&tcWaveRes[6], football2_endpossession_raw, football2_endpossession_raw_size, 700 ); - Sound_set(&tcWaveRes[7], football2_endquarter_raw, football2_endquarter_raw_size, 995 ); - Sound_set(&tcWaveRes[8], football2_touchdown_raw, football2_touchdown_raw_size, 2566 ); - Sound_set(&tcWaveRes[9], football2_safety_raw, football2_safety_raw_size, 726 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_CHARGESTART], football2_chargestart_raw, football2_chargestart_raw_size, 865 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_CHARGE], football2_charge_raw, football2_charge_raw_size, 946 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_TICK], football2_tick_raw, football2_tick_raw_size, 12 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_RUNBACK], football2_runback_raw, football2_runback_raw_size, 260 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_FIRSTDOWN], football2_firstdown_raw, football2_firstdown_raw_size, 138 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_ENDPLAY], football2_endplay_raw, football2_endplay_raw_size, 334 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_ENDPOSSESSION], football2_endpossession_raw, football2_endpossession_raw_size, 700 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_ENDQUARTER], football2_endquarter_raw, football2_endquarter_raw_size, 995 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_TOUCHDOWN], football2_touchdown_raw, football2_touchdown_raw_size, 2566 ); + Sound_set(&tcWaveRes[FOOTBALL2_SOUND_SAFETY], football2_safety_raw, football2_safety_raw_size, 726 ); // load images bmpScreen = GRRLIB_LoadTexture(football2_screen_png); - - // set up the power switch images - bmpPowerOff = GRRLIB_LoadTexture(football2_poweroff_png); - bmpPro1 = GRRLIB_LoadTexture(football2_pro1_png); - bmpPro2 = GRRLIB_LoadTexture(football2_pro2_png); for (y = 0; y < FOOTBALL2_BLIP_ROWS; y++){ for (x = 0; x < FOOTBALL2_BLIP_COLUMNS; x++){ @@ -128,65 +118,69 @@ void Football2_Init() } PlatformSetInput(0); - // turn on the game + // turn off the game Football2_SetSkill(0); - Football2_PowerOn(); + Football2_PowerOff(); bInited = TRUE; } -void Football2_DeInit() +void Football2_StopSound() { // stop all sounds... Platform_StopSound(); +} + +void Football2_DeInit() +{ + // stop all sounds... + Football2_StopSound(); + Football2_PowerOff(); GRRLIB_FreeTexture(bmpScreen); - GRRLIB_FreeTexture(bmpPowerOff); - GRRLIB_FreeTexture(bmpPro1); - GRRLIB_FreeTexture(bmpPro2); bInited = FALSE; } void Football2_Paint() { - int x, y; + int x, y, extra; BOOL power = Football2_GetPower(); - BOOL skill = Football2_GetSkill(); + int skill = Football2_GetSkill(); int p_switch; - p_switch = Platform_GetPowerSwitch(ONOFF_OFF12); + p_switch = Platform_GetPowerSwitchPlus(ONOFF_OFF12, &extra); if(power) { if(p_switch == -1) { - if(skill == 0) + if(skill%2 == 0) Football2_PowerOff(); - if(skill == 1) { + if(skill%2 == 1) { Football2_PowerOn(); - Football2_SetSkill(0); + Football2_SetSkill((extra == 0) ? LVL_ROOKIESLOW : LVL_PROSLOW); } } if(p_switch == 1) { - if(skill == 0) { + if(skill%2 == 0) { Football2_PowerOn(); - Football2_SetSkill(1); + Football2_SetSkill((extra == 0) ? LVL_ROOKIEFAST : LVL_PROFAST); } } } else { if(p_switch == 1) { Football2_PowerOn(); - Football2_SetSkill(0); + Football2_SetSkill((extra == 0) ? LVL_ROOKIESLOW : LVL_PROSLOW); } } // if (gMainWndP == NULL){ return; } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // visualize the control states if (power){ if (skill == 0){ - GRRLIB_DrawImg(realx(football2_pro_1_x), realy(football2_pro_1_y), bmpPro1, 0, 1, 1, 0xFFFFFFFF); + draw_switch(SWITCH_TYPE_1, football2_pro_1_x, football2_pro_1_y, SWITCH_POS_PRO1); } else { - GRRLIB_DrawImg(realx(football2_pro_2_x), realy(football2_pro_2_y), bmpPro2, 0, 1, 1, 0xFFFFFFFF); + draw_switch(SWITCH_TYPE_1, football2_pro_1_x, football2_pro_1_y, SWITCH_POS_PRO2); } for (y = 0; y < FOOTBALL2_BLIP_ROWS; y++){ @@ -200,7 +194,7 @@ void Football2_Paint() } } else { - GRRLIB_DrawImg(realx(football2_power_off_x), realy(football2_power_off_y), bmpPowerOff, 0, 1, 1, 0xFFFFFFFF); + draw_switch(SWITCH_TYPE_1, football2_pro_1_x, football2_pro_1_y, SWITCH_POS_OFF); } } @@ -229,12 +223,6 @@ void Football2_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void Football2_StopSound() -{ - // stop all sounds... - Platform_StopSound(); -} - //---------------------------------------------------------------------------- // local fcn's // @@ -419,7 +407,7 @@ void Football2_DrawYard(int nYard) if (sign == 1){ // draw direction on left - digit[idx].val = 1; + digit[idx].val = 0; digit[idx].type = DIGIT_TYPE_SPECIAL; idx++; } @@ -435,7 +423,7 @@ void Football2_DrawYard(int nYard) if (sign == -1){ // draw direction on right - digit[idx].val = 0; + digit[idx].val = 1; digit[idx].type = DIGIT_TYPE_SPECIAL; } } diff --git a/source/platform/Platform_football2.h b/source/platform/Platform_football2.h index 15a8588..cbab5be 100644 --- a/source/platform/Platform_football2.h +++ b/source/platform/Platform_football2.h @@ -53,6 +53,14 @@ Website : http://www.peterhirschberg.com #define football2_pro_2_x 91 #define football2_pro_2_y 295 +// Skills +#define LVL_ROOKIESLOW 0 // Pro1 +#define LVL_ROOKIEFAST 1 // Pro2 +#define LVL_PROSLOW 2 // Pro1 + Kick button +#define LVL_PROFAST 3 // Pro2 + Kick button + +#define IS_LVLPRO(x) (((x) == LVL_PROSLOW) || ((x) == LVL_PROFAST)) + // interface that the platform must provide for this game // functions exported to the game context diff --git a/source/platform/Platform_hockey.c b/source/platform/Platform_hockey.c index a7b755e..e0aebc8 100644 --- a/source/platform/Platform_hockey.c +++ b/source/platform/Platform_hockey.c @@ -48,7 +48,7 @@ Website : http://www.peterhirschberg.com // images static GRRLIB_texImg *bmpScreen; -static Sound_t tcWaveRes[9]; +static Sound_t tcWaveRes[HOCKEY_SOUND_NSOUNDS]; static Blip_t blip[HOCKEY_BLIP_COLUMNS][HOCKEY_BLIP_ROWS]; static Stat_t digit[2]; static Help_t help[] = { @@ -70,18 +70,19 @@ void Hockey_Init() { int x, y; - if (bInited) return; + if (bInited) + return; // Init sounds - Sound_set(&tcWaveRes[0], hockey_tick_raw, hockey_tick_raw_size, 14 ); - Sound_set(&tcWaveRes[1], hockey_deflect_raw, hockey_deflect_raw_size, 16 ); - Sound_set(&tcWaveRes[2], hockey_bump_raw, hockey_bump_raw_size, 35 ); - Sound_set(&tcWaveRes[3], hockey_poke_raw, hockey_poke_raw_size, 57 ); - Sound_set(&tcWaveRes[4], hockey_score_raw, hockey_score_raw_size, 1575 ); - Sound_set(&tcWaveRes[5], hockey_penalty_raw, hockey_penalty_raw_size, 1196 ); - Sound_set(&tcWaveRes[6], hockey_steal_raw, hockey_steal_raw_size, 531 ); - Sound_set(&tcWaveRes[7], hockey_endperiod_raw, hockey_endperiod_raw_size, 1205 ); - Sound_set(&tcWaveRes[8], hockey_endgame_raw, hockey_endgame_raw_size, 2382 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_TICK], hockey_tick_raw, hockey_tick_raw_size, 14 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_DEFLECT], hockey_deflect_raw, hockey_deflect_raw_size, 16 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_BUMP], hockey_bump_raw, hockey_bump_raw_size, 35 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_POKE], hockey_poke_raw, hockey_poke_raw_size, 57 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_SCORE], hockey_score_raw, hockey_score_raw_size, 1575 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_PENALTY], hockey_penalty_raw, hockey_penalty_raw_size, 1196 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_STEAL], hockey_steal_raw, hockey_steal_raw_size, 531 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_ENDPERIOD], hockey_endperiod_raw, hockey_endperiod_raw_size, 1205 ); + Sound_set(&tcWaveRes[HOCKEY_SOUND_ENDGAME], hockey_endgame_raw, hockey_endgame_raw_size, 2382 ); // load images bmpScreen = GRRLIB_LoadTexture(hockey_screen_png); @@ -113,10 +114,17 @@ void Hockey_Init() bInited = TRUE; } -void Hockey_DeInit() +void Hockey_StopSound() { // stop all sounds... Platform_StopSound(); +} + +void Hockey_DeInit() +{ + // stop all sounds... + Hockey_StopSound(); + Hockey_PowerOff(); GRRLIB_FreeTexture(bmpScreen); bInited = FALSE; } @@ -147,14 +155,14 @@ void Hockey_Paint() } } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // visualize the control states if (power){ if (skill == 0){ - draw_poweroff_a(hockey_pro_1_x, hockey_pro_1_y, POWER_POS_MODE1); + draw_switch(SWITCH_TYPE_2, hockey_pro_1_x, hockey_pro_1_y, SWITCH_POS_MODE1); } else { - draw_poweroff_a(hockey_pro_2_x, hockey_pro_2_y, POWER_POS_MODE2); + draw_switch(SWITCH_TYPE_2, hockey_pro_1_x, hockey_pro_1_y, SWITCH_POS_MODE2); } for (y = 0; y < HOCKEY_BLIP_ROWS; y++){ @@ -168,7 +176,7 @@ void Hockey_Paint() draw_digit(digit[x].x, digit[x].y, digit[x].val); } else { - draw_poweroff_a(hockey_power_off_x, hockey_power_off_y, POWER_POS_OFF); + draw_switch(SWITCH_TYPE_2, hockey_pro_1_x, hockey_pro_1_y, SWITCH_POS_OFF); } } @@ -194,13 +202,6 @@ void Hockey_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void Hockey_StopSound() -{ - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // diff --git a/source/platform/Platform_hockeyca.c b/source/platform/Platform_hockeyca.c index b333ece..73b6355 100644 --- a/source/platform/Platform_hockeyca.c +++ b/source/platform/Platform_hockeyca.c @@ -45,7 +45,7 @@ Website : http://www.peterhirschberg.com // images static GRRLIB_texImg *bmpScreen; -static Sound_t tcWaveRes[6]; +static Sound_t tcWaveRes[HOCKEYCA_SOUND_NSOUNDS]; static Blip_t blip[HOCKEYCA_BLIP_COLUMNS][HOCKEYCA_BLIP_ROWS]; static Blip_t goal; static Stat_t digit[2]; @@ -68,15 +68,16 @@ void HockeyCa_Init() { int x, y; - if (bInited) return; + if (bInited) + return; // Init sounds - Sound_set(&tcWaveRes[0], hockeyca_tick_raw, hockeyca_tick_raw_size, 13 ); - Sound_set(&tcWaveRes[1], hockeyca_bounce_raw, hockeyca_bounce_raw_size, 33 ); - Sound_set(&tcWaveRes[2], hockeyca_score_raw, hockeyca_score_raw_size, 3307 ); - Sound_set(&tcWaveRes[3], hockeyca_endplay_raw, hockeyca_endplay_raw_size, 762 ); - Sound_set(&tcWaveRes[4], hockeyca_endperiod_raw, hockeyca_endperiod_raw_size, 1654 ); - Sound_set(&tcWaveRes[5], hockeyca_endgame_raw, hockeyca_endgame_raw_size, 2543 ); + Sound_set(&tcWaveRes[HOCKEYCA_SOUND_TICK], hockeyca_tick_raw, hockeyca_tick_raw_size, 13 ); + Sound_set(&tcWaveRes[HOCKEYCA_SOUND_BOUNCE], hockeyca_bounce_raw, hockeyca_bounce_raw_size, 33 ); + Sound_set(&tcWaveRes[HOCKEYCA_SOUND_SCORE], hockeyca_score_raw, hockeyca_score_raw_size, 3307 ); + Sound_set(&tcWaveRes[HOCKEYCA_SOUND_ENDPLAY], hockeyca_endplay_raw, hockeyca_endplay_raw_size, 762 ); + Sound_set(&tcWaveRes[HOCKEYCA_SOUND_ENDQUARTER], hockeyca_endperiod_raw, hockeyca_endperiod_raw_size, 1654 ); + Sound_set(&tcWaveRes[HOCKEYCA_SOUND_ENDGAME], hockeyca_endgame_raw, hockeyca_endgame_raw_size, 2543 ); // load images bmpScreen = GRRLIB_LoadTexture(hockeyca_screen_png); @@ -108,10 +109,17 @@ void HockeyCa_Init() bInited = TRUE; } -void HockeyCa_DeInit() +void HockeyCa_StopSound() { // stop all sounds... Platform_StopSound(); +} + +void HockeyCa_DeInit() +{ + // stop all sounds... + HockeyCa_StopSound(); + HockeyCa_PowerOff(); GRRLIB_FreeTexture(bmpScreen); bInited = FALSE; } @@ -142,14 +150,14 @@ void HockeyCa_Paint() } } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // visualize the control states if (power){ if (skill == 0){ - draw_poweroff_a(hockeyca_pro_1_x, hockeyca_pro_1_y, POWER_POS_MODE1); + draw_switch(SWITCH_TYPE_2,hockeyca_pro_1_x, hockeyca_pro_1_y, SWITCH_POS_MODE1); } else { - draw_poweroff_a(hockeyca_pro_2_x, hockeyca_pro_2_y, POWER_POS_MODE2); + draw_switch(SWITCH_TYPE_2,hockeyca_pro_1_x, hockeyca_pro_1_y, SWITCH_POS_MODE2); } for (y = 0; y < HOCKEYCA_BLIP_ROWS; y++){ @@ -166,7 +174,7 @@ void HockeyCa_Paint() draw_digit(digit[x].x, digit[x].y, digit[x].val); } else { - draw_poweroff_a(hockeyca_power_off_x, hockeyca_power_off_y, POWER_POS_OFF); + draw_switch(SWITCH_TYPE_2,hockeyca_pro_1_x, hockeyca_pro_1_y, SWITCH_POS_OFF); } } @@ -191,13 +199,6 @@ void HockeyCa_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void HockeyCa_StopSound() -{ - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // diff --git a/source/platform/Platform_soccer.c b/source/platform/Platform_soccer.c index ff26e24..33657b0 100644 --- a/source/platform/Platform_soccer.c +++ b/source/platform/Platform_soccer.c @@ -45,7 +45,7 @@ Website : http://www.peterhirschberg.com // images static GRRLIB_texImg *bmpScreen; -static Sound_t tcWaveRes[6]; +static Sound_t tcWaveRes[SOCCER_SOUND_NSOUNDS]; static Blip_t blip[SOCCER_BLIP_COLUMNS][SOCCER_BLIP_ROWS]; static Blip_t goal; static Stat_t digit[2]; @@ -68,15 +68,16 @@ void Soccer_Init() { int x, y; - if (bInited) return; + if (bInited) + return; // Init sounds - Sound_set(&tcWaveRes[0], soccer_tick_raw, soccer_tick_raw_size, 21 ); - Sound_set(&tcWaveRes[1], soccer_bounce_raw, soccer_bounce_raw_size, 47 ); - Sound_set(&tcWaveRes[2], soccer_score_raw, soccer_score_raw_size, 1637 ); - Sound_set(&tcWaveRes[3], soccer_endplay_raw, soccer_endplay_raw_size, 793 ); - Sound_set(&tcWaveRes[4], soccer_endperiod_raw, soccer_endperiod_raw_size, 1746 ); - Sound_set(&tcWaveRes[5], soccer_endgame_raw, soccer_endgame_raw_size, 2687 ); + Sound_set(&tcWaveRes[SOCCER_SOUND_TICK], soccer_tick_raw, soccer_tick_raw_size, 21 ); + Sound_set(&tcWaveRes[SOCCER_SOUND_BOUNCE], soccer_bounce_raw, soccer_bounce_raw_size, 47 ); + Sound_set(&tcWaveRes[SOCCER_SOUND_SCORE], soccer_score_raw, soccer_score_raw_size, 1637 ); + Sound_set(&tcWaveRes[SOCCER_SOUND_ENDPLAY], soccer_endplay_raw, soccer_endplay_raw_size, 793 ); + Sound_set(&tcWaveRes[SOCCER_SOUND_ENDQUARTER], soccer_endperiod_raw, soccer_endperiod_raw_size, 1746 ); + Sound_set(&tcWaveRes[SOCCER_SOUND_ENDGAME], soccer_endgame_raw, soccer_endgame_raw_size, 2687 ); // load images bmpScreen = GRRLIB_LoadTexture(soccer_screen_png); @@ -108,10 +109,17 @@ void Soccer_Init() bInited = TRUE; } -void Soccer_DeInit() +void Soccer_StopSound() { // stop all sounds... Platform_StopSound(); +} + +void Soccer_DeInit() +{ + // stop all sounds... + Soccer_StopSound(); + Soccer_PowerOff(); GRRLIB_FreeTexture(bmpScreen); bInited = FALSE; } @@ -143,14 +151,14 @@ void Soccer_Paint() } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // visualize the control states if (power){ if (skill == 0){ - draw_poweroff_a(soccer_power_off_x, soccer_power_off_y, POWER_POS_MODE1); + draw_switch(SWITCH_TYPE_2,soccer_power_off_x, soccer_power_off_y, SWITCH_POS_MODE1); } else { - draw_poweroff_a(soccer_power_off_x, soccer_power_off_y, POWER_POS_MODE2); + draw_switch(SWITCH_TYPE_2,soccer_power_off_x, soccer_power_off_y, SWITCH_POS_MODE2); } for (y = 0; y < SOCCER_BLIP_ROWS; y++){ for (x = 0; x < SOCCER_BLIP_COLUMNS; x++){ @@ -165,7 +173,7 @@ void Soccer_Paint() draw_digit(digit[x].x, digit[x].y, digit[x].val); } else { - draw_poweroff_a(soccer_power_off_x, soccer_power_off_y, POWER_POS_OFF); + draw_switch(SWITCH_TYPE_2,soccer_power_off_x, soccer_power_off_y, SWITCH_POS_OFF); } } @@ -193,13 +201,6 @@ void Soccer_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void Soccer_StopSound() -{ - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // diff --git a/source/platform/Platform_soccer2.c b/source/platform/Platform_soccer2.c new file mode 100644 index 0000000..6336590 --- /dev/null +++ b/source/platform/Platform_soccer2.c @@ -0,0 +1,574 @@ +/* + * LEDhead for Wii + * Copyright (C) 2017-2020 Nebiun + * + * 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. + * + * 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 3 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. If not, see . + */ + +#include "soccer2.h" +#include "soccer2_screen_png.h" +#include "soccer2_ballout_raw.h" +#include "soccer2_highkick_raw.h" +#include "soccer2_beep_raw.h" +#include "soccer2_looseball_raw.h" +#include "soccer2_endgame_raw.h" +#include "soccer2_lowkick_raw.h" +#include "soccer2_endhalf_raw.h" +#include "soccer2_tick_raw.h" +#include "soccer2_goal_raw.h" +#include "soccer2_bounce_raw.h" + +// images +static GRRLIB_texImg *bmpScreen; + +static Sound_t tcWaveRes[SOCCER2_SOUND_NSOUNDS]; +static Blip_t blip[SOCCER2_BLIP_COLUMNS][SOCCER2_BLIP_ROWS]; +static Blip_t goalarea; +static Digit_t digit[2]; +static Help_t help[] = { + { WK_PLUS, { 38, 181} }, + { WK_U, { 34, 206} }, + { WK_MINUS, { 38, 237} }, + { WK_1, { 87, 175} }, + { WK_2, { 175, 175} }, + { WK_BLR1, {10, 268} }, + { WK_DPAD, { 128, 231} } +}; + +//---------------------------------------------------------------------------- +// +// +void Soccer2_Help() +{ + Platform_Help(help, sizeof(help)/sizeof(*help)); +} + +static BOOL bInited = FALSE; + +void Soccer2_Init() +{ + int x, y; + + if (bInited) + return; + + // Init sounds + Sound_set(&tcWaveRes[SOCCER2_SOUND_TICK], soccer2_tick_raw, soccer2_tick_raw_size, 8); + Sound_set(&tcWaveRes[SOCCER2_SOUND_LOOSEBALL], soccer2_looseball_raw, soccer2_looseball_raw_size,54); + Sound_set(&tcWaveRes[SOCCER2_SOUND_BALLOUT], soccer2_ballout_raw, soccer2_ballout_raw_size,461); + Sound_set(&tcWaveRes[SOCCER2_SOUND_GOAL], soccer2_goal_raw, soccer2_goal_raw_size, 1225); + Sound_set(&tcWaveRes[SOCCER2_SOUND_BEEP], soccer2_beep_raw, soccer2_beep_raw_size, 86); + Sound_set(&tcWaveRes[SOCCER2_SOUND_HIGHKICK], soccer2_highkick_raw, soccer2_highkick_raw_size, 79); + Sound_set(&tcWaveRes[SOCCER2_SOUND_LOWKICK], soccer2_lowkick_raw, soccer2_lowkick_raw_size, 93); + Sound_set(&tcWaveRes[SOCCER2_SOUND_ENDHALF], soccer2_endhalf_raw, soccer2_endhalf_raw_size, 1335); + Sound_set(&tcWaveRes[SOCCER2_SOUND_ENDGAME], soccer2_endgame_raw, soccer2_endgame_raw_size, 2234); + Sound_set(&tcWaveRes[SOCCER2_SOUND_BOUNCE], soccer2_bounce_raw, soccer2_bounce_raw_size, 144); + + // load images + bmpScreen = GRRLIB_LoadTexture(soccer2_screen_png); + + for (y = 0; y < SOCCER2_BLIP_ROWS; y++){ + for (x = 0; x < SOCCER2_BLIP_COLUMNS; x++){ + Blip_t *pblip = &blip[x][y]; + + pblip->x = (x * soccer2_blip_xspacing) + soccer2_blip_x; + pblip->y = (y * soccer2_blip_yspacing) + soccer2_blip_y; + pblip->status = -1; + } + } + goalarea.x = soccer2_goalarea_x; + goalarea.y = soccer2_goalarea_y; + goalarea.status = -1; + + // clean digit + // set digits + for(x = 0; x < 2; x++) { + digit[x].x = soccer2_digit_x + x * soccer2_digit_spacing; + digit[x].y = soccer2_digit_y; + digit[x].val = -1; + digit[x].type = DIGIT_TYPE_NORMAL; + } + + PlatformSetInput(0); + // turn on the game + Soccer2_SetSkill(0); + Soccer2_PowerOn(); + + bInited = TRUE; +} + +void Soccer2_StopSound() +{ + // stop all sounds... + Platform_StopSound(); +} + +void Soccer2_DeInit() +{ + // stop all sounds... + Soccer2_StopSound(); + Soccer2_PowerOff(); + GRRLIB_FreeTexture(bmpScreen); + bInited = FALSE; +} + +void Soccer2_Paint() +{ + int x, y, extra; + BOOL power = Soccer2_GetPower(); + int skill = Soccer2_GetSkill(); + int p_switch; + p_switch = Platform_GetPowerSwitchPlus(ONOFF_OFF12, &extra); + if(power) { + if(p_switch == -1) { + if(skill%2 == 0) + Soccer2_PowerOff(); + if(skill%2 == 1) { + Soccer2_PowerOn(); + Soccer2_SetSkill((extra == 0) ? LVL_ROOKIESLOW : LVL_PROSLOW); + } + } + if(p_switch == 1) { + if(skill%2 == 0) { + Soccer2_PowerOn(); + Soccer2_SetSkill((extra == 0) ? LVL_ROOKIEFAST : LVL_PROFAST); + } + } + } + else { + if(p_switch == 1) { + Soccer2_PowerOn(); + Soccer2_SetSkill((extra == 0) ? LVL_ROOKIESLOW : LVL_PROSLOW); + } + } + +// if (gMainWndP == NULL){ return; } + + // paint the backdrop + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); + + // visualize the control states + if (power){ + if (skill%2 == 0){ + draw_switch(SWITCH_TYPE_4, soccer2_power_off_x, soccer2_power_off_y, SWITCH_POS_PRO1); + } else { + draw_switch(SWITCH_TYPE_4, soccer2_power_off_x, soccer2_power_off_y, SWITCH_POS_PRO2); + } + + for (y = 0; y < SOCCER2_BLIP_ROWS; y++){ + for (x = 0; x < SOCCER2_BLIP_COLUMNS; x++){ + Blip_t *pblip = &blip[x][y]; + + if(pblip->status != -1) + draw_oblip(pblip->x, pblip->y, pblip->status); + } + } + if(goalarea.status != -1) + draw_oblip(goalarea.x, goalarea.y, goalarea.status); + + for(x = 0; x < 2; x++) + draw_digit_f(digit[x].x, digit[x].y, digit[x].val, digit[x].type); + } + else { + draw_switch(SWITCH_TYPE_4, soccer2_power_off_x, soccer2_power_off_y, SWITCH_POS_OFF); + } +} + +void Soccer2_ClearScreen() +{ + int x, y; + + Platform_StartDraw(); + + // erase the blips + for (y = 0; y < SOCCER2_BLIP_ROWS; y++){ + for (x = 0; x < SOCCER2_BLIP_COLUMNS; x++){ + Soccer2_DrawBlip(BLIP_OFF, x, y); + } + } + // erase the stat display + Soccer2_DrawStat(-1); + + Platform_EndDraw(); +} + +void Soccer2_PlaySound(int nSound, unsigned int nFlags) +{ + if(tcWaveRes[nSound].stream != NULL) + Platform_PlaySound(&tcWaveRes[nSound], nFlags); +} + +//---------------------------------------------------------------------------- +// local fcn's +// + +void Soccer2_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 Soccer2_DrawGoalareaFlag(BOOL status) +{ + if (status) { + // goalarea flag on + goalarea.status = BLIP_TYPE_NORMAL; + } + else { + // goalarea flag off + goalarea.status = -1; + } +} + +void Soccer2_DrawStat(int nStat) +{ + digit[0].type = DIGIT_TYPE_NORMAL; + digit[1].type = DIGIT_TYPE_NORMAL; + + if (nStat == -1){ + // erase the display + digit[0].val = -1; + digit[1].val = -1; + } else { + // draw 10s place + digit[0].val = nStat/10; + // draw 1s place + digit[1].val = nStat%10; + } +} + +void Soccer2_DrawSect(int nSect, BOOL side) +{ + digit[0].type = DIGIT_TYPE_NORMAL; + digit[0].val = (side == TRUE) ? nSect : (10 - nSect); + digit[1].type = DIGIT_TYPE_SPECIAL; + digit[1].val = (side == FALSE) ? 2 : 3; // Print U or H +} + +BOOL Soccer2_GetInputPASS(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInput1()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + + return FALSE; +} + +BOOL Soccer2_GetInputSHOOT(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 Soccer2_GetInputKICK(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 Soccer2_GetInputSCORE(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 Soccer2_GetInputTEAM(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 Soccer2_GetInputLEFTUP(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputLEFTUP()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Soccer2_GetInputLEFTDOWN(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputLEFTDOWN()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Soccer2_GetInputLEFT(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputLEFT()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Soccer2_GetInputRIGHTUP(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputRIGHTUP()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Soccer2_GetInputRIGHTDOWN(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputRIGHTDOWN()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + return FALSE; +} + +BOOL Soccer2_GetInputRIGHT(BOOL *pChange) +{ + static BOOL bLast = FALSE; + + if (pChange){ *pChange = FALSE; } + + // check the keys + if (Platform_GetInputRIGHT()) + { + if (!bLast && pChange) + { + *pChange = TRUE; + } + bLast = TRUE; + return TRUE; + } + + bLast = FALSE; + + return FALSE; +} + +BOOL Soccer2_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 Soccer2_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 Soccer2_TestForMovement() +{ + // check the keys + if (Platform_GetInputLEFT() + || Platform_GetInputUP() + || Platform_GetInputRIGHT() + || Platform_GetInputDOWN()) + { + return TRUE; + } + + return FALSE; +} + +void Soccer2_GetSize(int *w, int *h) +{ + *w = bmpScreen->w; + *h = bmpScreen->h; +} + diff --git a/source/platform/Platform_soccer2.h b/source/platform/Platform_soccer2.h new file mode 100644 index 0000000..9b695ff --- /dev/null +++ b/source/platform/Platform_soccer2.h @@ -0,0 +1,83 @@ +/* + * LEDhead for Wii + * Copyright (C) 2017-2020 Nebiun + * + * 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. + * + * 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 3 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. If not, see . + */ + +#ifndef __PLATFORM_SOCCER2_H__ +#define __PLATFORM_SOCCER2_H__ + +// [general] +#define soccer2_digit_spacing 12 +#define soccer2_digit_x 112 +#define soccer2_digit_y 6 +#define soccer2_digit_w 8 +#define soccer2_digit_h 9 +#define soccer2_blip_xspacing 25 +#define soccer2_blip_yspacing 21 +#define soccer2_blip_x 43 +#define soccer2_blip_y 42 +#define soccer2_power_off_x 29 +#define soccer2_power_off_y 269 +#define soccer2_goalarea_x 118 +#define soccer2_goalarea_y 22 + +// Skills +#define LVL_ROOKIESLOW 0 // Pro1 +#define LVL_ROOKIEFAST 1 // Pro2 +#define LVL_PROSLOW 2 // Pro1 + Score button +#define LVL_PROFAST 3 // Pro2 + Score button + +#define IS_LVLPRO(x) (((x) == LVL_PROSLOW) || ((x) == LVL_PROFAST)) + +// interface that the platform must provide for this game + +// functions exported to the game context +void Soccer2_Init(); +void Soccer2_Help(); +void Soccer2_DeInit(); +void Soccer2_Paint(); +void Soccer2_ClearScreen(); +void Soccer2_PlaySound(int nSound, unsigned int nFlags); +void Soccer2_StopSound(); +void Soccer2_GetSize(int *w, int *h); + +// "private" functions not exported to game context +void Soccer2_DrawBlip(int nBright, int x, int y); +void Soccer2_DrawStat(int nStat); +void Soccer2_DrawSect(int nSect, BOOL side); +void Soccer2_DrawGoalareaFlag(BOOL status); + +BOOL Soccer2_GetInputLEFTUP(BOOL *pChange); +BOOL Soccer2_GetInputLEFTDOWN(BOOL *pChange); +BOOL Soccer2_GetInputLEFT(BOOL *pChange); +BOOL Soccer2_GetInputRIGHTUP(BOOL *pChange); +BOOL Soccer2_GetInputRIGHTDOWN(BOOL *pChange); +BOOL Soccer2_GetInputUP(BOOL *pChange); +BOOL Soccer2_GetInputRIGHT(BOOL *pChange); +BOOL Soccer2_GetInputDOWN(BOOL *pChange); +BOOL Soccer2_GetInputKICK(BOOL *pChange); +BOOL Soccer2_GetInputPASS(BOOL *pChange); +BOOL Soccer2_GetInputSHOOT(BOOL *pChange); +BOOL Soccer2_GetInputTEAM(BOOL *pChange); +BOOL Soccer2_GetInputSCORE(BOOL *pChange); + +BOOL Soccer2_TestForMovement(); + +#endif diff --git a/source/platform/Platform_spacealert.c b/source/platform/Platform_spacealert.c index 2eee114..33d875f 100644 --- a/source/platform/Platform_spacealert.c +++ b/source/platform/Platform_spacealert.c @@ -34,27 +34,26 @@ Website : http://www.peterhirschberg.com */ #include "spacealert.h" +#include "slide2_png.h" +#include "slide3_png.h" #include "spacealert_screen_png.h" -#include "spacealert_poweron_png.h" -#include "spacealert_poweroff_png.h" -#include "spacealert_aimleft_png.h" -#include "spacealert_aimcenter_png.h" -#include "spacealert_aimright_png.h" +#include "missileattack_screen_png.h" #include "spacealert_fire_raw.h" #include "spacealert_hit_raw.h" #include "spacealert_lose_raw.h" #include "spacealert_win_raw.h" #include "spacealert_raider_raw.h" +#define SPACE_ALERT 0 +#define MISSILE_ATTACK 1 + // images static GRRLIB_texImg *bmpScreen; -static GRRLIB_texImg *bmpPowerOn; -static GRRLIB_texImg *bmpPowerOff; -static GRRLIB_texImg *bmpAimLeft; -static GRRLIB_texImg *bmpAimCenter; -static GRRLIB_texImg *bmpAimRight; +static GRRLIB_texImg *bmpPower; +static GRRLIB_texImg *bmpAim; static int nStick = 1; +static int game = -1; static BOOL bRaiderSound = FALSE; static BOOL bRaiderSoundPlaying = FALSE; @@ -62,58 +61,81 @@ static BOOL bRaiderSoundPlaying = FALSE; static void StartRaiderSound(); static void StopRaiderSound(); -static Sound_t tcWaveRes[5]; +static Sound_t tcWaveRes[SPACEALERT_SOUND_NSOUNDS]; static Blip_t blip[SPACEALERT_BLIP_COLUMNS][SPACEALERT_BLIP_ROWS]; static Stat_t digit[2]; -static Help_t help[] = { +static Help_t SpaceAlert_help[] = { { WK_2, { 86, 122 } }, { WK_BUD, { 88, 224 } }, { WK_LR, { 156, 265 } } }; +static Help_t MissileAttack_help[] = { + { WK_2, { 73, 98 } }, + { WK_BUD, { 71, 180 } }, + { WK_LR, { 166, 284 } } +}; //---------------------------------------------------------------------------- // // void SpaceAlert_Help() { - Platform_Help(help, sizeof(help)/sizeof(*help)); + Platform_Help(SpaceAlert_help, sizeof(SpaceAlert_help)/sizeof(*SpaceAlert_help)); +} +void MissileAttack_Help() +{ + Platform_Help(MissileAttack_help, sizeof(MissileAttack_help)/sizeof(*MissileAttack_help)); } static BOOL bInited = FALSE; -void SpaceAlert_Init() +static void game_init() { int x, y; - if (bInited) return; + if (bInited) + return; // Init sounds - Sound_set(&tcWaveRes[0], spacealert_fire_raw, spacealert_fire_raw_size, 109); - Sound_set(&tcWaveRes[1], spacealert_hit_raw, spacealert_hit_raw_size, 284); - Sound_set(&tcWaveRes[2], spacealert_lose_raw, spacealert_lose_raw_size, 1243); - Sound_set(&tcWaveRes[3], spacealert_win_raw, spacealert_win_raw_size, 850); - Sound_set(&tcWaveRes[4], spacealert_raider_raw, spacealert_raider_raw_size, 3902); + Sound_set(&tcWaveRes[SPACEALERT_SOUND_FIRE], spacealert_fire_raw, spacealert_fire_raw_size, 109); + Sound_set(&tcWaveRes[SPACEALERT_SOUND_HIT], spacealert_hit_raw, spacealert_hit_raw_size, 284); + Sound_set(&tcWaveRes[SPACEALERT_SOUND_LOSE], spacealert_lose_raw, spacealert_lose_raw_size, 1243); + Sound_set(&tcWaveRes[SPACEALERT_SOUND_WIN], spacealert_win_raw, spacealert_win_raw_size, 850); + Sound_set(&tcWaveRes[SPACEALERT_SOUND_RAIDER], spacealert_raider_raw, spacealert_raider_raw_size, 3902); // load images - bmpScreen = GRRLIB_LoadTexture(spacealert_screen_png); - bmpPowerOn = GRRLIB_LoadTexture(spacealert_poweron_png); - bmpPowerOff = GRRLIB_LoadTexture(spacealert_poweroff_png); - bmpAimLeft = GRRLIB_LoadTexture(spacealert_aimleft_png); - bmpAimCenter = GRRLIB_LoadTexture(spacealert_aimcenter_png); - bmpAimRight = GRRLIB_LoadTexture(spacealert_aimright_png); + if(game == SPACE_ALERT) + bmpScreen = GRRLIB_LoadTexture(spacealert_screen_png); + else + bmpScreen = GRRLIB_LoadTexture(missileattack_screen_png); + + bmpPower = GRRLIB_LoadTexture(slide2_png); + bmpAim = GRRLIB_LoadTexture(slide3_png); // set blips for (y = 0; y < SPACEALERT_BLIP_ROWS; y++){ for (x = 0; x < SPACEALERT_BLIP_COLUMNS; x++){ Blip_t *pblip = &blip[x][y]; - pblip->x = (int)((x * ((float)spacealert_blip_xspacing/100)) + spacealert_blip_x); - pblip->y = (int)((y * ((float)spacealert_blip_yspacing/100)) + spacealert_blip_y); + if(game == SPACE_ALERT) { + pblip->x = (int)((x * ((float)spacealert_blip_xspacing/100)) + spacealert_blip_x); + pblip->y = (int)((y * ((float)spacealert_blip_yspacing/100)) + spacealert_blip_y); + } + else { + pblip->x = (int)((x * ((float)missileattack_blip_xspacing/100)) + missileattack_blip_x); + pblip->y = (int)((y * ((float)missileattack_blip_yspacing/100)) + missileattack_blip_y); + } pblip->status = -1; } } // set digits for(x = 0; x < 2; x++) { - digit[x].x = spacealert_digit_x + x * spacealert_digit_spacing; - digit[x].y = spacealert_digit_y; + if(game == SPACE_ALERT) { + digit[x].x = spacealert_digit_x + x * spacealert_digit_spacing; + digit[x].y = spacealert_digit_y; + } + else { + digit[x].x = missileattack_digit_x + x * missileattack_digit_spacing; + digit[x].y = missileattack_digit_y; + } } PlatformSetInput(0); // start with the game off @@ -122,18 +144,35 @@ void SpaceAlert_Init() bInited = TRUE; } +void SpaceAlert_Init() +{ + game = SPACE_ALERT; + game_init(); +} + +void MissileAttack_Init() +{ + game = MISSILE_ATTACK; + game_init(); +} + +void SpaceAlert_StopSound() +{ + bRaiderSoundPlaying = FALSE; + bRaiderSound = FALSE; + + // stop all sounds... + Platform_StopSound(); +} + void SpaceAlert_DeInit() { // stop all sounds... - Platform_StopSound(); - bRaiderSoundPlaying = FALSE; - + SpaceAlert_StopSound(); + SpaceAlert_PowerOff(); GRRLIB_FreeTexture(bmpScreen); - GRRLIB_FreeTexture(bmpPowerOff); - GRRLIB_FreeTexture(bmpPowerOn); - GRRLIB_FreeTexture(bmpAimLeft); - GRRLIB_FreeTexture(bmpAimCenter); - GRRLIB_FreeTexture(bmpAimRight); + GRRLIB_FreeTexture(bmpPower); + GRRLIB_FreeTexture(bmpAim); bInited = FALSE; } @@ -152,11 +191,14 @@ void SpaceAlert_Paint() } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // visualize the control states if (power){ - GRRLIB_DrawImg(realx(spacealert_power_x), realy(spacealert_power_y), bmpPowerOn, 0, 1, 1, 0xFFFFFFFF); + if(game == SPACE_ALERT) + GRRLIB_DrawImg(realx(spacealert_power_x), realy(spacealert_power_y+5), bmpPower, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); + else + GRRLIB_DrawImg(realx(missileattack_power_x), realy(missileattack_power_y+5), bmpPower, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); for (y = 0; y < SPACEALERT_BLIP_ROWS; y++){ for (x = 0; x < SPACEALERT_BLIP_COLUMNS; x++){ @@ -168,24 +210,24 @@ void SpaceAlert_Paint() // Draw points for(x = 0; x < 2; x++) draw_digit(digit[x].x, digit[x].y, digit[x].val); - // Draw stick - switch (nStick) - { - case 0: - GRRLIB_DrawImg(realx(spacealert_slider_x), realy(spacealert_slider_y), bmpAimLeft, 0, 1, 1, 0xFFFFFFFF); - break; - case 1: - GRRLIB_DrawImg(realx(spacealert_slider_x), realy(spacealert_slider_y), bmpAimCenter, 0, 1, 1, 0xFFFFFFFF); - break; - case 2: - GRRLIB_DrawImg(realx(spacealert_slider_x), realy(spacealert_slider_y), bmpAimRight, 0, 1, 1, 0xFFFFFFFF); - break; - } } else { - GRRLIB_DrawImg(realx(spacealert_power_x), realy(spacealert_power_y), bmpPowerOff, 0, 1, 1, 0xFFFFFFFF); + if(game == SPACE_ALERT) + GRRLIB_DrawImg(realx(spacealert_power_x), realy(spacealert_power_y+27), bmpPower, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); + else + GRRLIB_DrawImg(realx(missileattack_power_x), realy(missileattack_power_y+27), bmpPower, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); } - + // Draw stick + if(game == SPACE_ALERT) { + x = realx(spacealert_slider_x); + y = realy(spacealert_slider_y); + } + else { + x = realx(missileattack_slider_x); + y = realy(missileattack_slider_y); + } + + GRRLIB_DrawImg(x+2+(nStick * 20), y, bmpAim, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); } void SpaceAlert_ClearScreen() @@ -220,16 +262,6 @@ void SpaceAlert_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void SpaceAlert_StopSound() -{ - bRaiderSoundPlaying = FALSE; - bRaiderSound = FALSE; - - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // @@ -346,25 +378,23 @@ BOOL SpaceAlert_GetInputFIRE(BOOL *pChange) { static BOOL bLast = FALSE; - if (pChange){ *pChange = FALSE; } + if (pChange) { + *pChange = FALSE; + } // check the keys - if (Platform_GetInput2()) - { - if (!bLast) - { - if (pChange) - { + if (Platform_GetInput2()) { + if (!bLast) { + if (pChange) { *pChange = TRUE; } } bLast = TRUE; - return TRUE; } - - bLast = FALSE; - - return FALSE; + else { + bLast = FALSE; + } + return bLast; } void SpaceAlert_GetSize(int *w, int *h) @@ -372,5 +402,3 @@ void SpaceAlert_GetSize(int *w, int *h) *w = bmpScreen->w; *h = bmpScreen->h; } - - diff --git a/source/platform/Platform_spacealert.h b/source/platform/Platform_spacealert.h index 2e31def..909365f 100644 --- a/source/platform/Platform_spacealert.h +++ b/source/platform/Platform_spacealert.h @@ -51,14 +51,29 @@ Website : http://www.peterhirschberg.com #define spacealert_slider_y 271 #define spacealert_power_x 87 #define spacealert_power_y 231 -#define spacealert_kfire_x 73 -#define spacealert_kfire_y 148 + +// [general] +#define missileattack_digit_spacing 12 +#define missileattack_digit_x 172 +#define missileattack_digit_y 65 +#define missileattack_digit_w 13 +#define missileattack_digit_h 14 +#define missileattack_blip_xspacing 1300 +#define missileattack_blip_yspacing 1700 +#define missileattack_blip_x 166 +#define missileattack_blip_y 95 +#define missileattack_slider_x 151 +#define missileattack_slider_y 292 +#define missileattack_power_x 78 +#define missileattack_power_y 188 // interface that the platform must provide for this game // functions exported to the game context void SpaceAlert_Init(); +void MissileAttack_Init(); void SpaceAlert_Help(); +void MissileAttack_Help(); void SpaceAlert_DeInit(); void SpaceAlert_Paint(); void SpaceAlert_ClearScreen(); diff --git a/source/platform/Platform_subchase.c b/source/platform/Platform_subchase.c index 5f48905..c9670c9 100644 --- a/source/platform/Platform_subchase.c +++ b/source/platform/Platform_subchase.c @@ -56,7 +56,7 @@ static GRRLIB_texImg *bmpDigits; static GRRLIB_texImg *bmpPowerOff; static GRRLIB_texImg *bmpPowerOn; -static Sound_t tcWaveRes[4]; +static Sound_t tcWaveRes[SUBCHASE_SOUND_NSOUNDS]; static Blip_t blip[SUBCHASE_BLIP_COLUMNS][SUBCHASE_BLIP_ROWS]; static Stat_t digit[2]; static Help_t help[] = { @@ -79,10 +79,10 @@ void SubChase_Init() int x, y; // Init sounds - Sound_set(&tcWaveRes[0], subchase_sonar_raw, subchase_sonar_raw_size, 119); - Sound_set(&tcWaveRes[1], subchase_charge_raw, subchase_charge_raw_size, 915); - Sound_set(&tcWaveRes[2], subchase_hit_raw, subchase_hit_raw_size, 1190); - Sound_set(&tcWaveRes[3], subchase_sink_raw, subchase_sink_raw_size, 1654); + Sound_set(&tcWaveRes[SUBCHASE_SOUND_SONAR], subchase_sonar_raw, subchase_sonar_raw_size, 119); + Sound_set(&tcWaveRes[SUBCHASE_SOUND_CHARGE], subchase_charge_raw, subchase_charge_raw_size, 915); + Sound_set(&tcWaveRes[SUBCHASE_SOUND_HIT], subchase_hit_raw, subchase_hit_raw_size, 1190); + Sound_set(&tcWaveRes[SUBCHASE_SOUND_SINK], subchase_sink_raw, subchase_sink_raw_size, 1654); // load images bmpScreen = GRRLIB_LoadTexture(subchase_screen_png); @@ -120,11 +120,17 @@ void SubChase_Init() } } -void SubChase_DeInit() +void SubChase_StopSound() { // stop all sounds... Platform_StopSound(); - +} + +void SubChase_DeInit() +{ + // stop all sounds... + SubChase_StopSound(); + SubChase_PowerOff(); GRRLIB_FreeTexture(bmpScreen); GRRLIB_FreeTexture(bmpBlipDim); GRRLIB_FreeTexture(bmpBlipBright); @@ -149,12 +155,12 @@ void SubChase_Paint() } // paint the backdrop - GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(0), realy(0), bmpScreen, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); // visualize the control states if (power) { - GRRLIB_DrawImg(realx(subchase_power_x), realy(subchase_power_y), bmpPowerOn, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(subchase_power_x), realy(subchase_power_y), bmpPowerOn, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); for (y = 0; y < SUBCHASE_BLIP_ROWS; y++){ for (x = 0; x < SUBCHASE_BLIP_COLUMNS; x++){ @@ -162,10 +168,10 @@ void SubChase_Paint() switch(pblip->status) { case BLIP_DIM: - GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlipDim, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlipDim, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); break; case BLIP_BRIGHT: - GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlipBright, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(pblip->x), realy(pblip->y), bmpBlipBright, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); break; case BLIP_OFF: default: @@ -175,12 +181,12 @@ void SubChase_Paint() } for(x = 0; x < 2; x++) { - GRRLIB_DrawTile(realx(digit[x].x), realy(digit[x].y), bmpDigits, 0, 1, 1, 0xFFFFFFFF, digit[x].val); + GRRLIB_DrawTile(realx(digit[x].x), realy(digit[x].y), bmpDigits, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF, digit[x].val); } } else { - GRRLIB_DrawImg(realx(subchase_power_x), realy(subchase_power_y), bmpPowerOff, 0, 1, 1, 0xFFFFFFFF); + GRRLIB_DrawImg(realx(subchase_power_x), realy(subchase_power_y), bmpPowerOff, 0, SCALE_X, SCALE_Y, 0xFFFFFFFF); } } @@ -209,13 +215,6 @@ void SubChase_PlaySound(int nSound, unsigned int nFlags) Platform_PlaySound(&tcWaveRes[nSound], nFlags); } -void SubChase_StopSound() -{ - // stop all sounds... - Platform_StopSound(); -} - - //---------------------------------------------------------------------------- // local fcn's // diff --git a/source/platform/ReadMe.txt b/source/platform/ReadMe.txt new file mode 100644 index 0000000..0be5b37 --- /dev/null +++ b/source/platform/ReadMe.txt @@ -0,0 +1,88 @@ +======================================================================== + MICROSOFT FOUNDATION CLASS LIBRARY : LEDhead +======================================================================== + + +AppWizard has created this LEDhead application for you. This application +not only demonstrates the basics of using the Microsoft Foundation classes +but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your LEDhead application. + +LEDhead.dsp + This file (the project file) contains information at the project level and + is used to build a single project or subproject. Other users can share the + project (.dsp) file, but they should export the makefiles locally. + +LEDhead.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CLEDheadApp application class. + +LEDhead.cpp + This is the main application source file that contains the application + class CLEDheadApp. + +LEDhead.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. + +LEDhead.clw + This file contains information used by ClassWizard to edit existing + classes or add new classes. ClassWizard also uses this file to store + information needed to create and edit message maps and dialog data + maps and to create prototype member functions. + +res\LEDhead.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file LEDhead.rc. + +res\LEDhead.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + + +///////////////////////////////////////////////////////////////////////////// + +For the main frame window: + +MainFrm.h, MainFrm.cpp + These files contain the frame class CMainFrame, which is derived from + CFrameWnd and controls all SDI frame features. + +///////////////////////////////////////////////////////////////////////////// + + + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named LEDhead.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, and your application is +in a language other than the operating system's current language, you +will need to copy the corresponding localized resources MFC42XXX.DLL +from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, +and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. +For example, MFC42DEU.DLL contains resources translated to German.) If you +don't do this, some of the UI elements of your application will remain in the +language of the operating system. + +///////////////////////////////////////////////////////////////////////////// diff --git a/source/platform/TODO.TXT b/source/platform/TODO.TXT new file mode 100644 index 0000000..c9f94c1 --- /dev/null +++ b/source/platform/TODO.TXT @@ -0,0 +1,4 @@ +BUGS +- if you switch to another program then back, focus is not set to game window +- baseball: no pro2 support +- football2: if game is tied after a quarter of overtime, game never ends! diff --git a/source/platform/help.c b/source/platform/help.c index 0f80f88..676a4c6 100644 --- a/source/platform/help.c +++ b/source/platform/help.c @@ -2,6 +2,10 @@ * LEDhead for Wii * Copyright (C) 2017-2020 Nebiun * + * 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. + * * 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 3 of the License, or @@ -24,10 +28,15 @@ #include "WKB_png.h" #include "WKBUD_png.h" #include "WKBLR_png.h" +#include "WKBLR1_png.h" #include "WKPLUS_png.h" #include "WKMINUS_png.h" #include "WKHOME_png.h" #include "WKDPAD_png.h" +#include "WKU_png.h" +#include "WKD_png.h" +#include "WKL_png.h" +#include "WKR_png.h" #include "WKUD_png.h" #include "WKLR_png.h" @@ -42,10 +51,15 @@ static void _key_init(void) key_img[WK_B] = GRRLIB_LoadTexture(WKB_png); key_img[WK_BUD] = GRRLIB_LoadTexture(WKBUD_png); key_img[WK_BLR] = GRRLIB_LoadTexture(WKBLR_png); + key_img[WK_BLR1] = GRRLIB_LoadTexture(WKBLR1_png); key_img[WK_PLUS] = GRRLIB_LoadTexture(WKPLUS_png); key_img[WK_MINUS] = GRRLIB_LoadTexture(WKMINUS_png); key_img[WK_HOME] = GRRLIB_LoadTexture(WKHOME_png); key_img[WK_DPAD] = GRRLIB_LoadTexture(WKDPAD_png); + key_img[WK_U] = GRRLIB_LoadTexture(WKU_png); + key_img[WK_D] = GRRLIB_LoadTexture(WKD_png); + key_img[WK_L] = GRRLIB_LoadTexture(WKL_png); + key_img[WK_R] = GRRLIB_LoadTexture(WKR_png); key_img[WK_UD] = GRRLIB_LoadTexture(WKUD_png); key_img[WK_LR] = GRRLIB_LoadTexture(WKLR_png); } @@ -58,7 +72,7 @@ void Platform_Help(Help_t *vect, int n) _key_init(); for(i=0; i