Posted: Wed Feb 25, 2004 7:01 pm Post subject: star field
I dont know if anyone previously did this, but this is a
program that makes stars move on the randomly and you can change the direction of the stars movement. You can also change the speed of the star movement with ALT and CTRL.
Posted: Wed Feb 25, 2004 7:06 pm Post subject: (No subject)
Pretty good, its gets flashy though, if you slow it down.
omni
Posted: Wed Feb 25, 2004 7:11 pm Post subject: (No subject)
ya i don't know how to get it a smooth animation and the ability to handle more stars. (it gets a lot slower with more stars)
Paul
Posted: Wed Feb 25, 2004 7:15 pm Post subject: (No subject)
Here, use View.Update, its ezness:
try this code, looks much better, with only 2 added lines
code:
%Jeffery Liu
setscreen ("graphics:787;541,nobuttonbar")
setscreen ("offscreenonly")
var x, y, c : int
var jeff : string (1)
var key : array char of boolean
var xchange, ychange : int
xchange := 1
ychange := 0
put "Move stars with arrow keys, "
put "Speed up with ALT "
put "Slow down with CTRL "
put "Press the any key .."
getch (jeff)
var xstars, ystars : array 1 .. 15 of int
for a : 1 .. upper (xstars)
randint (x, 0, maxx)
randint (y, 0, maxy)
%randint (c, 0, 255)
xstars (a) := x
ystars (a) := y %initializing the arrays
end for
drawfillbox (0, 0, maxx, maxy, black) %the screen is now black
var speed : int := 2
loop
Input.KeyDown (key)
if key (KEY_LEFT_ARROW) then
xchange := -1
ychange := 0
elsif key (KEY_RIGHT_ARROW) then
xchange := 1
ychange := 0
elsif key (KEY_UP_ARROW) then
xchange := 0
ychange := 1
elsif key (KEY_DOWN_ARROW) then
xchange := 0
ychange := -1
elsif key (KEY_ALT) then
if speed > 0 then
speed := speed - 1
end if
elsif key (KEY_CTRL) then
if speed < 10 then
speed := speed + 1
end if
end if
exit when key (KEY_ESC)
delay (speed)
for count : 1 .. upper (xstars) %drawing all the stars
drawstar (xstars (count), ystars (count), xstars (count) + 10, ystars (count) + 10, white)
end for
View.Update
for count : 1 .. upper (xstars) %erasing the stars
drawstar (xstars (count), ystars (count), xstars (count) + 10, ystars (count) + 10, black)
end for
for count : 1 .. upper (xstars) %increasing the coordinates of the stars
ystars (count) := ystars (count) + ychange
xstars (count) := xstars (count) + xchange
end for
for count : 1 .. upper (xstars)
if xchange = 1 then
if xstars (count) > maxx then %checking if stars hit right boundary
ystars (count) := Rand.Int (0, maxy)
xstars (count) := 0
end if
elsif xchange = -1 then
if xstars (count) < 0 then %left side
ystars (count) := Rand.Int (0, maxy)
xstars (count) := maxx
end if
elsif ychange = 1 then
if ystars (count) > maxy then %top
xstars (count) := Rand.Int (0, maxx)
ystars (count) := 0
end if
elsif ychange = -1 then
if ystars (count) < 0 then %bottom
xstars (count) := Rand.Int (0, maxx)
ystars (count) := maxy
end if
end if
end for
end loop
omni
Posted: Wed Feb 25, 2004 7:19 pm Post subject: (No subject)
thanks
jonos
Posted: Wed Feb 25, 2004 8:13 pm Post subject: (No subject)
nice looking program
shorthair
Posted: Wed Feb 25, 2004 8:21 pm Post subject: (No subject)
I like it , and its got some nice clean code , keep up your good work , and look into smoother animation for best results
apomb
Posted: Wed Feb 25, 2004 9:19 pm Post subject: (No subject)
I also like it ... using cls instead of redrawing the stars in black, and seting the background color to black, it is also less choppy ...quite neat code as well! nicely done
Sponsor Sponsor
omni
Posted: Thu Feb 26, 2004 12:45 pm Post subject: (No subject)
for some reason when I add the view.update, it moves slower. Is this normal, or is it my computer?
recneps
Posted: Thu Feb 26, 2004 3:45 pm Post subject: (No subject)
Thats normal, just lower delays
Cervantes
Posted: Thu Feb 26, 2004 6:25 pm Post subject: (No subject)
if you do what compwizz suggests and not redraw the background with a huge rectangle then you need to do the following
code:
colourback (color#)
%then whereever you want...
cls
Jodo Yodo
Posted: Sat Mar 06, 2004 10:57 pm Post subject: (No subject)
Purdy Stars
jonos
Posted: Sat Mar 06, 2004 10:59 pm Post subject: (No subject)
this topic is old, you didn't need to bring it up. but then again i brought back up two of the oldest, but my actions were justified because they were the oldest posts.
MacDaddyM
Posted: Mon May 17, 2004 5:17 pm Post subject: (No subject)
nice
omni
Posted: Tue Jun 15, 2004 3:56 pm Post subject: (No subject)
Made the animation smoother, by putting in View.Update.
Also added 3 layers. Ex: there is a background layer of stars that dont move that fast(dark colour), middle layer of stars that move and a top layer of stars that move fast(bright colour). I practiced the use of records in this program. Controls are still same.
Help on more efficient way of checking if the stars hit boundaries ?