Game For ECE 2035

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

graphics.cpp

Committer:
nasiromar
Date:
2021-11-19
Revision:
6:c9695079521d
Parent:
4:37d3935365f8
Child:
7:862062ffca62

File content as of revision 6:c9695079521d:

#include "graphics.h"

#include "globals.h"
#include "main_char.cpp"
#include "chest.cpp"
#include "castle.cpp"
#include "key.cpp"
#include "portal.cpp"
#include "tree.cpp"
#include "npc.cpp"
/*
In this file put all your graphical functions (don't forget to declare them first
in graphics.h). So when you want to draw something use this file. One cool function
to look at would be uLCD.blit() there are more like filled_rectangle etc... 
https://os.mbed.com/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/
This website is a good resource.
*/

void draw_player(int u, int v, int key)
{
    
    uLCD.BLIT(u,v,11,11,main_char_arr);
    //.filled_rectangle(u, v, u+11, v+11, RED);
}

#define YELLOW 0xFFFF00
#define BROWN  0xD2691E
#define DIRT   BROWN
void draw_img(int u, int v, const char* img)
{
    int colors[11*11];
    for (int i = 0; i < 11*11; i++)
    {
        if (img[i] == 'R') colors[i] = RED;
        else if (img[i] == 'Y') colors[i] = YELLOW;
        else if (img[i] == 'G') colors[i] = GREEN;
        else if (img[i] == 'D') colors[i] = DIRT;
        else if (img[i] == '5') colors[i] = LGREY;
        else if (img[i] == '3') colors[i] = DGREY;
        else colors[i] = BLACK;
    }
    uLCD.BLIT(u, v, 11, 11, colors);
    wait_us(250); // Recovery time!
}

void draw_nothing(int u, int v)
{
    // Fill a tile with blackness
    uLCD.filled_rectangle(u, v, u+10, v+10, BLACK);
}

void draw_wall(int u, int v)
{
    uLCD.filled_rectangle(u, v, u+10, v+10, BROWN);
}

void draw_plant(int u, int v)
{
    uLCD.BLIT(u,v,11,11,tree_arr);
}

void draw_key(int u, int v)
{
    uLCD.BLIT(u,v,11,11,key_arr);
}

void draw_npc(int u, int v)
{
    uLCD.BLIT(u,v,11,11,npc_arr);
}

void draw_portal(int u, int v)
{
    uLCD.BLIT(u,v,11,11,portal_arr);
}

void draw_castle(int u, int v)
{
    uLCD.BLIT(u,v,11,11,castle_arr);
}

void draw_chest(int u, int v){
     uLCD.BLIT(u,v,11,11,chest);
}

void draw_upper_status(int player_x, int player_y)
{
    uLCD.locate(0,0);
    uLCD.text_width(1);
    uLCD.text_height(1);
    uLCD.color(GREEN);
    uLCD.printf("X: [%2i] Y: [%2i]",player_x,player_y);
    
    // Draw bottom border of status bar
    
    // Add other status info drawing code here
}

void draw_lower_status(int hp, int mp)
{   
    // Draw top border of status bar
    uLCD.locate(0,15);
    uLCD.text_width(1);
    uLCD.text_height(1);
    uLCD.color(GREEN);
    uLCD.printf("HP: %3i MP: %3i",hp,mp);
    
    // Add other status info drawing code here
}

void draw_border()
{
    uLCD.filled_rectangle(0,     9, 127,  14, WHITE); // Top
    uLCD.filled_rectangle(0,    13,   2, 114, WHITE); // Left
    uLCD.filled_rectangle(0,   114, 127, 117, WHITE); // Bottom
    uLCD.filled_rectangle(124,  14, 127, 117, WHITE); // Right
}