ELEC2645 (2018/19) / Mbed 2 deprecated EL17MCD

Dependencies:   mbed

main.cpp

Committer:
el17mcd
Date:
2019-04-03
Revision:
5:8a2e96f7fb4d
Parent:
4:3b3a7f102250
Child:
6:5d57c758c31d

File content as of revision 5:8a2e96f7fb4d:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Maxim C. Delacoe
Username: EL 17 MCD
Student ID Number: 2011 58344
Date: 19/03/2019
*/
///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Bitmap.h"

N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);

const int tank_left[6][10] =   {
    { 0,0,0,1,1,1,0,0,0,0 },
    { 0,0,1,1,1,1,1,0,0,0 },
    { 0,0,1,1,1,1,1,1,1,0 },
    { 1,1,1,1,1,1,1,1,1,1 },
    { 1,0,1,0,1,0,1,0,1,0 },
    { 0,1,0,1,0,1,0,1,0,0 },                                                                
};
const int proj[5][5] =   {
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 1,1,1,1,1 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },                                                               
};
// Spawning tank and projectile at random position
// with visual feedback to build grid and hitbox system
void welcome()
{
    lcd.clear();
    lcd.printString("  ELEC 2645",0,0);
    lcd.printString("  Game  ",0,1);
    lcd.printString("   Project",0,2);
    lcd.printString("Max C. Delacoe",0,4);
    lcd.printString(" 2011 58344",0,5);
    lcd.refresh();
    wait(0.2);
}

int main()
{
    int tank_hb[40];
    lcd.init();
   // welcome();  // display welcome message 

    while(1) {  // infinite loop
        
        srand(time(NULL)); 
        char buffer[14];
        int t_pos_x = rand() % 77;
        int t_pos_y = rand() % 37;
        
//Takes the tanks x and y position (of its bottom left pixel of sprite) and
//determines the area it cover in terms of grid values.
        int i = 0;
        for (int i0 = 0; i0 < 4; i0++) {
        
            for (int i1 = 1; i1 < 11; i1++) {
            tank_hb[i] = (i0 + t_pos_y) * 84 + t_pos_x + i1;
            i++;
            }
        }
                                 
        lcd.clear();
        sprintf(buffer,"  %d  ",tank_hb[0] );
        lcd.printString(buffer,0,1);
        lcd.refresh();
        wait(1.5);
        lcd.clear();
        sprintf(buffer,"  %d  ",tank_hb[39] );
        lcd.printString(buffer,0,1);
        lcd.refresh();
        wait(1.5);
        lcd.clear();

      /*  
        int p_pos_x = rand() % 84;
        int p_pos_y = rand() % 48;
        int proj_hb = p_pos_y * 84 + p_pos_x + 1;
        
      //sprintf(buffer,"t_pos_x = %d ",t_pos_x);
        lcd.clear();
        lcd.drawSprite(t_pos_x,42 - t_pos_y,6,10,(int *)tank_left);
        lcd.drawSprite(p_pos_x - 2 ,44 - p_pos_y,5,5,(int *)proj);
        lcd.printString(buffer,0,1);
        lcd.refresh();*/
        wait(1);
  //  } 
}