Circular rope
Author |
Message |
The_Bean
|
Posted: Tue Nov 18, 2008 10:07 pm Post subject: Circular rope |
|
|
A rope tied at each end that you can manipulate and move around the screen.
Theres a problem with opposite side of the rope that your moving, it tries to go both ways , and splits apart.
To manipulate it, click and hold on a circle and move it around.
To increase or decrease the size of the rope, edit the variable points.
Turing: |
View.Set ("graphics:500,500;nobuttonbar;offscreenonly;position:center,center")
type specs :
record
x, y : real
ox, oy : real
dx, dy : real
s, a : real
r : int
end record
var points : int := 100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% only use even numbers
var uBound : int := points - 1
var p : array 0 .. uBound of specs
var xm, ym, bm : int
var lead : int := 0
function setAngle (x, y : real) : real
if x = 0 and y = 0 then
result 0
elsif x = 0 and y > 0 then
result 90
elsif x = 0 and y < 0 then
result 270
elsif y = 0 and x > 0 then
result 0
elsif y = 0 and x < 0 then
result 180
elsif x > 0 and y > 0 then
result arctand (y / x )
elsif x < 0 and y > 0 then
result 180 + arctand (y / x )
elsif x > 0 and y < 0 then
result 360 + arctand (y / x )
elsif x < 0 and y < 0 then
result 180 + arctand (y / x )
else
result 0
end if
end setAngle
proc Reset
for i : 0 .. uBound
p (i ).x := Rand.Int (0, maxx)
p (i ).y := Rand.Int (0, maxy)
p (i ).s := 1
p (i ).r := 3
end for
end Reset
proc Output
cls
for i : 0 .. uBound
Draw.Oval (round (p (i ).x ), round (p (i ).y ), p (i ).r, p (i ).r, 7)
%Draw.Line (round (p (i).x), round (p (i).y), round (p ((i + 1) rem points).x), round (p ((i + 1) rem points).y), 7)
end for
View.Update
end Output
proc SetOld
for i : 0 .. uBound
p (i ).ox := p (i ).x
p (i ).oy := p (i ).y
end for
end SetOld
proc Formation
var fini : boolean := true
loop
fini := true
SetOld
for i : 0 .. uBound
p (i ).a := setAngle (p ((i + 1) rem points ).ox - p (i ).ox, p ((i + 1) rem points ).oy - p (i ).oy )
p (i ).dx := cosd (p (i ).a ) * p (i ).s
p (i ).dy := sind (p (i ).a ) * p (i ).s
if Math.Distance (p (i ).x + p (i ).dx, p (i ).y + p (i ).dy, p ((i + 1) rem points ).ox, p ((i + 1) rem points ).oy ) > p (i ).r + p ((i + 1) rem points ).r then
p (i ).x + = p (i ).dx
p (i ).y + = p (i ).dy
fini := false
end if
end for
Output
exit when fini = true
end loop
end Formation
proc StringMove
var iTemp : int
var nTemp : int
loop
Mouse.Where (xm, ym, bm )
exit when bm ~ = 1
SetOld
p (lead ).a := setAngle (xm - p (lead ).ox, ym - p (lead ).oy )
p (lead ).x + = cosd (p (lead ).a ) * p (lead ).s
p (lead ).y + = sind (p (lead ).a ) * p (lead ).s
for i : lead - points div 2 + 1 .. lead
iTemp := (i rem points + points div 2) rem points
nTemp := (i rem points + points div 2 - 1) rem points
p (iTemp ).a := setAngle (p (nTemp ).ox - p (iTemp ).ox, p (nTemp ).oy - p (iTemp ).oy )
p (iTemp ).dx := cosd (p (iTemp ).a ) * p (iTemp ).s
p (iTemp ).dy := sind (p (iTemp ).a ) * p (iTemp ).s
if Math.Distance (p (iTemp ).x + p (iTemp ).dx, p (iTemp ).y + p (iTemp ).dy, p (nTemp ).ox, p (nTemp ).oy ) > p (iTemp ).r + p (nTemp ).r then
p (iTemp ).x + = p (iTemp ).dx
p (iTemp ).y + = p (iTemp ).dy
end if
end for
for i : lead .. lead + points div 2 - 1
iTemp := (i rem points + points div 2) rem points
nTemp := (i rem points + points div 2 + 1) rem points
p (iTemp ).a := setAngle (p (nTemp ).ox - p (iTemp ).ox, p (nTemp ).oy - p (iTemp ).oy )
p (iTemp ).dx := cosd (p (iTemp ).a ) * p (iTemp ).s
p (iTemp ).dy := sind (p (iTemp ).a ) * p (iTemp ).s
if Math.Distance (p (iTemp ).x + p (iTemp ).dx, p (iTemp ).y + p (iTemp ).dy, p (nTemp ).ox, p (nTemp ).oy ) > p (iTemp ).r + p (nTemp ).r then
p (iTemp ).x + = p (iTemp ).dx
p (iTemp ).y + = p (iTemp ).dy
end if
end for
Output
end loop
end StringMove
Reset
Formation
loop
Mouse.Where (xm, ym, bm )
if bm = 1 then
for i : 0 .. uBound
if Math.Distance (xm, ym, p (i ).x, p (i ).y ) < p (i ).r then
lead := i
StringMove
exit
end if
end for
end if
exit when hasch
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tallguy
|
Posted: Wed Nov 19, 2008 10:23 am Post subject: RE:Circular rope |
|
|
Ha ha, that is so sweet, random but really cool
good job |
|
|
|
|
|
The_Bean
|
Posted: Wed Nov 19, 2008 4:49 pm Post subject: Re: Circular rope |
|
|
Heres a rope with 2 definite ends.
You can change the rope design by changing: lineStyle 1-5
you can change the initial length of the rope by changing: points
'+' key increases the length of the rope
'-' key decreases the length of the rope
' ' to exit
Altered the movement, and allowed it to stay with your mouse unlike the previous version.
Also is much faster and looks better.
Turing: |
View.Set ("graphics:500,500;nobuttonbar;offscreenonly;position:center,center;title:Rope")
type specs :
record
x, y : real
ox, oy : real
dx, dy : real
s, a : real
r : int
end record
var points : int := 200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% starting length
var lineStyle : int := 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Changes design of the rope :
var uBound : int := points - 1 % 1=circles
var p : flexible array 0 .. uBound of specs % 2=link rope
var xm, ym, bm : int % 3=smooth rope
var lead : int := 0 % 4=1+2
var key : array char of boolean % 5=1+3
function setAngle (x, y : real) : real
if x = 0 and y = 0 then
result 0
elsif x = 0 and y > 0 then
result 90
elsif x = 0 and y < 0 then
result 270
elsif y = 0 and x > 0 then
result 0
elsif y = 0 and x < 0 then
result 180
elsif x > 0 and y > 0 then
result arctand (y / x )
elsif x < 0 and y > 0 then
result 180 + arctand (y / x )
elsif x > 0 and y < 0 then
result 360 + arctand (y / x )
elsif x < 0 and y < 0 then
result 180 + arctand (y / x )
else
result 0
end if
end setAngle
proc Reset
for i : 0 .. uBound
p (i ).x := Rand.Int (0, maxx)
p (i ).y := Rand.Int (0, maxy)
p (i ).s := 1
p (i ).r := 3
end for
p (0).x := maxx div 2
p (0).y := maxy div 2
end Reset
proc Output (style : int)
cls
if style = 2 or style = 4 then
for i : 0 .. uBound - 1
for decreasing k : 3 .. 1
Draw.ThickLine (round (p (i ).x ), round (p (i ).y ), round (p (i + 1).x ), round (p (i + 1).y ), k * 2, (3 - k ) + 42)
end for
end for
end if
if style = 3 or style = 5 then
for decreasing k : 3 .. 1
for i : 0 .. uBound - 1
Draw.ThickLine (round (p (i ).x ), round (p (i ).y ), round (p (i + 1).x ), round (p (i + 1).y ), k * 2, (3 - k ) + 42)
end for
end for
end if
if style = 1 or style = 4 or style = 5 then
for i : 0 .. uBound
Draw.Oval (round (p (i ).x ), round (p (i ).y ), p (i ).r, p (i ).r, 7)
end for
end if
View.Update
end Output
proc SetOld
for i : 0 .. uBound
p (i ).ox := p (i ).x
p (i ).oy := p (i ).y
end for
end SetOld
proc Formation
var fini : boolean := true
loop
fini := true
SetOld
for i : 1 .. uBound
p (i ).a := setAngle (p (i - 1).ox - p (i ).ox, p (i - 1).oy - p (i ).oy )
p (i ).dx := cosd (p (i ).a ) * p (i ).s
p (i ).dy := sind (p (i ).a ) * p (i ).s
if Math.Distance (p (i ).x + p (i ).dx, p (i ).y + p (i ).dy, p (i - 1).ox, p (i - 1).oy ) > p (i ).r + p (i - 1).r then
p (i ).x + = p (i ).dx
p (i ).y + = p (i ).dy
fini := false
end if
end for
Output (1)
exit when fini = true
Time.DelaySinceLast (5)
end loop
Output (lineStyle )
end Formation
proc StringMove
loop
Mouse.Where (xm, ym, bm )
exit when bm ~ = 1
p (lead ).x := xm
p (lead ).y := ym
for decreasing i : lead - 1 .. 0
p (i ).a := setAngle (p (i ).x - p (i + 1).x, p (i ).y - p (i + 1).y )
p (i ).x := cosd (p (i ).a ) * (p (i ).r + p (i + 1).r ) + p (i + 1).x
p (i ).y := sind (p (i ).a ) * (p (i ).r + p (i + 1).r ) + p (i + 1).y
end for
for i : lead + 1 .. uBound
p (i ).a := setAngle (p (i ).x - p (i - 1).x, p (i ).y - p (i - 1).y )
p (i ).x := cosd (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).x
p (i ).y := sind (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).y
end for
for i : 0 .. uBound
if p (i ).x > maxx - p (i ).r then
p (i ).x := maxx - p (i ).r
end if
if p (i ).x < p (i ).r then
p (i ).x := p (i ).r
end if
if p (i ).y > maxy - p (i ).r then
p (i ).y := maxy - p (i ).r
end if
if p (i ).y < p (i ).r then
p (i ).y := p (i ).r
end if
end for
Output (lineStyle )
end loop
end StringMove
proc MakeNew (i : int)
p (i ).r := 3
p (i ).a := Rand.Int (0, 360)
p (i ).x := cosd (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).x
p (i ).y := sind (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).y
end MakeNew
Reset
Formation
loop
Input.KeyDown (key )
Mouse.Where (xm, ym, bm )
if bm = 1 then
for i : 0 .. uBound
if Math.Distance (xm, ym, p (i ).x, p (i ).y ) < p (i ).r then
lead := i
StringMove
exit
end if
end for
end if
if key ('+') then
new p, upper (p ) + 1
points + = 1
uBound + = 1
MakeNew (upper (p ))
Output (lineStyle )
loop
Input.KeyDown (key )
exit when not key ('+')
end loop
end if
if key ('-') then
if upper (p ) > 0 then
new p, upper (p ) - 1
points - = 1
uBound - = 1
Output (lineStyle )
loop
Input.KeyDown (key )
exit when not key ('-')
end loop
end if
end if
exit when key (chr (32))
end loop
|
|
|
|
|
|
|
Homer_simpson
|
Posted: Fri Dec 05, 2008 2:17 am Post subject: Re: Circular rope |
|
|
neat, just add a little gravity it'll be sick |
|
|
|
|
|
ecookman
|
Posted: Fri Dec 05, 2008 8:20 am Post subject: RE:Circular rope |
|
|
one of the coolest programs i have seen good job...try to maske it so you contr0ool a central circle nad use the arrow keys to move it and as you move the rope becomes longer and longer |
|
|
|
|
|
SNIPERDUDE
|
Posted: Fri Dec 05, 2008 9:48 am Post subject: RE:Circular rope |
|
|
Haha, how about 3D snake? |
|
|
|
|
|
The_Bean
|
Posted: Fri Dec 05, 2008 1:43 pm Post subject: Re: Circular rope |
|
|
Wow it took a while for someone to comment!
Here it is with some gravity added in, and a new rope style.
The new rope style of 6: it makes a shape pointing in the proper direction, and you can specify the shape and the size of it.
Turing: |
View.Set ("graphics:500,500;nobuttonbar;offscreenonly;position:center,center;title:Rope")
type specs :
record
x, y : real
ox, oy : real
dx, dy : real
s, a : real
r : int
end record
var points : int := 100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% starting length
var lineStyle : int := 6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Changes design of the rope :
var numSides : int := 3 % only for style 6 % 1=circles
var ropeThickness : int := 5 % increase when using style 6 % 2=link rope
var uBound : int := points - 1 % 3=smooth rope
var p : flexible array 0 .. uBound of specs % 4=1+2
var xm, ym, bm : int % 5=1+3
var lead : int := 0 % different shapes
var key : array char of boolean
function setAngle (x, y : real) : real
if x = 0 and y = 0 then
result 0
elsif x = 0 and y > 0 then
result 90
elsif x = 0 and y < 0 then
result 270
elsif y = 0 and x > 0 then
result 0
elsif y = 0 and x < 0 then
result 180
elsif x > 0 and y > 0 then
result arctand (y / x )
elsif x < 0 and y > 0 then
result 180 + arctand (y / x )
elsif x > 0 and y < 0 then
result 360 + arctand (y / x )
elsif x < 0 and y < 0 then
result 180 + arctand (y / x )
else
result 0
end if
end setAngle
proc Reset
for i : 0 .. uBound
p (i ).x := Rand.Int (0, maxx)
p (i ).y := Rand.Int (0, maxy)
p (i ).s := 1
p (i ).r := ropeThickness
p (i ).a := 0
end for
p (0).x := maxx div 2
p (0).y := maxy div 2
end Reset
proc DrawRotatedShape (x, y, size : int, angle : real, sides, c : int)
var nSize : real := Math.Distance (x, y, x + size, y + size )
for i : round (angle - 360 div sides div 2) .. round (angle + 315) by 360 div sides
Draw.Line (round (cosd (i ) * nSize + x ), round (sind (i ) * nSize + y ), round (cosd (i + 360 div sides ) * nSize + x ), round (sind (i + 360 div sides ) * nSize + y ), 7)
end for
end DrawRotatedShape
proc Output (style : int)
cls
if style = 2 or style = 4 then
for i : 0 .. uBound - 1
for decreasing k : 3 .. 1
Draw.ThickLine (round (p (i ).x ), round (p (i ).y ), round (p (i + 1).x ), round (p (i + 1).y ), k * 2, (3 - k ) + 42)
end for
end for
end if
if style = 3 or style = 5 then
for decreasing k : 3 .. 1
for i : 0 .. uBound - 1
Draw.ThickLine (round (p (i ).x ), round (p (i ).y ), round (p (i + 1).x ), round (p (i + 1).y ), k * 2, (3 - k ) + 42)
end for
end for
end if
if style = 1 or style = 4 or style = 5 then
for i : 0 .. uBound
Draw.Oval (round (p (i ).x ), round (p (i ).y ), p (i ).r, p (i ).r, 7)
end for
end if
if style = 6 then
for i : 0 .. uBound
DrawRotatedShape (round (p (i ).x ), round (p (i ).y ), p (i ).r, p (i ).a, numSides, 7)
end for
end if
View.Update
end Output
proc SetOld
for i : 0 .. uBound
p (i ).ox := p (i ).x
p (i ).oy := p (i ).y
end for
end SetOld
proc Formation
var fini : boolean := true
loop
fini := true
SetOld
for i : 1 .. uBound
p (i ).a := setAngle (p (i - 1).ox - p (i ).ox, p (i - 1).oy - p (i ).oy )
p (i ).dx := cosd (p (i ).a ) * p (i ).s
p (i ).dy := sind (p (i ).a ) * p (i ).s
if Math.Distance (p (i ).x + p (i ).dx, p (i ).y + p (i ).dy, p (i - 1).ox, p (i - 1).oy ) > p (i ).r + p (i - 1).r then
p (i ).x + = p (i ).dx
p (i ).y + = p (i ).dy
fini := false
end if
end for
Output (1)
exit when fini = true
Time.DelaySinceLast (5)
end loop
Output (lineStyle )
end Formation
proc Gravity
for i : 0 .. uBound
p (i ).y - = 3
if p (i ).y < p (i ).r then
p (i ).y := p (i ).r
end if
end for
end Gravity
proc StringMove
loop
Mouse.Where (xm, ym, bm )
exit when bm ~ = 1
Gravity
p (lead ).x := xm
p (lead ).y := ym
for decreasing i : lead - 1 .. 0
p (i ).a := setAngle (p (i ).x - p (i + 1).x, p (i ).y - p (i + 1).y )
p (i ).x := cosd (p (i ).a ) * (p (i ).r + p (i + 1).r ) + p (i + 1).x
p (i ).y := sind (p (i ).a ) * (p (i ).r + p (i + 1).r ) + p (i + 1).y
end for
for i : lead + 1 .. uBound
p (i ).a := setAngle (p (i ).x - p (i - 1).x, p (i ).y - p (i - 1).y )
p (i ).x := cosd (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).x
p (i ).y := sind (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).y
end for
for i : 0 .. uBound
if p (i ).x > maxx - p (i ).r then
p (i ).x := maxx - p (i ).r
end if
if p (i ).x < p (i ).r then
p (i ).x := p (i ).r
end if
if p (i ).y > maxy - p (i ).r then
p (i ).y := maxy - p (i ).r
end if
if p (i ).y < p (i ).r then
p (i ).y := p (i ).r
end if
end for
Output (lineStyle )
Time.DelaySinceLast (10)
end loop
end StringMove
proc MakeNew (i : int)
p (i ).r := 3
p (i ).a := Rand.Int (0, 360)
p (i ).x := cosd (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).x
p (i ).y := sind (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).y
end MakeNew
Reset
Formation
loop
Input.KeyDown (key )
Mouse.Where (xm, ym, bm )
Gravity
if bm = 1 then
for i : 0 .. uBound
if Math.Distance (xm, ym, p (i ).x, p (i ).y ) < p (i ).r then
lead := i
StringMove
exit
end if
end for
end if
if key ('+') then
new p, upper (p ) + 1
points + = 1
uBound + = 1
MakeNew (upper (p ))
Output (lineStyle )
loop
Input.KeyDown (key )
exit when not key ('+')
end loop
end if
if key ('-') then
if upper (p ) > 0 then
new p, upper (p ) - 1
points - = 1
uBound - = 1
Output (lineStyle )
loop
Input.KeyDown (key )
exit when not key ('-')
end loop
end if
end if
Output (lineStyle )
exit when key (chr (32))
Time.DelaySinceLast (10)
end loop
|
|
|
|
|
|
|
The_Bean
|
Posted: Fri Dec 05, 2008 1:49 pm Post subject: Re: Circular rope |
|
|
ecookman wrote:
try to maske it so you contr0ool a central circle nad use the arrow keys to move it and as you move the rope becomes longer and longer
Uhhmm what?
Not sure what you mean so heres something to keep you busy.
Turing: |
View.Set ("graphics:max,max;nobuttonbar")
var key : array char of boolean
type specs :
record
x, y : real
a, s : real
end record
var ball : specs
var numSides : int
put "How many sides do u want on the shape (1-12): " ..
get numSides
cls
proc DrawRotatedShape (x, y, size : int, angle : real, sides, c : int)
var nSize : real := Math.Distance (x, y, x + size, y + size )
for i : round (angle - 360 div sides div 2) .. round (angle + 315) by 360 div sides
Draw.Line (round (cosd (i ) * nSize + x ), round (sind (i ) * nSize + y ), round (cosd (i + 360 div sides ) * nSize + x ), round (sind (i + 360 div sides ) * nSize + y ), 7)
end for
end DrawRotatedShape
ball.x := maxx div 2
ball.y := maxy div 2
ball.a := 90
ball.s := 3
loop
Input.KeyDown (key )
if key (KEY_UP_ARROW) then
ball.x + = cosd (ball.a ) * ball.s
ball.y + = sind (ball.a ) * ball.s
end if
if key (KEY_DOWN_ARROW) then
ball.x - = cosd (ball.a ) * ball.s
ball.y - = sind (ball.a ) * ball.s
end if
if key (KEY_RIGHT_ARROW) then
ball.a - = 5
end if
if key (KEY_LEFT_ARROW) then
ball.a + = 5
end if
exit when key (chr (32))
DrawRotatedShape (round (ball.x ), round (ball.y ), 50, ball.a, numSides, 7)
Time.DelaySinceLast (5)
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Homer_simpson
|
Posted: Fri Dec 05, 2008 2:00 pm Post subject: Re: Circular rope |
|
|
neat +100 bits for that |
|
|
|
|
|
drij
|
Posted: Fri Dec 05, 2008 4:17 pm Post subject: Re: Circular rope |
|
|
Very cool.
You know what I think would be an awesome addition to this?
Momentum.
It'd be that much more realistic if one could swing the rope around too. |
|
|
|
|
|
Alexmula
|
Posted: Fri Dec 05, 2008 4:47 pm Post subject: RE:Circular rope |
|
|
very nice chris is that last one for our lop project |
|
|
|
|
|
The_Bean
|
Posted: Fri Dec 05, 2008 5:15 pm Post subject: Re: Circular rope |
|
|
1) Momentum would be hard! But still i might try it.
2) Yes Alex part of it is in the LOP game. For the raft following the boat.
3) Here it is in a Snake game. (Arrow keys/WASD to move)
Turing: |
View.Set ("graphics:500,500;nobuttonbar;offscreenonly;position:center,center;title:Snake Game")
type specs :
record
x, y : real
ox, oy : real
dx, dy : real
s, a : real
r : int
end record
type stats :
record
x, y, r : int
end record
var points : int := 20
var lineStyle : int := 3
var candy : array 1 .. 2 of stats
var mines : array 1 .. 25 of stats
var uBound : int := points - 1
var p : flexible array 0 .. uBound of specs
var xm, ym, bm : int
var key : array char of boolean
var snakeColours : array - 2 .. 0 of int := init (192, 47, 47)
Text.ColourBack (7)
function setAngle (x, y : real) : real
if x = 0 and y > 0 then
result 90
elsif x = 0 and y < 0 then
result 270
elsif x > 0 and y > 0 then
result arctand (y / x )
elsif x < 0 and y > 0 then
result 180 + arctand (y / x )
elsif x > 0 and y < 0 then
result 360 + arctand (y / x )
elsif x < 0 and y < 0 then
result 180 + arctand (y / x )
else
result 0
end if
end setAngle
proc NewLink (i : int)
p (i ).r := 4
p (i ).a := Rand.Int (0, 359)
p (i ).x := cosd (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).x
p (i ).y := sind (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).y
end NewLink
proc SetGoodie (var item : stats )
item.x := Rand.Int (5, maxx - 5)
item.y := Rand.Int (5, maxy - 5)
item.r := 5
end SetGoodie
proc Initialize
p (0).x := maxx div 2
p (0).y := maxy div 2
p (0).r := 10
p (0).a := 90
p (0).s := 1
for i : 1 .. uBound
NewLink (i )
end for
for i : 1 .. upper (candy )
SetGoodie (candy (i ))
end for
for i : 1 .. upper (mines )
SetGoodie (mines (i ))
end for
end Initialize
proc Output
cls
for decreasing k : 0 .. - 2
for i : 0 .. uBound - 1
Draw.ThickLine (round (p (i ).x ), round (p (i ).y ), round (p (i + 1).x ), round (p (i + 1).y ), p (i ).r + k, snakeColours (k ))
end for
end for
for i : 1 .. upper (candy )
Draw.FillOval (candy (i ).x, candy (i ).y, candy (i ).r, candy (i ).r, 42)
Draw.FillOval (candy (i ).x, candy (i ).y, candy (i ).r - 1, candy (i ).r - 1, 0)
Draw.FillOval (candy (i ).x, candy (i ).y, candy (i ).r - 1, candy (i ).r - 1, 1)
end for
for i : 1 .. upper (mines )
Draw.ThickLine (round (cosd (45) * mines (i ).r ) + mines (i ).x, round (sind (45) * mines (i ).r ) + mines (i ).y, round (cosd (235) * mines (i ).r ) + mines (i ).x, round (sind (235) * mines (i ).r )
+ mines (i ).y, 3, 12)
Draw.ThickLine (round (cosd (135) * mines (i ).r ) + mines (i ).x, round (sind (135) * mines (i ).r ) + mines (i ).y, round (cosd (315) * mines (i ).r ) + mines (i ).x, round (sind (315) * mines (i ).r )
+ mines (i ).y, 3, 12)
end for
View.Update
end Output
proc Explosion (x, y : int)
for i : 0 .. 25
Draw.FillOval (x, y, i, i, 32 + i )
View.Update
Time.DelaySinceLast (15)
end for
cls
end Explosion
proc StringMove
Input.KeyDown (key )
if key (KEY_UP_ARROW) or key ('w') then
p (0).x + = cosd (p (0).a ) * p (0).s
p (0).y + = sind (p (0).a ) * p (0).s
if p (0).x + p (0).r > maxx then
p (0).x := maxx - p (0).r
end if
if p (0).x - p (0).r < 0 then
p (0).x := p (0).r
end if
if p (0).y + p (0).r > maxy then
p (0).y := maxy - p (0).r
end if
if p (0).y - p (0).r < 0 then
p (0).y := p (0).r
end if
if key (KEY_RIGHT_ARROW) or key ('d') then
p (0).a - = 2
end if
if key (KEY_LEFT_ARROW) or key ('a') then
p (0).a + = 2
end if
end if
for i : 1 .. uBound
p (i ).a := setAngle (p (i ).x - p (i - 1).x, p (i ).y - p (i - 1).y )
p (i ).x := cosd (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).x
p (i ).y := sind (p (i ).a ) * (p (i ).r + p (i - 1).r ) + p (i - 1).y
end for
end StringMove
proc CheckCollision
for i : 1 .. upper (candy )
if Math.Distance (p (0).x, p (0).y, candy (i ).x, candy (i ).y ) < p (0).r + candy (i ).r then
uBound + = 5
new p, uBound
for k : uBound - 4 .. uBound
NewLink (k )
end for
SetGoodie (candy (i ))
end if
end for
for i : 0 .. uBound
for k : 1 .. upper (mines )
if Math.Distance (p (i ).x, p (i ).y, mines (k ).x, mines (k ).y ) < p (i ).r + mines (k ).r then
uBound - = 5
new p, uBound
Explosion (mines (k ).x, mines (k ).y )
SetGoodie (mines (k ))
exit
end if
end for
exit when i >= uBound
end for
end CheckCollision
Initialize
loop
StringMove
Output
CheckCollision
exit when key (chr (32))
Time.DelaySinceLast (10)
if uBound <= 0 then
exit
end if
end loop
|
|
|
|
|
|
|
|
|