Code:
////#include [allegro.h]
////#include "Vector2.h"
////#include [list]
////#include [cmath]
////using namespace std;
////
//// int oldspace ;
//// int spacedown=0 ;
////
//// #define NUMBULLETS 12
////class Bullets
////{
////public:
//// Vector2 pos ;
//// bool isAlive ;
////
//// float xspeed, yspeed;
////
//// Bullets()
//// {
////
//// isAlive =false;
//// }
////
////
////};
////
//// class Player
//// {
//// public:
//// BITMAP *newbuff ;
//// Vector2 velocity ;
//// Vector2 acceleration ;
//// Vector2 force,look ;
//// float mass ;
//// float angle ;
//// float newEnemyX, newEnemyY;
////
//// Vector2 pos ;
//// Vector2 currPos;
//// Bullets bullets[NUMBULLETS];
////
////
//// Player()
//// {
////
//// angle =0.0f ;
//// force.x =0.0f ;
//// force.y =0.0f ;
//// acceleration.x =0.0f ;
//// acceleration.y =0.0f ;
//// velocity.x =0.0f ;
//// velocity.y=0.0f ;
//// mass =0.9f ;
////
//// newbuff = create_bitmap(20,20) ;
//// clear_to_color(newbuff,makecol(255,0,255));
//// look.x = 0 ;
//// look.y = -1 ;
//// pos.x = rand()% 20 ;
//// pos.y = rand() % 400 ;
//// }
////
//// void rotate(float r)
//// {
//// look.x= sinf(angle*M_PI/180) ;
//// look.y= -cosf(angle*M_PI/180) ;
////
////
////
//// angle+=r;
////
//// }
//// void thrust(float units)
//// {
//// force.x+=look.x*units ;
//// force.y+=look.y*units ;
//// }
//// void movePlayer(float timeDelta)
//// {
//// acceleration.x = force.x / mass ;
////
//// acceleration.y = force.y / mass ;
////
//// velocity.x = velocity.x + acceleration.x * timeDelta;
//// velocity.y = velocity.y + acceleration.y * timeDelta;
////
//// pos.x = pos.x + velocity.x * timeDelta;
//// pos.y = pos.y + velocity.y * timeDelta;
////
//// force.x = 0.0f;
//// force.y = 0.0f;
////
////
//// }
////
////
//// ~Player()
//// {
//// destroy_bitmap(newbuff) ;
//// }
//// } ;
////
//// int ticks =0 ;
////
//// void ticker()
//// {
//// ticks++ ;
//// }
////
////
////class Particle
////{
////public:
//// BITMAP *newbuff ;
//// Vector2 pos ;
//// Vector2 vel;
//// float angle ;
//// int r,g,b;
//// float angularVel ;
//// float size ;
//// bool isAlive ;
//// float TTL ;
//// float speed;
//// float fade;
//// int n ;
//// void setPos(float x, float y)
//// {
//// pos.x = x;
//// pos.y = y ;
//// }
//// Particle(float x, float y)
//// {
//// n = 0 +rand()% 2 ;
//// isAlive =true ;
//// switch(n)
//// {
//// case 0:
//// {
//// r=255,g=105,b=180;
//// break ;
//// }
////
//// case 1:
//// {
//// r=255,g=20,b=147;
//// break ;
//// }
//// }
////
//// speed = (float)0.0f+rand()%2 ;
//// fade=float(rand()%100)/1000.0f+0.05f;
//// angle =0.0f;
//// setPos(x,y) ;
//// vel.x = 0.0f;
//// vel.y = -cos(angle*180/M_PI)*speed ;
//// newbuff = create_bitmap(20,20);
//// clear_bitmap(newbuff);
//// clear_to_color(newbuff,makecol(255,0,255));
//// TTL =0.8f;
//// }
//// void Update(float x, float y)
//// {
//// switch(n)
//// {
//// case 0:
//// {
//// r=255,g=105,b=180;
//// break ;
//// }
////
//// case 1:
//// {
//// r=18 ,g=85,b=211;
//// break ;
//// }
//// }
////
////
//// pos.x+=vel.x*0.0975f ;
//// pos.y+=vel.y*0.0975f;
////
//// vel.y*=1.0f;
//// angle+=angularVel;
//// TTL-=fade;
////
////
////
//// if (TTL[0.05f) // If Particle Is Burned Out
//// {
//// TTL=0.5f; // Give It New Life
//// fade=float(rand()%100)/7500 + 0.0075f; // Random Fade Value
////
//// setPos(x+10,y+20) ;
//// speed = (float((rand()%9))+1);
//// angle = float(rand()%3 0);
////
//// vel.x = sin(angle) * speed;
//// vel.y = -cos(angle) *speed;
////
//// }
////
//// }
//// void Draw(BITMAP *backbuffer)
//// {
//// circlefill(newbuff,5,5,2,makecol(r,g,b)) ;
//// draw_sprite(backbuffer,newbuff,pos.x,pos.y) ;
//// }
//// ~Particle()
//// {
//// destroy_bitmap(newbuff) ;
//// }
////
////}
////;
////
////class ParticleEngine
////{
////public:
//// int random ;
//// Vector2 emitLoc ;
////
//// Particle *particles[100] ;
////
//// ParticleEngine(float x,float y)
//// {
//// for(int i =0;i[100;i++)
//// {
//// particles[i] = new Particle(x+10,y+20) ;
//// }
//// }
//// void Update(float x,float y)
//// {
//// for(int i=0;i[100;i++)
//// {
////
//// particles[i]-]Update(x,y) ;
////
//// }
////
//// }
//// void Draw(BITMAP *backbuffer)
//// {
//// for(int i=0;i[100;i++)
//// {
////
//// if(particles[i]-]isAlive)
//// {
//// particles[i]-]Draw(backbuffer) ;
//// }
////
//// }
//// }
////}
////
//// ;
////int main()
////{
//// srand(time(NULL)) ;
//// int n,r,g,b ;
//// n=r=g=b=0 ;
//// float length=0.0f,angle= 90;
//// if(!allegro_init())
//// {
////
////
//// set_color_depth(24) ;
//// PALETTE pallete ;
////
//// BITMAP *obstacle = create_bitmap(100,100) ;
//// clear_to_color(obstacle,makecol(0,255,0));
////
//// Player player1 ;
//// Player player2 ;
//// Player player3;
//// ParticleEngine particleEngine(player1.pos.x,player1.pos.y) ;
////
//// install_keyboard() ;
////
//// install_timer() ;
//// install_int_ex(ticker, BPS_TO_TIMER( 0));
////
////
////
////
////
//// if(!set_gfx_mode(GFX_AUTODETECT_WINDOWED, 40,480,0,0))
//// {
//// BITMAP* backbuffer = create_bitmap( 40,480) ;
////
////
//// BITMAP *background = create_bitmap( 40,480) ;
//// background = load_bitmap("space.bmp",pallete) ;
//// set_palette(pallete) ;
////
//// clear_to_color(backbuffer,makecol(0,0,0));
////
////
//// triangle(player1.newbuff ,0,19,10,0,19,19,makecol(255,255,255));
//// triangle(player2.newbuff,0,19,10,0,19,19,makecol(255,255,255));
//// triangle(player3.newbuff,0,19,10,0,19,19,makecol(255,255,255));
//// player3.pos.x = 320 ;
//// player3.pos.y = 240;
//// player3.look.x = 1;
//// player3.look.y=0;
//// while(!key[KEY_ESC])
//// {
//// n = 0 + rand() % 2 ;
//// switch(n)
//// {
//// case 0:
//// {
//// r=255,g=0,b=0;
//// break ;
//// }
////
//// case 1:
//// {
//// r=0,g=255,b=0;
//// break ;
//// }
//// }
//// //triangle(player1.newbuff ,0,19,10,0,19,19,makecol(0,0,0));
////
////
//// length =(float)sqrt(((player2.pos.x -player1.pos.x)*(player2.pos.x -player1.pos.x)) + ((player2.pos.y -player1.pos.y)*(player2.pos.y -player1.pos.y)) ) ;
////
////
////
//// draw_sprite(backbuffer,background,0,0) ;
////
//// particleEngine.Update(player1.pos.x,player1.pos.y);
//// particleEngine.Draw(backbuffer);
////
//// triangle(player1.newbuff,0,19,10,0,19,19,makecol(r,g,b));
////
//// triangle(player2.newbuff,0,19,10,0,19,19,makecol(0,0,255));
////
//// draw_sprite(background,obstacle,320,100) ;
////
//// player2.newEnemyX = sin((player2.pos.direction(player2.pos-player1.pos))*M_PI/180) ;
//// player2.newEnemyY = -cos((player2.pos.direction(player2.pos-player1.pos))*M_PI/180) ;
////
////
////
//// player2.pos.x+=player2.newEnemyX ;
//// player2.pos.y+=player2.newEnemyY ;
////
////
////
//// player3.pos.x+=player3.look.x;
//// player3.pos.y+=player3.look.y;
////
//// if(player3.pos.x]= 00)
//// {
//// player3.look.x = -player3.look.x;
//// angle = -angle ;
//// }
//// if(player3.pos.x[=0)
//// {
//// player3.look.x = -player3.look.x;
//// angle = -angle ;
//// }
////
////
////
////
//// if(key[KEY_RIGHT])
//// {
////
//// player1.rotate(2.0f);
//// }
////
////
////
////
//// if(key[KEY_LEFT])
//// {
//// player1.rotate(-2.0f);
////
//// }
////
////
//// if(key[KEY_UP])
//// {
////
////
////
//// player1.thrust(0.07f) ;
//// }
////
//// if(key[KEY_DOWN])
//// {
//// player1.thrust(-0.07f) ;
////
//// }
//// while(ticks == 0)
//// {
//// rest(1);//rest until a full tick has passed
//// }
////
//// while(ticks ] 0)
//// {
//// int old_ticks = ticks;
////
//// ticks--;
//// if(old_ticks [= ticks)//logic is taking too long: abort and draw a frame
//// break;
//// }
////
////
//// player1.movePlayer(0.4f) ;
////
//// rotate_sprite(backbuffer,player3.newbuff,player3.pos.x,player3.pos.y,ftofix(angle*250/3 0)) ;
//// rotate_sprite(backbuffer,player1.newbuff,player1.pos.x,player1.pos.y,ftofix((player1.angle) *2 /3 0)) ;
//// rotate_sprite(backbuffer,player2.newbuff,player2.pos.x ,player2.pos.y,ftofix((player2.pos.angle)*2 /3 0)) ;
////
////
////
////textprintf_ex(backbuffer,font,320,20,makecol(255,255,255),-1,"Player2 Distance y: %f", player2.pos.angle) ;
////
////
//// blit(backbuffer,screen,0,0,0,0,SCREEN_W,SCREEN_H) ;
////
//// clear_bitmap(backbuffer) ;
////
////
//// }
//// destroy_bitmap(backbuffer) ;
//// destroy_bitmap(background) ;
//// }
////
//// }
////
//// return 0 ;
////}
////
////
////END_OF_MAIN()
////
//
//#include <math.h>
//#include <allegro.h>
//struct Color
//{
// int r,g,b;
//}color[4];
//void delay() ;
//void resetColors() ;
//void delay(Color &) ;
//int main()
//{
// allegro_init() ;
// set_color_depth(32) ;
//
// if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)==0)
// {
// //allegro_message("Hello") ;
// }
// install_keyboard() ;
//
// BITMAP *backbuffer = create_bitmap(640,480) ;
// clear_bitmap(backbuffer) ;
//
// while(!key[KEY_ESC])
// {
//
// rectfill(backbuffer,220,220,320,320,makecol(255,0,0)) ;
//
// set_add_blender(255,0,0,3);
//
// drawing_mode(DRAW_MODE_TRANS, backbuffer,0,0);
//
//
// blit(backbuffer, screen, 0,0,0,0,640,480) ;
// }
//
//
// return 0 ;
//
//}
//END_OF_MAIN()/*
//
// /*delay() ;
// delay(color[1]) ;
// line(backbuffer,320,106,400,106,makecol(color[2].r,color[2].g,color[2].b));
// delay() ;
// delay(color[2]) ;
// line(backbuffer,320,142,400,142,makecol(color[3].r,color[3].g,color[3].b));
// delay() ;
//
// int r = 255 ;
// int g = 0 ;
// int b=0;
// int r1 = 0, r2 = 0, r3 = 255 ;
// color[0].r =255,color[0].g=0, color[0].b=0;
// color[1].r =0,color[1].g=0, color[1].b=255;
//
//void delay()
//{
// unsigned int i=0;
// while( i < 100000)
// {
// for(int j=0;j<10000;j++)
// {
// }
// i++ ;
// }
//}*/
//
//void delay(Color &color)
//{
//
//
// color.r=0;
// color.g =0 ;
// color.b =255;
//
//}
//
// /*
// color[2].r= 255 ;
// color[2].g=0;
// color[2].b=0;
// delay() ;
//
// color[1].r= 255 ;
// color[1].g=0;
// color[1].b=0;
// delay() ;
//
// color[0].r= 255 ;
// color[0].g=0;
// color[0].b=0;
//
// line(backbuffer,320,109,400,109,makecol(r,g,b));
// line(backbuffer,320,112,400,112,makecol(255,0,0));
// line(backbuffer,320,115,400,115,makecol(255,0,0));
// line(backbuffer,320,118,400,118,makecol(255,0,0));
// line(backbuffer,320,121,400,121,makecol(255,0,0));
// line(backbuffer,320,124,400,124,makecol(255,0,0));
// line(backbuffer,320,127,400,127,makecol(255,0,0));
// line(backbuffer,320,130,400,130,makecol(255,0,0));
// line(backbuffer,320,133,400,133,makecol(255,0,0));
// line(backbuffer,320,136,400,136,makecol(255,0,0));
// line(backbuffer,320,139,400,139,makecol(255,0,0));
// */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// // int r=0,g=0,b=0,x=0,y=0;
// // float angle =0.0f ;
// //BITMAP* buffer;
// //BITMAP *spacePic ;
// //void moveShip() ;
// //struct Particle_Type
// //{
// // double x;
// // double y;
// // double speed;
// // double angle;
// // int life;
// //}Particles[150];
// //
// //double Max_Angle = 2 * 3.14159;
// //
// //void Draw_Stuff()
//
// //{
// //
// //
// // clear_to_color(buffer, makecol(0, 0, 0));
// //
// // for(int i = 0; i< 150; i++)
// // {
// // if(Particles[i].life)
// // {
// // putpixel(buffer, Particles[i].x, Particles[i].y, makecol(r, g, b));
// // }
// // r++,g++,b++ ;
// // if(r>=255)
// // {
// // r=0 + rand()%255 ;
// //
// //
// // }
// // if(g>=255)
// // {
// //
// // g=r + rand()%b ;
// //
// // }
// // if(b>=255)
// // {
// //
// // b=r + rand()%g ;
// //
// // }
// // }
// //
// // rotate_sprite(buffer,spacePic,x,y,ftofix(angle));
// // //masked_blit(spacePic, buffer,0,0,0,0,spacePic->w,spacePic->h);
// // textprintf(buffer,font,320,10,makecol(255,0,0),"R: %d G: %d B: %d", r,g,b) ;
// // blit(buffer, screen, 0, 0, 0, 0,640, 480);
// //}
// //
// //int main()
// //{
// // srand(time(NULL)) ;
// // if(!allegro_init())
// // {
// // //allegro_message("Hello") ;
// // }
// //
// // set_color_depth(16);
// // if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)==0)
// // {
// // //allegro_message("Hello") ;
// // }
// // install_keyboard();
// // buffer = create_bitmap(640, 480);
// //
// // spacePic = load_bitmap("ship2.bmp", NULL) ;
// // //clear_to_color(spacePic, makecol(255, 0, 255));
// // while(!key[KEY_ESC])
// // {
// // if(key[KEY_SPACE])
// // {
// // for(int i = 0; i < 150; i++)
// // {
// // Particles[i].x = 320.0;
// // Particles[i].y = 240.0;
// // Particles[i].speed = rand() % 10 + 5;
// // Particles[i].angle = rand() % 360 + 1;
// // Particles[i].angle = Particles[i].angle * 3.14159 / 180;
// // Particles[i].life = rand() % 10 + 10;
// // }
// // }
// // for(int i = 0; i < 150; i++)
// // {
// // if(Particles[i].life > 0)
// // {
// // Particles[i].x += Particles[i].speed * cos(Particles[i].angle);
// // Particles[i].y += Particles[i].speed * sin(Particles[i].angle);
// // Particles[i].life--;
// // }
// // }
// // moveShip() ;
// //
// // Draw_Stuff();
// //
// // rest(50);
// // }
// // destroy_bitmap(buffer);
// // destroy_bitmap(spacePic);
// // allegro_exit();
// // return 0 ;
// //}
// //void moveShip()
// //{
// // if(key[KEY_UP])
// // {
// // --y ;
// // }
// //
// // if(key[KEY_DOWN])
// // {
// // ++y ;
// // }
// // if(key[KEY_LEFT])
// // {
// // angle-=1.0f;
// // }
// //
// // if(key[KEY_RIGHT])
// // {
// // angle+=1.0f;
// // }
// //}
#include <allegro.h>
#include <cstdlib>
int main()
{
int i;
allegro_init() ;
set_color_depth(32) ;
float r=64.0f,g=64.0f,b=64.0f ;
if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)==0)
{
//allegro_message("Hello") ;
}
install_keyboard() ;
bool lock = false;
BITMAP *backbuffer = create_bitmap(640,480);
clear_bitmap(backbuffer);
while(!key[KEY_ESC])
{
clear_bitmap(backbuffer);
drawing_mode(DRAW_MODE_TRANS, 0,0,0);
set_trans_blender(255,255,255,64);
srand(0);
for (i=0; i<128; i++) {
circlefill(backbuffer, 32 + rand()%200,200 + rand()%200, 32, makecol(64,64,64));
}
set_add_blender(255,255,255,64);
srand(0);
for (i=0; i<128; i++) {
circlefill(backbuffer, 400 + rand()%200,200 + rand()%200, 32, makecol(r,g,b));
}
if(!lock)
{
for(int i=0; i< 100; i++)
{
for(int g=0;g<100;g++)
{}
}
r+=0.1f;
g+=0.1f ;
b+=0.1f ;
if(r>70)
lock = true ;
}
else
{
r-=0.1f ;
g-=0.1f ;
b-=0.1f ;
if(r<64)
lock = false ;
}
blit(backbuffer, screen, 0,0,0,0,640,480) ;
}
return 0 ;
}
END_OF_MAIN()
Maybe you can have a look at it thanks. I will keep trying to do it.