Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: gooner on July 11, 2008

Title: Gooner bounce
Post by: gooner on July 11, 2008
With all you guys help i'm starting to get the hang of this.Although i haven't come into coding via the orthodox route i'm determined to make up for lost time.Shockwaves busy as we speak coming up with new challenges for me so no time to relax.

 :) :updance: :)
Title: Re: Gooner bounce
Post by: Xalthorn on July 11, 2008
That's really cool :)

You might want to check the high X bounce check as it seems to be a little off the edge.  This is only a minor point though, the thing works, it works smoothly, and I love what you've done with the colour and size change.

Whilst you're playing with circles, have you thought about having them bounce with gravity?  Or make them flow up the screen like bubbles?  They are both (relatively) gentle advances from what you've done already and if you get that to work, you could even make them bounce off each other (more complicated but so nice to watch).

Bring on more interpretations of Shocky's challenges :D
Title: Re: Gooner bounce
Post by: Clyde on July 11, 2008
Welldone on your efforts mate :)
Title: Re: Gooner bounce
Post by: rain_storm on July 11, 2008
Nice effort youre picking this all up very fast. cant wait to see a starfeild or some other effect
Title: Re: Gooner bounce
Post by: benny! on July 12, 2008
Good looking effect. The resizing fx is very cool.
Title: Re: Gooner bounce
Post by: gooner on July 13, 2008
Thanks everybody for their nice feedback. Hoping this week to get my head around some more complex routines this week including starfields gravity and gradients.Looking forward to your suggestions and any tips.Thanks again for your support.
 :cheers:
Title: Re: Gooner bounce
Post by: rain_storm on July 13, 2008
If you want to I could write up some simple starfeild effect and you could try to make the starfeild scroll about the screen. This will introduce you to arrays and loops which are the next step beyond variables. Unless of course shockwave has already got some challenge laid out for you
Title: Re: Gooner bounce
Post by: gooner on July 13, 2008
@rain_storm
Even though i'm in a privellage position to know Shockwave personally i truly do appreciate any routines you submit that help me.Its because people like yourself on this forum that motivates me to keep learning.
Title: Re: Gooner bounce
Post by: rain_storm on July 14, 2008
Okay you have seen how you can use variables to move a point around the screen. Last time if the point reached an edge you made the point move in the opposite direction. This time when you will be moving lotsa stars. There is an empty loop near the end, in this loop you will treate the arrays StarX(s) and StarY(s) the same way that you were moving X1,Y1,X2 and Y2 last time but this time you will do it in a loop the code is commented but if you need something explained like what a loop is then you know where to ask.

The screen is 800 pixels wide and 600 pixels high. You only have to move the stars along one axis (left -> right or top->bottom) any time a star reaches the last edge it must be replotted on the opposite edge.
Here is the starfeild take your time looking at the arrays StarX(),StarY() see how similar they are to variables then have a go at moving them around and checking their new positions. The for loop and array is a powerful combination so get to know them

Code: [Select]

 ' OPEN A SCREEN 800 PIXELS WIDE 600 PIXELS HIGH
 SCREEN 19,,2,

 ' DECLARE VARIABLES THAT WILL BE USED (REQUIRED BY MY VERSION OF FB NOTHING TO WORRY ABOUT)
 dim as integer Stars = 255 ' Number of Stars
 dim as integer ResX = 800 ' Screen Width
 dim as integer ResY = 600 ' Screen Height
 dim as integer size = 1 ' initial size of the sparkle for all stars
 dim as integer s ' s will be used as the loop counter its initial value is undefined

 ' DECLARE ARRAYS THAT WILL BE USED (REQUIRED BY MY VERSION OF FB NOTHING TO WORRY ABOUT)
 dim as integer StarX(Stars), StarY(Stars) ' these arrays are for X,Y co-ordinates. Both arays
                                           ' have a number of indexes equal to the value of Stars




 ' Start a Loop we will use its counter (s) as an index into the arrays
 ' counter starts at value 1 and increases by 1 with each run through the loop
 ' the loop terminates when the counter is greater than the value of Stars
 For s = 1 to Stars
     StarX(s) = ResX*rnd(1) ' random gives a fraction between 0.0 and 1.0 multiply this by screen width
     StarY(s) = ResY*rnd(1) ' random gives a fraction between 0.0 and 1.0 multiply this by screen height
 Next s ' <- At this point we increase the loop counter and jump to the start of the For-Next loop unless
        ' the counter is larger than the value of Stars (which is 255) in which case execution
        ' 'falls through' (exits the loop and continues execution of code below this point)

 SCREENSET 1,0:' SET WORKPAGE 1, VISIBLE PAGE 0 (DONT WORRY!)


 ' Main Loop ...
 DO
    ' Make stars sparkle ...
    size = size + 1
    If size > 3 Then
        size = 1
    Endif

    ' Draw two diagonal lines to make an effect that looks like a star sparkle
    For s = 1 to Stars
        Line (StarX(s)-size, StarY(s)-size)-(StarX(s)+size, StarY(s)+size)
        Line (StarX(s)+size, StarY(s)-size)-(StarX(s)-size, StarY(s)+size)
    Next s


    '--------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------
    ' Make the stars scroll from left to right This part I leave to you but here is something to work with
    For s = 1 to Stars
        ' Move each star around the screen
        ' Check if any star has been moved past the edge of a screen
        ' and if that is the case reposition the star at the other edge of the screen
    Next s
    '--------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------


    SCREENCOPY ' UPDATE SCREEN WITH NEW IMAGE
    SLEEP 40 ' WAIT FOR A SHORT TIME FOR SCREEN UPDATE TO COMPLETE THIS AVOIDS FLICKER
    CLS ' CLEAR THE SCREEN SO THAT WE CAN DRAW THE NEXT IMAGE
LOOP UNTIL INKEY$<>"" ' ETERNAL LOOP UNTIL USER PUSHES ANY KEY
Title: Re: Gooner bounce
Post by: stormbringer on July 14, 2008
good good good! go with 2d starfields and maybe some bouncing raster bars???
Title: Re: Gooner bounce
Post by: gooner on July 14, 2008
Thanks Rainstorm k+ for that mate.I completed your challenge and modified it slightly to
also incorparate some of the stuff Shockwave taught me Saturday.Its good to have the benefit of both your experiances to call upon.Keep the challenges coming.Cheers mate
 :cheers:
Title: Re: Gooner bounce
Post by: benny! on July 14, 2008
@gooner:
Sweet FX! Very well done.

@2D-starfield:
Little hint: when you do a standard 2D starfield - let's say from left to right -
you can add a more realistic fx when you draw e.g. 3 different kind of stars
to immitate a 3dimensional fx.

Stars in the front:
- move 3px from left to right each round
- have a brighter color (eg.#ffffff)
- are bigger (eg. 2px x 2px)

Stars in the middle:
- move 2px from left to right each round
- have a medium color (eg #aaaaaa)
- 1px x 1px

Stars in the background:
- move 1px from left to right each round
- have dark color (eg #666666)
- 1px x 1px (appear smaller because of darker color)

Title: Re: Gooner bounce
Post by: gooner on July 14, 2008
Thanks for the tips Benny top stuff.I will have a play around with it and upload it when done.Cheers mate :)
Title: Re: Gooner bounce
Post by: rain_storm on July 14, 2008
That was fast and you put in a scroller too :D Well karma for doing such a good job
Title: Re: Gooner bounce
Post by: Shockwave on July 14, 2008
Someone's been a busy fellow!

Well done mate!