Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2012, 12:46 PM   PM User | #31
salutsalut
New to the CF scene

 
Join Date: Nov 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
salutsalut is an unknown quantity at this point
I have found this

Code:
with instance_create(
    x+lengthdir_x(80,image_angle),
    y+lengthdir_y(80,image_angle),obj_bullet)
{
 xspeed=lengthdir_x(10,other.image_angle)
 yspeed=lengthdir_y(10,other.image_angle)
}
or this one

Code:
with instance_create(
    x+lengthdir_x(80,image_angle),
    y+lengthdir_y(80,image_angle),obj_bullet)
{
 xspeed=cos(other.image_angle*pi/180)*10     //convert degrees to radians when using these
 yspeed=-sin(degtorad(other.image_angle))*10 //i think the y component needs to be flipped
}
but I can't match it with your code.
salutsalut is offline   Reply With Quote
Old 11-08-2012, 07:38 PM   PM User | #32
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
*sigh*

Okay look at that code:
Code:
if ( x==0 || x==xmax || y==0 || y==ymax ) 
{ 
    bug.xspeed = - bug.xspeed; 
    bug.yspeed = - bug.yspeed; 
}
That can be read as "if EITHER the x or y position reaches EITHER the smallest or largest allowed value, then reverse the direction of BOTH the x and y movement."

CLEARLY that is NOT what you want. You want to reverse the x direction if x reaches the limits and *separately* reverse the y direction if y reaches the limits.

So very very simply:
Code:
if ( x==0 || x==xmax ) 
{ 
    bug.xspeed = - bug.xspeed; 
}
if ( y==0 || y==ymax ) 
{ 
    bug.yspeed = - bug.yspeed; 
}
TRY IT!
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-09-2012, 12:18 AM   PM User | #33
salutsalut
New to the CF scene

 
Join Date: Nov 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
salutsalut is an unknown quantity at this point
thank you, it works perfectly.

I will learn javascript one day, I promise.

salutsalut is offline   Reply With Quote
Old 11-09-2012, 01:01 AM   PM User | #34
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Now where in the world did you find that picture of me?

Of course, that was taken some time ago, while I still had a little hair on my head. (On the back; it doesn't show in that picture.)

<grin/>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
images, javascript, move, multi, school

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:33 AM.


Advertisement
Log in to turn off these ads.