•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Game Development section within the Software Development category of DaniWeb, a massive community of 427,382 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,037 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Game Development advertiser: Programming Forums
Views: 431 | Replies: 2
![]() |
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
i started making a game using c++ and allegro, but i keep getting a error can some one please help me out
this is the code
this is the code
#include <iostream>
#include <allegro.h>
#include "PlayerClass.h"
#include "Global.h"
using namespace std;
#define LEFT 4
#define RIGHT 6
#define UP 8
#define DOWN 2
volatile long speed_counter = 0;
void increment_speed_counter();
void init_crap(bool);
bool isCollision(const PlayerClass*, const PlayerClass*);
int Mainmenu();
int main()
{
Mainmenu ();
}
void Mainmenu();
{
string choice
cout << "1. fight" << endl;
cin >> choice;
if (choice == 1){
Fight();
}
else {
Mainmenu ();
}
}
void Fight(int argc, char *argv[])
{
bool fullscreen = false;
bool done = false;
init_crap(fullscreen);
PlayerClass player[2];
//int tx, int ty, int tw, int th, int tact, int tcode
player[0].setup(0, 440, 128, 128, 0, 0);
player[1].setup(800-128, 440, 128, 128, 0, 1);
BITMAP *buffer = create_bitmap(SCR_W,SCR_H);
BITMAP *background = load_bitmap("background.bmp", NULL);
BITMAP *chars = load_bitmap("chars.bmp", NULL);
int win = -1;
while (!done)
{
while (speed_counter > 0)
{
if (key[KEY_F5])
{
if ( fullscreen ) { set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCR_W, SCR_H, 0, 0); fullscreen = false; }
else { set_gfx_mode(GFX_AUTODETECT, SCR_W, SCR_H, 0, 0); fullscreen = true; }
}
if (key[KEY_F4] || key[KEY_ESC])
{
done = true;
}
//movement - player 1
if ( key[KEY_LEFT] )
{
player[0].move(LEFT);
}
else if ( key[KEY_RIGHT] )
{
player[0].move(RIGHT);
}
if ( !key[KEY_LEFT] && !key[KEY_RIGHT] )
{
player[0].noMove();
}
if ( key[KEY_RSHIFT] )
{
player[0].attack();
}
if ( key[KEY_SPACE] )
{
player[0].jump();
}
//movement - player 2
if ( key[KEY_A] )
{
player[1].move(LEFT);
}
else if ( key[KEY_D] )
{
player[1].move(RIGHT);
}
if ( !key[KEY_A] && !key[KEY_D] )
{
player[1].noMove();
}
if ( key[KEY_LSHIFT] )
{
player[1].attack();
}
if ( key[KEY_W] )
{
player[1].jump();
}
if (isCollision(&player[0], &player[1]))
{
if ( player[0].isAttacking && player[1].invincible == false )
{
player[1].hit();
}
if ( player[1].isAttacking && player[0].invincible == false )
{
player[0].hit();
}
if ( player[0].HP == 0 )
win = 1;
else if ( player[1].HP == 0 )
win = 0;
}
player[0].update();
player[1].update();
speed_counter--;
}//while (speed_counter > 0)
text_mode(-1);
vsync();
acquire_screen();
if ( win == -1 )
{
stretch_sprite(buffer, background, 0, 0, SCR_W, SCR_H);
//draw_char(buffer, background, 0, 0);
textprintf(buffer,font,0-1,30-1,makecol(0, 0, 0), "Player 1 - Arrow keys to move Space to jump RSHIFT to attack");
textprintf(buffer,font,0+1,30-1,makecol(0, 0, 0), "Player 1 - Arrow keys to move Space to jump RSHIFT to attack");
textprintf(buffer,font,0+1,30+1,makecol(0, 0, 0), "Player 1 - Arrow keys to move Space to jump RSHIFT to attack");
textprintf(buffer,font,0-1,30+1,makecol(0, 0, 0), "Player 1 - Arrow Keys to move Space to jump RSHIFT to attack");
textprintf(buffer,font,0-1,40-1,makecol(0, 0, 0), "Player 2 - WASD to move W to jump LSHIFT to attack");
textprintf(buffer,font,0+1,40-1,makecol(0, 0, 0), "Player 2 - WASD to move W to jump LSHIFT to attack");
textprintf(buffer,font,0-1,40+1,makecol(0, 0, 0), "Player 2 - WASD to move W to jump LSHIFT to attack");
textprintf(buffer,font,0+1,40+1,makecol(0, 0, 0), "Player 2 - WASD to move W to jump LSHIFT to attack");
textprintf(buffer,font,0,30,makecol(255,255,255), "Player 1 - Arrow keys to move Space to jump RSHIFT to attack");
textprintf(buffer,font,0,40,makecol(255,255,255), "Player 2 - WASD to move W to jump LSHIFT to attack");
textout_centre(buffer, font, "Mega Fighter V1.0", 400, 0, makecol(255,255,255));
textprintf(buffer, font, player[0].x+30, player[0].y - 10, makecol(0, 0, 0), "HP: %i", player[0].HP);
textprintf(buffer, font, player[1].x+30, player[1].y - 10, makecol(0, 0, 0), "HP: %i", player[1].HP);
player[0].draw(buffer, chars);
player[1].draw(buffer, chars);
}
else if ( win == 0 )
{
textout_centre(buffer, font, "P l a y e r 0 w i n s ", SCR_W/2, SCR_H/2, makecol(255,100,100));
}
else if ( win == 1 )
{
textout_centre(buffer, font, "P l a y e r 1 w i n s ", SCR_W/2, SCR_H/2, makecol(100,100,255));
}
blit(buffer, screen, 0, 0, 0, 0, SCR_W, SCR_H);
clear_bitmap(buffer);
release_screen();
}//while (!key[KEY_ESC])
return 0;
}
void init_crap(bool fullscreen)
{
allegro_init();
install_keyboard();
install_timer();
install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0);
install_joystick(JOY_TYPE_AUTODETECT);
LOCK_VARIABLE(speed_counter);
LOCK_FUNCTION(increment_speed_counter);
install_int_ex(increment_speed_counter,BPS_TO_TIMER(90));
set_color_depth(16);
if ( fullscreen ) { set_gfx_mode(GFX_AUTODETECT, SCR_W, SCR_H, 0, 0); }
else { set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCR_W, SCR_H, 0, 0); }
}
void increment_speed_counter()
{
speed_counter++;
}
bool isCollision( const PlayerClass *player1, const PlayerClass *player2 )
{
if ( (player1->x + player1->w > player2->x && player1->x < player2->x + player2->w) &&
(player1->y + player1->h > player2->y && player1->y < player2->y + player2->h))
return true;
return false;
}
•
•
Join Date: Jan 2008
Location: USA East Cost
Posts: 389
Reputation:
Rep Power: 1
Solved Threads: 37
Post your errors, but at a glance:
void Mainmenu();
{
string choice //missing semicolon
//.... I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
![]() |
•
•
•
•
•
•
•
•
DaniWeb Game Development Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 2D Game code. All Source files. (Game Development)
- Blackjack Game (Java)
- error message on program (C++)
- Win32 error (Windows NT / 2000 / XP / 2003)
- Error while playing game- BCCode : 1000008e (Motherboards, CPUs and RAM)
- Game crashes while playing any game. (Windows NT / 2000 / XP / 2003)
- Fatal Error, c0000005 Memory could not be read??? (Windows NT / 2000 / XP / 2003)
- why i can not load game on one partition but can on aother (Troubleshooting Dead Machines)
Other Threads in the Game Development Forum
- Previous Thread: Directx
- Next Thread: USB driver files


Linear Mode