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.


Topics - Emerov

Pages: [1]
1
Axe / Scaling Vectors Help
« on: June 04, 2012, 09:40:29 pm »
OK, so I have a golf-ish game where there is a ball that moves around the screen with separate x and y velocities which vary based on an angle chosen before the ball is hit. This all works perfectly fine, the ball bounces off the walls, etc. But when I try to apply friction to the ball's movement, I encounter some issues.

The process I am using to scale down my velocity vector while maintaining the same angle of motion is as follows:
   1. Find the magnitude of the vector
   2. Normalize the vector
   3. Decrease the value of the magnitude by a friction constant
   4. Multiply x and y velocity components by the new magnitude
My code looks like this:
Code: [Select]
.PUTTPUTT
P*16**cos(θ)->V             //P represents power, used to determine how fast the ball will move
P*16**sin(θ)->W             //V is the X-velocity; W is the Y-velocity
Repeat getKey(15)
 Pt-On(X+V->X/256, Y+W->Y/256, Pic0)     //X and Y are the position components
 127*W//sin(tan-1(V,W))->M               //M is the magnitude of the velocity vector
 M-F*W//M->W                //F is the friction constant. I multiply the new magnitude by each component before dividing by the current magnitude
 M-F*V//M->V                //because W//M would give a value of 0
 If X/256>90
  -V->V
 End
 If Y/256>59
  -W->W
 End
 DispGraphClrDraw
End

Depending on P and θ, the code may or may not work, and I can't figure out why; the ball does seemingly random stuff, often not even going in the right direction. ???
Also, I don't know if this is relevant, but when I debugged the magnitude, it changed whenever the ball bounced off the left or right of the screen, which I don't think should be happening.
Can anybody help me fix this?

2
Axe / Using tokens and strings together
« on: April 20, 2012, 03:07:40 am »
I'm attempting to access arbitrary OS vars from the calculator, and subsequently delete them. The code works with programs, groups, appvars, and letters, but whenever I try to access the vars represented by tokens, it does not work properly. Basically, I copy the randomly selected var name over into another string so that I can delete it, but the string doesn't seem to recognize the tokens following the first one. Here is my code (simplified):
Code: [Select]
.DELSUB2
Fix 5
"var "->Str3
"ABCDEFGHIJKLMNOPQRSTUVWXYZØ"->Str5
"L1L2L3L4L5L6"->Str6
"  "->Str8
sub(LSD)
Return

Lbl LSD                             //This will only ever delete L1. If the randomly selected number is not 0, then nothing will happen
Copy(rand^6*2+Str6,Str8,2)
DelVar Str8
Return

Lbl ABC                             //This works
Copy(rand^27+Str5,Str3+1,1)
DelVar Str3

Is there a way to get around this lack of string support for tokens? Like, can these variables be accessed via hex code or something? Thank you!

Pages: [1]