Added audio testing and a player
This commit is contained in:
+15
@@ -57,6 +57,21 @@ void InitTimer(){
|
||||
STRELOAD = 0x9C40;
|
||||
}
|
||||
|
||||
void InitAudio(){
|
||||
PINSEL1 |= 0b10 << 20;
|
||||
//init timer
|
||||
T0MR0 = 3124;
|
||||
T0MCR = 0b11;
|
||||
T0TCR = 1;
|
||||
ISER0 |= 1 << 1;
|
||||
}
|
||||
void ClearTimer0(){
|
||||
T0IR = 1;
|
||||
}
|
||||
void SetAudio(int value){
|
||||
DACR = value << 6;
|
||||
}
|
||||
|
||||
void ClearButtons(){
|
||||
//A button
|
||||
IO2IntClr = 1 << 10;
|
||||
|
||||
@@ -294,35 +294,16 @@ void Refresh_Area(Rectangle area){
|
||||
SendPixel(color.Red,color.Green,color.Blue);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Rectangle first_half = {{0,0},{0,0}};
|
||||
Rectangle second_half = {{0,0},{0,0}};
|
||||
Split_sprite(area,&first_half,&second_half);
|
||||
|
||||
Resize_Window(first_half);
|
||||
}
|
||||
void DrawPlayer(Rectangle area){
|
||||
Resize_Window(area);
|
||||
Write_Cmd(0x2C);
|
||||
for(int y= 0; y < first_half.Size.Height;y++){
|
||||
for(int x = 0; x < first_half.Size.Width+1;x++){
|
||||
Color color;
|
||||
Get_Color_From_Background((Point){x+first_half.Position.X,y+first_half.Position.Y},&color);
|
||||
SendPixel(color.Red,color.Green,color.Blue);
|
||||
for(int y = 0; y < area.Size.Height;y++){
|
||||
auto_screen_roloff(area,(Point){0,y});
|
||||
for(int x = 0; x < area.Size.Width+1;x++){
|
||||
SendPixel(0x58,0x2A,0x72);
|
||||
}
|
||||
}
|
||||
|
||||
if(second_half.Size.Height != 0 && second_half.Size.Width != 0){
|
||||
Resize_Window(second_half);
|
||||
Write_Cmd(0x2C);
|
||||
for(int y= 0; y < second_half.Size.Height;y++){
|
||||
for(int x = 0; x < second_half.Size.Width+1;x++){
|
||||
Color color;
|
||||
Get_Color_From_Background((Point){x+second_half.Position.X,y+second_half.Position.Y},&color);
|
||||
SendPixel(color.Red,color.Green,color.Blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Resize_Window(viewPort);
|
||||
*/
|
||||
}
|
||||
void Draw_stars(){
|
||||
Write_Cmd(0x2C);
|
||||
|
||||
@@ -101,5 +101,13 @@
|
||||
// Flash Accelerator
|
||||
#define FLASHCFG (*((volatile uint32_t *) 0x400FC000))
|
||||
|
||||
// DAC
|
||||
#define DACR (*((volatile uint32_t *) 0x4008C000))
|
||||
|
||||
#define T0TCR (*((volatile uint32_t *) 0x40004004))
|
||||
#define T0MR0 (*((volatile uint32_t *) 0x40004018))
|
||||
#define T0MCR (*((volatile uint32_t *) 0x40004014))
|
||||
#define T0IR (*((volatile uint32_t *) 0x40004000))
|
||||
|
||||
|
||||
#endif /* CONFIG_LPC1769_H_ */
|
||||
|
||||
+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