lenrokskate |
» 2010-06-09 18:12:19 tu masz moje stare auto w allegro - może coś wyciągniesz. [li]main.cpp[/li] #include <allegro.h> #include <cmath> #include "uchwyty.h" #include "timer.h" #include "bit.h"
#define p makecol(0,0,0)
#define op 0.0005
struct sA { float x; float y; }; struct sB { int x; int y; }; sA ruch; sB poz; float v; short z; short b = 1; short wv; int * depth = new int;
double tab_sin[ 72 ]; double tab_cos[ 72 ];
void laduj_sin_cos() { for( int i = 0; i < 72; i++ ) { tab_sin[ i ] = sin(( M_PI *( i * 5 ) ) / 180 ); tab_cos[ i ] = cos(( M_PI *( i * 5 ) ) / 180 ); } }
int main() { allegro_init(); install_keyboard(); * depth = desktop_color_depth(); if( * depth == 0 ) * depth = 32; set_color_depth( * depth ); delete depth; set_gfx_mode( GFX_AUTODETECT_WINDOWED, 760, 760, 0, 0 ); clear_to_color( screen, makecol( 255, 255, 255 ) ); ladTim(); poz.x = 120; poz.y = 170; ladujBit(); masked_blit( mapa, bufor, 0, 0, 0, 0, mapa->w, mapa->h ); laduj_sin_cos(); while( !key[ KEY_ESC ] ) { while( speed > 0 ) { if( v > 0 ) { if( key[ KEY_LEFT ] ) z--; if( key[ KEY_RIGHT ] ) z++; } if( key[ KEY_UP ] && b == 0 ) v -= 0.02; if( key[ KEY_UP ] && b == 1 ) v += 0.02; if( key[ KEY_UP ] && b == 2 ) v += 0.015; if( key[ KEY_UP ] && b == 3 ) v += 0.01; if( key[ KEY_DOWN ] && v > 0 ) v -= 0.02; if( key[ KEY_A ] ) { b++; rest( 100 ); } if( key[ KEY_Z ] ) { b--; rest( 100 ); } if( key[ KEY_SPACE ] ) { poz.x = 120; poz.y = 170; v = 0; z = 0; } speed--; } #ifdef _opor_ if( v >= 0 ) v -= op; if( v <= 0 ) v += op; #endif clear_to_color( bufor, makecol( 255, 255, 255 ) ); if( b > 3 ) b = 3; if( b < 0 ) b = 0; if( z > 71 ) z = 0; if( z < 0 ) z = 71; if( v > 0.2 && b == 1 ) v -= 0.005; if( v > 0.3 && b == 2 ) v -= 0.005; if( v > 0.4 ) v = 0.4; if( v < 0 && b != 0 ) v = 0; if( v <- 0.2 ) v += 0.005; ruch.x += v * tab_cos[ z ]; ruch.y += v * tab_sin[ z ]; if( ruch.x >= 1 || ruch.x <= - 1 ) { poz.x += int( ruch.x ); ruch.x = ruch.x - int( ruch.x ); } if( ruch.y >= 1 || ruch.y <= - 1 ) { poz.y += int( ruch.y ); ruch.y = ruch.y - int( ruch.y ); } blit( mapa, bufor, 0, 0, 0, 0, mapa->w, mapa->h ); if( getpixel( mapa, poz.x + 25, poz.y + 25 ) == makecol( 0, 0, 0 ) || getpixel( mapa, poz.x + 125, poz.y + 25 ) == makecol( 0, 0, 0 ) || getpixel( mapa, poz.x + 25, poz.y + 100 ) == makecol( 0, 0, 0 ) || getpixel( mapa, poz.x + 125, poz.y + 90 ) == makecol( 0, 0, 0 ) ) { masked_blit( bum, screen, 0, 0, 100, 0, bum->w, bum->h ); while( !key[ KEY_SPACE ] ) { } poz.x = 120; poz.y = 170; v = 0; z = 0; b = 1; } wv = short( v * 2 * 100 -( 0.5 * wv ) ); textprintf_centre_ex( bufor, czcionka, 190, 30, makecol( 0, 0, 0 ), - 1, "%d", wv ); if( b == 0 ) rectfill( bufor, 340, 23, 369, 51, makecol( 45, 240, 10 ) ); if( b == 1 ) rectfill( bufor, 340 + 28, 23, 369 + 28, 51, makecol( 45, 240, 10 ) ); if( b == 2 ) rectfill( bufor, 340 + 28 + 28, 23, 369 + 28 + 28, 51, makecol( 45, 240, 10 ) ); if( b == 3 ) rectfill( bufor, 340 + 28 + 28 + 29, 23, 369 + 28 + 28 + 28, 51, makecol( 45, 240, 10 ) ); masked_blit( sam, bufor,( z % 18 ) * 147,( z / 18 ) * 115, poz.x, poz.y, 147, 115 ); blit( bufor, screen, 0, 0, 0, 0, 760, 760 ); } allegro_exit(); return 0; } END_OF_MAIN();
uchwyty.h: #pragma once
BITMAP * bufor = NULL; BITMAP * sam = NULL; BITMAP * mapa = NULL; BITMAP * bum = NULL; BITMAP * saw = NULL; FONT * czcionka = NULL;
timer.h #pragma once
volatile long speed = 0; void increment_speed() { speed++; } END_OF_FUNCTION( increment_speed ); LOCK_VARIABLE( speed ); LOCK_FUNCTION( increment_speed );
void ladTim() { install_timer(); install_int_ex( increment_speed, BPS_TO_TIMER( 30 ) ); };
bit.h: #pragma once
void ladujBit() { bufor = create_bitmap( 760, 760 ); czcionka = load_font( "cz.pcx", default_palette, NULL ); if( !czcionka ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Brakuje czcionki!" ); allegro_exit(); exit( 0 ); } if( !bufor ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Nie mogę utworzyć bufora !" ); allegro_exit(); exit( 0 ); } sam = load_bmp( "sam.bmp", default_palette ); if( !sam ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Brakuje obrazka!" ); allegro_exit(); exit( 0 ); } bum = load_bmp( "bum.bmp", default_palette ); if( !bum ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Brakuje obrazka!" ); allegro_exit(); exit( 0 ); } mapa = load_bmp( "mapa.bmp", default_palette ); if( !mapa ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Brakuje obrazka!" ); allegro_exit(); exit( 0 ); } };
|