Title was supposed to be tic tac toe. haha
Ok. i dont know what i am doing wrong. It takes a couple of clicks sometimes to get the X or O to go onto the board. please help. what am i doing wrong?
The next feature i am going to add is a button on the bottom to reset the game. but i know how to do that.
I think it is because you are constantly trying to render which is crippling the event queue.
Set up a timer and only render when there are no events in the queue and you get a tick
Here is my scene manager which does this sort of thing:
An easy fix that might work is:
But the timer solution is more robust.
EDIT: Another option is to only render when:
-The window loses focus
-The window gains focus
-A mouse event
This would, in general consume less cpu than the timer solution, but, timers are still better in 2014.
so i tried using al_is_event_queue_empty() and it allows me to place the first x but then after that the program freezes. or appears to freeze at least. because it is still running just nothing happens.
next what i was going to try was the timer.
but also does not work. it gives the same results as the empty queue
int fps = 60;
ALLEGRO_TIMER *timer = NULL;
timer = al_create_timer(1.0/FPS);
al_register_event_source(EventQueue, al_get_timer_event_source(timer));
al_start_timer(timer);
while(!Exit)
{
if(button click)
{all the button clicks}
if(Event.type == ALLEGRO_EVENT_TIMER)
{
if(one == 1)
{
al_draw_bitmap(X, 0, 0, 0);
}
else if(one == 2)
{
al_draw_bitmap(O, 0, 0, 0);
}
if(two == 1)
{
al_draw_bitmap(X, 32, 0, 0);
}
else if(two == 2)
{
al_draw_bitmap(O, 32, 0, 0);
}
if(three == 1)
{
al_draw_bitmap(X, 64, 0, 0);
}
else if(three == 2)
{
al_draw_bitmap(O, 64, 0, 0);
}
if(four == 1)
{
al_draw_bitmap(X, 0, 32, 0);
}
else if(four == 2)
{
al_draw_bitmap(O, 0, 32, 0);
}
if(five == 1)
{
al_draw_bitmap(X, 32, 32, 0);
}
else if(five == 2)
{
al_draw_bitmap(O, 32, 32, 0);
}
if(six == 1)
{
al_draw_bitmap(X, 64, 32, 0);
}
else if(six == 2)
{
al_draw_bitmap(O, 64, 32, 0);
}
if(seven == 1)
{
al_draw_bitmap(X, 0, 64, 0);
}
else if(seven == 2)
{
al_draw_bitmap(O, 0, 64, 0);
}
if(eight == 1)
{
al_draw_bitmap(X, 32, 64, 0);
}
else if(eight == 2)
{
al_draw_bitmap(O, 32, 64, 0);
}
if(nine == 1)
{
al_draw_bitmap(X, 64, 64, 0);
}
else if(nine == 2)
{
al_draw_bitmap(O, 64, 64, 0);
}
}
}
Not quite,
you need a bool needsRedraw;
When you get a timer event, set needs redraw to true.
Then in your main loop, right after you wait for event, do:
if(event queue is empty and needs redraw) { clear the screen, draw flip set needsRedraw to false }
so for the bool redraw. i set every time the mouse button is pressed down it makes redraw true?
You could do that if you only ever plan to have that as your only trigger. Otherwise, the timer will ensure it happens 60 times per second if you set it true in there. I recommend the timer since you might want to add animation in the future.
so would i do this?
when i try that i now just get a black screen.
if(Event.type == ALLEGRO_EVENT_TIMER && Redraw == true)
No,
al_wait_for_event if(Event.type == ALLEGRO_EVENT_TIMER) { redraw = true; } else if(mouse event) { } if(al_event_queue_empty && redraw) { //do all drawing code redraw = false; }
The logic is:
if it has been at least 17ms, you have permission to redraw yourself.
if there are no events in the queue and you have permission to redraw yourself, then redraw yourself and revoke your permission to draw yourself.
Just a little tip,
instead of if(x == true) and if(x == false) you can write: if(x) and if(!x)
Also, if you have code, then put it in code blocks:
<code> your code </code>
getting there? it is still pretty spotty with it working.
seems like its working a little bit better though.
else if(ev.mouse.button & 1 && PTwo == 1 && nine == 0 && Event.mouse.x >= 64 && Event.mouse.x <= 96 && Event.mouse.y >= 64 && Event.mouse.y <= 96)
{
nine = 2;
POne = 1;
PTwo = 0;
}
else if(ev.mouse.button & 1 && Event.mouse.x >= 32 && Event.mouse.x <= 64 && Event.mouse.y >= 96 && Event.mouse.y <= 128)
{
Exit = true;
Restart = true;
}
}
if(Event.type == ALLEGRO_EVENT_TIMER)
{
Redraw = true;
}
if(al_is_event_queue_empty(EventQueue) && Redraw)
{
if(one == 1)
{
al_draw_bitmap(X, 0, 0, 0);
}
Could you try to integrate your code into this main.cpp template I have; I know this template works; Just that it's a little old:
Comment out whatever you do not need.
sure. i could do that.
I will work on it later today. i have to go for now. probably have it finished by tomorrow morning. I greatly appreciate all your trying to help and hope we can continue talking when i get around to finishing this.
Ok great. I'm just typing so you can respond when you're done.
already came to a problem though. at first i compiled it and got errors from
//#include <allegro5/allegro_vorbis.h>
//#include <allegro5/allegro_flac.h>
//#include <physfs.h>
because it could not find them and errors from im assuming everything that use those headers. so i commented them out. program runs but all that comes up is console window and a message box that says "Project1.exe has stopped working" a problem caused it to stop working bla bla bla
Hi
Here is a revised version of the template that I just tested and works perfectly:
The crash came from the line:
al_reserve_samples(64) which now requires a default mixer to work.
OK so i spent a good two hours last night and the template was proving to be way beyond me. but i will keep trying. It runs quite a bit better. but still not exactly right.
I put my code into this:
https://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Timers
feel free to ask questions about the stuff you don't understand. it may make good material for the wiki or a faq.
well yeah but im very much a beginner with allegro 5 and am by no means good with general c++ so the stuff i dont understand is like half the template jmasterx has posted.
Well, after you have a shot at figuring out, if you still have questions, you're always welcome to ask
Yeah i for sure will.
I am quite happy with my tic tac toe game as it is right now. it works out moderately well. not 100% but i will keep working on it.
Edit:
Just made some new parts to the board. i added a menu icon that does nothing. i mean its tic tac toe. but maybe ill use it for something eventually. and a quit button
Yeah, that's cool 
Like Thomas said, if you have any questions, we are all happy to answer. The template breaks things down into separate functions to keep the code more organized. You might not be familiar with functions yet and that's fine. With some more practice you will get the hang of it.
One of my first programs was a tic-tac-toe with A.I in vb .net, maybe you can eventually look into making a computer player for it.
One of my first programs was a tic-tac-toe with A.I in vb .net
vb.net? GET OFF MY LAWN. damn kids.
Yup, I learned programming in this order:
VB .NET -> C++/C -> C# -> SQL -> JavaScript -> Java -> PHP -> Objective-C.
I have not written anything in VB .NET in nearly 5 years though, but hey, you have to start somewhere; we young whipper-snappers can't imagine starting with assembly or cobol 
6 years ago I never imagined myself being able to program, but, one day I decided I wanted to learn it and I became really good at it quite quickly.
This is another game i have been working on. I need to really revise it though. What i need done is completely redo the inventory and bank system to make the items structures instead. only problem is im not fantastic with dealing with structures. but how i have it works... its just hard to add new items. tic tac toe was getting started with graphics so i can hopefully make this rpg using graphics. the character and tiles are what i made to try and get into that game.
And also something i think i should add. i am going to be starting my senior year of highschool and will be taking robotics. we will be using robotc vex sets. After highschool i plan on going to san francisco state university to study computer science with software engineering base.
Nice!
From my own experience of being in a computer science program, still continue to do as much hobby programming as you can. I find the types of problems you run into with school projects are not always representative of the problems you face as a professional software developer.In Uni, you can tell the students that do hobby programming, and those that just do the assignments.