Skip to content

Instantly share code, notes, and snippets.

@Gi133
Created December 21, 2011 08:14
Show Gist options
  • Select an option

  • Save Gi133/1505177 to your computer and use it in GitHub Desktop.

Select an option

Save Gi133/1505177 to your computer and use it in GitHub Desktop.
Old Sonic Clone
/*
TO DO:
1. Check player position so you can start increasing index
2. Move ground array's index so it seems like it's moving
3. Increase the speed at which the array is moving around.
4. Link the array speed to player speed so it decelerates, eventually.
*/
#include <stdint.h>
#include <stdlib.h>
#include "gba.h"
int main()
{
REG_DISPCNT = MODE4 | BG2_ENABLE;
int ground[239][20];
int player[20][16];
const int line=239;
int PLAYER_POSITION=0;
int PLAYER_SPEED=0;
int SPEED_MODIFIER=0;
int index=0; //The point where to start drawing the ground array
SetPaletteBG(1, RGB(31, 31, 31));
SetPaletteBG(2, RGB(0, 0, 0));
//Assign values inside the arrays//
//Ground Array
for (int row=0; row<=20; row++)
{
for (int cell=0; cell<=line; cell++)
{
if (cell %4==0)
{
ground[row][cell]=2;
}
else
{
ground [row][cell]=1;
}
}
}
//Player Array
for (int row=0; row<=20; row++) //Drawing the main body
{
for (int cell=4; cell<=8; cell++)
{
player[row][cell]=1;
}
}
for (int row=0; row<=4; row++) //Drawing the arms
{
for (int cell=0; cell<=10; cell++)
{
player[16-row][1+cell]=1;
}
}
player[18][7]=2;
while(1)
{
//Player Controls
if ((REG_P1 & KEY_RIGHT) == 0)
{
PLAYER_POSITION++;
PLAYER_SPEED++;
}
else if ((REG_P1 & KEY_LEFT) == 0)
{
PLAYER_POSITION--;
PLAYER_SPEED--;
}
else
{
if (PLAYER_SPEED>0)
{
PLAYER_SPEED--;
}
else if (PLAYER_SPEED<0)
{
PLAYER_SPEED++;
}
else
{
PLAYER_SPEED=0;
}
}
//draw pixels on GBA screen
ClearScreen8(2);
for (int row=0; row<=20; row++)
{
for (int cell=0; cell<=line; cell++)
{
PlotPixel8(cell, (row+139), ground[row][cell]);
}
}
PLAYER_POSITION=PLAYER_POSITION+PLAYER_SPEED;
for (int row=0; row<=20; row++)
{
for (int cell=0; cell<=12; cell++)
{
PlotPixel8(PLAYER_POSITION+cell, 137-row, player[row][cell]);
}
}
if ((PLAYER_POSITION+1)==235)
{
PLAYER_POSITION=0;
}
if (PLAYER_POSITION<=0)
{
PLAYER_POSITION=0;
}
WaitVSync();
FlipBuffers();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment