forums

TNT Basic Forums > Programming Q&A
Sprite col in a "for" loop
< Last Thread     Next Thread >
Author
Thread        Post A Reply

07-30-2004 12:25

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

I have some questions:

--If 2 objects collide and they have both a x and a y speed, what are their new speeds? For example, if object 1 (xspeed=2,yspeed=-2) and object 2 (xspeed=-1,yspeed=1) collide, what happens?

--How do I change the speed in a "for" loop? How can I check if one of the sprites collide with another sprite of this loop? I store all informations in arrays. My code is something like this:

for n=0 to allobjects-1
xpos[n]=xpos[n]+xvel[n]
ypos[n]=ypos[n]+yvel[n]
xpos[n]=wrap(xpos[n],0,640)
ypos[n]=wrap(ypos[n],0,480)
sprite n,xpos[n],ypos[n],0
if sprite col(n,0 to allobjects-1)
'change xvel and yvel
end if
next n


Thanks for the help!
-IBD

07-30-2004 15:54

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

1) The new speeds of the colliding objects are up to you; you could make them bounce off each other for a billiard ball effect, or you can just let them pass thru. If you want that bounce effect, you'll need to use some math to figure out the new path. I think I could figure it out if you want to do that.

2) Your loop already has the code needed to check collisions with all sprites in the loop:

quote:
if sprite col(n,0 to allobjects-1)
'change xvel and yvel
end if


To change the speed of the object, just put something in the "if block."
For example, if you want to make an object slow down with each collision, put this code:
quote:
if sprite col(n,0 to allobjects-1)
xvel[n]=0.6*xvel[n]
yvel[n]=0.6*yvel[n]
end if

07-30-2004 17:07

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

Yes, a Billiard effect is exactly what I want. I'm working on a space game like "TheZone" and all objects are in space, so they don't slow down with the time. All objects I want to use don't bounce off extremly (Meteors,rocks, Enemys, and so on).

Can you do the Maths for me?? :-)


To my code: It works now. In the "real" code I included something wrong and it didn't worked. Don't worry about this.

07-30-2004 18:56

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Hey, I've got an idea. I'll make an example out of it and submit it to be put in the directory.

07-31-2004 22:51

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

I'm going to be out next week, so if I don't have it done today don't expect to see it for a while.

08-08-2004 14:12

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

Ok. Do that example.

In the futurebasic demo there is an example like this but I don't have it anymore.

08-08-2004 18:38

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Haha guess you were waiting? Alright, I'll get back to work, but it might take longer than I expected; that is, unless you're okay with the collision engine only taking balls of equal mass and equal size. That would make it much simpler.

08-08-2004 18:40

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

OOh wait a second. You said they don't bounce exactly? If by that you mean the collisions are inelastic, then that will make it simpler.

08-08-2004 23:29

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

That's a nice job eekay :-)

I did it when I started playing with C, it was a good challenge... setting up the equation for conservation of momentum, and for the conservation of energy you get the amount of momentum that must be passed between the two balls... turns out a pretty neat result...

Moreover remember that the momentum of two balls colliding can only be passed in the direction perpendicular to the tangent.

08-09-2004 05:02

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

whoa! sounds complicated! I hope YOU can do it and then I can try to understand some parts.

OK. I'm waiting. :-D

08-09-2004 10:09

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

argh this is goin to be hard...

Ok: what is "momentum"?

Momentum is the algebric sum of mass*velocity of all objects.

Every closed system usually "conserves momentum":

Say we have two balls, one going against the other: we can say that the first has velocity=2 and ...

Ok this is going to be waaaaaay too long.

I'll give you an adapted (to TNT) version from my program

Ok suppose you have two balls, ball1 and ball2, with coordinates ball1x,ball1y,ball2x,ball2y and velocities ball1vx ,ball1vy,ball2vx,ball2vy radiuses ball1r and ball2r.



if ( (ball1x-ball2x)^2+(ball1y-ball2y)^2<(ball1r + ball2r)^2 )

float xdiff= ball2x -ball1x;
float ydiff=-( ball2y -ball1y);

float diffdir= atan2(ydiff,xdiff);

float distance=sqrt(xdiff*xdiff+ydiff*ydiff);
float radiussum= ball2r+ball1r;

float dx=(radiussum-distance+0.1)/2*cos(diffdir);
float dy=-((radiussum-distance+0.1)/2*sin(diffdir));

ball1x=ball1x-dx;
ball2x=ball2x+dx;
ball1y =ball1y -dy;
ball2y =ball2y +dy;




float sxvel= ball1vx - ball2vx;

float syvel= -(ball1vy - ball2vy);

float totvel=sqrt(sxvel*sxvel+syvel*syvel);

float veldir= atan2(syvel,sxvel);

float rebvel= cos(veldir-diffdir)*totvel;

float dvx=rebvel*cos(diffdir);
float dvy=-rebvel*sin(diffdir);

ball1vx=ball1vx-dvx*elasticity;
ball1vy=ball1vy-dvy*elasticity;
ball2vx=ball2vx+dvx*elasticity;
ball2vy=ball2vy+dvy*elasticity;

end if


Oh, where "elasticity" is approximately how much you want the balls to be bouncy, and atan2(y,x) is a c function that can be translated with TNT's "invtan" like this:

if x>0 then atan2(y,x)=invtan(y/x)
if x<0 then atan2(y,x)=invtan(y/x)+180

therefore the line

"float diffdir= atan2(ydiff,xdiff);"

should be translated with:

"if xdiff>=0 then float diffdir= invtan(ydiff/xdiff)
if xdiff<0 then float diffdir= invtan(ydiff/xdiff)+180"

and this way every time atan2 appears in the code.

Oh, the balls are supposed to have the same mass... if they dont it's not too hard to adjust but I'll leave it to the reader as an exercise ;-P

08-10-2004 08:45

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Egad these equations are getting ugly! This better work...

08-10-2004 23:27

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

ARRGGH these equations are terrible!!! I tried to avoid converting the calculations to angles thinking they would just be converted back into their x and y components anyway, but the ratios that I use force me to make exceptions every time the bottom value becomes zero!

Matteo, I think putting the mass into consideration is a lot harder for me than for you...but please don't do it, let me finish.

08-11-2004 00:24

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

It's good to see you in an effort :-)

In the end things that bounce are very nice in videogames.

Instead, I would not care about exceptions when the denominator, TNT somehow handles "infinites" nicely: try compiling this:

float a=0
float b=1/a
print(b)
print(invtan(b))

anyhow you will see it can give different results if you put a=-0 instead of a =0!!!

08-11-2004 09:12

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Wow you're right! I was wondering if nan meant infinity.

08-11-2004 09:31

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Strange...at first it seems to work, but if the balls go too fast, their energies begin to multiply.

Which is strange, because the velocities are calculated with the equations for conservation of momentum and energy...

Maybe you guys could help...

08-11-2004 10:03

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Not quite done

Well, the first problem was due to the balls not separating correctly after a collision. I got that fixed though, so the example looks good. However, the code is still buggy, because for some reason energy is not conserved in collisions. Same with momentum. As I said, my equations are based on those very laws, so I don't know why it isn't working.

Elastic Collisions

08-11-2004 16:20

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

To conserve momentum you must just impose that when 2 balls collide the difference in velocity "dvx and dvy" (delta v) of the first one is opposite to the second one, hope I'm clear. That is, if the first ball is going with vx1=2 and vy1=3 and the second one has vx2=5 and vy2=4, after colliding they must have speeds such that vx1+vx2=2+5=7 and vy1+vy2=3+4=7

The main problem is how much momenutm pass from one ball to the other. this should be imposed by conservation of energy.

And the final point, you can only transfer momentum along the orthogonal to the tangent, which implies some ratios between the dvx and dvy.

Probably you got the first and third points right (otherwise it does not look good) but you missed the second

08-12-2004 20:31

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

YES IT WORKS!

Hurrah I got it to work! Matteo, it was the second problem. I used this site to help me, but I only got it to work using your cos(diffdir-veldir) method. That's when I realized: that is how you found the dot product of the two vectors. Man, I should have used your code from the beginning instead of trying to derive everything!

Well maybe not, at least I have a greater understanding of dot products now.

Here it is: Elastic Collisions

08-12-2004 21:35

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Update

I made elasticity variable. Now the example can show perfectly inelastic collisions to perfectly elastic collisions, so the file name had to change.

Ball Collisions

08-12-2004 22:41

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

Great physics job!

Wow! I'm impressed! That sure wasn't easy!

It's really a great physics+coding exercise, isn't it? Makes your brain work but when you get it working it's o-so-cool!

Unfortunately this really is the example where TNT gives off a *terrible* performance: you would have MUCH better results using sprites.

While TNT is pretty fast at moving sprites, scaling, rotating and transparencies, it's INCREDIBLY slow at drawing operations, such as drawing circles.

I did about the same program in C with Allegro:

On a 300 MHz Pentium2 I would get about 70 FPS with 300 balls with radius 20 bouncing around... that sure was cool :-)


You know what's the next step? Putting gravity between balls!

I did that , I had about 100 coloured little balls twirling around in galaxy-like shapes... really great screensaver, but there are some problems in the physics that I could not manage to avoid, due to the discrete time approximations.

If you ever find a PC you can check it at

http://www.radicalrebound.com/particles.zip

08-12-2004 22:58

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

Oh, and great coding and explainations!

08-12-2004 23:20

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Thanks. =) Yes, it was a good exercise. It felt really good when I got it to work.

I wish I could see 200 balls bouncing around, each affected by the gravity of the rest. Sounds chaotic.

Yeah, so there you go Fischgurkensenf. Hope it helps.

08-13-2004 14:34

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

Great!!!! I'll include it in my code!

Thank you all, I never could do that (now)!

08-13-2004 18:01

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

awww.... now I have another problem. I changed the code a bit so it works with sprites.

How can I do it with shapes that aren't perfectly round? I don't want to have perfect physics, but the sprites don't move smooth THIS way: (Test it with a sprite that doesn't have a round shape, or a nearly round shape)

Look at the "here I have problems" part.

Thank you :-)

'-----------------------------------------------------------------------------------
'Ball Collisions
'Eric Doi (eekaydee)
'edoi@charter.net
'8-12-04

'This example shows the relationship between mass, velocity, elasticity, point of contact,
' conservation of energy, and conservation of momentum in ball collisions.

'Thanks to Matteo for the code that this was built from.

'Controls
' Arrow keys -accelerate the highlighted ball
' Spacebar -switches the ball you control
' "s" key -slows down the speed of each ball.
' Mouse click -slows the game down
'-----------------------------------------------------------------------------------


'_____Setup_________________________________________________________________________

graphics mode 640,480
set framerate 60
set pen color white
paint canvas
load images 128

int numOfBalls=5 'Change this to add more balls. Just be sure to specify the starting position, mass, and radius for each ball.

int elasticity=0.99 'Elasticity is a value from 0 to 1: 0 will result in perfectly INELASTIC collisions (masses stick together), and a value of 1 will result in perfectly ELASTIC collisions


float X[numOfBalls],Y[numOfBalls]
float Vx[numOfBalls],Vy[numOfBalls]
float M[numOfBalls]
float radius[numOfBalls]

'_____Initial Values Make sure to add more for each ball you add. _______________

int n
for n=0 to numOfBalls-1
x[n]=random(0,640)
y[n]=random(0,480)
sprite n,x[n],y[n],0
while sprite col(n,0 to numofballs)<>-1
x[n]=random(0,640)
y[n]=random(0,480)
sprite n,x[n],y[n],0
draw frame
wend
radius[n]=random(5,15)
m[n]=radius[n]*2
next n


'_____Game Loop_____________________________________________________________________

int control
repeat
int key=raw key scancode(keyboard raw key)

'Controls
if key=49 then control=wrap(control+1,0,numOfBalls-1) 'spacebar changes control ball index
if mouse button then delay 100 'pause on mouse button
if up then Vy[control]=Vy[control]-0.5
if down then Vy[control]=Vy[control]+0.5
if left then Vx[control]=Vx[control]-0.5
if right then Vx[control]=Vx[control]+0.5
if pressed(1) 's key slows down the velocities each frame
int stopCount
for stopCount=0 to numOfBalls-1
Vx[stopCount]=Vx[stopCount]/1.1
Vy[stopCount]=Vy[stopCount]/1.1
next stopCount
end if

int a,b
for a=0 to numOfBalls-1
for b=0 to numOfBalls-1
if b>a 'only check combinations that haven't been checked yet; for example, there's no need to check (0,1) and then (1,0).
float xDiff=X-X[a]
float yDiff=-(Y-Y[a])
float distance=sqrt(xDiff^2+yDiff^2)


if sprite col(a,b)=b 'if balls a and b are touching

'find angle between balls
if xdiff>=0 then float diffdir= invtan(ydiff/xdiff)
if xdiff<0 then float diffdir= invtan(ydiff/xdiff)+180

float dVx=Vx[a]-Vx
float dVy=-(Vy[a]-Vy)

float totVel=sqrt(dVx^2+dVy^2)

if totVel>0
if dVx>=0 then float veldir =invtan(dVy/dVx)
if dVx<0 then float veldir = invtan(dVy/dVx)+180

'the impulse is the amount of transferred momentum. The impulse can only be transferred along the point of contact.
float impulse=(1+elasticity)*(M[a]*M)/(M[a]+M)*totVel*cos(veldir-diffdir)

float VxfA=-impulse*cos(diffdir)/M[a]+Vx[a]
float VyfA=impulse*sin(diffdir)/M[a]+Vy[a]
float VxfB=impulse*cos(diffdir)/M+Vx
float VyfB=-impulse*sin(diffdir)/M+Vy

Vx[a]=VxfA
Vy[a]=VyfA
Vx=VxfB
Vy=VyfB
end if

if sprite col(a,b)=b 'here I have problems
x[a]=x[a]+vx[a]
Y[a]=Y[a]+Vy[a]

x=x+vx
Y=Y+Vy

sprite a,x[a],y[a],0
sprite b,x,y,0
end if
end if
end if
next b
next a

for a=0 to numOfBalls-1

X[a]=X[a]+Vx[a]
Y[a]=Y[a]+Vy[a]

x[a]=wrap(x[a],0,640)
y[a]=wrap(y[a],0,480)

sprite a,x[a],y[a],0
next a

draw frame

until pressed(12)

08-13-2004 22:20

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

One thing is that you should show signs of mass and radius. The game might work oddly if the radius is random but the sprites are always the same size. In other words, enter the image's actual radius.

08-13-2004 22:40

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Oh, and your problem (sorry): you should leave that problem section out. If you look at the next loop, you are already applying the velocity, so just delete this whole "if" block:

quote:

if sprite col(a,b)=b 'here I have problems
x[a]=x[a]+vx[a]
Y[a]=Y[a]+Vy[a]

x=x+vx
Y=Y+Vy

sprite a,x[a],y[a],0
sprite b,x,y,0
end if



One more thing. I noticed that you removed the dX and dY parts. That is the cause of the strange sticking of the sprites.

08-14-2004 07:27

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

So.. I included the dx and dy part again and don't use the if part.

But the problem is: the "radius" of the sprite isn't equal everywhere if the sprite isn't perfectly round. if I use a radius bigger than the sprite is, the sprites move back a little bit each time they collide. If I use a smaller radius, the sprites "stick"....

So I think it would be good if they are as far away to each other as they collided.

08-14-2004 18:15

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

I found that it is much faster if I use "if sprite col(a,0 to numofballs-1)<>-1" than the complex "for a" and "for b" loops...

but how do I have to change the code that it works with this?
b=sprite col(a,0 to numofballs-1)
doesn't work.....

I hope you're understanding me!

08-14-2004 19:40

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

b=sprite col(b,0 to numofballs-1)

but you still need to check that b>a

As for the shapes...well, it would be terribly hard to make it work correctly with irregular shapes. If you used vector graphics, then it would be easy, but you're using sprites. You would have to somehow find the radius at every possible angle, either pre storing it or using some kind of pixel reading of the image.

08-15-2004 00:10

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

You would also have to do a lot of other things... such as finding the inclination of the tangent when two shapes touch... remember impulse can only be given in the direction perpendicular to the tangent. morever if this direction does not pass through the baricenter you get also a rotational effect!

Now, here's a nice exercise: collisions between "sticks" floating in the void!!! So you must find also the rotational effect!

And finally sticks and balls!!

Then sticks ovals and rectangles!

yh

08-15-2004 08:41

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

O.O

I'm sorry, but I REALLY can't understand you.... I'm speaking german and I'm going to school (8th class) and we don't have physics like THAT...

But I try to do my best :-)

08-15-2004 10:30

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

the main point is that if you are not happy with collisions between circles, then it's going to be a LOT of work...

08-15-2004 10:51

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

Yes, I understood that.

or a code could be: (first draw the sprite on a white canvas)

for n=0 to 100
if pixel color (sin(anglebetweenobjects)*n,cos(anglebetweenobjects)*n)<>white
radiusYouUseThisTime[a]=radiusYouUseThisTime[a]+1
end if
next n


I..... think.... it could work....maybe?

08-15-2004 14:25

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Actually that is pretty much what I meant. Good job. Dunno how fast it would be, but I think it could work.

08-21-2004 16:01

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

new example out

here you can find a new example:

ibd.yuccatree.org/files/asterom.sit

Tell me what you think about it. I think it works fine. Maybe there are some small bugs. (?)

-IBD

08-21-2004 16:08

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

ahhhhh... the link doesn't work, but that doesn't matter. just type it in.

08-21-2004 16:31

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

Gorgeous!

08-21-2004 17:06

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

gorgeous=herrlich!!!

Thanks. Nice to hear that. Maybe it will become a game sometime... I'm working on it.

08-21-2004 19:00

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

correct link

test:

http://ibd.yuccatree.org/files/asterom.sit

http://ibd.yuccatree.org/files/asterom.sit

08-21-2004 22:14

Posted by:
Stephen Lund

Location:
Michigan USA

Click Here to Email Stephen Lund   Find more posts by Stephen Lund

Nice! example,


Great example, maybe if you put a little more programming in to it, you could make a really COOL game,

Awesome example,

Stephen

08-22-2004 00:43

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Wow, that does look nice. A lot of pre rendering though huh?
The collisions look fine; the shapes are more or less spherical, so it's not a noticable problem I guess. Good job.

I really like the parallax scrolling of the stars though...simple I suppose, but it looks awesome.

08-22-2004 09:29

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

Thank you.

I'm working on a new example with 3 different types of meteors...

08-24-2004 17:07

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

now I have another problem. hope you can help me.

How can I check if it's POSSIBLE that the two sprites collided? sometimes they're in each other after they collided and then change their speed again. So they move together (because it's a realistic calculation) and then move again out. and then in,out,in,out...... and so on. How can calculate if they are moving TOGETHER???

please help, and soon you can get the new example ;-)

I think my code is very long, about 900 lines only for some physics. hope i can optimise it a bit. But first I need your help. Matteo and eekaydee, I'm waiting!

08-27-2004 14:09

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

HA!!!

I've just come to chicago a days ago... from italy... I'll be staying here 4 years for a PhD... I'm sorry but now I will have to use all my energy in an effort to survive, sorry, now it's all on your back eekay...

08-27-2004 14:13

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

oh, maybe I got the problem: you have to separate the objects!!! if you don't separate the objects after collision you risk that they touch again the next frame... understood?

08-28-2004 18:24

Posted by:
Stephen Lund

Location:
Michigan USA

Click Here to Email Stephen Lund   Find more posts by Stephen Lund

Why don't you put you example it the TNT Directory,

Stephen

08-28-2004 18:32

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

matteo: I allready separate the sprites after they touched. I'm working on a fix. I think I'll release the demo next week.

stephen: Good idea. But I wait until I finished the version with 3 different rocks. The example is getting big, it's about 1.4 MB.

08-28-2004 19:35

Posted by:
Stephen Lund

Location:
Michigan USA

Click Here to Email Stephen Lund   Find more posts by Stephen Lund

Are you turning it in to a game, are you going to make it so you can shot at the rocks,

Stephen

08-29-2004 11:49

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

Yes. In the example you won't be able to shoot.

09-05-2004 14:20

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

ALOHA!

Hey! I'm back from Hawaii! I love island time.

Wow matteo, a PhD? Awesome. What in?

Fitz, I think matteo's right...you gotta separate the objects once you know they collided. If it's not working, maybe you're not separating them enough.

09-05-2004 15:44

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

I SEPERATE THE ROCKS!!!!

The problem is that they rotate... if they rotate and the radius from the centre to the out is higher than in the previous frame, they "stay" in the each other...

But....... Collisions in my example are seldom, and the problem above happens to 5%... I don't fix the problem... And I post the game NEXT friday ;-), I forgot it...

09-07-2004 17:22

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

>The problem is that they rotate... if they rotate and the radius from the centre to the out is higher than in the previous frame, they "stay" in the each other...

Hmmmm... that's interesting... well you can separate them a bit more anyway...

Wow eekay, how's hawai? there must be some great surfin' there!! Maui & sons...

I've just started doing a PhD in mathematical economics at northwestern university... much less exciting than hawai I guess, but I guess there are many more boring jobs...

I'm a bit worried of the cold of the winter and of the load of work they might put on us... Usually I manage to study much less than my companions, let's see if I can do it also here...

But everyone here cites najorf's law: "It will be much harder than you expect, even if you take into account najdorf's law..."

huh, god knows what this year is gonna be like...

09-07-2004 18:12

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

Separating them "a bit more" won't do it, it looks like popping...It doesn't matter.... Collisions aren't often.


Off Topic: Najdorf (matteo), can you give me a good c/c++ tutorial to start with? I'm interested if I can do the same things with c++ as with tnt...... You said you "are on c". I look at the iDevGames forum, too.

09-08-2004 17:33

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

Hmmm...

As far as I understood you can use C almost exactly as you use TNT, i.e. using global variables to store information that must be passed from one function to another and to pass values inside functions.

Learning to use C this way is just a matter of getting used to putting ";" at the end of every line and a few minor differences in the sintax of "for", "if"...

The main problem for me was to see something in action from the start, otherwise I would just get bored:

In order to create a window, draw graphics and handle input you need some library: If you manage to get it working on X(ask on idev) Allegro is quite powerful and relatively simple (but dont expect tnt...)

Now what is the problem? Libraries use some things that are not in TNT and you must learn roughly (although then you can decide not to use much), such as structs and pointers.


Anyway the real hard part is actually getting one compiler+IDE+library that you manage to make work...

then learn about structs and pointers

then start using the library to make something pretty.

that's it

09-08-2004 18:02

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

In a week or two, I'll get Xcode, so that is the compiler I need...

I allready looked "over" a tutorial about c/c++, and I think I got some things, but I still have to learn a bit more.

Do you know something about "simple media direct layer"??? Some people recommend this...

Allegro seems to be easy enough for me......

What about opengl? Is it too hard?

We ( I ) could open a new thread about this, it's going OT.

09-08-2004 22:52

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

the hard bit i found about learning Object-Oriented languages is about creating your own classes. i mean, in tnt, if you want a sprite, juste write sprite. In OOP, you have to code this function yourself. It's not that hard, it's just that you don't make it like in TNT ( i mean, i downloaded TNT and two hours later i have done a quarter of Hubbub ) you'll spend time writing functions ( and rewriting them as you get better and realise they really sucked! )

good luck
my personnal favorite language is Java, it's Cross-Platform ( OS X users run withouth any problems, other platforms need to download plug-in ) and it's almost as fast as C with a very similar coding ( don't believe people saying it's really slow, it has gotten a lot betteer among the years )

09-08-2004 23:35

Posted by:
Stephen Lund

Location:
Michigan USA

Click Here to Email Stephen Lund   Find more posts by Stephen Lund

example

Hi,

How is your example coming?

Steve

09-11-2004 15:27

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

FINALLY: NEW EXAMPLE OUT!!!

So.....

My example is out, you can download the source code here:
http://ibd.yuccatree.org/files/space_example.sit
The builded version is here:
http://ibd.yuccatree.org/files/space_example_build.sit

Tell me what you think about the graphics/the coding!!!

Q: Why didn't you release the example some weeks earlier?
A: My problem is that I code the example on one Mac and upload it on another. So I just FORGOT it 2-3 times to load the code from one computer to the other, and then upload it. *hits himself* :-D

09-15-2004 10:34

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

:-(

Nobody wants to test my example or give a feedback??? Where are the other TNT users gone?

-IBD

09-15-2004 15:43

Posted by:
Stephen Lund

Location:
Michigan USA

Click Here to Email Stephen Lund   Find more posts by Stephen Lund

sorry

It's really cool,

Are you tuning it in to a game, mabe when you shot the meteorites they will explode in to a bunch of little ones,

Cool,
Stephen

09-15-2004 15:47

Posted by:
Fischgurkensenf

Location:
Bern, Switzerland

Click Here to Email Fischgurkensenf   Find more posts by Fischgurkensenf

@stephen: Yes, that's what I'm up to. Do you know "theZone" (or maybe "the zone")??? That's the style I want to get. perhaps there also are some parts of "asterax". Thanks for your feedback.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.