Skip to content

Instantly share code, notes, and snippets.

@smooki
Created April 21, 2012 10:46
Show Gist options
  • Save smooki/2436565 to your computer and use it in GitHub Desktop.
Save smooki/2436565 to your computer and use it in GitHub Desktop.
#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(220,220,200));
pos_x = 0;
pos_y = 0;
}
void Car::Update(int timeOffset)
{
//
}
void Car::Draw(void)
{
al_draw_bitmap(bitmap, 0,0,0);
}
Car::~Car(void)
{
al_destroy_bitmap(bitmap);
}
#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;
};
#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;
}
}
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;
if (init() == -1) return -1;
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);
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,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