Autor Tópico: Instalando biblioteca Allegro4.2 para jogos + tutorial (04/03/2007)  (Lida 2201 vezes)

Offline solanoalves

  • Usuário Ubuntu
  • *
  • Mensagens: 398
  • Arch Linux
    • Ver perfil
E ae galera, gostei dessa biblioteca e vou postar como foi que fiz para instalar e compilar já que muitos tem problemas e acabam garimpando todo o google e mesmo assim, por azar, não encontram. Sei que é muito difícil não encontrar, mas aqui vai :

No terminal digite:

Código: [Selecionar]
sudo apt-get install liballegro4.2 liballegro4.2-dev
Aqui meu sources.list caso no seu de erro:

Código: [Selecionar]
deb-src http://br.archive.ubuntu.com/ubuntu/ dapper main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://br.archive.ubuntu.com/ubuntu/ dapper-updates main restricted
deb-src http://br.archive.ubuntu.com/ubuntu/ dapper-updates main restricted
deb http://br.archive.ubuntu.com/ubuntu/ dapper-updates main restricted
deb-src http://br.archive.ubuntu.com/ubuntu/ dapper-updates main restricted

## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://br.archive.ubuntu.com/ubuntu/ dapper universe main restricted multiverse
deb-src http://br.archive.ubuntu.com/ubuntu/ dapper universe

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://br.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse
deb-src http://br.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse
deb http://br.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse
deb-src http://br.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu dapper-security main restricted
deb-src http://security.ubuntu.com/ubuntu dapper-security main restricted
deb http://security.ubuntu.com/ubuntu dapper-security universe
deb-src http://security.ubuntu.com/ubuntu dapper-security universe

## Cristhian Marillat
# deb http://www.debian-multimedia.org sarge main
# deb http://www.debian-multimedia.org etch main
# deb http://www.debian-multimedia.org sid main

#mercury-messenger
#deb http://julio.gdhpress.com.br/apt/ ./


#deb http://blognux.free.fr/debian unstable main


#ntfs-3g

#deb http://givre.cabspace.com/ubuntu/ dapper main main-all
#   or
#deb http://ntfs-3g.sitesweetsite.info/ubuntu/ dapper main main-all
#   or
#deb http://flomertens.keo.in/ubuntu/ dapper main main-all


#AUTOMATIX REPOS START

#deb http://www.getautomatix.com/apt dapper main

#deb http://archive.canonical.com/ubuntu dapper-commercial main

#deb http://archive.ubuntu.com/ubuntu dapper-updates universe multiverse

deb http://archive.ubuntu.com/ubuntu dapper-security main restricted universe multiverse
#AUTOMATIX REPOS END


deb http://ftp.osuosl.org/pub/pculture.org/democracy/linux/repositories/ubuntu edgy/

Bom aqui um código funcionando 100% que faz uns efeitos de cores na tela:

salve como testeallegro.c

Código: [Selecionar]
#include <stdio.h>
#include <stdlib.h>

#include <allegro.h>

#define MAX_X 800
#define MAX_Y 600
#define V_MAX_X 0
#define V_MAX_Y 0
#define COLOR_BITS 8

int inicia(void);
void principal(void);
void finaliza(void);

int main (void)
{
if (!inicia())
{
finaliza();
return -1;
}

principal();

finaliza();
return 0;
}
END_OF_MAIN();

int inicia (void)
{
allegro_init();

install_keyboard();

set_color_depth(COLOR_BITS);
if (set_gfx_mode(GFX_AUTODETECT, MAX_X, MAX_Y, V_MAX_X, V_MAX_Y) < 0)
{
printf("Erro ao inicializar o modo grafico.\n");
return (FALSE);
}

set_palette(desktop_palette);

return (TRUE);
}

      void principal (void)
      {
            int i;
            int cor;
            PALETTE pal;

            /* Limpa a tela (para o codigo de cor 0). */
            clear(screen);

            /*
                  Torna ativa a black_palette, paleta pre-definida pelo
                  Allegro que contem apenas a cor preta, para todos os codigos.
                  Fazemos isso para que os retangulos feitos a seguir nao sejam
                  vistos ao serem desenhados.
            */
            set_palette(desktop_palette);

            /*
                  Desenha retangulos preenchidos, cada um com codigos
                  de cor variando de 0 a 63, em sequencia.
            */
            for (i = 0; i < 64; i++)
            {
                  rectfill(screen, i * 12.5, 0, (i + 1) * 12.5, 599, i);
            }

            /* Gera tons de azuis */
            for (i = 0; i < 64; i++)
            {
                  pal[i].r = 0;
                  pal[i].g = 0;
                  pal[i].b = i;
            }

            while (!keypressed())
            {
                  /* Torna ativa a paleta pal */
                  set_palette(pal);

                  /*
                        Troca os valores de cada codigo de cor,
                        causando um efeito de animacao.
                  */
                  cor = pal[63].b;
                  for (i = 63; i > 0; i--)
                  {
                        pal[i].b = pal[i - 1].b;
                  }
                  pal[0].b = cor;
            }
      }


void finaliza (void)
{
allegro_exit();
}

Para compilar digite:

Código: [Selecionar]
gcc testeallegro.c -o testeallegro `allegro-config --libs`
USE CRASE para `allegro-config --libs`

ai rode no terminal

Código: [Selecionar]
./testeallegro

Offline Diego_Rocha

  • Usuário Ubuntu
  • *
  • Mensagens: 372
  • Slackware current
    • Ver perfil
Re: Instalando biblioteca Allegro4.2 para jogos + tutorial (04/03/2007)
« Resposta #1 Online: 05 de MAR?O de 2007, 00:18 »
Carambaaaaaaa que loca, muito show mesmo cara, valeuu t++

Offline mariojr

  • Usuário Ubuntu
  • *
  • Mensagens: 31
    • Ver perfil
Re: Instalando biblioteca Allegro4.2 para jogos + tutorial (04/03/2007)
« Resposta #2 Online: 13 de Abril de 2007, 14:02 »
o allegro eh uma biblioteca grafica muito util.. vlw  :)

Darcamo

  • Visitante
Re: Instalando biblioteca Allegro4.2 para jogos + tutorial (04/03/2007)
« Resposta #3 Online: 13 de Abril de 2007, 16:00 »
Tem um livro muito bom sobre programação de jogos (Game Programming All in One Second Edition) em que o autor usa a biblioteca allegro. Eu li boa parte do livro e fui implementando o jogo que o autor vai desenvolvendo. Só que o código dele tá em C e eu fui fazendo em C++. Tava bem interessante, mas fiquei com pouco tempo e parei. Aí o jogo ficou meio incompleto.

Também já dei uma olhada na SDL antes de tentar a allegro e cheguei até a fazer um jogo de tetris. Mas eu gostei mais da allegro.