c++collationallegro

I am trying to do collation in ALLEGRO c++ with many walls


So I am trying to make a game that has collation in it and I have been trying and looking for what works for me.

This is the class.cpp file

    #include "Player.h"
#include <iostream>
#include <string>
#include <allegro5/allegro.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro.h>
#include <locale>
#include <sstream>
#include <Windows.h>
#include <math.h>
#include "allegro5/allegro_primitives.h"
#include <fstream>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h> 
#include <conio.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <stdio.h>

using namespace std;


Player::Player()
{
}


Player::~Player()
{
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool _Touch(int allegro_key) {
    al_install_keyboard();
    ALLEGRO_KEYBOARD_STATE keyState;
    al_get_keyboard_state(&keyState);

    if (allegro_key >= 256) return false;
    if (al_key_down(&keyState, allegro_key)) {
        cout << allegro_key << endl;
        return true;
    }
    else {
        return false;
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////



void Player::_Draw_cross(ALLEGRO_EVENT &event, ALLEGRO_EVENT_QUEUE *queue, ALLEGRO_BITMAP *CROSS, int &x, int &y) {
    Cross = CROSS;
    al_draw_bitmap(CROSS, x, y, 0);
    if (_FLAG_s) {
        if (_Touch(ALLEGRO_KEY_W)) {
            y -= 5;
        }
        if (_Touch(ALLEGRO_KEY_A)) {
            x -= 5;
        }
        if (_Touch(ALLEGRO_KEY_D)) {
            x += 5;
        }

    }
    else if (_FLAG_t) {

        if (_Touch(ALLEGRO_KEY_S)) {
            y += 5;
        }
        if (_Touch(ALLEGRO_KEY_A)) {
            x -= 5;
        }
        if (_Touch(ALLEGRO_KEY_D)) {
            x += 5;
        }
    }
    else if (_FLAG_x) {
        cout << "DD" << endl;
        if (_Touch(ALLEGRO_KEY_W)) {
            y -= 5;
        }
        if (_Touch(ALLEGRO_KEY_S)) {
            y += 5;
        }
        if (_Touch(ALLEGRO_KEY_A)) {
            x -= 5;
        }

    }
    else if (_FLAG_y) {
        if (_Touch(ALLEGRO_KEY_W)) {
            y -= 5;
        }
        if (_Touch(ALLEGRO_KEY_S)) {
            y += 5;
        }

        if (_Touch(ALLEGRO_KEY_D)) {
            x += 5;
        }

    }
    else {
    if (_Touch(ALLEGRO_KEY_W)) {
        y -= 5;
    }
    if (_Touch(ALLEGRO_KEY_S)) {
        y += 5;
    }
    if (_Touch(ALLEGRO_KEY_A)) {
        x -= 5;
    }
    if (_Touch(ALLEGRO_KEY_D)) {
        x += 5;
    }
    }
}
bool Player::_Draw_wall(float x, float y, float x2, float y2, ALLEGRO_COLOR color, int s, int t) {
    al_draw_filled_rectangle(x, y, x2, y2, color);
    int s1 = (al_get_bitmap_height(Cross) + s), t1 = (al_get_bitmap_width(Cross) + t);
    if (s1 >= x && s <= x2 && t1 >= y && t <= y2) {
        if      (s <= x) {
            _FLAG_x = true;
        }
        else if (s >= x2) {
            _FLAG_y = true;
        }
        else if (t1 <= y) {
            _FLAG_s = true;
        }
        else if (t >= y2) {
            _FLAG_t = true;
        }
        else {
            _FLAG_x = false, _FLAG_y = false, _FLAG_s = false, _FLAG_t = false;
        }
        return true;
    }
    else { 
        _FLAG_x = false, _FLAG_y = false, _FLAG_s = false, _FLAG_t = false;
        return false; }
}

and I am trying to use

        player._Draw_wall(0, 0, 20, 1080, al_map_rgb(255, 255, 255), x, y);
        player._Draw_wall(0, 0, 1920, 20, al_map_rgb(255, 255, 255), x, y);

but the only one that works is the last one.

can anyone help with getting more then 1 player._Draw_wall to work (I need a undefined amount of them).


Solution

  • I'm not really sure what you're exactly trying to achieve, and what is your problem, but by looking at your code, I immediately spot some issues:

    If you could specify further, what your original problem is (does the first wall not get drawn?), i'll look into that as well.