Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Reaver1

Allegro and a game test...

This topic is 5560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I was trying to make an engine like in worms or scorched earth. I mean that there''ll be a terrain and it will dissapear in explosion (just the radius of the explosion, not the whole terrain) and I stopped on having a ball (added this one to test collision detection) dropping to the lowest levels of hell instead of stopping on the terrain, which simply doesn''t want to draw itself on the screen, dunno y. Plz help, here''s my code:
#define __GTHREAD_HIDE_WIN32API

#include "allegro.h"

int y;
float yf = 150.0f;
float gravf = 0.001f;

int main()
{    
    allegro_init();
    set_color_depth(desktop_color_depth());
    set_gfx_mode(GFX_SAFE, 320, 240, 0, 0);
    install_keyboard();

    BITMAP *buffer = create_bitmap(SCREEN_W, SCREEN_H);

    rectfill(buffer, 0, 200, 320, 240, makecol(50, 100, 0));
    
    BITMAP *teren = create_sub_bitmap(buffer, 0, 200, 320, 40);
    
    blit(teren, buffer, 0, 0, 0, 200, 320, 40);
    blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
    
    readkey();
    
    while(!key[KEY_ESC])
    {           
        clear(buffer);
        if(key[KEY_SPACE])
        {
            for(int i = 0; i < 30; i++)
            {
                circlefill(buffer, 160, 200, i, makecol(0, 0, 0));
                blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
                rest(2);
            }
        }
        y = (int)yf;
        circlefill(buffer, 160, y, 10, makecol(255, 0, 0));
        if(getpixel(buffer, 160, y+11)!=makecol(50, 100, 0))
        {
        yf += gravf;
        gravf += 0.001f;
        }
        
        masked_blit(teren, buffer, 0, 0, 0, 200, 320, 40);
        blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
    }
    
    allegro_exit();
    return 0;
}
END_OF_MAIN();
Linux is like a Wig-Wam: no Gates, no Windows, Apache inside.

Share this post


Link to post
Share on other sites
Advertisement
I am not an Allegro genius, but I can tell you some things. All of the code seems to be without compile-time errors that I can catch. Are there any warnings that are generated? Also, you will need physics for this! You need some physics code in place to make it stop at the terrain and then explode. You can use a physics library, or use a crude method by writing an array, and writing out the terrain in an array, then making a certain number be the collision number. Just my two cents.

Scott Simontis
e-mail:ageofscott@comcast.net
AIM:ssimontis

Share this post


Link to post
Share on other sites
Nah, that''s just a test, I''ll think of some psyhics later. And no, the code compiles excellent. It works when I don''t write the clear(buffer) function, but that''s what I WANT to do. In other way the ball would leave a trace, and I don''t want that... The problem is, that the terrain dissapears after the readkey()... it shouldn''t :|

Share this post


Link to post
Share on other sites
http://www.allegro.cc/manual/view_function.php?_id=1167&request=1064175454&

If you read the above documentation of the create_sub_bitmap() function, you will find that the sub bitmap (terren) shares the same memory as the origional bitmap (buffer). So when you clear the buffer everything you did goes away.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!