Added audio testing and a player
This commit is contained in:
+74
-3
@@ -19,6 +19,13 @@ const Point SCREEN_ORIGIN = {0,0};
|
||||
const Size SCREEN_SIZE = {240,320};
|
||||
const Rectangle SCREEN = {SCREEN_ORIGIN,SCREEN_SIZE};
|
||||
|
||||
typedef struct Player_t{
|
||||
Rectangle Hitbox;
|
||||
int HP;
|
||||
}Player;
|
||||
|
||||
Player player;
|
||||
|
||||
void init(void)
|
||||
{
|
||||
ILI9341_Initial();
|
||||
@@ -27,6 +34,16 @@ void init(void)
|
||||
int scrolling = 0;
|
||||
bool need_to_scroll = false;
|
||||
|
||||
bool on = true;
|
||||
void TIMER0_IRQHandler(void){
|
||||
//8000HZ smaple rate
|
||||
ClearTimer0();
|
||||
|
||||
SetAudio(800);
|
||||
on = true;
|
||||
SetAudio(200);
|
||||
}
|
||||
|
||||
void EINT3_IRQHandler(void){
|
||||
int buttonPressed = Detect_AB_buttons();
|
||||
if(buttonPressed == 2){
|
||||
@@ -39,13 +56,12 @@ void EINT3_IRQHandler(void){
|
||||
|
||||
int timer_count = 0;
|
||||
int scroller_divider = 25;
|
||||
int scroll_increment = 1;
|
||||
void SysTick_Handler(){
|
||||
timer_count += 1;
|
||||
|
||||
//update the screen
|
||||
|
||||
if(timer_count >= scroller_divider){
|
||||
increment_scroll(-1);
|
||||
increment_scroll(-scroll_increment);
|
||||
need_to_scroll = true;
|
||||
timer_count = 0;
|
||||
}
|
||||
@@ -89,22 +105,76 @@ void scroll_array(int **array,int **newArray,int width,int height){
|
||||
}
|
||||
}
|
||||
|
||||
Player CreatePlayer(){
|
||||
int HP = 100;
|
||||
Size playerSize = {15,30};
|
||||
Point position = {SCREEN_SIZE.Width / 2 - playerSize.Width /2,SCREEN_SIZE.Height / 2 - playerSize.Height/2};
|
||||
Rectangle playerHitbox = {position,playerSize};
|
||||
Player player = {playerHitbox,HP};
|
||||
return player;
|
||||
}
|
||||
|
||||
void RefreshPlayer(Point vector){
|
||||
Refresh_Area(player.Hitbox);
|
||||
|
||||
player.Hitbox.Position.X += vector.X;
|
||||
player.Hitbox.Position.Y += vector.Y;
|
||||
|
||||
if(player.Hitbox.Position.Y < 0)
|
||||
player.Hitbox.Position.Y = SCREEN_SIZE.Height - 1;
|
||||
|
||||
if(player.Hitbox.Position.X + player.Hitbox.Size.Width > SCREEN_SIZE.Width)
|
||||
player.Hitbox.Position.X = SCREEN_SIZE.Width - player.Hitbox.Size.Width;
|
||||
if(player.Hitbox.Position.X < 0)
|
||||
player.Hitbox.Position.X = 0;
|
||||
|
||||
DrawPlayer(player.Hitbox);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
init();
|
||||
InitButtons();
|
||||
InitTimer();
|
||||
InitAudio();
|
||||
LedSetState8(128+32+8+2);
|
||||
Point text_origin = {240 / 2 - 8/2,(320 / 6) * 5 - 4};
|
||||
|
||||
player = CreatePlayer();
|
||||
|
||||
Resize_Window(SCREEN);
|
||||
Draw_stars();
|
||||
|
||||
while (true)
|
||||
{
|
||||
int JoystickState = JoystickGetState();
|
||||
|
||||
Point vec = {0,0};
|
||||
int increment = 1;
|
||||
|
||||
if(JoystickState & (1 << 4)){
|
||||
vec.X -= increment;
|
||||
}
|
||||
if(JoystickState & (1 << 3)){
|
||||
vec.Y += increment;
|
||||
}
|
||||
if(JoystickState & (1 << 2)){
|
||||
vec.X += increment;
|
||||
}
|
||||
if(JoystickState & (1 << 1)){
|
||||
vec.Y -= increment;
|
||||
}
|
||||
if(JoystickState & 1){
|
||||
//empty
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(need_to_scroll){
|
||||
scroll(scrolling);
|
||||
need_to_scroll = false;
|
||||
|
||||
vec.Y -= 1;
|
||||
|
||||
int digits = number_of_digits(scrolling);
|
||||
char newStr[digits+1];
|
||||
convert_to_string(scrolling,digits,&newStr);
|
||||
@@ -115,6 +185,7 @@ int main(void) {
|
||||
Refresh_Area(areaToRefresh);
|
||||
DrawText(new_origin,newStr,charSize);
|
||||
}
|
||||
RefreshPlayer(vec);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user