Files
gullradriel 1dbfc50dbe Stable merge v2.2.0 (#2736)
* Update README.md

Actually valid complete ali h4m link

* Fake brightness reimplementation  (#2444)

* Fake brightness reimplementation
* indentation
* added call to the function which is caching the display settings values
* use cached values instead of pmem

* app manager (#2442)

* fix unset autostart
* clean up - add comments to prevent misleading
* move the app to external and with necessary changes
* replace autostart app

* Add + - buttons in Encoder dial settings (#2447)

* M10 additional parser (#2448)

* Remember previous capture settings (#2450)

* Renamed parameters in rx_capture.ini file (#2452)

* Rename settings in file to match screen
* Renamed variables for hopefully better clarity

* Navigation buttons (#2458)

* regenerate bitmap data
* pagination in submenu
* using little font so we are not eating menu buttons

* docker improvements (#2455)

* Update README.md

New metal case link

* The gerber files of the portapack H4 (#2463)

* Create README.txt

* Update README.txt

* Add files via upload

The gerber files of the portapack h4.

* delete

* Upload the gerber files for H4

* Update README.md (#2456)

Added a link to Lab401.com as a purchase option for EU customers.
(Lab401 was added as the EU exclusive distributor for the H4M - https://opensourcesdrlab.com/pages/distributors)

* Update README.md

* rename bitmaps into bmp

* disabling button on main menu, change labels and add 'icons' (#2466)

* disabling button on main menu, change labels and add 'icons'

* fix reverse order of buttons

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* fix for empty text prompt crash (#2468)

* added discord server information (#2471)

* Add the feature to decide rotate direction of encoder (#2472)

* Update README.md

Lab401 link with our redirection

* Fix encoder setting p.mem issue (#2475)

* Update README.md

Discord badge was broken, switching to shields.io

* Add fast flash script for sdcard switch hardware (#2480)

* fix cmake_minimum_required to 3.16 (#2499)

* fix fallthrough warning (#2497)

* Flipper tx: use file_path, example file (#2496)

* added subghz_dir
* use subghz_dir from file_path
* example file

* Externalize antenna calc and wav view (#2498)

* externalize antenna calc and wav view
* Added a tool to check if all the pictures in graphics are used in internal apps

* APRS: add frequency settings for Brazil (#2494)

* Add frequency settings for Brazil, named 'BR' that tunes to 145.570 MHz.
* Also added: Japan: 144.640 MHz (JAP), Thailand: 144.900 MHz (THA), Philippines: 144.740 MHz (PHI)
* Reordered list by increasing frequency
Co-authored-by: gullradriel <3157857+gullradriel@users.noreply.github.com>

* Added different modulations in signal generator (#2492)

* Added DSB, AM 100% mod index and AM 50% mod index. Changed UI.

* put back app in 'Utilities' (#2500)

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* fix baseband (#2501)

* externalize wipe sdcard (#2502)

* Removing vim swap files (#2503)

* Removing vim swap files
* Added vim swap file to .gitignore

* Add modal to turn off screen when charging is detected (#2514)

* Moved country-specific FREQMAN files to the separate repository set up for it. (#2517)

* fix docker build warnings in dockerfile-nogit (#2518)

* Add new app "hopper" app. (#2482)

* make both jammer and hopper exist
* add example hopper payload
* example files
* swap scanner and recon app location

* Add widget preview tool (#2520)

* PoC

* opt

* opt

* Playlist editor (#2506)

* make both exist
* format
* fix focusing issue
* add example hopper payload
* fix compiler err
* clean up
* correct linker script addr
* lint
* PoC
* unknown: write_line issue
* clean up
* merge
* fix read line
* remove debug code
* fix english
* support new file
* support enter delay
* fix crash
* remove debug code
* some final tune

* Support Bug Key AKA Auto Key for OOK Editor app (#2523)

* _

* some final tune

* textual

* rename following gull's suggestion

* add cursor to font viewer app (#2528)

* Allow disable/enable waveform in Audio app to remove decoding problem on some frequencies

* Added different modulations in signal generator

* Added DSB, AM 100% mod index and AM 50% mod index. 
* Changed UI.
* Added pulsed CW

* Adding Wefax demodulation mode inside Audio App (#2539)

* Adding_new_WFAX_GUI_mode_Audio_App

* Wefax_APT_demodulation_structure

* Solving REC Apt signal.wav from WFAX

* clang format issues

* correcting comments

* Breakout - The Portapack remake game rises from the pirate's lair (#2541)

* Breakout - The Portapack remake game rises from the pirate's lair

* Fixes

* Added a signature

* Trivial textual change about missing SD content (#2542)

* _

* _

* waveform fix 3 and trivial change (#2540)

* Moved games to new game menu (#2544)

* Moved games to new game menu
* There's enough games to have a menu now and I plan to make more. Having them in "Utilities" made no sense.

* Wefax warning fix modulation fix (#2543)

* changed order of modulations, changed case to avoid capture
* added missing AMAudioFMApt mode to dump pmem
* reorder demod, adding missing ones, fix warnings
* removed uneeded 'previous_modulation', renamed WFAX to AMFM to match other places
* removing uneeded 'previous_modulation' uneeded check in change_modulation
* move capture at the end so AMAUdioFMApt is matching the other arrays for position 4
* added AMFM to Recon Level and Scanner

* clang + more details in some comments

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* Snake (#2549)

* Create the Shopping Cart Lock app

Will demonstrate tomorrow. Don't merge until I do 😁

* Fixes for HTotoo's comments 😎

* Improved audio the best I can.

If nobody has any ideas to further improve high frequencies of the audio, the hardware may not be capable. I still need to check with line-out to better speaker to make sure it's not just the speaker, but it shouldn't be.

* Compared against baseband_api.cpp - matched some things better but still playback seems to be missing higher fq sounds

* renamed wav files to a more specific / less generic name

* indentation + using variables instead of litteral names for wav files to use

* indentation

* Made a Snake game - enjoy

* Code formatting. I always forget.

* move to keep sort order

* Update external.ld

Sorry I should have also asked if there was any reason that address ranges 0xADDA0000--0xADDD0000 were skipped in external.ld.  I assumed there wasn't so I changed it to be consecutive using the same 0x10000 step as the other modules.  If there is any reason to skip them then we should add a comment to note it.  Of course these are all just temporary address values used for linking and get overwritten by a kludgy "search & replace" during the build process.

Resolves enhancement request #764

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>
Co-authored-by: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com>

* Nested Debug menu into Utilities menu to tidy Home screen (#2551)

* rename rand pwd app (#2552)

* _

* remove wip code that forgot to add in old branch

* Moved speaker 1px to the right to match muted icon variant. (#2554)

* Stopwatch external app (#2553)

* updated bitmaps for speaker icon (#2555)

* updated bitmaps for speaker icon
* removed opera cake icon that was added by mistake
* adding missing Game menu source png
* cyan for Game menu
* regenerated icons

* Breakout icon change (#2556)

- Changed Breakout icon
- Changed Tetris icon color to green

* Snake icon change (#2557)

* Remove deprecated QR Code code (#2558)

* Setting for faster Button Repeat delays (#2559)

* Setting for faster Button Repeat delays

* Tweak fast delay times

* Tweak delay times

* Added description line and tweaked delay again

* OokBrute app opt (#2561)

* zooming_spectrum_AMFM_mode (#2565)

* Update README.md

Fixing opesourcesdrlab link

* Update README.md

Other link broken

* WeFax rx ext app (#2566)

* wf3

* Ookbrute (#2354)

* Revert "Ookbrute (#2354)"

This reverts commit abb8143eec.

* fix

* test edition

* re enable ble

* re enable ert

* steal amfm stuff

* something happens

* save bmp on start btn

* kinda works

* exit crash fixed

* redline, remove some hardcoded

* removed cpu killer red line, and some fixes

* simplify #1

* seems ok. time to improve

* added hidden freq offset to receiver model, so wefax can be set to the "correct" freq without users needs to substract 300 hz

* badly implemented sync detection, and disabled it.

* fix for fix

* fixes

* fix offset to real life off

* no line on freq enter

* fixes

* Doom - Mayhem Edition (#2570)

* Doom - Mini Mayhem version

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Doom - Mayhem Edition

Made the Doom - Mayhem Edition game. Some little bugs but good enough for nightly.

* Code formatting. Forgot like always.

* give more initial ammo until i put ammo around the maze to collect

* Update Doom main.cpp for better icon (#2575)

* fix external app address list (#2573)

* Add WEFAX freqman file (#2567)

* Add WEFAX freqman file
* fix bad escaped spaces and unicode characters

* Add icon for the doom game (#2574)

* Add icon for the doom game
* Add b/w .png to convert as doom icon

* Added wefax offset to audio app too. (#2572)

* added wefax offset to audio app too.

* moved from head to cpp

* Put ticker class and pp_colors in hpp file in namespace and remove helper files (#2577)

* stopwatch opt (#2578)

* stopwatch opt

* comments

* format

* fxi ms display when user tune display level

* issue template fine tune (#2579)

* Combined cpp files, stuffed helper files in hpp, updates start and game over screens (#2583)

* Combine cpp, move helpers to hpp (#2584)

* naming space (#2585)

* Tetris: Combined cpp files. Helper files into hpp. Dark mode. Encoder on. (#2587)

* Adding_Waterfall_ZOOM_x2_in_AM_modes_Audio_App (#2586)

* adding zoom_factor to app settings
* separated zoom_factor settings for AM and AMFM
* fix order so zoom factor is also applied correctly on modulation change
* fix zoom not applied when changing bandwidth
* temporary disable the Scanner so we are not breaking the nightly. Until we are choosing to finally remove it or find a better solution

---------

Co-authored-by: gullradriel <3157857+gullradriel@users.noreply.github.com>
Co-authored-by: gullradriel <gullradriel@no-mail.com>

* Fixed the I Tetromino rotation using SRS (Super Rotation System) (#2588)

* Externalize dump pmem (#2590)

* initial commit

* clang

* memory icon

* text output and exit button, FOCUS OVERRIDE TO AVOID COMPILATION ERROR

* modem and data_structure_version accessor

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* remove dead code (#2593)

* remove not yet enabled screening app (#2594)

* move default splash into sdcard (#2595)

* move bmps to sdcard
* remove unrelated files
* gitignore
* credit
* format

* Externalize scanner (#2589)

* externalize scanner
* NFM as main baseband as it's the biggest used one
* fix modulation bug introduced with AMFM

* Externalize level (#2596)

* removing ability to focus on RSSI bars and to launch level app, until a solution to launch external apps from internal ones is given
* externalize Level app

* Remove unneeded AMFM support in those apps (#2597)

* Create CODE_OF_CONDUCT.md

* Create pull_request_template.md

* Create SECURITY.md

* Create CONTRIBUTING.md (#2598)

* Force 433.92 and remove metadata check (#2599)

* Force 433.92 and remove metadata check: we already know the frequency for all files so don't need a million metadata files to match.
* Variable fixes and move to header

* Added more Wefax stations (#2600)

* Delete sdcard/FREQMAN/WEFAX.TXT

Replace with 2 files

* Add more WeFax frequencies

* Update comments

* Oops wrong folder

* Oops wrong folder

* Change comments

* Remove RF TX and use PATX baseband for audio --> speaker out only (#2601)

* Force 433.92 and remove metadata check

We already know the frequency for all files so don't need a million metadata files to match.

* Remove RF TX. Improve PATX baseband.

* code formatting of course

* Issue template again (#2602)

* test1

* test2

* add tap tempo to metronomic app (#2605)

* _

* format

* fix new tree in Arch

* solving_Audio_App_AM_GUI_Problem_issue_2604 (#2609)

* make the ptext_prompt func can define which keyboard to enter (#2608)

* _

* format

* use define

* prevent long life var for audio app - AM (#2610)

* static vars so no external linkage is possible

* persistent settings and no more global living variables

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* theme fix again (#2611)

* theme fix again

* _

* user can disable battery change hint (#2612)

* theme fix again

* _

* _

* GFX EQ App (#2607)

* Make the beginnings of rf3d
* Name change...
* Add mood button
* Remove forced amp settings and add persistent user settings
* Fix options bar layout and SettingsManager
* Make the background paint to black again after opening fq modal
* fix audio/mod/settings and cleaned unneeded parts
* Mapped bars to audio spectrum
* Improved frequency response... still needs work i think
* add on_freqchg to be able to answer to serial frequency change command
* Made calculations for 14 bars to fit screen and little adjustments
* Visual improvements
Co-authored-by: gullradriel

* Improved make_bitmap tool (#2615)

* Enhance Graphic Equalizer Visualization with Improved Frequency Bands and Response (#2614)

* Custom waterfall colors (#2617)

* Custom waterfall gradient
* Installing a custom waterfall gradient via fileman
* default file for user friendly swap
Co-authored-by: gullradriel <gullradriel@no-mail.com>

* Delete dead code in ble_rx_app.cpp (#2620)

Duplicate include on line 24 removed.

* Fix default waterfall file (#2621)

* correct default settings from file
* correct colors names

* fix comments (#2622)

* Touch on waterfall to set cursor pos (#2624)

* init

* fix typo that found by Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Adding 8.33KHz spacing (#2628)

* Adding 8.33KHz spacing
* remove extern options_db_t freqman_steps which is now brought by ui_receiver.hpp
* use freqman db steps instead of static array
Co-authored-by: gullradriel <gullradriel@no-mail.com>

* Added menu group for transceivers (#2623)

* Added menu group for transceivers

* Reorder apps icons

* Support IPS screen & brightness set for IPS screen (#2629)

* _

* format

* format

* format

* Fix bug that created by PR "Added menu group for transceivers" (#2630)

* spectrum cursor opt again (#2634)

* spectrum cursor opt

* fmt

* remove blink

* remove End event

* cleanup

* Update README.md

Links were dead for opensourcesdrlab

* Fix for #2538 (#2635)

* Fix for #2538

Fix for #2538
Added on_bandwidth_changed Callback to ui_transmitter.hpp
Modified the field_bw.on_change lambda in the TransmitterView constructor to trigger the on_bandwidth_changed callback
Connected the Callback in ui_siggen.cpp

I am not a C++ programmer so this change was proposed by Gemini AI.

I have built and tested the App and it works as expected and I don't think the change will have any unexpected side effects.

* Fix clang issues

Fix clang issues

* Update ui_transmitter.cpp

typo

* Revised change

The proposed change mirrors the way a change to the frequency (on_edit_frequency) is triggered in ui_siggen by the tx_view.
The bw parameter is not passed because it is stored in _setting in the tx_view and will be read by update_config.
A change to the bw is not checked against auto_update to keep its behaviour consistent with a change to the gain, amplitude or frequency.

* Make changes to the channel_bandwidth dynamic whist playing

Behaviour of channel bandwidth is now consistent with frequency, amp and gain.

* comment edit

* revert hackrf submodule checkpoint to the repo

* comment

---------

Co-authored-by: zxkmm <zxkmm@hotmail.com>

* Adding_WFM_AM_mode_to_Audio_App (#2644)

* Adding_WFM_AM_mode_to_Audio_App
* more precise values for cos and sin theta, fix sen_theta to sin_theta
* fix sen_theta to sin_theta

* going back to WFM as main baseband in main.cpp as NFM is now making the apps crashing. Looks like last additions to WFM made it bigger. (#2646)

* remove dead code (#2647)

* Update ui_tetris.cpp (#2650)

Start "I" tetromino a bit higher and block rotate if it will cause out of bounds collision.

* Noaa apt decoder (#2648)

* Explicit_naming_wefax_NOAA_and_small_addition (#2651)

* slightly improved ads-b receiver module (#2649)

* slightly improved ads-b receiver module:
* fix Heading, Speed and Vrate decoders
* decode more ModeS messages
* log all ModeS messages (except DF11)
* fix formatting (clang-style); advice on data alignment taken into account
* ADS-B module: convert Indicated AirSpeed to True AirSpeed if altitute is known
* ADS-B rx module: replacing floating point with integer arithmetic

* adding 10Hz and 50Hz to freqman_steps (#2652)

* Improve_RF_sensitivity_NOAA_signal (#2654)

* Upload the PCB file of PortaPack H4 and update the schematic file (#2657)

* Create README.txt

* Update README.txt

* Add files via upload

The gerber files of the portapack h4.

* delete

* Upload the gerber files for H4

* Create README.txt

This is the V1.0 version PCB file of PortaPack H4.

* Upload the pcb file for H4

* Update README.txt

* Update LCD_TF_Schematic.pdf

* Jammer app add modes (#2659)

* Add new jammer modes

Overview

This PR enhances the PortaPack Jammer app by introducing eight new signal types, ported from my Flipper Zero RF Jammer app (https://github.com/RocketGod-git/flipper-zero-rf-jammer). These modes expand the app's capability to disrupt a wide range of RF communication protocols, from analog radios to modern digital systems. The implementation preserves the original app structure, resolves namespace conflicts, and ensures compatibility with the Mayhem firmware.

New Modes

The following modes have been added to the options_type in ui_jammer.hpp, with corresponding signal generation in proc_jammer.cpp:

Noise: Generates broadband white noise to interfere with analog and digital signals (e.g., Wi-Fi, Bluetooth, key fobs). Highly effective for overwhelming receivers across a frequency range.

Sine: Produces a continuous, unmodulated sine wave to jam narrowband receivers, ideal for analog FM/AM radios or telemetry systems.

Square: Emits a harmonic-rich square wave, disrupting digital protocols (e.g., OOK, ASK) and systems sensitive to sharp transitions, such as remote keyless entry.

Sawtooth (Experimental): Generates a sawtooth wave with a unique harmonic profile, useful for testing interference against PWM-based or niche analog systems.

Triangle (Experimental): Creates a triangle wave with minimal harmonics, suitable for exploratory jamming of narrowband systems or receiver linearity testing.

Chirp: Outputs a rapid frequency-sweeping chirp signal, effective against frequency-hopping and spread-spectrum systems (e.g., some Wi-Fi, Bluetooth, or military radios).

Gauss: Generates Gaussian noise to mimic natural interference, targeting digital systems like GPS or data links by degrading signal-to-noise ratios.

Brute (Experimental): Transmits a constant maximum-amplitude signal to saturate simple receiver front-ends, useful for brute-force jamming of basic analog devices.

* Add new jammer modes

Overview

This PR enhances the PortaPack Jammer app by introducing eight new signal types, ported from my Flipper Zero RF Jammer app (https://github.com/RocketGod-git/flipper-zero-rf-jammer). These modes expand the app's capability to disrupt a wide range of RF communication protocols, from analog radios to modern digital systems. The implementation preserves the original app structure, resolves namespace conflicts, and ensures compatibility with the Mayhem firmware.

New Modes

The following modes have been added to the options_type in ui_jammer.hpp, with corresponding signal generation in proc_jammer.cpp:

Noise: Generates broadband white noise to interfere with analog and digital signals (e.g., Wi-Fi, Bluetooth, key fobs). Highly effective for overwhelming receivers across a frequency range.

Sine: Produces a continuous, unmodulated sine wave to jam narrowband receivers, ideal for analog FM/AM radios or telemetry systems.

Square: Emits a harmonic-rich square wave, disrupting digital protocols (e.g., OOK, ASK) and systems sensitive to sharp transitions, such as remote keyless entry.

Sawtooth (Experimental): Generates a sawtooth wave with a unique harmonic profile, useful for testing interference against PWM-based or niche analog systems.

Triangle (Experimental): Creates a triangle wave with minimal harmonics, suitable for exploratory jamming of narrowband systems or receiver linearity testing.

Chirp: Outputs a rapid frequency-sweeping chirp signal, effective against frequency-hopping and spread-spectrum systems (e.g., some Wi-Fi, Bluetooth, or military radios).

Gauss: Generates Gaussian noise to mimic natural interference, targeting digital systems like GPS or data links by degrading signal-to-noise ratios.

Brute (Experimental): Transmits a constant maximum-amplitude signal to saturate simple receiver front-ends, useful for brute-force jamming of basic analog devices.

* refactor the serial log logic of BLE Rx (#2660)

* Prepare for display orientation part 1 (#2661)

* fix png part

* screen max width fixes (#2663)

* max width fixes

* format

* Audio to right (#2664)

* r.align

* Storing_selected_NOAA_filter_in_settings_file (#2665)

* Storing_selected_NOAA_filter_in_settings_file

* format_issues

* wfm_filters_GUI_name_std (#2668)

* getres cmd (#2671)

* ui new coord system examples and macros (#2672)

* Detector RX ext app (#2673)

* Jammer improvements (#2674)

* Add new jammer modes
Overview:
This PR enhances the PortaPack Jammer app by introducing eight new signal types, ported from my Flipper Zero RF Jammer app (https://github.com/RocketGod-git/flipper-zero-rf-jammer). These modes expand the app's capability to disrupt a wide range of RF communication protocols, from analog radios to modern digital systems. The implementation preserves the original app structure, resolves namespace conflicts, and ensures compatibility with the Mayhem firmware.

New Modes

The following modes have been added to the options_type in ui_jammer.hpp, with corresponding signal generation in proc_jammer.cpp:

Noise: Generates broadband white noise to interfere with analog and digital signals (e.g., Wi-Fi, Bluetooth, key fobs). Highly effective for overwhelming receivers across a frequency range.

Sine: Produces a continuous, unmodulated sine wave to jam narrowband receivers, ideal for analog FM/AM radios or telemetry systems.

Square: Emits a harmonic-rich square wave, disrupting digital protocols (e.g., OOK, ASK) and systems sensitive to sharp transitions, such as remote keyless entry.

Sawtooth (Experimental): Generates a sawtooth wave with a unique harmonic profile, useful for testing interference against PWM-based or niche analog systems.

Triangle (Experimental): Creates a triangle wave with minimal harmonics, suitable for exploratory jamming of narrowband systems or receiver linearity testing.

Chirp: Outputs a rapid frequency-sweeping chirp signal, effective against frequency-hopping and spread-spectrum systems (e.g., some Wi-Fi, Bluetooth, or military radios).

Gauss: Generates Gaussian noise to mimic natural interference, targeting digital systems like GPS or data links by degrading signal-to-noise ratios.

Brute (Experimental): Transmits a constant maximum-amplitude signal to saturate simple receiver front-ends, useful for brute-force jamming of basic analog devices.

* Fixed and made brutal.

This PR introduces user-focused improvements to the Jammer App in the HackRF PortaPack Mayhem Firmware, enhancing usability and flexibility. The changes address specific user requirements for a more intuitive default configuration, continuous waveform support, and dynamic setting adjustments during transmission.

* jammer fix (#2676)

* jammer fix

* Adding_BPF_selection_to_the_NOAA_APT_signal (#2675)

* Adding_BPF_selection_to_the_NOAA_APT_signal
* comments, spell mistake .

* trivial apps folder movement (#2677)

* Clean_LCD_beat_in_NOAA_Rx_App (#2678)

* Added ability to enter custom tone values in Morse app (#2679)

* Added ability to enter custom tone values in Morse app

Added the ability to type in a custom tone value in the morse TX app (issue#2582)

*Click on the tone field to open a keyboard for entering in a desired value between 100hz - 9999hz.

*Maintains original step value of 20 when scrolling the rotary wheel.

* Update ui_morse.cpp

Replaced std::to_string with to_string_dec_uint

* Moved tone_input_buffer init to in-class

* removed some std stuff only used here (#2681)

* 80mhz jammer range (#2682)

Looks great 😎🤘🚀

* Radio app improvements (#2680)

* Rename looking glass preset for clarity and consistency (#2686)

* Gfx widget and Radio (#2685)

* widgetize
* gfx and Radio improvement
* format + handle not wfm visual states
* wf or gf

* Externalize widget (#2688)

* Add all jammer modes in hopper app (#2691)

Added all modes that jammer app supports in hopper app.

* Super secret dont look (#2690)

* Add new jammer modes

Overview

This PR enhances the PortaPack Jammer app by introducing eight new signal types, ported from my Flipper Zero RF Jammer app (https://github.com/RocketGod-git/flipper-zero-rf-jammer). These modes expand the app's capability to disrupt a wide range of RF communication protocols, from analog radios to modern digital systems. The implementation preserves the original app structure, resolves namespace conflicts, and ensures compatibility with the Mayhem firmware.

New Modes

The following modes have been added to the options_type in ui_jammer.hpp, with corresponding signal generation in proc_jammer.cpp:

Noise: Generates broadband white noise to interfere with analog and digital signals (e.g., Wi-Fi, Bluetooth, key fobs). Highly effective for overwhelming receivers across a frequency range.

Sine: Produces a continuous, unmodulated sine wave to jam narrowband receivers, ideal for analog FM/AM radios or telemetry systems.

Square: Emits a harmonic-rich square wave, disrupting digital protocols (e.g., OOK, ASK) and systems sensitive to sharp transitions, such as remote keyless entry.

Sawtooth (Experimental): Generates a sawtooth wave with a unique harmonic profile, useful for testing interference against PWM-based or niche analog systems.

Triangle (Experimental): Creates a triangle wave with minimal harmonics, suitable for exploratory jamming of narrowband systems or receiver linearity testing.

Chirp: Outputs a rapid frequency-sweeping chirp signal, effective against frequency-hopping and spread-spectrum systems (e.g., some Wi-Fi, Bluetooth, or military radios).

Gauss: Generates Gaussian noise to mimic natural interference, targeting digital systems like GPS or data links by degrading signal-to-noise ratios.

Brute (Experimental): Transmits a constant maximum-amplitude signal to saturate simple receiver front-ends, useful for brute-force jamming of basic analog devices.

* Super secret

* You gotta get (Get) that (That) dirt off your shoulder

* Add 1ms hop option to hopper app + 0ms (freeze UI) (#2692)

* add dark theme (#2695)

* Made the Dino Game (#2697)

* Add vendor name in bluetooth rx app (#2696)

* add macaddress db, add vendor name in bluetooth rx app

* show "missing macaddress.db" instead of unknown if db not found

* bluetooth rx list with colors based on mac vendor

* bug fix

* Modified Text Editor to handle long presses. (#2698)

* Improved FPV_ANALOG.txt FREQMAN file (#2700)

* Improved FPV_ANALOG.txt FREQMAN file
Removed unused or super rare analog fpv bands: U, O, H, D
Added 1.2GHz -1.3GHz channels sometimes used for long range analog fpv


* Corrected and updated the labels to be more consistent.

Corrected the labels to be more consistent.

I also somehow messed up the correct channels because 1.3GHz FPV is not fully standardized, but these channels seem to be the most common.
It should be all correct now.

Example transmitters using those channels:
https://greenchip.com.ua/0-0-1615-2.html
https://flymod.net/en/item/walksnail_vtx_9ch
https://pl.aliexpress.com/item/1005006505365351.html

* Filemanager: go to parent directory keep track of the right selected … (#2702)

* Filemanager: go to parent directory keep track of the right selected item and page number
* review: avoid unnecessary copies in get_extension

* ADSB database update (tools, db) (#2701)

* enhance make_airlines_db tool
* enhance make_icao24_db tool
* update airlinescode (.txt, .db), aircraftdatabase/icao24 (.csv, .db)

* Made the Space Invaders game. Argh matey! (#2709)

* Made the Space Invaders game. Argh matey!
* Format code, sigh.

* Made the Blackjack game (#2712)

* Made the Blackjack game
* Format Blackjack main.cpp
* Changed spade to diamond for dark mode visibility
* Format code

* Update app icons for Space Invaders and Dino Game (#2713)

* BLE Rx Improvements (#2710)

* Work to allow for unique beacon parsing functions.
* Fix Copyright
* Update firmware/application/apps/ble_rx_app.cpp
* Update firmware/baseband/proc_btlerx.cpp
* PR suggestions.
* Fix String.
* Refactor

* Added 3d printed cases for the H4M (#2715)

* Battleship (#2720)

* Made the Battleship 2P 2PP game - FSK is wip
* Using POCSAG

* Adding simple FSK Rx Processor. Can be used with New Apps. (#2716)

* Work to allow for unique beacon parsing functions.

* Fixing pull.

* Changes.

* Formatting.

* Fix Copyright

* Update firmware/application/apps/ble_rx_app.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update firmware/baseband/proc_btlerx.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* PR suggestions.

* Fix String.

* FSK Rx Improvements. Works for my custom protocol.

* Fix buffer size.

* Refactor

* Formatting.

* Formatting.

* Fixing compiling, and BLE Rx UI/Performance.

* More improvements.

* Fixing stuck state.

* More stuck parsing fix.

* Combining PR changes.

* Improvements from previous PR.

* Fix dbM calculation relative to device RSSI.

* Formatting.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: TJ <tj.baginski@cognosos.com>

* Add blue bar to subghzd+weather (#2724)

* AIS map improv (#2725)

* AIS map improv

* format code mismatch with vc

* Add radio settings, new app icon, and other UI improvements (#2732)

* update submodule (#2734)

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* update version (#2735)

Co-authored-by: gullradriel <gullradriel@no-mail.com>

---------

Co-authored-by: Erwin Ried <1091420+eried@users.noreply.github.com>
Co-authored-by: hackrfstuff <leszczyleszczy@icloud.com>
Co-authored-by: sommermorgentraum <24917424+zxkmm@users.noreply.github.com>
Co-authored-by: Totoo <ttotoo@gmail.com>
Co-authored-by: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com>
Co-authored-by: E.T. <tamas@eisenberger.hu>
Co-authored-by: OpenSourceSDRLab <opensourcesdr@outlook.com>
Co-authored-by: quantum-x <simon.yorkston@gmail.com>
Co-authored-by: gullradriel <gullradriel@no-mail.com>
Co-authored-by: Lucas C. Villa Real <lucasvr@users.noreply.github.com>
Co-authored-by: Davide Rovelli <103165301+daviderud@users.noreply.github.com>
Co-authored-by: Gaurav Chaturvedi <oddtazz@users.noreply.github.com>
Co-authored-by: RocketGod <57732082+RocketGod-git@users.noreply.github.com>
Co-authored-by: Lerold <github@lerold.slmail.me>
Co-authored-by: Brumi-2021 <86470699+Brumi-2021@users.noreply.github.com>
Co-authored-by: dark-juju <2839275+dark-juju@users.noreply.github.com>
Co-authored-by: Benjamin Møller <37707273+LupusE@users.noreply.github.com>
Co-authored-by: Oleg Belousov <belousov.oleg@gmail.com>
Co-authored-by: haruk <104354987+exe-noisy@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Luca <61653175+iu2frl@users.noreply.github.com>
Co-authored-by: Richard <richard.toy@gmail.com>
Co-authored-by: zxkmm <zxkmm@hotmail.com>
Co-authored-by: horrordash <45861453+horrordash@users.noreply.github.com>
Co-authored-by: Alien <2142224+mythic-alien@users.noreply.github.com>
Co-authored-by: Petro Danylevskyi <petro@danylevskyi.com>
Co-authored-by: Tommaso Ventafridda <33782489+tomventa@users.noreply.github.com>
Co-authored-by: Netro <146584182+iNetro@users.noreply.github.com>
Co-authored-by: plomek <86431917+plomek@users.noreply.github.com>
Co-authored-by: TJ <tj.baginski@cognosos.com>
2025-07-11 16:33:21 +02:00

880 lines
31 KiB
C++

/*
* ------------------------------------------------------------
* | Made by RocketGod |
* | Find me at https://betaskynet.com |
* | Argh matey! |
* ------------------------------------------------------------
*/
#include "ui_spaceinv.hpp"
namespace ui::external_app::spaceinv {
// Game constants
#define PLAYER_WIDTH 26
#define PLAYER_HEIGHT 16
#define PLAYER_Y 280
#define BULLET_WIDTH 3
#define BULLET_HEIGHT 10
#define BULLET_SPEED 8
#define MAX_BULLETS 3
#define INVADER_WIDTH 20
#define INVADER_HEIGHT 16
#define INVADER_ROWS 5 // Classic 5 rows
#define INVADER_COLS 6 // Reduced for more movement space on narrow PP screen
#define INVADER_GAP_X 10
#define INVADER_GAP_Y 8 // Gap between invaders
#define MAX_ENEMY_BULLETS 3
#define ENEMY_BULLET_SPEED 3
// Game state
static int game_state = 0; // 0=menu, 1=playing, 2=game over, 3=wave_complete
static bool initialized = false;
static int player_x = 120;
static uint32_t score = 0;
static int lives = 3;
static uint32_t wave = 1;
static uint32_t speed_bonus = 0;
static uint32_t wave_complete_timer = 0;
// Cannon Bullets
static int bullet_x[MAX_BULLETS] = {0, 0, 0};
static int bullet_y[MAX_BULLETS] = {0, 0, 0};
static bool bullet_active[MAX_BULLETS] = {false, false, false};
// Enemy bullets
static int enemy_bullet_x[MAX_ENEMY_BULLETS] = {0, 0, 0};
static int enemy_bullet_y[MAX_ENEMY_BULLETS] = {0, 0, 0};
static bool enemy_bullet_active[MAX_ENEMY_BULLETS] = {false, false, false};
static uint32_t enemy_fire_counter = 0;
// Invaders
static bool invaders[INVADER_ROWS][INVADER_COLS];
static int invaders_x = 40;
static int invaders_y = 60;
static int invader_direction = 1;
static uint32_t invader_move_counter = 0;
static uint32_t invader_move_delay = 30;
static bool invader_animation_frame = false;
// Menu state
static bool menu_initialized = false;
static bool game_over_initialized = false;
static bool blink_state = true;
static uint32_t blink_counter = 0;
static int16_t prompt_x = 0;
// Timer
static Ticker game_timer;
static Callback game_update_callback = nullptr;
static uint32_t game_update_timeout = 0;
static uint32_t game_update_counter = 0;
// Painter
static Painter painter;
// For high score access
static SpaceInvadersView* current_instance = nullptr;
void check_game_timer() {
if (game_update_callback) {
if (++game_update_counter >= game_update_timeout) {
game_update_counter = 0;
game_update_callback();
}
}
}
void Ticker::attach(Callback func, double delay_sec) {
game_update_callback = func;
game_update_timeout = delay_sec * 60;
}
void Ticker::detach() {
game_update_callback = nullptr;
}
static void init_invaders() {
// Initialize invader array
for (int row = 0; row < INVADER_ROWS; row++) {
for (int col = 0; col < INVADER_COLS; col++) {
invaders[row][col] = true;
}
}
invaders_x = 40;
invaders_y = 60;
invader_direction = 1;
invader_move_counter = 0;
// Clear any active enemy bullets
for (int i = 0; i < MAX_ENEMY_BULLETS; i++) {
enemy_bullet_active[i] = false;
}
// Clear any active player bullets
for (int i = 0; i < MAX_BULLETS; i++) {
bullet_active[i] = false;
}
}
static void save_high_score() {
if (current_instance && score > current_instance->highScore) {
current_instance->highScore = score;
// Settings are automatically saved when the view is destroyed
}
}
static void init_menu() {
painter.fill_rectangle({0, 0, 240, 320}, Color::black());
auto style_green = *ui::Theme::getInstance()->fg_green;
auto style_yellow = *ui::Theme::getInstance()->fg_yellow;
auto style_cyan = *ui::Theme::getInstance()->fg_cyan;
int16_t screen_width = 240;
int16_t title_x = (screen_width - 15 * 8) / 2;
int16_t divider_width = 24 * 8;
int16_t divider_x = (screen_width - divider_width) / 2;
int16_t instruction_width = 22 * 8;
int16_t instruction_x = (screen_width - instruction_width) / 2;
int16_t prompt_width = 12 * 8;
prompt_x = (screen_width - prompt_width) / 2;
painter.fill_rectangle({0, 30, screen_width, 30}, Color::black());
painter.draw_string({title_x, 42}, style_green, "SPACE INVADERS");
painter.draw_string({divider_x, 70}, style_yellow, "========================");
painter.fill_rectangle({instruction_x - 5, 100, instruction_width + 10, 80}, Color::black());
painter.draw_rectangle({instruction_x - 5, 100, instruction_width + 10, 80}, Color::white());
painter.draw_string({instruction_x, 110}, style_cyan, " ROTARY: MOVE SHIP");
painter.draw_string({instruction_x, 130}, style_cyan, " SELECT: FIRE");
painter.draw_string({instruction_x, 150}, style_cyan, " DEFEND EARTH!");
// Draw point values
auto style_purple = *ui::Theme::getInstance()->fg_magenta;
painter.draw_string({50, 190}, style_purple, "TOP ROW = 30 PTS");
painter.draw_string({50, 205}, style_yellow, "MID ROW = 20 PTS");
painter.draw_string({50, 220}, style_green, "BOT ROW = 10 PTS");
// Draw high score
if (current_instance) {
auto style_white = *ui::Theme::getInstance()->fg_light;
std::string high_score_text = "HIGH SCORE: " + std::to_string(current_instance->highScore);
int16_t high_score_x = (screen_width - high_score_text.length() * 8) / 2;
painter.draw_string({high_score_x, 240}, style_white, high_score_text);
}
menu_initialized = true;
}
static void init_game_over() {
painter.fill_rectangle({0, 0, 240, 320}, Color::black());
auto style_red = *ui::Theme::getInstance()->fg_red;
auto style_yellow = *ui::Theme::getInstance()->fg_yellow;
auto style_cyan = *ui::Theme::getInstance()->fg_cyan;
auto style_white = *ui::Theme::getInstance()->fg_light;
int16_t screen_width = 240;
// Game Over title
int16_t title_x = (screen_width - 9 * 8) / 2;
painter.draw_string({title_x, 42}, style_red, "GAME OVER");
// Divider
int16_t divider_width = 24 * 8;
int16_t divider_x = (screen_width - divider_width) / 2;
painter.draw_string({divider_x, 70}, style_yellow, "========================");
// Score box
int16_t box_width = 22 * 8;
int16_t box_x = (screen_width - box_width) / 2;
painter.fill_rectangle({box_x - 5, 100, box_width + 10, 80}, Color::black());
painter.draw_rectangle({box_x - 5, 100, box_width + 10, 80}, Color::white());
// Display scores
std::string score_text = "SCORE: " + std::to_string(score);
int16_t score_x = (screen_width - score_text.length() * 8) / 2;
painter.draw_string({score_x, 120}, style_cyan, score_text);
std::string wave_text = "WAVE: " + std::to_string(wave);
int16_t wave_x = (screen_width - wave_text.length() * 8) / 2;
painter.draw_string({wave_x, 140}, style_cyan, wave_text);
// High score section
if (current_instance) {
if (score > current_instance->highScore) {
// New high score!
std::string new_high = "NEW HIGH SCORE!";
int16_t new_high_x = (screen_width - new_high.length() * 8) / 2;
painter.draw_string({new_high_x, 200}, style_yellow, new_high);
std::string high_score_text = std::to_string(score);
int16_t high_score_x = (screen_width - high_score_text.length() * 8) / 2;
painter.draw_string({high_score_x, 220}, style_yellow, high_score_text);
} else {
// Show existing high score
std::string high_label = "HIGH SCORE:";
int16_t label_x = (screen_width - high_label.length() * 8) / 2;
painter.draw_string({label_x, 200}, style_white, high_label);
std::string high_score_text = std::to_string(current_instance->highScore);
int16_t high_score_x = (screen_width - high_score_text.length() * 8) / 2;
painter.draw_string({high_score_x, 220}, style_white, high_score_text);
}
}
game_over_initialized = true;
}
static void draw_player() {
// Clear the entire player area
painter.fill_rectangle({0, PLAYER_Y - 4, 240, PLAYER_HEIGHT + 8}, Color::black());
// Draw the classic Space Invaders cannon
Color green = Color::green();
// Top part - the cannon barrel
painter.draw_hline({player_x + 12, PLAYER_Y}, 2, green);
painter.draw_hline({player_x + 12, PLAYER_Y + 1}, 2, green);
// Upper body
painter.draw_hline({player_x + 11, PLAYER_Y + 2}, 4, green);
painter.draw_hline({player_x + 11, PLAYER_Y + 3}, 4, green);
painter.draw_hline({player_x + 10, PLAYER_Y + 4}, 6, green);
painter.draw_hline({player_x + 10, PLAYER_Y + 5}, 6, green);
// Main body
painter.draw_hline({player_x + 2, PLAYER_Y + 6}, 22, green);
painter.draw_hline({player_x + 2, PLAYER_Y + 7}, 22, green);
painter.draw_hline({player_x + 1, PLAYER_Y + 8}, 24, green);
painter.draw_hline({player_x + 1, PLAYER_Y + 9}, 24, green);
painter.draw_hline({player_x, PLAYER_Y + 10}, 26, green);
painter.draw_hline({player_x, PLAYER_Y + 11}, 26, green);
painter.draw_hline({player_x, PLAYER_Y + 12}, 26, green);
painter.draw_hline({player_x, PLAYER_Y + 13}, 26, green);
painter.draw_hline({player_x, PLAYER_Y + 14}, 26, green);
painter.draw_hline({player_x, PLAYER_Y + 15}, 26, green);
}
static void draw_invader(int row, int col) {
int x = invaders_x + col * (INVADER_WIDTH + INVADER_GAP_X);
int y = invaders_y + row * (INVADER_HEIGHT + INVADER_GAP_Y);
// Clear the area first
painter.fill_rectangle({x, y, INVADER_WIDTH, INVADER_HEIGHT}, Color::black());
// Different colors and shapes for different rows
Color color;
if (row == 0) {
color = Color::red(); // Top row - 30 points
} else if (row == 1 || row == 2) {
color = Color::yellow(); // Middle rows - 20 points
} else {
color = Color::green(); // Bottom rows - 10 points
}
// Draw different invader types based on row
if (row == 0) {
// Top row - squid-like invader (30 points)
if (invader_animation_frame) {
// Frame 1 - arms down
painter.draw_hline({x + 8, y + 2}, 4, color);
painter.draw_hline({x + 6, y + 3}, 8, color);
painter.draw_hline({x + 4, y + 4}, 12, color);
painter.draw_hline({x + 2, y + 5}, 16, color);
painter.draw_hline({x + 2, y + 6}, 16, color);
painter.draw_hline({x, y + 7}, 20, color);
painter.draw_hline({x, y + 8}, 20, color);
painter.draw_hline({x + 2, y + 9}, 2, color);
painter.draw_hline({x + 6, y + 9}, 8, color);
painter.draw_hline({x + 16, y + 9}, 2, color);
painter.draw_hline({x + 4, y + 10}, 2, color);
painter.draw_hline({x + 14, y + 10}, 2, color);
} else {
// Frame 2 - arms up
painter.draw_hline({x + 8, y + 2}, 4, color);
painter.draw_hline({x + 6, y + 3}, 8, color);
painter.draw_hline({x + 4, y + 4}, 12, color);
painter.draw_hline({x + 2, y + 5}, 16, color);
painter.draw_hline({x + 2, y + 6}, 16, color);
painter.draw_hline({x, y + 7}, 20, color);
painter.draw_hline({x, y + 8}, 20, color);
painter.draw_hline({x + 4, y + 9}, 2, color);
painter.draw_hline({x + 8, y + 9}, 4, color);
painter.draw_hline({x + 14, y + 9}, 2, color);
painter.draw_hline({x + 2, y + 10}, 2, color);
painter.draw_hline({x + 16, y + 10}, 2, color);
}
} else if (row == 1 || row == 2) {
// Middle rows - crab-like invader (20 points)
if (invader_animation_frame) {
// Frame 1 - arms in
painter.draw_hline({x + 4, y + 2}, 2, color);
painter.draw_hline({x + 14, y + 2}, 2, color);
painter.draw_hline({x + 2, y + 3}, 2, color);
painter.draw_hline({x + 6, y + 3}, 8, color);
painter.draw_hline({x + 16, y + 3}, 2, color);
painter.draw_hline({x + 2, y + 4}, 16, color);
painter.draw_hline({x, y + 5}, 6, color);
painter.draw_hline({x + 8, y + 5}, 4, color);
painter.draw_hline({x + 14, y + 5}, 6, color);
painter.draw_hline({x, y + 6}, 20, color);
painter.draw_hline({x + 2, y + 7}, 16, color);
painter.draw_hline({x + 4, y + 8}, 2, color);
painter.draw_hline({x + 14, y + 8}, 2, color);
painter.draw_hline({x + 2, y + 9}, 4, color);
painter.draw_hline({x + 14, y + 9}, 4, color);
} else {
// Frame 2 - arms out
painter.draw_hline({x + 4, y + 2}, 2, color);
painter.draw_hline({x + 14, y + 2}, 2, color);
painter.draw_hline({x + 2, y + 3}, 2, color);
painter.draw_hline({x + 6, y + 3}, 8, color);
painter.draw_hline({x + 16, y + 3}, 2, color);
painter.draw_hline({x + 2, y + 4}, 16, color);
painter.draw_hline({x, y + 5}, 6, color);
painter.draw_hline({x + 8, y + 5}, 4, color);
painter.draw_hline({x + 14, y + 5}, 6, color);
painter.draw_hline({x, y + 6}, 20, color);
painter.draw_hline({x + 2, y + 7}, 16, color);
painter.draw_hline({x + 4, y + 8}, 2, color);
painter.draw_hline({x + 14, y + 8}, 2, color);
painter.draw_hline({x, y + 9}, 2, color);
painter.draw_hline({x + 6, y + 9}, 2, color);
painter.draw_hline({x + 12, y + 9}, 2, color);
painter.draw_hline({x + 18, y + 9}, 2, color);
}
} else {
// Bottom rows - octopus-like invader (10 points)
if (invader_animation_frame) {
// Frame 1
painter.draw_hline({x + 6, y + 2}, 8, color);
painter.draw_hline({x + 4, y + 3}, 12, color);
painter.draw_hline({x + 2, y + 4}, 16, color);
painter.draw_hline({x, y + 5}, 20, color);
painter.draw_hline({x, y + 6}, 20, color);
painter.draw_hline({x + 4, y + 7}, 4, color);
painter.draw_hline({x + 12, y + 7}, 4, color);
painter.draw_hline({x + 2, y + 8}, 4, color);
painter.draw_hline({x + 8, y + 8}, 4, color);
painter.draw_hline({x + 14, y + 8}, 4, color);
painter.draw_hline({x + 4, y + 9}, 2, color);
painter.draw_hline({x + 14, y + 9}, 2, color);
} else {
// Frame 2
painter.draw_hline({x + 6, y + 2}, 8, color);
painter.draw_hline({x + 4, y + 3}, 12, color);
painter.draw_hline({x + 2, y + 4}, 16, color);
painter.draw_hline({x, y + 5}, 20, color);
painter.draw_hline({x, y + 6}, 20, color);
painter.draw_hline({x + 4, y + 7}, 4, color);
painter.draw_hline({x + 12, y + 7}, 4, color);
painter.draw_hline({x + 2, y + 8}, 4, color);
painter.draw_hline({x + 8, y + 8}, 4, color);
painter.draw_hline({x + 14, y + 8}, 4, color);
painter.draw_hline({x + 2, y + 9}, 2, color);
painter.draw_hline({x + 16, y + 9}, 2, color);
}
}
}
static void draw_all_invaders() {
for (int row = 0; row < INVADER_ROWS; row++) {
for (int col = 0; col < INVADER_COLS; col++) {
if (invaders[row][col]) {
draw_invader(row, col);
}
}
}
}
static void clear_all_invaders() {
for (int row = 0; row < INVADER_ROWS; row++) {
for (int col = 0; col < INVADER_COLS; col++) {
if (invaders[row][col]) {
int x = invaders_x + col * (INVADER_WIDTH + INVADER_GAP_X);
int y = invaders_y + row * (INVADER_HEIGHT + INVADER_GAP_Y);
painter.fill_rectangle({x, y, INVADER_WIDTH, INVADER_HEIGHT}, Color::black());
}
}
}
}
static void clear_all_enemy_bullets() {
// Clear any visible enemy bullets
for (int i = 0; i < MAX_ENEMY_BULLETS; i++) {
if (enemy_bullet_active[i]) {
painter.fill_rectangle({enemy_bullet_x[i], enemy_bullet_y[i], BULLET_WIDTH, BULLET_HEIGHT}, Color::black());
enemy_bullet_active[i] = false;
}
}
}
static void fire_enemy_bullet() {
// Find a random invader to fire from
int active_count = 0;
for (int row = 0; row < INVADER_ROWS; row++) {
for (int col = 0; col < INVADER_COLS; col++) {
if (invaders[row][col]) active_count++;
}
}
if (active_count == 0) return;
int shooter = rand() % active_count;
int count = 0;
for (int row = 0; row < INVADER_ROWS; row++) {
for (int col = 0; col < INVADER_COLS; col++) {
if (invaders[row][col]) {
if (count == shooter) {
// Fire from this invader
for (int i = 0; i < MAX_ENEMY_BULLETS; i++) {
if (!enemy_bullet_active[i]) {
int x = invaders_x + col * (INVADER_WIDTH + INVADER_GAP_X);
int y = invaders_y + row * (INVADER_HEIGHT + INVADER_GAP_Y);
enemy_bullet_x[i] = x + INVADER_WIDTH / 2;
enemy_bullet_y[i] = y + INVADER_HEIGHT;
enemy_bullet_active[i] = true;
return;
}
}
}
count++;
}
}
}
}
static void update_enemy_bullets() {
for (int i = 0; i < MAX_ENEMY_BULLETS; i++) {
if (enemy_bullet_active[i]) {
// Clear old position - but protect the border line
if (enemy_bullet_y[i] != 49) { // Don't clear if we're exactly on the border line
painter.fill_rectangle({enemy_bullet_x[i], enemy_bullet_y[i], BULLET_WIDTH, BULLET_HEIGHT}, Color::black());
}
enemy_bullet_y[i] += ENEMY_BULLET_SPEED;
if (enemy_bullet_y[i] > 320) {
enemy_bullet_active[i] = false;
} else {
// Draw at new position
painter.fill_rectangle({enemy_bullet_x[i], enemy_bullet_y[i], BULLET_WIDTH, BULLET_HEIGHT}, Color::red());
// Check collision with player
if (enemy_bullet_x[i] >= player_x &&
enemy_bullet_x[i] <= player_x + PLAYER_WIDTH &&
enemy_bullet_y[i] >= PLAYER_Y &&
enemy_bullet_y[i] <= PLAYER_Y + PLAYER_HEIGHT) {
// Player hit!
enemy_bullet_active[i] = false;
lives--;
// Update lives display
auto style = *ui::Theme::getInstance()->fg_green;
painter.fill_rectangle({5, 30, 100, 20}, Color::black());
painter.draw_string({5, 30}, style, "Lives: " + std::to_string(lives));
if (lives <= 0) {
game_state = 2; // Game over
save_high_score();
}
}
}
}
}
}
static void update_invaders() {
uint32_t adjusted_delay = (speed_bonus >= invader_move_delay) ? 1 : invader_move_delay - speed_bonus;
if (++invader_move_counter >= adjusted_delay) {
invader_move_counter = 0;
// Clear old positions
clear_all_invaders();
// Check bounds - find the actual leftmost and rightmost invaders
int leftmost = INVADER_COLS;
int rightmost = -1;
for (int col = 0; col < INVADER_COLS; col++) {
for (int row = 0; row < INVADER_ROWS; row++) {
if (invaders[row][col]) {
if (col < leftmost) leftmost = col;
if (col > rightmost) rightmost = col;
}
}
}
bool hit_edge = false;
if (invader_direction > 0) {
// Moving right - check rightmost invader
int right_edge = invaders_x + rightmost * (INVADER_WIDTH + INVADER_GAP_X) + INVADER_WIDTH;
if (right_edge >= 240) {
hit_edge = true;
}
} else {
// Moving left - check leftmost invader
int left_edge = invaders_x + leftmost * (INVADER_WIDTH + INVADER_GAP_X);
if (left_edge <= 0) {
hit_edge = true;
}
}
// Move invaders
if (hit_edge) {
invaders_y += 15; // Move down
invader_direction = -invader_direction;
} else {
invaders_x += invader_direction * 8; // Horizontal movement
}
// Toggle animation frame
invader_animation_frame = !invader_animation_frame;
// Draw new positions
draw_all_invaders();
}
// Enemy firing logic - only in hard mode or always with lower frequency
if (!current_instance || !current_instance->easy_mode) {
if (++enemy_fire_counter >= 120) { // Fire every 2 seconds at 60fps
enemy_fire_counter = 0;
fire_enemy_bullet();
}
}
}
static void fire_bullet() {
for (int i = 0; i < MAX_BULLETS; i++) {
if (!bullet_active[i]) {
bullet_active[i] = true;
bullet_x[i] = player_x + PLAYER_WIDTH / 2 - BULLET_WIDTH / 2;
bullet_y[i] = PLAYER_Y - BULLET_HEIGHT;
break;
}
}
}
static void update_bullets() {
for (int i = 0; i < MAX_BULLETS; i++) {
if (bullet_active[i]) {
painter.fill_rectangle({bullet_x[i], bullet_y[i], BULLET_WIDTH, BULLET_HEIGHT}, Color::black());
bullet_y[i] -= BULLET_SPEED;
if (bullet_y[i] < 50) {
bullet_active[i] = false;
} else {
painter.fill_rectangle({bullet_x[i], bullet_y[i], BULLET_WIDTH, BULLET_HEIGHT}, Color::white());
}
}
}
}
static void check_collisions() {
for (int i = 0; i < MAX_BULLETS; i++) {
if (!bullet_active[i]) continue;
for (int row = 0; row < INVADER_ROWS; row++) {
for (int col = 0; col < INVADER_COLS; col++) {
if (!invaders[row][col]) continue;
int inv_x = invaders_x + col * (INVADER_WIDTH + INVADER_GAP_X);
int inv_y = invaders_y + row * (INVADER_HEIGHT + INVADER_GAP_Y);
// Simple collision check
if (bullet_x[i] < inv_x + INVADER_WIDTH &&
bullet_x[i] + BULLET_WIDTH > inv_x &&
bullet_y[i] < inv_y + INVADER_HEIGHT &&
bullet_y[i] + BULLET_HEIGHT > inv_y) {
// Hit!
bullet_active[i] = false;
painter.fill_rectangle({bullet_x[i], bullet_y[i], BULLET_WIDTH, BULLET_HEIGHT}, Color::black());
invaders[row][col] = false;
painter.fill_rectangle({inv_x, inv_y, INVADER_WIDTH, INVADER_HEIGHT}, Color::black());
// Score based on row: top=30, middle=20, bottom=10
if (row == 0) {
score += 30;
} else if (row == 1 || row == 2) {
score += 20;
} else {
score += 10;
}
return;
}
}
}
}
}
static void check_wave_complete() {
// Check if all invaders are destroyed
bool all_destroyed = true;
for (int row = 0; row < INVADER_ROWS; row++) {
for (int col = 0; col < INVADER_COLS; col++) {
if (invaders[row][col]) {
all_destroyed = false;
break;
}
}
if (!all_destroyed) break;
}
if (all_destroyed) {
// Next wave!
wave++;
speed_bonus = (wave - 1) * 3; // Each wave is slightly faster
if (speed_bonus > 15) speed_bonus = 15; // Cap the speed increase
// Clear any enemy bullets before transitioning
clear_all_enemy_bullets();
// Set state to wave complete and start timer
game_state = 3;
wave_complete_timer = 60; // 1 second at 60fps
// Clear screen and show wave message - but preserve the border line
painter.fill_rectangle({0, 51, 240, 269}, Color::black()); // Start at 51 to preserve line at 49
// Redraw the border line to ensure it's intact - stupid bullet clearing wants to damage it
painter.draw_hline({0, 49}, 240, Color::white());
auto style = *ui::Theme::getInstance()->fg_green;
std::string wave_text = "WAVE " + std::to_string(wave);
int wave_x = (240 - wave_text.length() * 8) / 2;
painter.draw_string({wave_x, 150}, style, wave_text);
return;
}
// Check if invaders reached player
for (int row = 0; row < INVADER_ROWS; row++) {
for (int col = 0; col < INVADER_COLS; col++) {
if (invaders[row][col]) {
int y = invaders_y + row * (INVADER_HEIGHT + INVADER_GAP_Y);
if (y + INVADER_HEIGHT >= PLAYER_Y) { // Actual collision with player
game_state = 2; // Game over
save_high_score();
return;
}
}
}
}
}
void game_timer_check() {
if (game_state == 0) {
// Menu state
if (!menu_initialized) {
init_menu();
}
if (++blink_counter >= 30) {
blink_counter = 0;
blink_state = !blink_state;
auto style = *ui::Theme::getInstance()->fg_red;
if (blink_state) {
painter.draw_string({prompt_x, 260}, style, "PRESS SELECT");
} else {
painter.fill_rectangle({prompt_x, 260, 16 * 8, 20}, Color::black());
}
}
} else if (game_state == 1) {
// Playing state
update_bullets();
update_enemy_bullets();
update_invaders();
check_collisions();
check_wave_complete();
// Update score display
static uint32_t last_score = 999999;
if (score != last_score) {
last_score = score;
auto style = *ui::Theme::getInstance()->fg_green;
painter.fill_rectangle({5, 10, 100, 20}, Color::black());
painter.draw_string({5, 10}, style, "Score: " + std::to_string(score));
// Redraw border line after score update (in case it was damaged) - stupid bullet clearing wants to damage it
painter.draw_hline({0, 49}, 240, Color::white());
}
// Periodically redraw the border line to fix any damage because it's a pain in the ass
static uint32_t border_redraw_counter = 0;
if (++border_redraw_counter >= 60) { // Once per second - might make less if causing flickering
border_redraw_counter = 0;
painter.draw_hline({0, 49}, 240, Color::white());
}
} else if (game_state == 2) {
// Game over state
if (!game_over_initialized) {
init_game_over();
}
if (++blink_counter >= 30) {
blink_counter = 0;
blink_state = !blink_state;
auto style = *ui::Theme::getInstance()->fg_red;
if (blink_state) {
painter.draw_string({prompt_x, 260}, style, "PRESS SELECT");
} else {
painter.fill_rectangle({prompt_x, 260, 16 * 8, 20}, Color::black());
}
}
} else if (game_state == 3) {
// Wave complete state - wait for timer
if (--wave_complete_timer <= 0) {
// Timer expired, start next wave
game_state = 1;
// Clear and redraw game area - preserve border line
painter.fill_rectangle({0, 51, 240, 269}, Color::black()); // Start at 51 to preserve line
// Restore UI
auto style = *ui::Theme::getInstance()->fg_green;
painter.draw_string({5, 10}, style, "Score: " + std::to_string(score));
painter.draw_string({5, 30}, style, "Lives: " + std::to_string(lives));
// Redraw the border line in case it was damaged again
painter.draw_hline({0, 49}, 240, Color::white());
// Initialize new wave of invaders
init_invaders();
draw_all_invaders();
draw_player();
}
}
}
SpaceInvadersView::SpaceInvadersView(NavigationView& nav)
: nav_{nav} {
add_children({&dummy, &button_difficulty});
current_instance = this;
game_timer.attach(&game_timer_check, 1.0 / 60.0);
// Update button text based on loaded setting
button_difficulty.set_text(easy_mode ? "Mode: EASY" : "Mode: HARD");
button_difficulty.on_select = [this](Button&) {
easy_mode = !easy_mode;
button_difficulty.set_text(easy_mode ? "Mode: EASY" : "Mode: HARD");
// Settings will be saved when the view is destroyed
};
}
SpaceInvadersView::~SpaceInvadersView() {
// Settings are automatically saved when destroyed
current_instance = nullptr;
}
void SpaceInvadersView::on_show() {
}
void SpaceInvadersView::paint(Painter& painter) {
(void)painter;
if (!initialized) {
initialized = true;
game_state = 0;
menu_initialized = false;
game_over_initialized = false;
blink_state = true;
blink_counter = 0;
player_x = 107;
score = 0;
lives = 3;
wave = 1;
speed_bonus = 0;
// Initialize arrays
for (int i = 0; i < MAX_BULLETS; i++) {
bullet_active[i] = false;
bullet_x[i] = 0;
bullet_y[i] = 0;
}
for (int i = 0; i < MAX_ENEMY_BULLETS; i++) {
enemy_bullet_active[i] = false;
enemy_bullet_x[i] = 0;
enemy_bullet_y[i] = 0;
}
init_invaders();
}
}
void SpaceInvadersView::frame_sync() {
check_game_timer();
set_dirty();
}
bool SpaceInvadersView::on_encoder(const EncoderEvent delta) {
if (game_state == 1) {
if (delta > 0) {
player_x += 5;
if (player_x > 214) player_x = 214;
draw_player();
} else if (delta < 0) {
player_x -= 5;
if (player_x < 0) player_x = 0;
draw_player();
}
set_dirty();
}
return true;
}
bool SpaceInvadersView::on_key(const KeyEvent key) {
if (key == KeyEvent::Select) {
if (game_state == 0) {
// Start game
game_state = 1;
button_difficulty.hidden(true);
score = 0;
lives = 3;
wave = 1;
speed_bonus = 0;
invader_move_delay = 30;
enemy_fire_counter = 0;
init_invaders();
painter.fill_rectangle({0, 0, 240, 320}, Color::black());
painter.draw_hline({0, 49}, 240, Color::white());
auto style = *ui::Theme::getInstance()->fg_green;
painter.draw_string({5, 10}, style, "Score: 0");
painter.draw_string({5, 30}, style, "Lives: 3");
draw_all_invaders();
draw_player();
set_dirty();
} else if (game_state == 1) {
fire_bullet();
} else if (game_state == 2) {
// Return to menu
game_state = 0;
menu_initialized = false;
game_over_initialized = false;
button_difficulty.hidden(false);
set_dirty();
}
}
return true;
}
} // namespace ui::external_app::spaceinv