|
Player class not recognized |
agonvs
Member #15,917
March 2015
|
Here are my errors: 1>------ Build started: Project: Dem Bones, Configuration: Release Win32 ------ Here's skeleton.cpp: 1 #include<allegro5/allegro.h>
2 #include<allegro5/allegro_primitives.h>
3 #include<allegro5/allegro_image.h>
4 #include<allegro5/allegro_audio.h>
5 #include<allegro5/allegro_acodec.h>
6 #include<iostream>
7 #include<fstream>
8#include"entity.h"
9#include"player.h"
10#include"globals.h"
11 using namespace std;
12
13 int main()
14 {
15 float gameTime = 0;
16 int frames = 0;
17 int gameFPS = 0;
18 if(!(al_init()))
19 cout << "Couldn't initialize Allegro." << cout;
20 if(!(al_install_joystick()))
21 cout << "Couldn't install joystick." << endl;
22 al_init_image_addon();
23 al_init_primitives_addon();
24 ALLEGRO_DISPLAY *display = NULL;
25 display = al_create_display(1280,720);
26 ALLEGRO_BITMAP* bkgd;
27 bkgd = al_load_bitmap("bkgd.pcx");
28 ALLEGRO_EVENT_QUEUE *event_queue = NULL;
29 event_queue = al_create_event_queue();
30 if(!event_queue)
31 cout << "al_create_event_queue failed." << endl;
32 ALLEGRO_TIMER *timer;
33 timer = al_create_timer(1.0/60);
34 al_register_event_source(event_queue, al_get_timer_event_source(timer));
35 gameTime = al_current_time();
36 al_register_event_source(event_queue, al_get_joystick_event_source());
37 ALLEGRO_JOYSTICK* joy = al_get_joystick(0);
38 ALLEGRO_JOYSTICK_STATE jst;
39 //~ buttons button;
40 direction dir = RIGHT;
41 bool alive = true;
42 bool render=false;
43 al_start_timer(timer);
44 int x = 0, y = -720;
45 Player player;
46 while(alive)
47 {
48 ALLEGRO_EVENT ev;
49 al_wait_for_event(event_queue, &ev);
50 al_get_joystick_state(joy, &jst);
51 if (ev.type == ALLEGRO_EVENT_JOYSTICK_AXIS)
52 {
53 if (((jst.stick[2].axis[0] == 0) && (jst.stick[2].axis[1] == 0)) || ((jst.stick[1].axis[0] == 0) && (jst.stick[1].axis[1] == 0)) || ((jst.stick[3].axis[0] == 0) && (jst.stick[0].axis[1] == 0)))
54 dir = NONE;
55 if (((jst.stick[2].axis[0] == 1) && (jst.stick[2].axis[1] == 0)) || ((jst.stick[1].axis[0] == 1) && (jst.stick[1].axis[1] == 0)) || ((jst.stick[3].axis[0] == 1) && (jst.stick[0].axis[1] == 0)))
56 dir = RIGHT;
57 if (((jst.stick[2].axis[0] == -1) && (jst.stick[2].axis[1] == 0)) || ((jst.stick[1].axis[0] == -1) && (jst.stick[1].axis[1] == 0)) || ((jst.stick[3].axis[0] == -1) && (jst.stick[0].axis[1] == 0)))
58 dir = LEFT;
59 }
60 //~ if (ev.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN)
61 //~ if (jst.button[9])
62 //~ button = NINE;
63 //update
64 else if (ev.type == ALLEGRO_EVENT_TIMER)
65 {
66 render = true;
67
68
69 if (dir == LEFT)
70 {
71
72 }
73 if (dir == RIGHT)
74 {
75
76 }
77
78 if (al_current_time() - gameTime >= 1)
79 {
80 gameTime = al_current_time();
81 gameFPS = frames;
82 frames = 0;
83 }
84 }
85
86 //render
87 if (render && al_is_event_queue_empty(event_queue))
88 {
89 //~ al_set_target_bitmap(al_get_backbuffer(display));
90
91 al_clear_to_color(al_map_rgb_f(0,0,0));
92 al_draw_bitmap(bkgd, x, y, 0);
93 al_flip_display();
94
95
96 }
97
98 if (jst.button[9])
99 alive = false;
100 }
101 //~ al_destroy_bitmap(image);
102 al_destroy_timer(timer);
103 al_destroy_event_queue(event_queue);
104 return 0;
105 }
Here's player.cpp: 1#include "entity.h"
2#include"player.h"
3#include<allegro5\allegro5.h>
4
5void Player::Initialize(int x, int y, int velX, int velY, ALLEGRO_BITMAP* image)
6{
7 mX = x;
8 mY = y;
9 mVelX = velX;
10 mVelY = velY;
11 mImage = image;
12 idle = true;
13 dying = false;
14 injured = false;
15 jumping = false;
16 falling = false;
17 shooting = false;
18 idleForward = true;
19 tint = false;
20 flipped = false;
21 r = 1;
22 g = 0;
23 b = 0;
24 transparency = 0;
25 frame = 0;
26 count = 0;
27}
28
29void Player::Update()
30{
31 if (idle)
32 {
33 if (count == 5)
34 {
35 if (idleForward)
36 {
37 if (frame == 2)
38 {
39 frame--;
40 count = 0;
41 idleForward = false;
42 }
43 else
44 {
45 frame++;
46 count = 0;
47 }
48 }
49 else
50 {
51 if (frame = 0)
52 {
53 frame++;
54 count = 0;
55 idleForward = true;
56 }
57 else
58 {
59 frame--;
60 count = 0;
61 }
62 }
63 }
64 count++;
65 }
66
67}
68
69void Player::Render()
70{
71 if (tint)
72 if (flipped)
73 al_draw_tinted_bitmap_region(mImage, al_map_rgba_f(r, g, b, transparency), (frame * 256), 0, 256, 256, mX, mY, ALLEGRO_FLIP_HORIZONTAL);
74 else
75 al_draw_tinted_bitmap_region(mImage, al_map_rgba_f(r, g, b, transparency), (frame * 256), 0, 256, 256, mX, mY, 0);
76 else
77 if (flipped)
78 al_draw_bitmap_region(mImage, (frame * 256), 0, 256, 256, mX, mY, ALLEGRO_FLIP_HORIZONTAL);
79 else
80 al_draw_bitmap_region(mImage, (frame * 256), 0, 256, 256, mX, mY, 0);
81}
What is it I'm missing here? |
jmasterx
Member #11,410
October 2009
|
Could you post player.h your error relates to C++ not recognizing Player class, so odds are it did not compile correctly (header). Agui GUI API -> https://github.com/jmasterx/Agui |
agonvs
Member #15,917
March 2015
|
Sure. Here's player.h: 1#pragma once
2#include "entity.h"
3#include<allegro5\allegro.h>
4
5class Player: public Entity
6{
7private:
8 bool idle, dying, injured, jumping, falling, shooting, idleForward, tint, flipped;
9 float r, g, b, transparency;
10 int frame, count, mX, mY, mVelX, mVelY, mWidth, mHeight;
11 ALLEGRO_BITMAP* mImage[3];
12
13public:
14 void Initialize(int x, int y, int velX, int velY, ALLEGRO_BITMAP* image[3]);
15 void Update();
16 void Render();
17 bool collide(int collideX, int collideY, int width, int height);
18 int getVelX(){return mVelX;}
19 int getVelY(){return mVelY;}
20};
Here's entity.h: #pragma once #include<iostream> class Entity { public: virtual void Initialize() = 0; virtual void Update() = 0; virtual void Render() = 0; };
|
jmasterx
Member #11,410
October 2009
|
I don't know if it makes a difference in this case but could you try adding virtual to those 3 methods in Player? virtual void Initialize(int x, int y, int velX, int velY, ALLEGRO_BITMAP* image[3]); virtual void Update(); virtual void Render(); I'm thinking maybe without the virtual, it does not register with the vtable and still considers Player as abstract. Edit: Looks like your way is correct http://www.tutorialspoint.com/cplusplus/cpp_interfaces.htm Not sure what's wrong. Agui GUI API -> https://github.com/jmasterx/Agui |
agonvs
Member #15,917
March 2015
|
Yeah, it was saying it was abstract after I worked on it a bit, then I tried void virtual instead of virtual void without the = 0 at the end. That seemed to work. Thanks anyways! |
|