Skip to content

Commit

Permalink
Tweak global variable names to use '_'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lam Bui committed Jan 25, 2016
1 parent 4e3e655 commit 7c816c6
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions starfield_blind2/arm9/source/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
Starfield demo
- Simulate a horizontal scrolling starfield using a framebuffer (no background tiles or sprites)
- Stars are tracked as an array of Star
- We will do the logic and drawing during the Vblank period
- We will do the logic and drawing during the V_blank period
Bonus:
- Added ability to scroll from the left of the right of the screen
- Add key input to control horizontal scrolling direction/speed
- TO-DO: Add staged speed increases
- TO-DO: Add twinkling stars
- TO-DO: Add option for different sized stars
- TO-DO: Performance timing between memcpy vs DMA?
***/

Expand All @@ -17,8 +22,10 @@
#define SPACE_COLOR RGB15(0,0,0) // black
#define STAR_COLOR RGB15(31,31,31) // white

// control flags
#define SCROLL_RIGHT 0 // '0' - start at left of screen. '1' - start at right of screen
enum {
SCROLL_RIGHT = 0,
SCROLL_LEFT
};

// our Star object
typedef struct {
Expand All @@ -29,7 +36,9 @@ typedef struct {
} Star;

// our Stars
Star stars[NUM_OF_STARS];
Star _stars[NUM_OF_STARS];
// scrolling state
int _scroll_state = SCROLL_RIGHT;

// wipe everything to make sure we're drawing on an empty screen
void ClearScreen() {
Expand All @@ -45,10 +54,10 @@ void InitStars() {
int i;

for(i = 0; i < NUM_OF_STARS; i++) {
stars[i].x = rand() % SCREEN_WIDTH;
stars[i].y = rand() % SCREEN_HEIGHT;
stars[i].speed = (rand() % MAX_STAR_SPEED) + 1; // because the range is 1-4. We don't want stars that are stopped
stars[i].color = STAR_COLOR;
_stars[i].x = rand() % SCREEN_WIDTH;
_stars[i].y = rand() % SCREEN_HEIGHT;
_stars[i].speed = (rand() % MAX_STAR_SPEED) + 1; // because the range is 1-4. We don't want stars that are stopped
_stars[i].color = STAR_COLOR;
}
}

Expand All @@ -58,14 +67,14 @@ void EraseStar(Star *star) {
}

void MoveStar(Star *star) {
if(SCROLL_RIGHT)
if(_scroll_state == SCROLL_RIGHT)
star->x += star->speed;
else
star->x -= star->speed;

// checks to see if it falls off screen. If it does, we create a new star
if(star->x > SCREEN_WIDTH) {
star->x = (SCROLL_RIGHT) ? 0 : SCREEN_WIDTH;
star->x = (_scroll_state == SCROLL_RIGHT) ? 0 : SCREEN_WIDTH;
star->y = rand() % SCREEN_HEIGHT;
star->speed = (rand() % MAX_STAR_SPEED) + 1;
}
Expand Down Expand Up @@ -94,10 +103,21 @@ int main() {

// do logic and drawing for our starfield during Vblank
while(1) {

// get the current state of our keys
scanKeys();

// control the scrolling with the d-pad
if(keysHeld() & KEY_LEFT)
_scroll_state = SCROLL_RIGHT;
else if(keysHeld() & KEY_RIGHT)
_scroll_state = SCROLL_LEFT;

// do our drawing stuff
for(i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) {
EraseStar(&stars[i]);
MoveStar(&stars[i]);
DrawStar(&stars[i]);
EraseStar(&_stars[i]);
MoveStar(&_stars[i]);
DrawStar(&_stars[i]);
}

// make sure we pause for the whole VBlank period before we end
Expand Down

0 comments on commit 7c816c6

Please sign in to comment.