need some help
Jun 25, 2011 at 12:07pm UTC
Hi Guys,
Im following a tutorial but i've got a problem but i didn't know how to solve.
Im using Dev C++.
The error is:
1 2 3 4
12 C:\Dev-Cpp\pengo\main.cpp In file included from main.cpp
21 C:\Dev-Cpp\pengo\Player.cpp expected init-declarator before "Player"
21 C:\Dev-Cpp\pengo\Player.cpp expected `,' or `;' before "Player"
C:\Dev-Cpp\pengo\Makefile.win [Build Error] [main.o] Error 1
main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
#include <stdlib.h>
#include <windows.h>
#include <iostream>
#include "Console.h"
#include "Player.h"
#include "Player.cpp"
using namespace std;
/******************************************************************************
Constante variabelen
******************************************************************************/
const int PengoUp = VK_UP;
const int PengoDown = VK_DOWN;
const int PengoLeft = VK_LEFT;
const int PengoRight = VK_RIGHT;
const int PengoPauze = VK_PAUSE;
const int GameExit = VK_ESCAPE;
//const int PengoSchiet = VK_SHIFT;
char PengoCharacter = '*' ;
const int GameDelay = 250;
/******************************************************************************
Globale functies
******************************************************************************/
int main()
{
Player myPlayer = CreatePlayer();
MoveCursor(myPlayer.X, myPlayer.Y);
cout << PengoCharacter;
int myKey;
do
{
DWORD myTime = timeGetTime();
while (timeGetTime() < (myTime + GameDelay));
myKey = PeekVirtualKey();
if (myKey != 0)
{
GetVirtualKey();
switch (myKey)
{
case PengoUp:
{
myPlayer.Direction = 1;
} break ;
case PengoDown:
{
myPlayer.Direction = 2;
} break ;
case PengoLeft:
{
myPlayer.Direction = 3;
} break ;
case PengoRight:
{
myPlayer.Direction = 4;
} break ;
}
}
MoveCursor(myPlayer.X, myPlayer.Y);
cout << " " ;
MovePlayer(myPlayer);
MoveCursor(myPlayer.X, myPlayer.Y);
cout << PengoCharacter;
} while (myKey != GameExit);
getchar();
return 0;
}
Player.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#ifndef __PLAYER_H__
#define __PLAYER_H__
/******************************************************************************
Structures
******************************************************************************/
struct Player
{
int X, Y;
int Direction;
};
/******************************************************************************
Globale functies - definities
******************************************************************************/
Player CreatePlayer();
void MovePlayer(Player& player)
#endif
player.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#include "Player.h"
/******************************************************************************
Globale functies
******************************************************************************/
Player CreatePlayer()
{
Player myPlayer;
myPlayer.X = 40;
myPlayer.Y = 12;
myPlayer.Direction = None;
return myPlayer;
}
void MovePlayer(Player& player)
{
switch (player.Direction)
{
case 1:
{
if (player.Y > 0)
{
player.Y--;
}
else
{
player.Direction = 0;
}
} break ;
case 2:
{
if (player.Y < 24)
{
player.Y++;
}
else
{
player.Direction = 0;
}
} break ;
case 3:
{
if (player.X > 0)
{
player.X--;
}
else
{
player.Direction = 0;
}
} break ;
case 4:
{
if (player.X < 79)
{
player.X++;
}
else
{
player.Direction = 0;
}
} break ;
}
}
Jun 25, 2011 at 12:50pm UTC
Jun 25, 2011 at 1:52pm UTC
Thanks for your fast reaction.
It works fine now. I have read the Article thanks for that, i have download a better IDE.
Topic archived. No new replies allowed.