Hello, I am making a program that will draw a ramps for a bike game. It does that by making many lines which form a ramp or other figures. For one of the ramps I have a small problem. In the game if something is too smooth, it will slip and go to fast and fall (this is a bug). Because my program makes super smooth ramps, the bikes slips and falls. To see what I am talking about go here . And press up. It will go super fast and start spinning. This is not supposed to happen. I want to make it less smooth by drawing an extra layer on top of the ramp.

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main() {
    Sleep(5000);
    int sx = 700;
    int sy = 200;
    int startx[25]; //this is so the ramp will not be slippery
    int starty[25]; //this is so the ramp will not be slippery

float count = 0; //then we add 0.25
float counti = 0; //other count too see which element in the array to fill
    int ex = 700;
    int ey = 500;
    int i = 0;

for (i = 0; i < 200; i++) {
    count+=0.25;
    if (count == 2) {
    count = 0;
    startx[(int)counti] = sx;
    starty[(int)counti] = sy;


    counti++;
    }
     sy+=1;
     sx-=1;
       SetCursorPos(sx,sy);
   mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
   ex-=3;
SetCursorPos(ex,ey);
Sleep(150);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Sleep(150);

  }

int d = 0;
while (d < 24) {
SetCursorPos(startx[d]-1,starty[d]-1);
    d++;
   mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
SetCursorPos(startx[d]-1,starty[d]-1);
Sleep(150);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Sleep(150);
  }

  }

To run the program, you should quickly switch to canvas rider drawer or any other painting program (like Windows Paint). But as you may see, the layer does not draw correctly. I can't figure out how to make it go right on top layer of ramp. So how do you think I can do this?

m4ster_r0shi commented: This game is awesome. I think I'm addicted. +7

How about something less tricky. Something like this:

#include <windows.h>
#include <iostream>
#include <cmath>

bool IsPressed(int vkey) { return GetAsyncKeyState(vkey) >> 15; }

void MouseMove(int dx, int dy)
{
    POINT point; GetCursorPos(&point);
    SetCursorPos(point.x + dx, point.y + dy);
}

const double slope_max    = 1.35;
const double slope_change = 0.15;

const double line_length  = 16;

#define LOOP_BODY \
    dx =  cos(atan(slope)) * line_length; \
    dy = -sin(atan(slope)) * line_length; \
\
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); \
    MouseMove(dx, dy); \
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); \
\
    Sleep(25);

int main()
{
    std::cout << "hit F8 to begin" << std::endl;

    while (!IsPressed(VK_F8)) Sleep(25);

    double slope, dx, dy;

    for (slope = 0;           slope < slope_max; slope +=  slope_change) { LOOP_BODY }
    for (slope =  slope_max;  slope > 0;         slope -=  slope_change) { LOOP_BODY }
    for (slope = 0;          -slope < slope_max; slope += -slope_change) { LOOP_BODY }
    for (slope = -slope_max; -slope > 0;         slope -= -slope_change) { LOOP_BODY }
}
commented: Thanks! I don't have time right now, I will try that soon! +4

Nevermind, bad question.

I remember needing to write a program that generates curve functions, as in specify a begin point an end point and a point or points the curve needs to pass through. Sadly I never got around to it.

But! My math teacher told me it involved solving three or more equations .. or something.

@sergent
http://sourceforge.net/apps/mediawiki/cpwiki/index.php?title=Indentation
I'll comment further when I can stomach reading your code.

> How about something less tricky.
Like for example using a function instead of some hacky multi-line macro.

commented: Thanks lol, I am self-taught programmer so my code doesn't always look pretty. My whole program is much bigger so I just quickly cut & paste small portion of it. +4

How about something less tricky.

I was referring to the algorithm. Tweaking the parameters (slope_max, slope_change and line_length) can
produce interesting results. Making slope_change and line_length variable can also yield very interesting results.

Like for example using a function instead of some hacky multi-line macro.

There's nothing wrong with hacky multi-line macros. On the contrary, they make my code more boost-like :D

I was referring to the algorithm. Tweaking the parameters (slope_max, slope_change and line_length) can
produce interesting results. Making slope_change and line_length variable can also yield very interesting results.


There's nothing wrong with hacky multi-line macros. On the contrary, they make my code more boost-like :D

Noo! That's what inline functions are for..

> There's nothing wrong with hacky multi-line macros.
Mmm'kay...
Accidentally "forget" to add the { } around the invocation of the macro.
a) does it still compile
b) does it still work

If your answers are like mine ("yes" and "no"), then perhaps you need another approach.

I decided to first try to do it the super hard way. I made a small algorithm that finds all points of the line (I know there is another one, but it looks harder then mine, so I will not use that one). Then I will try to find the minimum y on a particular x axis, and then I will draw several lines on top of the ramp on the y's and x's. And if you think this code is messy, you should read all the code, it looks even more horrible. I will post all of it later, when I make it look all nice and stuff.

If your answers are like mine ("yes" and "no"), then perhaps you need another approach.

Okay. This will work fine (and I have to put a semicolon at the end, otherwise it won't compile):

#define LOOP_BODY \
do { \
\
    dx =  cos(atan(slope)) * line_length; \
    dy = -sin(atan(slope)) * line_length; \
\
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); \
    MouseMove(dx, dy); \
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); \
\
    Sleep(25); \
} while(0)

What's the next test?

You can try to use a math function like y=2^(x/3) set your x and y coordinates for the ramp (it would look like this).

The function looks like a ramp and depending on the increment for x you can make it more or less smooth and you can change the length of the ramp by setting the upper bound of the for() loop used to make the ramp.

Sergent I just wanted to thank you for that link... hours of fun :D

commented: Reps to encourage you for more good posts +9

I've found that the math function "y = (x^2)/n" is easy to work with, assume n is the height and width of the window (they need to be the same) and the curve (parabola) the function produces will pass through (0,0) and the upper-right-most coordinate of the viewing window.

So then you have a function to make a parabola that looks like this with a defined height and width (see attachment).

otherwise it's much more complicated, I used this graph for mouse sensitivity in a project. If you knew the math you could use an expression parsing library to find the functions for curves that pass through specific points.

http://www.codeproject.com/KB/recipes/FastMathParser.aspx#idExample

commented: :) +4

You can try to use a math function like y=2^(x/3) set your x and y coordinates for the ramp (it would look like this).

The function looks like a ramp and depending on the increment for x you can make it more or less smooth and you can change the length of the ramp by setting the upper bound of the for() loop used to make the ramp.

I kinda want the sexy pattern on the buttom too, maybe I will use your way for other ramps, because I want my program to make different once.

Sergent I just wanted to thank you for that link... hours of fun

Yeah, the game is addicting, I think too addicting, ESCAPE WHILE YOU STILL CAN!!!

Thanks a lot everyone, you helped me a lot :) I am right now making a web-site for the project, it is completely free, I got about 60% of the code done, so I should post the link to the web-site with the program really soon. It is open source, so you all can help me improve it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.