Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Fantasy

Pages: 1 2 [3] 4
31
Graphics / Draw map from text file
« on: July 04, 2011, 06:22:46 am »
Quote from: "WitchD0ctor"
You never call DrawMap

well here is the problem i cant do Game.Draw(Map[a]) it gives me error

32
Graphics / Draw map from text file
« on: July 03, 2011, 10:49:15 pm »
hello everyone

so i'm trying to make a load map function and draw map function but i cant get it to work correctly, here is the code.

Code: [Select]

#include <SFML\Graphics.hpp>
#include <iostream>
#include <string>
#include <fstream>

int Map[100][100];
int loadCounterX=0;
int loadCounterY=0;

int mapSizeX;
int mapSizeY;

bool once=false;

void LoadMap (const char *filename)
{
std::ifstream openfile(filename);
if(openfile.is_open())
{
while(!openfile.eof())
{
if(once==false)
{
openfile>>mapSizeX>>mapSizeY;
once = true;
}
openfile >> Map[loadCounterX][loadCounterY];
loadCounterX++;
if(loadCounterX>=mapSizeX)
{
loadCounterX=0;
loadCounterY++;
}
}
}
}

void DrawMap()
{
for(int i=0; i<mapSizeX; i++)
for(int a=0; a<mapSizeY; a++)
Game.Draw(Map[i][a]);
}


int WindowWidth = 800, WindowHight = 600, ColorDepth = 32;
std::string WindowTitle = "The Final Game !!!";

sf::RenderWindow Game(sf::VideoMode(WindowWidth, WindowHight, ColorDepth), WindowTitle);

int main()
{
sf::Event Event;

const char *tiles[2];
tiles[1]=("Data/Images/grass.png");
tiles[2]=("Data/Images/dirt.png");

Game.SetFramerateLimit(60);

while(Game.IsOpened())
{
while(Game.GetEvent(Event))
{


}


Game.Clear();
Game.Display();
}

return 0;
}


text file
10 2
1111111111
0000000000


33
Graphics / move sprite in the opposite direction and bullet problem
« on: June 24, 2011, 06:42:01 pm »
Quote from: "section_two"
Put "int dir=1" outside the game loop

Code: [Select]

   ...
   int dir=1;
   ...
   while (App.IsOpened())
   {
         ...
         if(X>=700)dir=-1;
         if(X<=0)dir=1;
         sprbox.Move(100 * dir * ElapsedTime, 0);
         ...
   }


oo how stupid of me now it works, sorry but i have been deving for 21 hours now straight and i haven't got any sleep, so sorry about the stupidity LOL.
going to get some sleep now so i wouldst make more of a fool of me self

34
Graphics / move sprite in the opposite direction and bullet problem
« on: June 24, 2011, 05:37:08 pm »
Code: [Select]
int main()
{
RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");

Event Event;
bullet bullet;
App.SetFramerateLimit(60);

//----------------------------------------------------------------------------------------------------------------
Image imgbox,imghero;
Sprite sprbox,sprhero;

int HeroHP=100,EnemyHP=100     ,     HeroDmg=10,EnemyDmg=10;

imgbox.LoadFromFile("e.png");
imgbox.CreateMaskFromColor(Color(255,0,255));

imghero.LoadFromFile("h.png");
imghero.CreateMaskFromColor(Color(255,0,255));

sprbox.SetImage(imgbox);
sprhero.SetImage(imghero);

sprbox.SetPosition(20,200);
bullet.Loadfile();
//----------------------------------------------------------------------------------------------------------------



while (App.IsOpened())
{
float ElapsedTime = App.GetFrameTime();

while (App.GetEvent(Event))
{
if (Event.Type == Event::Closed)
App.Close();

// Escape key pressed
if ((Event.Type == Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();

if (Event.Type == sf::Event::KeyReleased && Event.Key.Code == sf::Key::Space)
bullet.moveme(App,ElapsedTime);
 
}

if (App.GetInput().IsKeyDown(Key::Right)) sprhero.Move(100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(Key::Left)) sprhero.Move(-100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(Key::Up)) sprhero.Move( 0, -100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(Key::Down)) sprhero.Move(0, 100 * ElapsedTime);

App.Clear();
int x=10;
bullet.DrawBullt(App);
if(EnemyHP>=0)
{
if(CheckCollision(sprhero,sprbox))
EnemyHP=EnemyHP-HeroDmg;

int BoxX = sprbox.GetPosition().x;
int BoxY = sprbox.GetPosition().y;

int HeroX = sprhero.GetPosition().x;
int HeroY = sprhero.GetPosition().y;

std::cout<< "HeroHP= " << HeroHP << "\t" <<  "EnemyHP= " << EnemyHP << "\t" <<  "X= " << BoxX << "\t" << "Y=" << BoxY << "\t"<< std::endl;

/*
//------------------------ Make enemy follow Hero -------------------------------------------------
if(BoxX<HeroX)
sprbox.Move(20 * ElapsedTime, 0);

if(BoxY<HeroY)
sprbox.Move(0, 20 * ElapsedTime);



if(BoxY>HeroY)
sprbox.Move(0, -20 * ElapsedTime);

if(BoxX>HeroX)
sprbox.Move(-20 * ElapsedTime, 0);
//------------------------ Make enemy follow Hero -------------------------------------------------
*/
int dir=1;

if(BoxX>=700)
{
dir=-1;
//sprbox.Move(100 * dir * ElapsedTime, 0);
}
if(BoxX<=20)
{
dir=1;
sprbox.Move(100 * dir * ElapsedTime, 0);
}
App.Draw(sprbox);
}


App.Draw(sprhero);
App.Display();
}
    return 0;
}

35
Graphics / move sprite in the opposite direction and bullet problem
« on: June 24, 2011, 02:00:53 pm »
Quote from: "section_two"
Hi
Code: [Select]

         if(X<=700)
            sprbox.Move(100* ElapsedTime, 0);
         else
            sprbox.Move(-200* ElapsedTime, 0);



Everytime sprbox goes LEFT 200, in the next loop, X < 700 , so.....RIGHT again.


You can do something like:

Code: [Select]
 
   ...
   int dir=1;
   ...
   while (App.IsOpened())
   {
         ...
         if(X>=700)dir=-1;
         if(X<=0)dir=1;
         sprbox.Move(100 * dir * ElapsedTime, 0);
         ...
   }



didnt work

36
Graphics / move sprite in the opposite direction and bullet problem
« on: June 23, 2011, 07:48:52 pm »
hello everyone

i'm trying to make an enemy sprite to move to the end of the screen which is right and then move back to the start of the screen (left), but i only could make move in one direction i cant make it move in the opposite direction.

Code: [Select]


   while (App.IsOpened())
   {
int X = sprbox.GetPosition().x;
int Y = sprbox.GetPosition().y;

if(X<=700)
sprbox.Move(100* ElapsedTime, 0);

else
sprbox.Move(-200* ElapsedTime, 0);
}


[Edit]
Quote from: "section_two"

You can do something like:

Code: [Select]
 
   ...
   int dir=1;
   ...
   while (App.IsOpened())
   {
         ...
         if(X>=700)dir=-1;
         if(X<=0)dir=1;
         sprbox.Move(100 * dir * ElapsedTime, 0);
         ...
   }



that didnt work i tried it but still didnt work.
alos i have another problem where i want if you press Space bar the bullet will move through the screen, i did that but i have to keep pressing space, however i solved that problem latter by doing this
Code: [Select]

sf::Event event
while (window.GetEvent(event))
{
    if (event.Type == sf::Event::KeyReleased && event.Key.Code == sf::Key::Space)
    {
        bullet.moveme(App,ElapsedTime);
    }
}


but the problem is i have to press space to move the bullet about 2px, so i keep pressing space to move the bullet which is not what i want.

37
Graphics / Re: trying to do fire animation
« on: June 20, 2011, 12:03:32 am »
Quote from: "Hiura"
Quote from: "Fantasy"
i looked at http://www.sfml-dev.org/wiki/en/sources/frame_anim_animated but i didn't really understand a lot from it but i did my best.
Did you try the sample ? Just ask if something in particular is unclear.

Quote from: "Fantasy"
the end result is all i see is Sprt7 and it doesnt loop again to draw Sprt1 i dont know why is that
In fact all sprites are drawn but the second one goes over the first, the third overs the second, ... the seventh over the sixth, in that order. Why ? Because there is no Display between the Draw.


well there are some things i dont understand and its not because its complicated its because i still didn't study what pointers are and how to work with them, but other than that i think its a good tutorial.

but i dont understand one thing is that how can you display only one part of a sprite but not the whole sprite ? for example if i want to only show the first 32px ->X and 32px->Y, i know how in allegro but not in sfml.
 
WOW thank you so much now its working, i did as you said
Code: [Select]
for(int x=1; x<=7; x++)
{
Game.Draw(Sprt1);
Game.Display();
Game.Draw(Sprt2);
Game.Display();
Game.Draw(Sprt3);
Game.Display();
Game.Draw(Sprt4);
Game.Display();
Game.Draw(Sprt5);
Game.Display();
Game.Draw(Sprt6);
Game.Display();
Game.Draw(Sprt7);
}

now its working but its animating very fast, even though i fixed the FPS to 60FPS its still animating fast like crazy.

ok so i guess i'm going to get 60 fire sprites instead of 7 to make it slower and more realistic, and i think i'm going to use array to load the 60 sprites, its going to be a looooong long page of code for 60 sprites.

38
Graphics / trying to do fire animation
« on: June 19, 2011, 11:32:47 pm »
hello everyone
so i have 7 images of fire and i was trying to make an animation with them but from the looks of it i failed.

i looked at http://www.sfml-dev.org/wiki/en/sources/frame_anim_animated but i didn't really understand a lot from it but i did my best.

here is what i did

Code: [Select]
int main()
{
Event Event;
Clock Clock;


//Create SFML windows
RenderWindow Game(VideoMode(800,600,32), "Game");

Image Img1;
Sprite Sprt1;
Image Img2;
Sprite Sprt2;
Image Img3;
Sprite Sprt3;
Image Img4;
Sprite Sprt4;
Image Img5;
Sprite Sprt5;
Image Img6;
Sprite Sprt6;
Image Img7;
Sprite Sprt7;

Img1.LoadFromFile("1.png");
Sprt1.SetImage(Img1);
Sprt1.Move(100,100);
Img2.LoadFromFile("2.png");
Sprt2.SetImage(Img2);
Sprt2.Move(100,100);
Img3.LoadFromFile("3.png");
Sprt3.SetImage(Img3);
Sprt3.Move(100,100);
Img4.LoadFromFile("4.png");
Sprt4.SetImage(Img4);
Sprt4.Move(100,100);
Img5.LoadFromFile("5.png");
Sprt5.SetImage(Img5);
Sprt5.Move(100,100);
Img6.LoadFromFile("6.png");
Sprt6.SetImage(Img6);
Sprt6.Move(100,100);
Img7.LoadFromFile("7.png");
Sprt7.SetImage(Img7);
Sprt7.Move(100,100);

Game.UseVerticalSync(true);

//Game loop
while(Game.IsOpened())
{

float Framerate = 1.f / Clock.GetElapsedTime();
Clock.Reset();

//Event handle loop
while(Game.GetEvent(Event))
{

if(Event.Type == Event::Closed)
Game.Close();

if (Game.GetInput().IsKeyDown(Key::Escape))
Game.Close();

if (Game.GetInput().IsKeyDown(Key::Num1))
StartPlaying();

if (Game.GetInput().IsKeyDown(Key::Num2))
Settings();
}

String Text("Press 1 to start playing the game\n"
"Press 2 to open Settings\n"
"Press ESC to Exit the game\n");

Text.SetColor(Color(255, 0, 0));
Text.Move(100.f, 100.f);

//Clear the game window
Game.Clear();

//Display Text
Game.Draw(Text);
//
for(int x=1; x<=7; x++)
{
Game.Draw(Sprt1);
Game.Draw(Sprt2);
Game.Draw(Sprt3);
Game.Draw(Sprt4);
Game.Draw(Sprt5);
Game.Draw(Sprt6);
Game.Draw(Sprt7);
}
//Display SFML graphics to window
Game.Display();

}
return 0;

}


the end result is all i see is Sprt7 and it doesnt loop again to draw Sprt1 i dont know why is that

39
Graphics / [Solved] transparency problem
« on: June 16, 2011, 11:40:13 am »
Quote from: "Laurent"
http://www.sfml-dev.org/documentation/1.6/classsf_1_1Image.php#ae9a15fe9a4750295845b5ae081c2ec50

thank i should visit the documentation more often LOL
thankx for the help

40
Graphics / [Solved] transparency problem
« on: June 16, 2011, 11:35:10 am »
ok so after i used  
Code: [Select]
Image.CreateMaskFromColor(Color(255,0,255)); function its not working as i hoped, here is how it looks


the magenta color suppose to be transcendent but its not, here is the original image


[Solved]
ok if i use JPG image it doesnt work but if i use png image it works weird, so anyways its not AMD Driver fault xD

41
Window / Manage multiple screens in a game
« on: June 13, 2011, 11:07:38 pm »
hello everyone
so i'm working on a game and i want to be able to switch between one screen and another, for example when the game starts you will see the main menu then when the player click on settings for example a new screen will come up, and when the player press back it will go back to the main menu.

so how can i do that ? how can i make multiple screen with each screen has its own consoles?

also if the player press key F in settings it will do some function but if he press key F in the main screen it will do different function.

thankx

42
General / GPU usage is very high AMD 5870
« on: May 20, 2011, 07:10:15 pm »
Quote from: "Groogy"
Well that's because your framerate there will be huge. You never sleep or wait anything so you will be running as fast as the CPU can.


so if i lock my frame rate to 60 it will lower both cpu and gpu usage right ?

43
General / GPU usage is very high AMD 5870
« on: May 20, 2011, 05:53:50 pm »
Quote from: "Laurent"
How can you see the GPU consumption?

Can you show us your source code?


i use AMD Catalyst Control Center to see my GPU usage.
as for the source code its just a simple black windows

Code: [Select]

#include <SFML/Window.hpp>

int main()
{
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");

    bool Running = true;
    while (Running)
    {
        App.Display();
    }

    return 0;
}

44
General / GPU usage is very high AMD 5870
« on: May 20, 2011, 05:35:07 pm »
Quote from: "Laurent"
Is it really the GPU, or do you mean "the CPU"?


yes its the GPU not CPU.
its the graphics processing unit that is getting 60% usage

45
General / GPU usage is very high AMD 5870
« on: May 20, 2011, 05:28:11 pm »
hello everyone
i have a 5870 with Drivers 11.5 and my GPU usage is 60% when i build and run my game in SFML.
i don't have anything in my game its just a black windows, so why is it using 60% ?!!
thankx

Pages: 1 2 [3] 4
anything