Author Topic: Snow Demo  (Read 7593 times)

0 Members and 1 Guest are viewing this topic.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Snow Demo
« on: January 25, 2014, 08:22:52 pm »
This is a demo of snow falling that I made. Basically, press any key to exit.

There is no melting yet. I'm still working on it.

If you want more information, ask me.

Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Snow Demo
« Reply #1 on: January 25, 2014, 08:33:17 pm »
How do you detect snowflake collision?

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Snow Demo
« Reply #2 on: January 25, 2014, 08:39:21 pm »
I have all of the coordinates in Y.X format (i.e. Y=7 and X=12 would be 7.12), and each time I need to know if a snowflake is in a spot, I check sum(L1=Y+.01X). If it's 1, a snowflake is in that spot.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Snow Demo
« Reply #3 on: January 25, 2014, 08:54:06 pm »
Hmm, you could use a matrix (it uses indices the same as pixel coords or homescreen coordinates, so "Y" then "X").

This way, the program doesn't start to slow down as more snow flakes are added. Basically, just create an 8*16 matrix (it will be huge, being the size of a 128 element list). Then you can just check if a snow flake is already in a spot as if you were reading homescreen coordinates:
Code: [Select]
[A](Y,X

This might speed things up a bit (not sure).

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Snow Demo
« Reply #4 on: January 25, 2014, 08:55:23 pm »
This looked kinda simple, but I liked how it had collision detection for snowflakes.
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Snow Demo
« Reply #5 on: January 25, 2014, 08:59:17 pm »
Hmm, you could use a matrix (it uses indices the same as pixel coords or homescreen coordinates, so "Y" then "X").

This way, the program doesn't start to slow down as more snow flakes are added. Basically, just create an 8*16 matrix (it will be huge, being the size of a 128 element list). Then you can just check if a snow flake is already in a spot as if you were reading homescreen coordinates:
Code: [Select]
[A](Y,X

This might speed things up a bit (not sure).

You're right! Now, it will only take 128 iterations of a For( loop (plus a little bit extra time) to move and display the snowflakes, not to mention to extra size of a matrix! :P

Besides, I think it's pretty fast already.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Snow Demo
« Reply #6 on: January 25, 2014, 09:13:20 pm »
Haha, touché :P

Also, what rules are you using? Like, do you move down 1/2 the time, and move left/right 1/4 of the time?

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Snow Demo
« Reply #7 on: January 25, 2014, 09:17:53 pm »
What I do, in pseudocode:

:If a snowflake can move down,
:Then
::Erase the snowflake there.
::Change the snowflake coordinates to that spot.
::Calculate random direction between left, right, or staying put.
::If the snowflake can move there,
:::Change the snowflake coordinates to that spot.
::Draw the snowflake where it belongs.
:End
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Snow Demo
« Reply #8 on: January 25, 2014, 10:14:31 pm »
Judging by your screenshot, your program would actually run a lot faster with a matrix, since it seems like you are only keeping track of one snowflake at a time. I didn't realize that until just now as I was about to post my attempt x.x Mine handles multiple flakes at a time :/

EDIT: Oops, now I see that it does handle multiple flakes. I am too sleepy.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Snow Demo
« Reply #9 on: January 26, 2014, 01:55:08 am »
I haven't checked both your code, but does your programs run through a list of numbers, looping through it using a For loop? Because the fastest way would probably be to repeat code for each snowflake and use no For loop. It would be a brutal, size-inefficient and bruteforce approach, though (which I think I demonstrated in a TI-BASIC Phoenix clone once, and some people probably remember the infamous screen inverter by Netham45). :P

Code: [Select]
If 1=[A](1,1:Output(1,1+B,"M
If 1=[A](1,2:Output(1,2+B,"M
If 1=[A](1,3:Output(1,3+B,"M
If 1=[A](1,4:Output(1,4+B,"M
If 1=[A](1,5:Output(1,5+B,"M
If 1=[A](2,1:Output(2,1+B,"M
If 1=[A](2,2:Output(2,2+B,"M
If 1=[A](2,3:Output(2,3+B,"M
If 1=[A](2,4:Output(2,4+B,"M
If 1=[A](2,5:Output(2,5+B,"M
If 1=[A](3,1:Output(3,1+B,"M
If 1=[A](3,2:Output(3,2+B,"M
If 1=[A](3,3:Output(3,3+B,"M
If 1=[A](3,4:Output(3,4+B,"M
If 1=[A](3,5:Output(3,5+B,"M

Not that I really recommend doing this, but just in case someone really wanted to make his program as fast as possible at any cost. :P
« Last Edit: January 26, 2014, 02:06:06 am by DJ Omnimaga »
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Snow Demo
« Reply #10 on: January 26, 2014, 08:37:54 am »
Mine draws the flakes when they are newly added at the top of the screen, then it searches the matrix for snowflakes that can move down. It erases those ones and draws their new position.

Also, DJ_O, you didn't need the "1=" part of those If statements.
* Xeda112358 runs

The way I test for flakes that can move is I store the matrix rotated so that column 1 is the first row of snow flakes. Then each snow flake is represented by the column number it is in (so if it is homescreen column 6, it has a 6 in the matrix). My code is then:
Code: [Select]
Matr>list([A],8,L2 ;get the last row
For(A,7,1,-1
Matr>list([A],A,L1
L1*(L1 and not(L2→L3 ;This checks if anything in L1 can move down into L2
;"not(L2" leaves a 0 where there is already a flake, else 1 if empty
;Then "L1 and not(L2" leaves a 1 if there is a snowflake above an empty space
L1-Ans→L1 ;remove the snowflakes that can move down from L1
While max(L3
max(L3→B ;location of the snowflake furthest to the right
0→L3(Ans ;remove the snowflake from L3, the list of moveable flakes
0→[A](B,A ;remove it from the matrix
Output(A,B," ;Erase it
min(16,max(1,B+1-2int(2rand ;randomly move left/right
If L2(Ans ;check if the space is occupied
B
Ans→[A](Ans,A+1 ;write the snowflake to the new coordinate
Output(A+1,Ans,"*
End
L1→L2 ;now This row becomes the new lower row
End

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Snow Demo
« Reply #11 on: January 26, 2014, 09:00:46 am »
Pretty neat little demo here. :)

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Snow Demo
« Reply #12 on: January 26, 2014, 09:07:15 am »
Yup, i like the falling snow too.

Maybe you could speed it a bit up by using axe and make it use pixels, more frequentley, that may look like an epic snow storm IMO :)
« Last Edit: January 26, 2014, 09:07:28 am by Sorunome »

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Snow Demo
« Reply #13 on: January 26, 2014, 11:13:42 am »
Mine draws the flakes when they are newly added at the top of the screen, then it searches the matrix for snowflakes that can move down. It erases those ones and draws their new position.

Also, DJ_O, you didn't need the "1=" part of those If statements.
* Xeda112358 runs

The way I test for flakes that can move is I store the matrix rotated so that column 1 is the first row of snow flakes. Then each snow flake is represented by the column number it is in (so if it is homescreen column 6, it has a 6 in the matrix). My code is then:
Code: [Select]
Matr>list([A],8,L2 ;get the last row
For(A,7,1,-1
Matr>list([A],A,L1
L1*(L1 and not(L2→L3 ;This checks if anything in L1 can move down into L2
;"not(L2" leaves a 0 where there is already a flake, else 1 if empty
;Then "L1 and not(L2" leaves a 1 if there is a snowflake above an empty space
L1-Ans→L1 ;remove the snowflakes that can move down from L1
While max(L3
max(L3→B ;location of the snowflake furthest to the right
0→L3(Ans ;remove the snowflake from L3, the list of moveable flakes
0→[A](B,A ;remove it from the matrix
Output(A,B," ;Erase it
min(16,max(1,B+1-2int(2rand ;randomly move left/right
If L2(Ans ;check if the space is occupied
B
Ans→[A](Ans,A+1 ;write the snowflake to the new coordinate
Output(A+1,Ans,"*
End
L1→L2 ;now This row becomes the new lower row
End

Can you give me the full code?
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Snow Demo
« Reply #14 on: January 26, 2014, 11:37:02 am »
From Source Coder:
Code: [Select]
{16,8->dim([A]
DelVar EE[A]→[A]
ClrHome
2→S
Repeat E>=128 or getKey=45
For(B,1,S
Repeat not([A](Ans,1
randInt(1,16
End
Ans→[A](Ans,1
Output(1,Ans,"*
E+1→E
If E=128
S→B
End
Matr>list([A],8,L2
For(A,7,1,-1
Matr>list([A],A,L1
L1*(L1 and not(L2→L3
L1-Ans→L1
While max(L3
max(L3→B
0→L3(Ans
0→[A](B,A
Output(A,B,"
min(16,max(1,B+1-2int(2rand
If L2(Ans
B
Ans→[A](Ans,A+1
Ans→L2(Ans
Output(A+1,Ans,"*
End
L1→L2
End
End

EDIT: Forgot a line.