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.


Topics - Jimicro

Pages: [1]
1
General / Handling time to delay?
« on: January 09, 2011, 08:33:29 pm »
Hi all.

I have a little game with a shooting feature I want to hold down a button to shoot but I don´t want it to shoot all the time, so can I use sf::Clock to just make it wait between all generating shots?

2
Graphics / use shapes in vector
« on: January 04, 2011, 10:05:46 pm »
I have a problem.

I have a class method where I declare a new Shape. i want to stack this in a vector.

Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>

class Circle : sf::Shape
{
    private:
    sf::Shape circle;
    int radius;
    std::vector <Circle*> circles;
    int x;
    int y;
    public:
    void generateCircle();
    void setValues(int x, int y);
    void draw(sf::RenderWindow& App);
    Circle();
};



and the method

Code: [Select]


void Circle::generateCircle()
{
    Circle* circle = new Circle;
    circles->sf::Shape ?
    circles.push_back(circle);
}

how can I declare the shape in to the vector?

3
Graphics / Draw sprite using vector
« on: December 29, 2010, 09:21:32 pm »
Hello!

I am trying to use std::vector stl too make a little shootergame. But I don´t know how to save a sprite to a vector.

I have
Code: [Select]

#include "Sprite.h"

Bullet::Bullet()
{
    x = 100;
    y = 100;
    if(!Image.LoadFromFile("bullet.jpg"))
    {
        //Error
    }
}

void Bullet::shoot()
{
    Bullet* bullet1 = new Bullet;
    bullet1->SetImage(Image);
    bullets.push_back(bullet1);
}

void Bullet::drawBullet()
{
    bullet.SetImage(Image);
}

void Bullet::generateBullet()
{
    Bullet* bullet = new Bullet;
    bullets.push_back(bullet);

}
void Bullet::draw(sf::RenderWindow& App)
{
    App.Draw(bullet);
}



But the I can´t save the file to the vector who are vector<Sprite*> bullets; in bullet class.

I want to App.Draw(bullets);

What do I need to do?

4
Window / Many events
« on: February 18, 2010, 02:15:47 am »
Hello

Is there away you can have many different events?

Like different classes and functions.

sf::Event Run;
sf::Event Meny;

Like that?

5
General / Vector2f
« on: January 27, 2010, 03:32:01 pm »
Why do I get the error: 'Vector2f ' does not name a type?

Have I forgot something in my class?

6
Graphics / Drawing Images problem
« on: January 25, 2010, 07:49:33 pm »
Hello

I´m on a school projekt to do a little game. But I´m stuck. I don´t know how to draw images when they are in another file. The compiler says that Draw it´s no a function to the class. Here is the soruce for better description.

Code: [Select]
view.cpp #include <SFML/Graphics.hpp>
#include <fstream>
#include <iostream>

using namespace sf;
using namespace std;

class Map: public Sprite
{
    private:
    sf::Sprite sprite;
    char num;
    char level[12][12];
    int height;

    //Create image
   sf::Image blockImage;
   sf::Image groundImage;
   sf::Image wallImage;

    public:
    void openFile();
    void updateMap();
    void loadAllImages();
    void update();
    Map();

};


void Map::openFile()
{
    height = 0;

    //Read textfle (2D char array)
   ifstream file;
   file.open("level.txt");


   std::string line;

    while(getline(file, line))
   {
      for(int width = 0; width < 12; width++)
      {
         level[height][width] = line.at(width);
      }
      height++;
   }
   //Close file stream
   file.close();
}
void Map::loadAllImages()
{
   //Create Sprite
   Sprite blockTile(blockImage);
   Sprite groundTile(groundImage);
   Sprite wallTile(wallImage);
}

void Map::updateMap()
{

    //Scroll through level and display corresponding image of tile
      for(int y = 0; y < 12; y++)
      {
         for(int x = 0; x < 12; x++)
         {
            num = level[y][x];

            if(num == '1')
            {

               this->sprite.SetPosition(x*50, y*50);
               this->sprite.SetImage(blockImage);

            }
            else if(num == '2')
            {
               this->sprite.SetPosition(x*50, y*50);
               this->sprite.SetImage(groundImage);
            }
            else if(num == '3')
            {
                this->sprite.SetPosition(x*50, y*50);
                this->sprite.SetImage(wallImage);
            }
         }
      }
}


and the other file that contains main function.

Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <fstream>
#include "view.cpp"

using namespace sf;
using namespace std;


int main()
{

    Map map;
    map.openFile();

    map.updateMap();
    //Display using SFML
    //Render Window
    sf::RenderWindow App(sf::VideoMode(640, 480), "Shoot");
    //Game loop
    while (App.IsOpened())
    {
      sf::Event Event;
      while(App.GetEvent(Event))
      {
         if(Event.Type == sf::Event::Closed)
         {
            App.Close();
         }
      }
    map.loadAllImages();


    App.Draw();
    // Clear the screen with white color
    App.Clear(sf::Color(0, 0, 255));
    //Display sprites
    App.Display();
   }
   return EXIT_SUCCESS;
   //*/
}


Hope you can help me :)

Pages: [1]