here is my other code. I cannot fix this and i have spent a lot of time on it. sorry about my other code... its a little... scrubby
cStar cpp file
Code:
#include "stdafx.h"
cStar::cStar(){
srand (time(NULL));
image = al_load_bitmap("./resources/images/star.png");
if(!image){
fprintf(stderr, "failed to create bouncer bitmap!\n");
}
fVel_X = 0.0;
fVel_Y = rand() % 4 + 1;
fPos_X = rand() % 800 + 1;
fPos_Y = 0.0;
}
bool cStar::init_Star(bool arg){
srand (time(NULL));
image = al_load_bitmap("resource/images/star.png");
if(!image){
fprintf(stderr, "failed to create bouncer bitmap!\n");
}
if(arg){
fVel_X = rand() % 4 + 1;
fVel_Y = 0.0;
bMenu = true;
} else {
//add random code
bMenu = false;
}
return true;
}
void cStar::Update(){
fPos_X += fVel_X;
fPos_Y += fVel_Y;
fprintf(stderr, "update\n");
}
void cStar::Render(){
//al_draw_bitmap(image, 0, 0,0);
al_draw_bitmap(image, fPos_X, fPos_Y,0);
}
void cStar::SetData(cStar sData){
iSize_X = sData.iSize_X;
iSize_Y = sData.iSize_Y;
fVel_X = sData.fVel_X;
fVel_Y = sData.fVel_Y;
fPos_X = sData.fPos_X;
fPos_Y = sData.fPos_Y;
bMenu = sData.bMenu;
}
cStar .h file
Code:
#pragma once
class cStar: public cObject {
public:
//data
int iSize_X, iSize_Y;
float fVel_X, fVel_Y, fPos_X, fPos_Y;
bool bMenu;
//functions
bool init_Star(bool arg);
void Update();
void Render();
void SetData(cStar sData);
cStar();
~cStar(){
al_destroy_bitmap(image);
}
private:
ALLEGRO_BITMAP *image;
};
ok time for the main function that calls it... sorry this code is pretty sloppy
Code:
#include "stdafx.h"
const float FPS = 60;
int fMain_Loop()
{
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_BITMAP *image = NULL;
ALLEGRO_TIMER *timer = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
cList list;
bool redraw = true;
bool doexit = false;
//Start of init code
if(!al_init()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize allegro!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
if(!al_init_image_addon()){
al_show_native_message_box(display, "Error", "Error", "Failed to initialize Image Addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
if(!al_install_mouse()) {
al_show_native_message_box(display, "Error", "Error", "Failed to install mouse!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
//end of init code
display = al_create_display(800,600);
if(!display) {
al_show_native_message_box(display, "Error", "Error", "Failed to create display!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
event_queue = al_create_event_queue();
if(!event_queue) {
al_show_native_message_box(display, "Error", "Error", "Failed to create event_queue!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
al_destroy_timer(timer);
return -1;
}
image = al_load_bitmap("bitship.png");
if(!image){
al_show_native_message_box(display, "Error", "Error", "Failed to load image!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
al_draw_bitmap(image,0,0,0);
al_flip_display();
al_rest(5.0);
timer = al_create_timer(1.0 / FPS);
if(!timer) {
al_show_native_message_box(display, "Error", "Error", "Failed to create timer!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
if(!al_install_mouse()) {
al_show_native_message_box(display, "Error", "Error", "Failed to install mouse!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
//Regester event stuffs
al_register_event_source(event_queue, al_get_display_event_source(display));
al_register_event_source(event_queue, al_get_timer_event_source(timer));
al_register_event_source(event_queue, al_get_mouse_event_source());
al_start_timer(timer);
while(!doexit)
{
srand (time(NULL));
int tmp = rand() % 5 + 0;
do{
fprintf(stderr, "trying create star %d\n", tmp);
--tmp;
cStar star;
list.Append(star);
}while(tmp > 0);
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
if(ev.type == ALLEGRO_EVENT_TIMER) {
redraw = true;
}
else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
doexit = true;
}
else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES || ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY) {
}
else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
}
//Personal fun code
if(redraw && al_is_event_queue_empty(event_queue)) {
redraw = false;
al_clear_to_color(al_map_rgb(0,0,0));
list.Update();
list.Render();
al_flip_display();
}
}
al_destroy_bitmap(image);
al_destroy_display(display);
al_destroy_timer(timer);
al_destroy_event_queue(event_queue);
return 0;
}