Allegro

Pages: 1234
It's compilers that need to be supported. Dev-C++ comes with MinGW and sfml does have libraries for it. Though you may want to try Code::Blocks. I hear it's superior to Dev-C++.
Code::Block should be superior and SFML should be more comfortable, but i cant get it runnign and the guide that should teach me how to get it running, dont say anything about the things needed. Like SFML-system.dll, where shouldi hadd it and how i add it.
If it's complaining about dlls, then the set up must have been good. dlls are in path_to_sfml_folder/bin, I think. Either move them to windows/system32 or to where your code is.
took some time but i got it running. Now i need to learn SFML basics
Last edited on
http://www.sfml-dev.org/tutorials/1.6/window-window.php
Im trying to do this tutorial, it is the first one and already im having problm swith Code::Blocks and SFML. So what dll i need to add where and what do i but under linker options in project options.
yes i read the gettign staerted. even then i messed around and hour to get it working and in the end i still didnt understand what the hell did i do to get it working. Il look for a better tutorial.
Last edited on
ok i gotthe dll-s and stuff like that sorted out.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <SFML/Window.hpp>

int main()
{
    // Create the main window
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");

    // Start main loop
    bool Running = true;
    while (Running)
    {
        App.Display();
    }

    return EXIT_SUCCESS;
}

This code should create a window. So i think this is a Windows window not CMD window, but i get command prompt window. and it seem that the entyre program freezes then. Btw this is the tutorial code not mine.
Libraries are often hard to set up like that. I really wish I could help. Sorry.
Been at it for hours and i simply cant get it working. I have no ide what is the problem here. It name says it should be simple and fast, but i have yet to see the simplisity. I have checked te gettign started tutorial, double checked, triple checked, still nothing. i get 50+ errors i dont know how many excactly cause the box has its lilmits.

So atleast for now, il stick to Allegro, cause atm it seems alot more simplerer than SFML.
So i got the selection working fine, so the next thing to do is to make them move.

I was thinking about a class file that gets the ID and beginngin location of the circle. And then houses the command that makes it move. SOmething like ID , destynation x, destinatyon y. And the under that command has the movement stuff. Up, Down, Left, Right, and Diagonal.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class MoveCommand{
      private:
              int Object_ID;
              int Objectlocation_x;
              int Objectlocation_y;
              int destination_x;
              int destination_y;
      public:
             MoveCommand (GetLocation, GetDestination);
             GetLocation(Object_ID, Objectlocation_x, Objectlocaion_y);
             GetDestination(destination_x, destination_y);
             };
             
MoveCommand::MoveCommand(GetLocation, GetDestination){
             if(Objectlocation_x < destination_x){
                 for(int i= 0; Objectlocation_x <= destination_x; i++){
                                Objectlocation_x++;
                                             }  
                                 }
             if(Objectlocation_x > destination_x){
                 for(int i=0; Objectlocation_x >= destination_x){
                                 Objectlocation_x--;
                                             }
                                 }
             if(Objectlocation_y < destination_y){
                 for(int i = 0; Objectlocation_y <= destination_y; i++){
                                 Objectlocation_y++;
                                             }
                                 }
             if(Objectlocation_y > destination_y){
                 for(int i = 0; Objectlocation_y >= destination_y; i++){
                                 Objectlocation_y--;
                                             }
                                 }
             }

this is what i came up with. I dont know if this works.
Last edited on
Firstly, no. This isn't syntactically correct. MoveCommand is a constructor. GetLocalion and GetDestination are functions, I assume. They don't have return types declared. Also, how can a constructor accept functions?
Secondly, no. The logic is wrong too. This is equivalent to Objectlocation = destination. To make a thing move, you need to add a little to its coordinates before redrawing.

Here is a plain example:
1
2
3
4
5
6
7
8
9
10
11
12
float px = ..., py = ...; //position
float tx = ..., ty = ...; //target
const float speed = 1;

while(true){//the main loop
   float dist = distane(px - tx, py - ty);//distance between two points, defined as sqrt(dx*dx+dy*dy)
   if(dist>speed){ //if you haven't reached your destination
      px += (px-tx)/dist*speed;//equations for smooth movement on a line
      py += (py-ty)/dist*speed;
   }
   draw_something(px, py);
}

Normally you'd put most of it in a class, so that it looks like
1
2
3
4
5
Character c(...);
while(true){
   c.update();
   c.draw();
}

Notice that now the speed of your character depends on frame rate. When you feel comfortable with this method and the simple maths behind it, try to figure out, how you could use a timer, to choose the right position, even if frame rate is lagging.
i was thinking that the Object should keep its ID in the scene only its x and y coordinates would change.

I did something im not sure what i did, i problably messed this up cause i wanted to use a class, and in makeing os i messed things up bad.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class MoveCommand{
      private:
              int Object_ID;
              int Objectlocation_x;
              int Objectlocation_y;
              int destination_x;
              int destination_y;
      public:
             MoveCommand ();
             GetLocation(Object_ID, Objectlocation_x, Objectlocaion_y);
             GetDestination(destination_x, destination_y);
             };

MoveCommand::GetLocation(int ID, int x, int y){
                                   Object_ID = ID;
                                   Objectlocation_x= x;
                                   Objectlocation_y = y;
                                   }
                                   
MoveCommand::GetDestination(int x, int y){
                                   destination_x =x;
                                   destination_y = y;
                                   }
                                   
MoveCommand::MoveCommand(){
            float px = Objectlocation_x, py=Objectlocation_y;
            float tx = destination_x, ty = destination_y;
            const float speed = 1;
            
            while(true){
                        float dist = distance(px - tx, py - ty);
                        if(dist > speed){
                                px +=(px-tx)/dist*speed;
                                py +=(py-ty)/dist*speed;
                                }
              circlefill(buffer, px, py, radius, makecol(0, 0, 255)); 
             }


Basiclly i used my old class whati created and made it some changes. I probably messed up good.
Last edited on
Still not good. The constructor is meant for initialization. And your functions still don't have return types.

What you need is not a MoveCommand class, but an improved Cicles class (struct. or whichever you like.).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
struct Circle{
   float px, py, tx, ty, rdius;

   Circle(float posx, float posy, float rad) {//for more comfortable creation of circles
      px = tx = posx;//so that the circle doesn't move
      py = ty = posy;
      radius = rad;
   }

   void set_target(float x, float y){
      tx = x;
      ty = y;
   }

   void update(){
      float dist = distance(px - tx, py - ty);
      const float speed = 1;//you may want to make this a member or a static member in the future
      if(dist > speed){//moves the object one step further
         px +=(px-tx)/dist*speed;
         py +=(py-ty)/dist*speed;
      }
   }

   void draw(){
      circlefill(buffer, px, py, radius, makecol(0, 0, 255));
   }
};

Now, in your code, where you would draw a circle, instead do
1
2
scene[i].update();
scene[i].draw();
I see. draw() needs a conversion from float to int ot all floats must be turned to int, cause circlefill accpets only ints
[Warning] passing `float' for converting 2 of `void circlefill(BITMAP*, int, int, int, int)'


And i know now why SFML doesent work for me, i use ATI grpahic card, and SFML has some problems with it, so i have to wait for SFML2 to run it.
Ok now only thing missing is to make it move whidout me having to click eatch time. Atm, eatch time i click it moves one step in the opposite direction.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
bool new_mouse2 = mouse_b & 2;
   if(new_mouse2 != old_mouse2){
                 old_mouse2 = new_mouse2;     
   if(new_mouse2){
            textprintf(buffer, font, 0, 40, makecol(255, 255, 255), "%s", str);
            cursor_x = mouse_x;
            cursor_y = mouse_y;
    
            
     for(int i = 0; i < scene.size(); i++){  
            if (distance(cursor_x-scene[i].px, cursor_y-scene[i].py) 
            <= scene[i].radius){
                         selected = i;
            if (selected ==i){
              scene[i].get_target(cursor_x, cursor_y);
              scene[i].update();
              scene[i].draw();
                                     }
                                }
                                             
                       } 
                       
            textprintf(buffer, font, 0, 10, makecol(255, 255,255), "selected = %i", selected);                       
            return 1;
            }
       }
The problem is your game loop. Now it only redraws when getMouseInfo returns 1. You need it to redraw constantly.
That's just
1
2
3
4
5
while( !key[KEY_ESC])
{
  getMouseInfo(); 
  updateScreen();
}
(I didn't get the point of switcher..)
switcher just turns the mouse of for a second, for the moment when it draws.
You may have noticed a black rectangle on some of the circles with the last example. Mostly when you try to move the mouse fast.
Here Wmz used a variable called switcher to determine wether or not the mouse cursor should be displayed. If something needs to be drawn to the screen, updateScreen() will first deactivate the mouse so that it does not interrupt the process, once the update is finished, the while loop will continue and redraw the mouse cursor directly to the screen.


Since im failry new to Allegro and anything connected to using graphics, i use allegro basic tutorial and you help.
Last edited on
1
2
3
4
5
6
7
8
9
while( !key[KEY_ESC])
{
  rest(50); //this makes a pause 50 milliseconds long
  if(mouse_b & 1 || mouse_b & 2){
  getMouseInfo(); 
  updateScreen();
                       }
  updateScreen();
}

simething like this, although this just might create a infinite loop and program crashes.
Last edited on
You check mouse_b inside getMouseInfo, and if mouse_b is not 0, the screen in redrawn on line 6. Thus lines 4, 6 and 7 are not needed. Though aren't a cause either. It sounds like something due to allegro. I think you'll have to find a tutorial that has continuous motion in it, so that you see if there are any differences.
(or did that "might" imply that you didn't try yet?..)
Last edited on
Pages: 1234