Created
April 21, 2012 13:02
-
-
Save smooki/2436997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Car.h" | |
#include <allegro5/allegro.h> | |
Car::Car(void) | |
{ | |
bitmap = al_create_bitmap(128, 128); | |
al_set_target_bitmap(bitmap); | |
al_clear_to_color(al_map_rgb(0,220,0)); | |
pos_x = 20; | |
pos_y = 20; | |
} | |
void Car::Update(int timeOffset) | |
{ | |
// | |
} | |
void Car::Draw(void) | |
{ | |
al_draw_bitmap(bitmap, pos_x, pos_y, 0); | |
} | |
Car::~Car(void) | |
{ | |
al_destroy_bitmap(bitmap); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <allegro5/allegro.h> | |
#pragma once | |
class Car | |
{ | |
public: | |
Car(void); | |
void Update(int timeOffset); | |
void Draw(void); | |
~Car(void); | |
private: | |
ALLEGRO_BITMAP *bitmap; | |
float pos_x, pos_y; | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <allegro5/allegro.h> | |
#include "Car.h" | |
const float FPS = 60; | |
const int SCREEN_W = 640; | |
const int SCREEN_H = 480; | |
const int BOUNCER_SIZE = 32; | |
ALLEGRO_DISPLAY *display = NULL; | |
ALLEGRO_EVENT_QUEUE *event_queue = NULL; | |
ALLEGRO_TIMER *timer = NULL; | |
int init() { | |
if(!al_init()) { | |
fprintf(stderr, "failed to initialize allegro!\n"); | |
return -1; | |
} | |
timer = al_create_timer(1.0 / FPS); | |
if(!timer) { | |
fprintf(stderr, "failed to create timer!\n"); | |
return -1; | |
} | |
display = al_create_display(SCREEN_W, SCREEN_H); | |
if(!display) { | |
fprintf(stderr, "failed to create display!\n"); | |
al_destroy_timer(timer); | |
return -1; | |
} | |
al_clear_to_color(al_map_rgb(255, 0, 255)); | |
al_set_target_bitmap(al_get_backbuffer(display)); | |
event_queue = al_create_event_queue(); | |
if(!event_queue) { | |
fprintf(stderr, "failed to create event_queue!\n"); | |
al_destroy_display(display); | |
al_destroy_timer(timer); | |
return -1; | |
} | |
return 0; | |
} | |
void dispose() { | |
al_destroy_timer(timer); | |
al_destroy_display(display); | |
al_destroy_event_queue(event_queue); | |
} | |
int main(int argc, char **argv){ | |
bool redraw = true; | |
int init_status = init(); | |
if (init_status != 0) return init_status; | |
Car car = Car(); | |
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_clear_to_color(al_map_rgb(0,0,0)); | |
al_flip_display(); | |
al_start_timer(timer); | |
int red = 0; | |
ALLEGRO_BITMAP *bitmap = al_create_bitmap(128, 128); | |
al_set_target_bitmap(bitmap); | |
al_clear_to_color(al_map_rgb(0,220,0)); | |
al_set_target_bitmap(al_get_backbuffer(display)); | |
while(1) | |
{ | |
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) { | |
break; | |
} | |
if(redraw && al_is_event_queue_empty(event_queue)) { | |
redraw = false; | |
al_clear_to_color(al_map_rgb(0,0,red++ % 256)); | |
al_draw_bitmap(bitmap, 20, 200, 0); | |
car.Draw(); | |
al_flip_display(); | |
} | |
} | |
dispose(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment