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

Pages: [1]
1
Graphics / Re: Scaled sprite size
« on: October 05, 2014, 01:24:04 pm »
Thanks for the reply. I do not insist on scaling the images. I just wondered how it would be fair for every screen resolution. But this way only a fixed window size would solve the problem I think

2
Graphics / Scaled sprite size
« on: October 05, 2014, 11:42:09 am »
Hey,

I am planning to develop a 2D Arcade game. Since I am the only one in my team, I need to manage the programming as well as the designing. I think I will stay with little pixel sprites. Now I have the problem that I don't know how I should scale them for each screen resolution. I have a 1920x1080px screen and the character is for example 64x128px big. What factor would be optimal? Any tips?

I hope my english is understandable :)

3
General / Re: Need help with a problem in my game
« on: February 27, 2014, 08:40:59 am »
May I ask for the title of the book?

Of course you can. But the book is written in german. The title is "C++ Lernen und professionell anwenden" which simply means sth. like "How to learn C++ and use it professionally". You can suggest me a book too, i was searching some for later anyways. I guess it's ok if it is in english.

Quote
And some hints concerning forum posts for the next time: Please use a descriptive thread title ("Need help with a problem in my game" is one of the most generic titles ever), and don't quote the full message if it's just above. You can also use
 
tags for syntax highlighting.

Thanks :)

Thank you for the tips :D

4
General / Re: Need help with a problem in my game
« on: February 26, 2014, 07:35:41 pm »
So what's the problem now? In your last post you stated that you "just tested it out". This looks like everything is fine.
If it isn't, you need to describe your current problem  ;)


If it's just the same as above (only one coin drawn): Your function draw_coins() is only called once per loop and only draws a single coin. So if you want to draw all coins you just have to loop over your vector and draw all spawned coins.


By the way: There are several things you could improve.
At first and foremost: EDIT: I've just seen that the formatting is wrecked by pastebin. The "RAW paste data" is ok. Pretty formatting! Your code is a mess. Just use consistent(!!!!!) and simple indendation (2 spaces, 4 spaces, 1 tab per block, just as you like, but be consistent).
And please get rid of those #pragma region things. Although they should make the code more readable, they clutter it more than necessary.

And then, the content: Why do you have a std::vector of somehow "constant" size? Why don't you use it the way it is supposed and push_back every new object? You could for example add newly spawned coins to the vector and remove any coins that would be collected or somehow moved offscreen. This would simplify drawing a lot! Just loop through the vector (google for C++11 for-range-loops) and draw each object. Bang, there you are.

You are making your code more complicated than necessary. KISS: Keep it simple and stupid :)
It seems you have a programming background somehow based on a mashup of C and C++. Where did you learn to program? Did you read a book? There is much potential for improvement, young padawan  ;D

Thank you very much :D I will try this when I find the time. My codes are usually more complicated than necessary :D Uhm.. I learned C++ more or less from a book. I havent even finished it completely but I plan to read it from 0 in the next time. Furthermore i will try to programm more useful programs for me to improve my experience.

5
General / Re: Need help with a problem in my game
« on: February 26, 2014, 04:05:12 pm »
Is there no one who can help me?

6
General / Re: Need help with a problem in my game
« on: February 22, 2014, 03:55:03 pm »
Yea makes sense :D I just tested it out

7
General / Re: Need help with a problem in my game
« on: February 22, 2014, 03:45:58 pm »
Thank you for the reply. I totally forgot that i clear the screen. So i tried to remove the window.clear() function but i didnt work. I can just copy my main.cpp. You dont need the header files and it's just the beginning state of the game so it's no problem for me:

http://pastebin.com/ErYDz5nA

8
General / Need help with a problem in my game
« on: February 22, 2014, 12:52:50 pm »
Hi community,

at first my english is not the best because im german. If you dont understand something just ask for it and i'll try to explain. Now to my problem. Currently i am writing a game. It's very simple. For testing i use colored RectangleShapes later i will add sprites. So you have the one box for the character and you can only move up and down. 50 pixels up and 50 down until you hit the end of the window. Furthermore you have to collect coins. This coins will move from the right towards you.

To draw random coins in a "grid" i prepared a vector. So i can give each of the 12 coins a random number from 0 to 1 and then i draw one coin who has the number 1. My problem is that when i want to draw a new coin, the other one disappears. I need help with it that i have multiple coins. Here is the code you need:

The vector of the coins
Code: [Select]
vector<sf::RectangleShape>coins(12, sf::RectangleShape(coin));

Using my function drawing one coin to use whichCoin to draw other coins
Code: [Select]
whichCoin = set_coins(coins, coinPosition);

while (mainWindow.isOpen())
{
loops = 0;
if(frameClock.getElapsedTime().asMilliseconds() >= updateRate && loops < maxFrameskip)
{
frameClock.restart();
coins[whichCoin].move(-2.5, 0);
if(coins[whichCoin].getPosition().x + 50 <= mainWindow.getSize().x - 50)
{
whichCoin = set_coins(coins, coinPosition);
}

loops++;
}

... continue of the while loop
}

The function i used + the function to draw these coins
Code: [Select]
int set_coins(vector<sf::RectangleShape>& object, int position)
{
int maxSpawn = 0; //max spawnable coins per column
int setSpawn[12]; //sets the spawn for each of the 12 coins

srand(time(NULL)); //reset the previous random numbers

for(int a = 0; a <= 11; a++)
{
setSpawn[a] = rand() % 2; //set 0 or 1 for each of the 12 coins
//cout << setSpawn[a] << endl; //test to check the spawns
}

for(int i = 0; i < object.size(); i++)
{
if(maxSpawn < 1) //allow only 1 coin to spawn per column
{
if(setSpawn[i] == 1) //if the spawn of the coin is 1
{
object[i].setSize(sf::Vector2f(50, 50));
object[i].setFillColor(sf::Color::Green);
object[i].setPosition(position, i*50);

return i;
}
}

maxSpawn = maxSpawn + setSpawn[i];
}
}

void draw_coins(sf::RenderWindow& window, vector<sf::RectangleShape>& object, int position)
{
window.draw(object[position]);
}

I hope you can help me ._.

Pages: [1]