Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
- Committer:
- el17mcd
- Date:
- 2019-04-03
- Revision:
- 6:5d57c758c31d
- Parent:
- 5:8a2e96f7fb4d
- Child:
- 7:a3ccabdebe2e
File content as of revision 6:5d57c758c31d:
/*
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];
int proj_hb[25];
lcd.init();
// welcome(); // display welcome message
while(1) { // infinite loop
srand(time(NULL));
int t_pos_x = rand() % (84-1-10); // Tank position
int t_pos_y = rand() % (48-1-6);
int p_pos_x = rand() % (84-1-5); // projectile position
int p_pos_y = rand() % (48-1-5);
//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++;
}
}
i = 0;
for (int i0 = 0; i0 < 5; i0++) {
for (int i1 = 1; i1 < 6; i1++) {
proj_hb[i] = (i0 + p_pos_y) * 84 + p_pos_x + i1;
i++;
}
}
bool hit = false;
for (int i0 = 0; i0 < 25; i0++) {
for (int i1 = 0; i1 < 40; i1++) {
if (proj_hb[i0] == tank_hb[i1]) {hit = true;}
}
if(hit == true) {break;}
}
// bool hit = false;
lcd.clear();
lcd.drawSprite(t_pos_x,42 - t_pos_y,6,10,(int *)tank_left);
lcd.drawSprite(p_pos_x,43 - p_pos_y,5,5,(int *)proj);
lcd.refresh();
wait(0.5);
if (hit == true){
lcd.clear();
lcd.printString("HIT",0,1);
lcd.refresh();
wait(2.0);
}
}
}
/*
char buffer[14];
sprintf(buffer,"t_pos_x = %d ",t_pos_x);
lcd.printString(buffer,0,1);
*/