-
Notifications
You must be signed in to change notification settings - Fork 78
Add basic tetris to dev #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
petabyt
wants to merge
9
commits into
reticulatedpines:dev
Choose a base branch
from
petabyt:tetris
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1929047
tetris: add tetris.c
petabyt 529a52e
tetris: add makefile
petabyt 5710243
Create README.rst
petabyt ae0272e
tetris: Add personal portable tetris library
petabyt b7d3670
ptetris.h tabs->spaces
petabyt 8d85009
Remove astyle call in ptetris Makefile
petabyt 505e505
Updated ptetris
petabyt 8d39d70
Fix some bugs in tetris
petabyt 030bf0a
Merge branch 'reticulatedpines:dev' into tetris
petabyt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Force format | ||
| $(info $(shell astyle --style=allman tetris.c ptetris.h)) | ||
|
|
||
| TOP_DIR=../.. | ||
| MODULE_NAME=tetris | ||
| MODULE_OBJS=tetris.o | ||
| include $(TOP_DIR)/modules/Makefile.modules | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| #include <stdio.h> | ||
| #include <dryos.h> | ||
| #include <module.h> | ||
| #include <menu.h> | ||
| #include <config.h> | ||
| #include <bmp.h> | ||
| #include <console.h> | ||
| #include <math.h> | ||
|
|
||
| uint32_t pt_colors[] = | ||
| { | ||
| COLOR_WHITE, /* Background color */ | ||
| COLOR_RED, | ||
| COLOR_GREEN1, | ||
| COLOR_ORANGE, | ||
| COLOR_DARK_RED, | ||
| COLOR_MAGENTA, | ||
| }; | ||
|
|
||
| // bmp manually drawing seems very slow | ||
| #define PT_CUSTOM_DRAW_BLOCK | ||
| void pt_draw_block(int bx, int by, uint32_t col) | ||
| { | ||
| bmp_fill(pt_colors[col], 30 + bx * 20, 30 + by * 20, 20, 20); | ||
| } | ||
|
|
||
| #include "ptetris.h" | ||
|
|
||
| int running = 0; | ||
|
|
||
| extern int menu_redraw_blocked; | ||
|
|
||
| void tetris_task() | ||
| { | ||
| int sleeploop = 0; | ||
|
|
||
| pt_reset(); | ||
| running = 1; | ||
| TASK_LOOP | ||
| { | ||
| clrscr(); | ||
|
|
||
| while (!running) | ||
| { | ||
| msleep(1); | ||
| } | ||
|
|
||
| pt_render(); | ||
|
|
||
| bmp_printf(FONT_LARGE, 300, 10, "Score: %d", pt.score); | ||
| bmp_printf(FONT_LARGE, 300, 70, "Press [Q] to Quit"); | ||
|
|
||
| msleep(200); | ||
|
|
||
| if (pt_step()) | ||
| { | ||
| bmp_printf(FONT_LARGE, 300, 70 + 60, "Game Over"); | ||
| goto quit; | ||
| } | ||
| } | ||
|
|
||
| quit: | ||
| menu_redraw_blocked = 0; | ||
| clrscr(); | ||
| running = 0; | ||
| } | ||
|
|
||
| unsigned int tetris_keypress(unsigned int key) | ||
| { | ||
| if (!running) | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| /* Mess with "RNG" */ | ||
| pt_rand_x += key; | ||
|
|
||
| /* Tell tetris_task to stop loop when | ||
| receiving button input */ | ||
| running = 0; | ||
|
|
||
| switch(key) | ||
| { | ||
| case MODULE_KEY_Q: | ||
| clrscr(); | ||
| menu_redraw_blocked = 0; | ||
| return 0; | ||
| case MODULE_KEY_PRESS_LEFT: | ||
| pt_handle_input(PT_LEFT); | ||
| break; | ||
| case MODULE_KEY_PRESS_RIGHT: | ||
| pt_handle_input(PT_RIGHT); | ||
| break; | ||
| case MODULE_KEY_PRESS_UP: | ||
| pt_handle_input(PT_ROT); | ||
| break; | ||
| case MODULE_KEY_PRESS_DOWN: | ||
| pt_handle_input(PT_DOWN); | ||
| break; | ||
| } | ||
|
|
||
| pt_render(); | ||
|
|
||
| running = 1; | ||
| return 0; | ||
| } | ||
|
|
||
| static MENU_SELECT_FUNC(tetris_start) | ||
| { | ||
| menu_redraw_blocked = 1; | ||
| task_create("tetris_task", 0x1e, 0x4000, tetris_task, (void*)0); | ||
| } | ||
|
|
||
| struct menu_entry tetris_menu[] = | ||
| { | ||
| { | ||
| .name = "ML Tetris", | ||
| .select = tetris_start, | ||
| .help = "Tetris on your DSLR", | ||
| }, | ||
| }; | ||
|
|
||
| unsigned int tetris_init() | ||
| { | ||
| menu_add("Games", tetris_menu, COUNT(tetris_menu)); | ||
| return 0; | ||
| } | ||
|
|
||
| unsigned int tetris_deinit() | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| MODULE_CBRS_START() | ||
| MODULE_CBR(CBR_KEYPRESS, tetris_keypress, 0) | ||
| MODULE_CBRS_END() | ||
|
|
||
| MODULE_INFO_START() | ||
| MODULE_INIT(tetris_init) | ||
| MODULE_DEINIT(tetris_deinit) | ||
| MODULE_INFO_END() | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it adds a dependency to the ML build system for "astyle", since all modules are built for all cams. I don't really want to do that. If you're volunteering to convert all ML code to be compatible, and then add an astyle dep, that's different! But it also feels like a separate task.
Probably remove this dep?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can comment it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Annoyingly, there's an "official" coding style in doc/CODING_STYLE - which even suggests using astyle! But it is very clear this is not followed consistently.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if the entire repo was formatted consistently, but that would be too big of a diff and mess with history+branches