header file
#include <allegro.h>
#include <string>
struct field{
//origin cordinates and extreme cordinates plus the radius
int x,y,radius,color;
};
class particle{
public:
int x;
int y;
int radius;
int color;
BITMAP*bmp;
//int mass;
int getx(){return this->x;}
int gety(){return this->y;}
int getradius(){return this->radius;}
particle(BITMAP*bmp,int x,int y,int radius, int color);
void draw(void);
};
class godparticle: public particle{
private:
int pull;
public:
field gfield;
//constructor
godparticle(BITMAP*bmp,int x,int y,int radius,int color):particle(bmp,x,y,radius,color){
this->gfield.x=x;
this->gfield.y=y;
this->gfield.radius=radius+50;
this->gfield.color=color+1;
}
// godparticle(){}
void draw();
};
class peasantparticle:public particle{
public:
//int formovedirection;
//godparticle formovegodparticle;
peasantparticle(BITMAP*bmp,int x, int y, int radius, int color):particle(bmp,x,y,radius,color){}//ends here constructor
//haha cant believe im actually commenting shit s
int check_surrounding(BITMAP* bmp,godparticle p,int x,int y);
int update_position(int x,int y);
int move(int direction,godparticle p);
void revolve_around(godparticle p);
//void revolve_call(BITMAP*bmp,int x,int y, int color);
void draw();
//for mutlithreading
void* threadfunction(void*){
}
//haha
};
functions.cpp
//okay for class particle now
#include <math.h>
#include "particles.h"
void revolve_call(BITMAP*bmp,int x,int y, int color){
putpixel(bmp,x,y,color);
rest(1);
putpixel(bmp,x,y,color);
//rest(5);
}
particle::particle(BITMAP*bmp,int ox,int oy,int radius,int color){
//this->mass=mass;
this->x=ox;
this->y=oy;
this->radius=radius;
this->bmp=bmp;
this->color=color;
}
void particle::draw(){
circlefill(this->bmp,this->x,this->y,this->radius,this->color);
}
//Oh god more whitespace, HI MOM
void peasantparticle::draw(){particle::draw();}
int peasantparticle::move(int direction,godparticle p){
//0 for left 1 for right
int halt=0;
if(direction){
while(x+radius!=SCREEN_W||halt!=1){
if(check_surrounding(bmp,p,x,y)==1)halt=1;
circlefill(bmp,x,y,radius,0);
x+=radius;
circlefill(bmp,x,y,radius,color);
rest(50);
if(x==SCREEN_W-radius)halt=1;
}//while ends
return 1;
}//direction right
else {
while(x-radius!=0){
check_surrounding(bmp,p,x,y);
circlefill(bmp,x,y,radius,0);
x-=radius;
circlefill(bmp,x,y,radius,color);
rest(50);
}
}
}
//revolve_around
void peasantparticle::revolve_around(godparticle p){
int x,y,radius;
x=p.x;y=p.y;radius=p.gfield.radius;
// do_circle(this->bmp,x,y,radius,this->color,revolve_call);
for(double angle=1;angle<=360;angle++){
int xcor,ycor;
xcor=x+( (radius)*cos(angle) );
ycor=y+( (radius)*sin(angle) );
int r=this->radius;
circlefill(bmp,xcor,ycor,r,this->color);
rest(50);
circlefill(bmp,xcor,ycor,r,0);
}//set done
}
//another function goes here
//check_surrounding a stupid function
int peasantparticle::check_surrounding(BITMAP*bmp,godparticle p,int x,int y){
if(sqrt( (float) (p.x - this->x)*(p.x - this->x) + (p.y - this->y) *(p.y - this->y) )<(p.gfield.radius+this->radius)){
circlefill(bmp,x,y,radius,0);
revolve_around(p);
return 1;
}//end if
else{return 0;}
}
//for god particle a more stupid function
void godparticle::draw(){
particle::draw();
circle(this->bmp,this->gfield.x,this->gfield.y,this->gfield.radius,this->gfield.color);
}
//a supid function
main.cpp
//c++ Allegro chasingstars
#include <pthread.h>
#include "particles.h"
#include <allegro.h>
#include <math.h>
#include <stdlib.h>
int main(){
//initialize stuff and set grahpics
allegro_init();
install_keyboard();
set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
install_timer();
srand(time(NULL));
//variables
pthread_t t1,t2,t3;
godparticle higgs(screen,200,300,50,1);
higgs.draw();
peasantparticle body1(screen,0,100,20,9);
body1.draw();
body1.move(1,higgs);
peasantparticle body2(screen,0,200,20,13);
body2.draw();
body2.move(1,higgs);
peasantparticle body3(screen,SCREEN_W-10,400,10,2);
body3.draw();
body3.move(0,higgs);
while(!key[KEY_ESC]);
return 0;
}
END_OF_MAIN()