mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-07 06:02:20 -04:00
Tetris: Combined cpp files. Helper files into hpp. Dark mode. Encoder on. (#2587)
This commit is contained in:
parent
20c64c98bd
commit
4b000c8da6
6 changed files with 653 additions and 921 deletions
105
firmware/application/external/tetris/ui_tetris.hpp
vendored
105
firmware/application/external/tetris/ui_tetris.hpp
vendored
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2024 Mark Thompson
|
||||
* 2025 updates by RocketGod (https://betaskynet.com/)
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
|
@ -22,6 +23,7 @@
|
|||
#ifndef __UI_TETRIS_H__
|
||||
#define __UI_TETRIS_H__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "event_m0.hpp"
|
||||
#include "message.hpp"
|
||||
|
@ -29,16 +31,113 @@
|
|||
#include "random.hpp"
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
#include "limits.h"
|
||||
#include "ui_widget.hpp"
|
||||
|
||||
namespace ui::external_app::tetris {
|
||||
|
||||
enum {
|
||||
White,
|
||||
Blue,
|
||||
Yellow,
|
||||
Purple,
|
||||
Green,
|
||||
Red,
|
||||
Maroon,
|
||||
Orange,
|
||||
Black,
|
||||
};
|
||||
|
||||
extern const Color pp_colors[];
|
||||
extern Painter painter;
|
||||
extern bool but_RIGHT;
|
||||
extern bool but_LEFT;
|
||||
extern bool but_UP;
|
||||
extern bool but_DOWN;
|
||||
extern bool but_SELECT;
|
||||
|
||||
void cls();
|
||||
void background(int color);
|
||||
void foreground(int color);
|
||||
void locate(int x, int y);
|
||||
void fillrect(int x1, int y1, int x2, int y2, int color);
|
||||
void rect(int x1, int y1, int x2, int y2, int color);
|
||||
void printf(std::string str);
|
||||
void printf(std::string str, int v);
|
||||
|
||||
#define wait(x) chThdSleepMilliseconds(x * 1000)
|
||||
|
||||
using Callback = void (*)(void);
|
||||
|
||||
class Ticker {
|
||||
public:
|
||||
Ticker() = default;
|
||||
void attach(Callback func, double delay_sec);
|
||||
void detach();
|
||||
};
|
||||
|
||||
extern Ticker game;
|
||||
extern Ticker joystick;
|
||||
|
||||
extern unsigned char level;
|
||||
extern const float delays[4];
|
||||
extern unsigned int score;
|
||||
extern bool firstTime;
|
||||
extern bool gameStarted;
|
||||
extern unsigned char nextFigure;
|
||||
extern short board[20][10];
|
||||
extern const int colors[8];
|
||||
extern const short DIMENSION;
|
||||
extern const short DIMENSION_NEXT;
|
||||
extern short figuresX[7][4];
|
||||
extern short figuresY[7][4];
|
||||
|
||||
unsigned int GenerateRandomSeed();
|
||||
void Init();
|
||||
void ShowScore();
|
||||
void ShowNextFigure();
|
||||
void DrawCursor(int color, unsigned char lev);
|
||||
void ShowLevelMenu();
|
||||
void ReadJoystickForLevel();
|
||||
void EndPlay();
|
||||
void StartGame();
|
||||
void copyCoordinates(short X[], short Y[], unsigned char index);
|
||||
bool BottomEdge(int x);
|
||||
bool LeftEdge(int y);
|
||||
bool RightEdge(int y);
|
||||
bool OutOfBounds(int y, int x);
|
||||
void PutBorders(short x, short y);
|
||||
void Tetromino(unsigned char c);
|
||||
void Initialize(unsigned char c);
|
||||
void Rotate();
|
||||
void DrawFigure();
|
||||
void DeleteFigure();
|
||||
void OnAttached();
|
||||
bool MoveDown(char delta);
|
||||
void MoveLeft();
|
||||
void MoveRight();
|
||||
void SoftDrop();
|
||||
bool InCollisionDown(char delta);
|
||||
bool InCollisionLeft();
|
||||
bool InCollisionRight();
|
||||
void ReadJoystickForFigure();
|
||||
void CheckLines(short& firstLine, short& numberOfLines);
|
||||
unsigned int UpdateScore(short numOfLines);
|
||||
void UpdateBoard();
|
||||
bool IsOver();
|
||||
void ShowGameOverScreen();
|
||||
void InitGame();
|
||||
void PlayGame();
|
||||
void OnTasterPressed();
|
||||
void pause_game();
|
||||
|
||||
class TetrisView : public View {
|
||||
public:
|
||||
TetrisView(NavigationView& nav);
|
||||
void on_show() override;
|
||||
|
||||
std::string title() const override { return "Tetris"; };
|
||||
std::string title() const override { return "Tetris"; }
|
||||
|
||||
void focus() override { dummy.focus(); };
|
||||
void focus() override { dummy.focus(); }
|
||||
void paint(Painter& painter) override;
|
||||
void frame_sync();
|
||||
bool on_encoder(const EncoderEvent event) override;
|
||||
|
@ -61,4 +160,4 @@ class TetrisView : public View {
|
|||
|
||||
} // namespace ui::external_app::tetris
|
||||
|
||||
#endif /*__UI_TETRIS_H__*/
|
||||
#endif /* __UI_TETRIS_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue