A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.

Dependencies:   mbed MotionSensor

main.h

Committer:
el17sm
Date:
2019-04-20
Revision:
7:4aaa37a711a1
Parent:
6:104c2506237e

File content as of revision 7:4aaa37a711a1:

#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "math.h"
#include "sprites.h"

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


bool moving = false;
float player_pos[2] = {39,27};
float future_player_pos[2] = {39,27};
int face = 2;
int counter = 0;

bool matrix_collision_test(int pos_x, int pos_y, int map_no, int width, int length){
    for (int j = pos_y; j < pos_y+length; j++){
        for(int i = pos_x; i < pos_x+width; i++){
            if ((j>=48) || (i>=84) || (j<0) || (i<0)) {
            }
            else if ((level_map[0][j][i] == 1)) {
                return false;
            }
        }
    }
    return true;
}

void move_player() {
    
    Vector2D mapped_coord = gamepad.get_mapped_coord();
    future_player_pos[0] = player_pos[0] + mapped_coord.x;
    future_player_pos[1] = player_pos[1] - mapped_coord.y;
    if(matrix_collision_test(future_player_pos[0], player_pos[1], 0, 6, 5)){
        player_pos[0] = future_player_pos[0];
    }
    if(matrix_collision_test(player_pos[0], future_player_pos[1], 0, 6, 5)){
        player_pos[1] = future_player_pos[1];
    }
    moving = false;
    if (abs(mapped_coord.x) + abs(mapped_coord.y) > 0.1f){
        moving = true;
        if (mapped_coord.y < 0 && abs(mapped_coord.y) > abs(mapped_coord.x)){
            face = 2;
        }
        else if (mapped_coord.y > 0 && abs(mapped_coord.y) > abs(mapped_coord.x)){
            face = 0;
        }
        else if (mapped_coord.x > 0 && abs(mapped_coord.x) > abs(mapped_coord.y)){
            face = 1;
        }
        else if (mapped_coord.x < 0 && abs(mapped_coord.x) > abs(mapped_coord.y)){
            face = 3;
        }
    }    
}