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 - caelestis

Pages: [1]
1
General discussions / Can someone compile this on mac?
« on: February 01, 2010, 05:14:55 am »
I do not have a mac, but my friend asked me to do a quick program and I made it to find out he is on a mac. So can you compile this for a mac (32 bits) and also include and linked libraries? (Don't know what they are on mac)

Code: [Select]

#include <cmath>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Window/Input.hpp>
#include <SFML/System/Randomizer.hpp>

using namespace sf;

const int W_WIDTH = 1200;
const int W_HEIGHT = 600;
float scaleFactor = 1;
float speed = 4;

Image gradientImage;
Sprite gradient;

int getRepetitions() {
return (int) (W_WIDTH/(gradientImage.GetWidth()*scaleFactor)) + 10;
}

float getWidth() {
return gradientImage.GetWidth()*scaleFactor;
}

void setRandomDirection() {
int random = Randomizer::Random(0,1);
if (random == 0) speed = -speed;
}

int main(int argc, char **argv) {
RenderWindow window(VideoMode(W_WIDTH,W_HEIGHT,24), "Optokinetic Simulator");
const Input & inp = window.GetInput();

gradientImage.LoadFromFile("gradient.png");
gradient.SetImage(gradientImage);
gradient.SetScaleY((float) W_HEIGHT);
Event e;

while (window.IsOpened()) {
while (window.GetEvent(e)) {
if (e.Type == Event::Closed)
window.Close();
if (inp.IsKeyDown(Key::Up)) {
setRandomDirection();
scaleFactor /= 1.3;
gradient.SetScaleX(scaleFactor);
}
if (inp.IsKeyDown(Key::Down)) {
setRandomDirection();
scaleFactor *= 1.3;
gradient.SetScaleX(scaleFactor);
}
}

window.Clear(Color(0,0,0)); //Set background to black

//Loop moving sequence
if (abs((int)gradient.GetPosition().x) > getWidth()*5) gradient.SetPosition(0,0);
else gradient.Move(speed,0);

Vector2f originalPos = gradient.GetPosition(); //To restore position after we are done drawing repetitions of the image
for (int i = -5; i < getRepetitions(); ++i) {
gradient.SetPosition(originalPos.x+i*getWidth(), -230); //Some bug in SFML?
if (gradient.GetPosition().x <= W_WIDTH) window.Draw(gradient);
}
gradient.SetPosition(originalPos);

window.Display();
}
return 0;
}


Please and thank you.

If mac wasn't so proprietary I could've done it myself. Sorry.

If you could also look over the code, the gradient is 1 pixel high, and I have to set the location of the image to be -230 in the y axis. I do not know why it doesn't start at 0,0 after I scale it.

2
Graphics / A question about collision detection
« on: January 20, 2010, 11:10:54 pm »
I thought of another design in which when the next move will be a possible collision, the bounding box of the wall gets passed to the sprite and it will calculate how much left it has to move. Either that or I do above and iterate moves of one pixel until I reach target destination (which would be bad because it would calculate boxes over and over every move of one pixel)

3
Graphics / A question about collision detection
« on: January 20, 2010, 10:42:25 pm »
I made my collision detection system so that when the window Draw sprites, it will check if it collided with anything and set a flag to alert that sprite. The sprite is set to move itself every time it is drawn, but sometimes, it will move past an object a small amount. This is because I've set it to move to the spot past the wall and then check to see if it collided afterwards, which is not the effect I wanted.

I'm trying to think about ways to fix this. Should I make it so that it moves only 1 pixel each time and then check collision of the sprite or perhaps it should only start moving by one pixel when it anticipates that the next point it moves to will be a collision? I'm worried about moving one pixel because I think it might be an inefficient and inelegant design. Any suggestions?

Oh, and one more thing. I'm having to calculate a new bounding box each time I want to use the collision detection function, getting it from the offsets+GetSubRect and I think this is also a clunky design.

4
Graphics / Overload draw?
« on: January 13, 2010, 03:18:03 am »
How would I overload the draw function for RenderWindow so that I can update the objects properties before I draw it? I'm a little noobish sorry.

Pages: [1]
anything