diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-06-11 12:41:56 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-06-11 12:41:56 -0400 |
commit | fb05a5aaadd0da3d20dfd492c1978a76fe15743b (patch) | |
tree | 289e22dbeddc7b02b035840cb200692f4601d7e1 /source | |
parent | 824e603b236b7fd8302b3a6ca65ad05c1afa7fbc (diff) |
fix power settings; rand() for flapbird
Diffstat (limited to 'source')
-rw-r--r-- | source/flapbird.c | 28 | ||||
-rw-r--r-- | source/main.c | 3 |
2 files changed, 27 insertions, 4 deletions
diff --git a/source/flapbird.c b/source/flapbird.c index f2dd2cf..800e892 100644 --- a/source/flapbird.c +++ b/source/flapbird.c @@ -1,5 +1,8 @@ #include "buttons.h" #include "dogs.h" +#include "hal.h" + +#include <stdint.h> static const unsigned char bird[] = { 8, 8, @@ -20,11 +23,23 @@ static int py; static int vy; static int counter; +static uint32_t next = 31415926; + +int rand() +{ + uint32_t tr = RTC->TR; + uint32_t dr = RTC->DR; + next = next * (0x197244 + dr) + tr; + return (unsigned int)(next / 65536) % 32768; +} + +#define NEW_BAR() (rand() % 50 + 5) + void flapbird_init() { score = 0; - t1x = DISP_WIDTH / 2, t1o = 15; - t2x = DISP_WIDTH, t2o = 49; + t1x = DISP_WIDTH / 2, t1o = NEW_BAR(); + t2x = DISP_WIDTH, t2o = NEW_BAR(); py = DISP_HEIGHT / 2 - 4; vy = 0; counter = 0; @@ -69,11 +84,16 @@ int flapbird_loop() score = (py + 2 > t2o - 10 && py + 6 < t2o + 10) ? score + 1 : 0; t1x -= 2; - if (t1x <= -5) + if (t1x <= -5) { t1x = DISP_WIDTH; + t1o = NEW_BAR(); + } + t2x -= 2; - if (t2x <= -5) + if (t2x <= -5) { t2x = DISP_WIDTH; + t2o = NEW_BAR(); + } return 100; } diff --git a/source/main.c b/source/main.c index fd753ea..89f3cf0 100644 --- a/source/main.c +++ b/source/main.c @@ -67,6 +67,9 @@ static void alarm_callback(RTCDriver *rtcp, rtcevent_t event) int main(void) { halInit(); + + RCC->CR &= ~(RCC_CR_PLLON); // Ensure that the PLL is off (unused). + //chSysInit(); buttons_init(); |