Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: C++ Allegro  (Read 1017 times)

0 Members and 1 Guest are viewing this topic.

PoeFacedKilla

Prussian Killer Bee
C++ Allegro
« on: September 30, 2007, 04:49:57 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
I've been working on a breakout game in C++ Allegro, i've gotten the main scroll left and right engine down, but when i try to make collision it won't move and it starts exactly where i don't want it too.
Code: [Select]
#include <a llegro.h>

void init();
void deinit();

int main() {
init();
/* Bar */
BITMAP *bar = NULL;
bar = load_bitmap("bar.bmp", NULL);
/* Buffer */
BITMAP *buffer = NULL;
buffer = create_bitmap(640,480);
/* Walls */
BITMAP *wall = NULL;
wall = load_bitmap("side.bmp", NULL);
/* Walking Engine */
int sprite_x = -100;
int wall_1_x = 0;
while (!key[KEY_ESC]) {
if(key[KEY_LEFT]) {
sprite_x--;
} else if(key[KEY_RIGHT]) {
sprite_x++;
}
/* Into 1st Wall */
if(sprite_x = 0) {
sprite_x++;
}
draw_sprite(buffer, bar, sprite_x, 0);
draw_sprite(buffer, wall, 0, 0);
blit(buffer, screen, 0, 0, 0, 0, 640, 480);
}

deinit();
return 0;
}
END_OF_MAIN()

void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}

install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}

void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
« Last Edit: December 25, 2007, 03:43:49 am by 4Sword »
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine

BuffaloBurgers

U B DA WAT!?
Re: C++ Allegro
« Reply #1 on: October 02, 2007, 08:55:13 pm »
  • *
  • Reputation: +7/-0
  • Offline Offline
  • Gender: Male
  • Posts: 535
if(sprite_x = 0) {
sprite_x++;
}


wut dis fro'??// if u tell the gaem dat u want to change teh frame but den expect it two move it won't work
Logged


EEE HUNG HUNG HA HA

COLORADO 27 - OKLAHOMA 24
Re: C++ Allegro
« Reply #2 on: October 03, 2007, 12:41:16 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1141
Quote
int sprite_x = -100;

Are you sure that here it's -100, not 100?

Anyway,
change this:

Code: [Select]
if(sprite_x = 0) {
sprite_x++;
}

into this:

Code: [Select]
if(sprite_x == -sprite_width) { //replace sprite_width with the width of the image.
sprite_x--;
}
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.203 seconds with 43 queries.

anything