Message Board


Message Board > Fenix / Bennu / Gemix / DIV > bounce bounce bounce

March 30, 2007, 01:20
raverdave
Don't Give A F*CK
155 posts

I need some help rebounding a ball correctly:
The process currently looks like this:

Code:
PROCESS ball(x,y,graph)

PRIVATE
    spd=3;
    direct;
    Begin
        size=50;
        direct=rand(0,360000);
        Loop
            xadvance(direct,spd);
            if(x<=0 || x>640)
                
                  //insert rebound code

            end
            if(y<=0 || y>=480)
            
                  //insert rebound code


            End

            frame;


        end

    End 



It was a bigger process but nothing I tried worked correctly, I am using xadvance and not advance as i dont want the balls graph to rotate!atm the direction (angle start) is random for testing purpose.....
This needs to be an exact and simple solution as the same code needs to be used to rebound off bricks
____________
Gimme my toetag already...
#
March 30, 2007, 01:36
Sandman
F3n!x0r
1194 posts

Here Dave. Even with xadvance()...and even with the faulty bounce code...
code
I told Dave this yesterday, be he didn't listen very well.
Please, Dave, next time listen to me when I tell you something and don't ignore it. And especially, think for yourself instead of letting me doing the programming for you, as it won't help yourself.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
March 30, 2007, 01:58
raverdave
Don't Give A F*CK
155 posts

Is it me or does that statement sound like someone trying to badly ridicule somebody else in public, not only that,but in a place that is meant to be designed to help people??

Quote:
think for yourself instead of letting me doing the programming for you


I dunno about anybody but that part makes me..hmmmm...feel let down, and...perhaps even...makes me feeeeel like KILLING

In fact it makes me feel like quitting the crap I am doing for nothing but fun and to contribute to the fenix community, and if I dont feel any better soon then that's what is gunna happen

[Edited on March 30, 2007 by raverdave]
____________
Gimme my toetag already...
#
March 30, 2007, 02:16
raverdave
Don't Give A F*CK
155 posts

Ok thats long enough to feel crap,the project is deleted,it was only a fun side project to try an arkanoid with a cut down editor I had written for a scrolling shootemup,but meghghghg..byebye
____________
Gimme my toetag already...
#
March 30, 2007, 03:07
Sandman
F3n!x0r
1194 posts

I'm not trying to ridicule you, I'm trying to help you. I'm sorry I made you feel let down, but what I said was how I perceived your actions, which I apparently perceived wrongly.
Too bad it didn't work out. If you want to continue your project some time, remember you sent me your code as a backup. Good luck.

As for the code:
It's probably possible to get rid of the If()s and make the code statement-only, which can be faster. Something along the lines of:
Code:
int waitnumberofframesfornextbounce = 2; // needs to be declared
loop
    direct = ((leftrightbounceinthisframe--<=0)&&(x<0||x>320))?
              180000-direct+(leftrightbounceinthisframe=waitnumberofframesfornextbounce)*0:
             ((updownbounceinthisframe--<=0)&&(y<0||y>200))?
             -direct+(updownbounceinthisframe=waitnumberofframesfornextbounce)*0:direct;
    xadvance(direct,speed);
    frame;
end

____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
April 1, 2007, 13:50
Mezzmer
Square-theorist
792 posts

oh dear
____________
#
April 1, 2007, 15:48
Eckolin
Quite Whiskered
388 posts

Raverdave's code looks better.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
April 1, 2007, 17:22
Sandman
F3n!x0r
1194 posts

Raverdave's code doesn't work.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
April 1, 2007, 21:07
Eckolin
Quite Whiskered
388 posts

I would use the horizontal and vertical speed of the ball.

Code:

loop
    xplus=((x<=0) || (x>=320)) ? -xplus : xplus;
    yplus=((y<=0) || (y>=200)) ? -yplus : yplus;
    x+=xplus;
    y+=yplus;
    frame;
end


____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
April 2, 2007, 03:13
raverdave
Don't Give A F*CK
155 posts

Well,what it was, I needed a system to use for both rebounding off the edges AND rebounding correctly off the bricks, I probably represented the problem too much in a simplistic form, anyhow for the sake of sanity I have been trying different things still, its not that simple a problem to work out, especially the rebounding off the bricks... I have tried surrounding the ball with 4 processes called tophit,bottomhit,lefthit and righthit, the naming is obvious! ok I wanted them to follow the balls coords at all times, so i simply called the processes from the ball process so that within the 4 processes i could simply say:

x=father.x;
y=father.y;


Now this system had an advantage of course because i could tell easily which part of the 'ball' hit which side of the brick, simply because it didnt check the ball but the 4 processes surrounding the ball

abit like this:

Code:
 -
|O|
 - 


Now then a few problems occur really, firstly they dont exactly keep up with the balls coordinates,there is some sort of lag,so you will see visually each one lag behind by 1 or 2 pixels, now you might say big deal, but actually it is a big deal, it needs to be exact or else you will have nasty results like the ball getting stuck within a brick! The second problem is that this method does not take into account a hit on the corner of a brick, if this isnt checked then again you will find the ball getting stuck within a brick,simply i think because 2 hits are registered at once. So the problem, what is an exact way to tell this 2 dimensional flat ass sprite, that it has hit a brick (another normal2d flat ass sprite,and that it has either hit the brick on the top,side or bottom... So as you can see my initial cry for help I obviously simplified too much! If you have ideas then i want to hear them, i dont want people,some i could name,who simply say,bah its easy, i could do it now if i could be bothered..blahblahblah, because in my opinion to do it correctly is not easy and i will know some half assed bullshit solutiion if i see one!

***GASP***
and thats all!

[Edited on April 2, 2007 by raverdave]
____________
Gimme my toetag already...
#
April 2, 2007, 04:49
Sandman
F3n!x0r
1194 posts

The lag is probably caused because the son processes are executed before the father processes. This causes the sons to have outdated coordinates of the father. A fix is to set the PRIORITY of the son processes to -1 (In Fenix versions where the priority system is not broken, 0.84a and I thought the latest batch had it fixed as well (0.84b didn't)).

My suggestion is to first do a box-collision detection between the ball and any brick, until non are left to check or there was a collision detected. If one was detected, there needs to be a perfect detection, to verify the collision is valid, which can be done by the slow function collision().
Then you need to check where the ball hit the brick, which could be done like so: imagine 8 regions around the brick: right, topright, top, topleft, left, bottomleft, bottom and bottomright.
When the ball is in a non-diagonal region, the problem isn't hard (IE use the already given code for bouncing on walls).
For the diagonal regions however, you need to specify what you want done with it. Hitting a corner with a ball gives unexpected results in practise (of course it's logical), so you could make it go a random direction back into the region it came from (which would probably look nice). Alternatively you could take the corner as if it were a diagonal wall, for which you could write some code on how to bounce of a diagonal wall (which would probably also look nice).
The bouncecode off an angled wall could be like so:
Code:
newangle = 2*wallangle-oldangle;

newangle: the new angle of the ball
wallangle: the angle at which the wall is placed
oldangle: the angle at which the ball hits the wall
You can suit the angles to your code. For a diagonal wall you can use the angle of 45000, 135000, 225000 or -45000 (315000). You could use this code for the nondiagonal regions as well, as the matter of fact, which could make the code even faster.

Have fun and good luck
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
April 2, 2007, 11:16
raverdave
Don't Give A F*CK
155 posts

i thought about this way too,but its a helluva checking and the ball would speed up and slow down during the game so this needs taking into account
____________
Gimme my toetag already...
#
April 2, 2007, 14:40
Woody
HEAD BLACK MAN
722 posts

Use a hardness map and map_get_pixel in the ball process from the ball's position so you don't get lag.
____________
boredome is the bitter fruit of too much routine
#
April 2, 2007, 18:05
Eckolin
Quite Whiskered
388 posts

Outbreak uses arrays.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
April 2, 2007, 19:25
raverdave
Don't Give A F*CK
155 posts

yes,now we are talking,i too was thinking of arrays,but couldnt quite..craft it in my mind....yet!!

btw,that game is ok apart from...there's only one angle it seems,was this an abandoned project??
____________
Gimme my toetag already...
#
April 2, 2007, 21:05
Eckolin
Quite Whiskered
388 posts

Everything I do is a potential abandoned project.

It would work with different angles. At some point it had a random horizontal speed at spawn and a more circular paddle.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
April 3, 2007, 11:07
raverdave
Don't Give A F*CK
155 posts

Well I totally changed the approach to this, or I TRIED to, going by some article written on the technique using arrays I converted the code best I could which is here:
Code:
Process ball(x,y,graph)
private
    BallNewX;
    BallNewY;
    balltilex;
    balltiley;
    tilex;
    tiley;
    id5;
    tileabove;
    tilebelow;
    tileleft;
    TileRight;
    TileUpLt;
    TileUpRt;
    TileLowLt;
    TileLowRt;
    HeadingUpLt;
    HeadingLowLt;
    HeadingUpRt;
    HeadingLowRt;
    collis;
    Begin
        Loop
            col=collis;
            id5=(collision(type brick));
            BallNewX = BallPosX + BallDirX;
            BallNewY = BallPosY + BallDirY;
            BallTileX = BallNewX / TileSizeX;
            BallTileY = BallNewY / TileSizeY;
            BallPosX = BallPosX + BallDirX;
            BallPosY = BallPosY + BallDirY;

            From TileY = BallTileY-1 To BallTileY+1
                From TileX = BallTileX-1 To BallTileX+1
                    If(Map.row[tilex].column[tiley].tile>59)
                        if(id5)
                            Collis = True;

                            If (TileY == BallTileY - 1 And TileX == BallTileX)
                                TileAbove = True;
                            end

                            If (TileY == BallTileY + 1 And TileX == BallTileX)
                                TileBelow = True ;
                            End

                             If (TileY == BallTileY And TileX == BallTileX - 1)
                                TileLeft  = True;
                             end
                             If (TileY == BallTileY And TileX == BallTileX + 1)
                                TileRight = True;
                            end
                            If (TileY == BallTileY - 1 And TileX == BallTileX - 1)
                                TileUpLt  = True;
                            end
                            If (TileY == BallTileY - 1 And TileX == BallTileX + 1)
                                TileUpRt  = True;
                            end
                            If (TileY == BallTileY + 1 And TileX == BallTileX - 1)
                                TileLowLt = True ;
                            end

                             If (TileY == BallTileY + 1 And TileX == BallTileX + 1)
                                TileLowRt = True ;
                            end
                          else
                          collis=0;
                         end
                     end

                end

            end


            If (BallDirX < 0 And BallDirY < 0) HeadingUpLt  = True; end
            If (BallDirX < 0 And BallDirY > 0) HeadingLowLt = True; end
            If (BallDirX > 0 And BallDirY < 0) HeadingUpRt  = True; end
            If (BallDirX > 0 And BallDirY > 0) HeadingLowRt = True; end
            
            If(collis)

                If (TileLeft And TileAbove Or TileLeft And TileBelow Or TileRight And TileAbove Or TileRight And TileBelow)
                    BallDirX = -BallDirX;
                    ballDirY = -BallDirY;
                    Else
                        If (TileLeft Or TileRight)
                            BallDirX = -BallDirX;
                            ElseIf (TileAbove Or TileBelow)
                                BallDirY = -BallDirY;
                                ElseIf (( HeadingUpLt And TileLowLt ) Or ( HeadingLowLt And TileUpLt ) Or ( HeadingUpRt And TileLowRt ) Or ( HeadingLowRt And TileUpRt ))
                                    BallDirX = -BallDirX;

                                 ElseIf (( HeadingUpLt And TileUpRt ) Or ( HeadingUpRt And TileUpLt ) Or ( HeadingLowLt And TileLowRt ) Or ( HeadingLowRt And TileLowLt ))
                                    BallDirY = -BallDirY;
                                  ElseIf (TileUpLt Or TileUpRt Or TileLowLt Or TileLowRt)
                                    BallDirX = -BallDirX;
                                    BallDirY = -BallDirY;
                             end

                end
            End
            X = BallPosX + BallDirX;
            Y = BallPosY + BallDirY;

            if(y<0 || y>=480)
                balldiry=-balldiry;
            end
            if(x<=0 || x>=640)
               BallDirX = -BallDirX;
            end

            Frame(10);
        End
    End 


I hope you can appreciate how hard it is to understand and convert somebody elses code!
Anyhow a few problems
The original code to my understanding never resetted a variable called collis to 0, so i have put it in there like so:
Code:
  If (TileY == BallTileY + 1 And TileX == BallTileX + 1)
                                TileLowRt = True ;
                            end
                          else
                          collis=0;
                         end 

Now,for some odd reason,when the ball reaches the left hand edge of the screen,fenix quits out totally,no error,nothing,rather like a alt+x really..I have no idea, Also as it stands i notice that it can go into some continues loop,again tgis is no good,so it can hit a brick,rebound,hit a wall,rebound and hit a brick rebound then go back to where it was, or in other words triangulate..
For those interested anyhow the code is here:
http://raverdave.serveftp.com/files/RD-Ball.rar
This shows clearly the triangulation...
I have probably oncerted the code wrong or something,anyhow if you start the ball at a different location changing the globals:
BallPosX = 204;
BallPosY = 72;
to something else then do so,then you will see the problem of fenix simply quittung out! if it reaches the left edge!
____________
Gimme my toetag already...
#
April 4, 2007, 01:01
raverdave
Don't Give A F*CK
155 posts

hmm yeh well,no replies eh,ok,can anybody tell me what i can use to get the value of the colour of the map in a fpg,so i can use this map_get_pixel, also can 16bit fpgs be used??
I am trying the hardness maps approach
____________
Gimme my toetag already...
#
April 4, 2007, 02:03
Sandman
F3n!x0r
1194 posts

You can use 16bit FPG's, make sure you set Fenix to 16bit, using set_mode().

To make sure you're getting the right colour code, I recommend making a dummy graph, which contains the colours you're using for the hardnessmap, and get the colour codes from them.
For example, you use the colour RED. So then you make a dummy graph with the same colour RED as the hardnessmaps and you perform map_get_pixel() on the dummy graph (which can be 1 pixel big) and you got the proper code. This is advisable, because I heard something about different videocards using different codes. With this method, that does not matter at all. You can just do map_get_pixel() on the hardnessmap and compare it to the code you got from the dummy map.
On a side note, if you're using only one colour in the hardnessmap, you could also check if the pixel you want to check is !=0, providing the background is indeed 0. But that's not a very pretty way.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#

Message Board > Fenix / Bennu / Gemix / DIV > bounce bounce bounce

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!