Vector Particles, Volcano

Previous topic - Next topic

CW

This is just a little thing I threw together in a day. I've been thinking of doing a tank-battle type of game, but I needed a way to set shot angle and power, and than let the program plot the trajectory under gravity from there. Vector math to the rescue! That lead to setting random angles and power levels, and plotting LOTS of projectiles in this little volcano program. How many particles can your rig comfortably maintain? To maximize rendering speed, I do no keyboard or mouse checks. Press Esc to exit, or just wait for the cycle count to complete. Happy Coding!
-CW
Code (glbasic) Select

/////////////////////////////////////////////////////////////////////////
//                             VOLCANO
// Written by Craig Waterman
// 01/25/13
// ----------------------------------------------------------------------
// This project uses vector math to animate a small volcano.

/////////////////////////////////////////////////////////////////////////

////////////////////////////  Initialize  ///////////////////////////////
//
// Change PARTICLE_COUNT to set number of particles to use.
// (Try 0 to 100000, or more. How many can your machine handle?)

CONSTANT PARTICLE_COUNT = 3000

GLOBAL sx,sy
GETSCREENSIZE sx, sy // Volcano is positioned in the center of the screen. (Screen can be resized.)

LOCAL Altitude%,Horizontal_Location%
LOCAL Path$=GETCURRENTDIR$()
LOADFONT Path$+"MyFont1.png",1
SETFONT 1

TYPE Particle
Particle_Number#
X_Velocity = 0.0
X_Birth_Tick# = 0 // Hold the clock tick when a particle is born. Trajectory is based on time from birth.
Y_Velocity = 0.0
Color% = 0.0
ENDTYPE

GLOBAL Particles[] AS Particle,Surge
DIM Particles[PARTICLE_COUNT+1] // Up to PARTICLE_COUNT particles will simultaneously erupt from the volcano.
// Note that the count begins with zero, but the dim needs one extra to properly format.
            // Format: Particles[Particle Number][X_Velocity][Y_Velocity][Color of particle in RGB(value,value,value)]

GOSUB Initialize_Particles
GOSUB DrawLandscape
/////////////////////////////// BODY ////////////////////////////////////////

FOR Tick = 0 TO 1000 //Tick is the number of clock cycles in the full animation.

FOR P_Inumerate = 0 TO PARTICLE_COUNT
Altitude = INTEGER(Particles[P_Inumerate].Y_Velocity*(Tick-Particles[P_Inumerate].X_Birth_Tick));IF Altitude <-13 THEN Altitude = -13
Particles[P_Inumerate].Y_Velocity=Particles[P_Inumerate].Y_Velocity - .32

IF Altitude >-13 // Top of volcano is 13 pixels high, so ground is at -13, and any particle at -13 needs to be reset.
    Horizontal_Location = (Particles[P_Inumerate].X_Velocity*(Tick-Particles[P_Inumerate].X_Birth_Tick) + (sx/2) )
    SETPIXEL Horizontal_Location,400-Altitude,Particles[P_Inumerate].Color
ELSE
Initialize_Particle(P_Inumerate,Tick)
ENDIF
NEXT // P_Inumerate
Surge = Surge + 1

SHOWSCREEN

NEXT // Tick

PRINT "Finished!",sx/2-60,sy/2+75
PRINT "Press Key",sx/2-60,sy/2+100
SHOWSCREEN
KEYWAIT
END
///////////////////////////////////////////////////////////////////
////////////////////////  Functions ///////////////////////////////
// ------------------------------------------------------------- //
// ---  VECTORCOMPONENT  ---
// ------------------------------------------------------------- //
FUNCTION Initialize_Particle: Particle_Num,BirthTick
LOCAL Angle#,Power%
Angle = RND(60)+60
Power = RND(1000)+525+INTEGER(COS(Surge*12)*75) //To add visual interest, I allow the projectile power to surge.
Particles[Particle_Num].X_Velocity = COS(Angle)*Power/100
Particles[Particle_Num].Y_Velocity = SIN(Angle)*Power/75
Particles[Particle_Num].Color = RGB(255,RND(100),255)// Violet color with a random greenish component.
Particles[Particle_Num].X_Birth_Tick = BirthTick
RETURN
ENDFUNCTION // VECTORCOMPONENTX
///////////////////////////////////////////////////////////////////
//////////////////////////  Subs  /////////////////////////////////
// ------------------------------------------------------------- //
// ---  DRAWLANDSCAPE  ---  I like a Minimalist Style.
// ------------------------------------------------------------- //
SUB DrawLandscape:

CLEARSCREEN
DRAWLINE 10,414,(sx-10),414,RGB(0,255,0) // Draw Ground

LOCAL VolcanoColor% = RGB(255,0,0)
DRAWLINE (sx/2-13),413,(sx/2-5),396,VolcanoColor;DRAWLINE (sx/2+13),413,(sx/2+5),396,VolcanoColor // Draw Volcano
DRAWLINE (sx/2-5),396,(sx/2+5),396,VolcanoColor// Draw Volcano
USEASBMP;SHOWSCREEN;SLEEP 500 //Delay .5 seconds to allow user to admire the landscape before the eruption.
ENDSUB // DRAWLANDSCAPE
// ------------------------------------------------------------- //
// ---  INITIALIZE_PARTICLES  ---
// ------------------------------------------------------------- //
SUB Initialize_Particles:
FOR Counter = 0 TO PARTICLE_COUNT
Initialize_Particle(Counter,0)
NEXT
ENDSUB // INITIALIZE_PARTICLES
///////////////////////////////////////////////////////////////////

bigsofty

It's actually a lot of fun to mess around with the parameters of the particles, well done!  :good:
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

spicypixel

Quote from: CW on 2013-Mar-05
This is just a little thing I threw together in a day. I've been thinking of doing a tank-battle type of game

Sounds like someone else enjoyed Pocket Tanks Deluxe a few years back too :)
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

erico

Great coding there! And quite a small list.
Altough I can´t understand much of what is going on... :(

Sys here could manage around 30k particles on full speed. ;)

CW

#4
Thx guys. I'm glad you all enjoyed it. Spicy, I'm afraid I predate Pocket Tanks Deluxe by quite a bit. The first tank battle game I met was way back on the Amiga, and it was love at first first sprite. That game was written in C and had a lot of neat weapons and effects. My favorite tactic was to tunnel under my opponents and rain destruction on them from below. A mountain of dirt makes wonderful armor.  =D  Then WORMS came out, and I absolutely loved Tarzan-ing around the screen, planting wickedly nasty booby-traps, and swinging away before they went off. (Banana-bomb, anyone? Exploding sheep?) I was really into Red Dwarf at the time, and I named all of my worms after that show's main characters. Ah, good times. Good times.

Erico, one of the best ways to learn programing strategies  is to read other peoples code. I'm not the best example to follow. I'm a bit of a hack, and I know it. Without a doubt, I do things every day which make real programers cringe. But if you are interested in seeing how this volcano program works on a nuts-and-bolts level, including what all the math numbers mean, I would be willing to whip up a fully commented version for you. Just let me know.

Let me know also if you have ever worked with vectors. If desired, I can include a little primer on that too. Just enough to understand what this program is doing. Vector math is very powerful. You run into it in College Algebra, Trigonometry, Calc, Physics and Linear Algebra; so if you have had an introduction to it doing something like programing, it can really reduce the math-anxiety that comes with meeting something new, and knowing you are going to be graded on how well you learn.

Happy Coding!
-CW

"No Silicon Heaven?!! Preposterous!! Where would all the Calculators go??" -Kryton XYB-3C, of the mining ship Red Dwarf.

fuzzy70

@CW, The Amiga game in question wouldn't have been "Scorched Tanks" by any chance. Me & a few mates I used to house share with used to have a weekly tournament on that, along with SF2 & Mario Kart on the SNES  :D

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

CW

#6
Right you are Fuzzy! That game was called Scorched Tanks.

Here is a YouTube video of an early version of the game. This version didn't yet have the full weapon set or the ability to move the tanks, but it gives the flavor of the game.

http://www.youtube.com/watch?v=P-9O1TOSfCM

According to Wikipedia, Scorched Tanks wasn't written in C, it was written in a form of Basic for the Amiga. (I didn't know that.)  :good:
It was also based on a game for DOS called Scorched Earth; which had much crapper graphics and far fewer weapons.  :glare:

Now that I think about it, I remember that there was an example program listed in the C=64 Programer's Manual, by Jim Butterfield, which allowed you to set power and angle and try to launch a banana at a target. It was written in Basic and used the really crappy C=64 graphics character set. It's wasn't quite Tank Battle, but it used the same sort of math.

My first computer was a Commodore 64, for which I paid $500, new. (Two months later they slashed the price in half.) I used to stay up all night programing on that thing. I graduated from tape-drive to 8" floppy drive on the same day the first Space Shuttle blew up. Ah yes. 64K of ram and a 300 baud modem. Who could ask for more? Actually some of the games on the old '64 were surprisingly good. My favorites were MULE, Jumpman Jr., and Modem Wars. Ah.. good times. Good times. Did you ever have a Commie-64?

Cheers!
-CW   

fuzzy70

I think Scorched Tanks was written in AMOS but not 100% sure as was a long time ago  :D

I did indeed have a C64 although naming my favorites would not be an easy task as there was so many of them, ones which stand out from the top of my head are (in no particular order), The Sentinel, Bruce Lee, Fort Apocalypse, Raid over Moscow, Beach Head, Paradroid, Uridium, Son of Blagger, Spindizzy just to name a few. I also loved the Summer/Winter games etc along with Racing Car Destruction set but all of those where a right pain in the arse to play until I got a disk drive, the memories of remembering to reset the tape counter on the old C2N cassette unit & logging the position of each part are not fond ones  :puke:

There was one game called Forbidden Forest I believe which was scary as hell with the lightning effect flashing up spiders etc, well at least it was for a 12-13 yr old back then, it should have had a 18 rating  :D.

I still have a lot of my old computers like 2 C64's (original "Bullnose" & the latter redesigned one), a C128, various Speccys, BBC Master, various Amigas & some not so common/popular ones like Enterprise Elan, Camputers Lynx, Oric, Sam Coupe etc. All of which are boxed up in my loft thanks to emulators  :good:

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

CW

#8
Wiki says Scorched Tanks was written in Amos. That should give encouragement to all GL-BASIC programers. You can do some neat things in Basic.  :)

I didn't recognize most of the games you listed, but I did play Bruce Lee and loved it. Did you ever play Elite? That game was soo fast, smooth and great that it could only have been written in machine language, with the Basic command set switched out. The Commodore-64 has the ability to switch off BASIC, freeing up the ram underneath for something like 80k of ram in all for machine language. (I dabbled in Assembly Language on the 64.) Elite came with a funky plastic lens thing which you had to place on your screen to read the anti-piracy code, before you could play. It was an awesome 3-D space game, done all in wire-frame graphic lines, where you had to upgrade your ship and fight off pirates in real time as you traveled from solar-system to solar-system to sell your cargo.  Then, do you remember a game called Mission Impossible, where you had to sneak into a evil-villain's secret base, but he greets you with the (spoken!) words "Another visitor. Stay a while. Stay FOREVER!!" That is just one of those classic tag lines which stays with you; like "I Hunger. RUN COWARD! RUN! RUN! MERRAHAHAH!!!!" in Senistar.  (An arcade, and later an Amiga game.) Then there was Out Of This World on the Amiga, which was so beautiful and so revolutionary in its sophistication, graphics, and story line, that it was hard to believe it could run on a home computer. It is still a neat storyline today.

http://www.youtube.com/watch?v=WKD8UT4cRxI     <== Part 1
http://www.youtube.com/watch?v=SVOM5C9-7OI      <== Part 2
http://www.youtube.com/watch?feature=endscreen&v=VcD4KeYO30o&NR=1   <== Part 3


I never played Forbidden Forest, but I looked it up on You-tube. I can totally relate to the fear a game like that can cause. Some of our younger users might scoff at the notion if they see the game, now, on You-tube. But read some of the comments. Others were just as frightened by that game and its sequel, Beyond the Forbidden Forest, as you were. Imagination is a powerful thing. In an age of pixelated graphics, imagination drives the fear. (and who is more imaginative than a kid?) I can still remember how the first DOOM caused my heart to leap in my chest as my buddy screamed, "He's BEHIND You! HE'S BEHIND YOU!!!" Even DOOM is tame by today's standards.

I am amazed that you still have your old systems. How fun! You have a lot of computers I never even heard of before. Probability because they were only sold in Europe. We had the Rotten Apple, the Vic-20, the Commie-64, the Trash-80, Sinclare, and a few assorted closet-stuffers (like Adam) which never really took off. Hold on to those old systems. They may be worth some real money one day.   =D

Cheers!
-CW

CW

#9
Note: I just located a high-rez version of Out Of This World which is much truer to the Amiga version (rather than the Genesis version.) Previous links updated. Check it out.  :good:
-CW

fuzzy70

Ahh the good old "lenslok" copy protection or whatever it was called, I remember that  :good:.

Elite I think I skipped on the C64 & other micro's as I already had it on my BBC 'B' although I did get it on the Amiga when it was released, looked awesome going from wireframe to solid 3D. Mission Impossible was another fave but managed to escape my list somehow  :o

Out of this World (Another World in the UK) was great, also Flashback from the same developers upped the graphics to a new level for me.

Don't worry all my old 8'bits are all safe & not going anywhere, just making an odd trip out occasionally for some air & nostalgia moments  =D

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

spicypixel

Quote from: CW on 2013-Mar-09
Spicy, I'm afraid I predate Pocket Tanks Deluxe by quite a bit.

PTD was also on the Amiga :D
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

bigsofty

Just saw the end of Another World in that youtube video for the first time... wow, was that a game ahead of it's time! I am in total awe, that the one coder created this game engine and all of it's artwork too(the amount of various animations alone are amazing).  :nw:
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

erico

Hello CW, thanks for the offer, but I'm affraid I'd have to wait a while before I would have time to study...but super thanks! :good:

CW

#14
Hey Spicy, I just looked up PTD and was amazed at the number of weapons it supports. Up to 295! And the graphics look great! I see it is a one or two player game, so if I ever get a smart phone I will defiantly have to have this one. It seems an ideal way to kill time on plane-flights, at dentist offices, on the loo, in church, on the loo in church, during oil changes, in bank-queues, at stop-lights, while my girlfriend is yacking, etc, etc..  :P

Hey Softy! I too am in awe of what Eric Chahi accomplished. He holds an almost god-like status among old-timer programers.  :enc: It is interesting to read the development story behind Another World. http://en.wikipedia.org/wiki/Another_World_%28video_game%29

Did you know that Another World had a sequel, called Heart of the Alien? The sequel picks up exactly where the first game left off, but takes place from the alien-companion's point of view. A certain plot-twist in the game pissed a lot of people off, and rumor has it that even Eric Chahi disapproved, but he was ignored by Interplay, who developed the game. (Mr. Chahi wasn't involved.) If you are interested in seeing the sequel, here are the links.

http://www.youtube.com/watch?v=dcLABummKho  <== Part 1
http://www.youtube.com/watch?v=xnGGJfv3bqA     <== Part 2


Hey Erico! I completely understand. I too am pretty busy at the moment, working on my Animation Spreadsheet program. I just wrote a nifty little color-wheel function for it, which I might post here in the coming days, for anyone who is interested.  8)

Cheers all! Happy coding.
-CW