JS Lemming's Blood engine.

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

JS Lemming's Blood engine.

Post by Falco Girgis »

Don't be offended, because it's only natural for me to ask for it after how cool it was. Do you think that you could post it, with LOTS of notes and an explanation? I was looking for something like that to implement in the DC shooter (what kind of a shooter doesn't have massive blood spray?). Not only that, but unless you're gay I'm sure you'd want that in NEStix Chaotix.

I know I can't just "copy and paste" into my DC source, but I think that if I understand the physics and mechanics, I can adequately reproduce it in C++ and on Dreamcast for that matter.

C'mon JS Lemming, share the goods. Do it for your Dev Team, do it for your people...
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Sorry I didn't post sooner.

I was thinking, the blood engine for the mario game was a bit limited, so I built you a brand new one. This baby can spew blood in 360 degrees!

Code: Select all

;Particle Blood Engine
;By JS Lemming

;Init graphics mode
Graphics 800,600

;Seed the random generator
SeedRnd(MilliSecs())

;Set buffer to backbuffer
SetBuffer BackBuffer()

;Blood type/class
Type Blood
	Field x#		;float var. holds x coord of particle
	Field y#		;float var. holds y coord of particle
	Field xvel#		;float var. holds x velocity of particle
	Field yvel#		;float var. holds y velocity of particle
	Field life		;int var. holds # of frames until particle deleted
End Type

;float var. holds gravitational force for realistic simulation
Global Gravity# = 0.4

;int var. holds the relative frame amount for the life of the particle
Global MaxBloodLife = 30


;This is not relevent to the engine itself. Just for this demonstration
Global TestAngle = 0
Global TestIntensity = 65


Function Create_Blood(x,y,angle,intensity)
;arguments explained:
;	x: coord starting location of particle
;	y: coord starting location of particle
;	angle: angle at which blood shall spew
;	intensity: amount of particles to be generated

	;loop until intensity is met
	For i = 0 To intensity
	
		;create a new particle
		Blood.Blood = New Blood
		
		;determine its x and y coord give or take 3 pixels for realism
		Blood\x = x + Rnd(-3,3)
		Blood\y = y + Rnd(-3,3)
		
		;determine rel angle by giveing or takeing about 50 degrees for realism
		RelativeAngle = angle + Rnd(-55,55)
		
		;determine its velocity based on the angle
		Blood\xvel = (Cos(RelativeAngle) * (intensity/Rnd(10,24)))
		Blood\yvel = (Sin(RelativeAngle) * (intensity/Rnd(10,24)))
	
	
		;determine the life of the blood based on the Max life
		;randomly subtract a number between (intensity/12) to 
		;round of edges
		Blood\life = MaxBloodLife + Rnd(-(intensity/12),0)
	
	Next

End Function


Function Update_Blood()

	;loop through all Blood particles
	For cur.Blood = Each Blood
	
		;adust coords based on velocities
		cur\x = cur\x + cur\xvel
		cur\y = cur\y + cur\yvel
		
		;simulate gravity
		cur\yvel = cur\yvel + Gravity
		
		;decrese it's life
		cur\life = cur\life - 1
	
		;the longer the life the darker the color red.
		;if alpha power is available, use that instead
		Color 255-(MaxBloodLife-cur\life)*8,0,0
	
		;draw a 2x2 pixel square to represent the particle
		Rect cur\x,cur\y,2,2
		
		;delete particle if its life has expired
		If cur\life < 0 Then Delete cur	
	
	Next

End Function


;main loop
While KeyDown(1) = False
	Cls
	
	;These have no releavence in the engine, just the demo
	If KeyDown(205) Then TestAngle = TestAngle + 4
	If KeyDown(203) Then TestAngle = TestAngle - 4
	If KeyDown(200) Then TestIntensity = TestIntensity + 1
	If KeyDown(208) Then TestIntensity = TestIntensity - 1	
	If TestAngle > 360 Then TestAngle = TestAngle - 360
	If TestAngle < 0 Then TestAngle = TestAngle + 360
	Color 220,220,220
	Text 0,0,"Angle: "+TestAngle
	Text 0,12,"Intensity: "+TestIntensity
	Text 0,580,"Controls: Space Bar, Arrow Keys, Esc Key"
	
	;key: Space Bar
	If KeyDown(57)
	
		;Use of the function in action
		Create_Blood(400,300,TestAngle,TestIntensity)
	
	EndIf
	
	;run code to update the particle blood
	Update_Blood()
	
	Flip
Wend


;kill program
End
Try it out!

I hope I commented that mug enough, if not let me know and I'll answer your questions.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

OMFG! Beautiful.

Looks like that Geometry class is really helping, huh?
I don't take geometry till next semester. I'm really jelous.

I saw them sinus and cosinuses. Good lord, I have no clue what they are. But that is smartness. I loves it JSL, I do...
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

I'm ENRAGED.

BlitzPlus doesn't have Rand()!?! Whatta peice of shit!

What is this Rnd() garbage!??!

I want my Rand() back!

:bow: :worship:

OMFG! t3h power of rand():

http://bobbeetec.com
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Hey, I was thinking...

I took a screenshot of your blood. It is all one color, right? Then it slowly gets darker as it goes along?

I drew little blotches of different shades of red (3 shades), and it looked BEAUTIFUL.

No offense to your magnificent blood, but it looks like it was meant to be a bit more cartoony to me.

I think if you draw the blood how you've been doing, but just add a little bit of a tiny bit darker red, and an even less amount of a little bit darker shade, it'll look perfect.


Don't like flame me or anything, I've never used your blood so I wouldn't know what'd happen. Also, you may of already tried that. Sorry if I'm being a dumbass. :?
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

I was looking back over that and I've decided that is the greatest job I've ever seen you do as far as commenting goes. Niceness.

BTW, this is random and off-topic, but what of Timothy? Did he die? Too good to go to the forums? Has he not seen the beauty of your new creation?
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Super Sonic wrote:OMFG! Beautiful.

Looks like that Geometry class is really helping, huh?
I don't take geometry till next semester. I'm really jelous.

I saw them sinus and cosinuses. Good lord, I have no clue what they are. But that is smartness. I loves it JSL, I do...
OMG!!! I was seriously kidding about geometry being usefull the other week. MAN!!! :lol: :lol: :lol: Let me sum that class up for you in 4 words... "The angle is congruent." say that phrase over 10 times, emphasizing each word diferently each time, and you have my geometry class. Its a joke to me. All I have to do is use pencil led sticks to hold up my eyelids and I pass that class. My current average in that class is over 100.

I leanred all that sine and cosing crap back when I made "Space Masters". Remember how you could shoot in 360 degrees. Yep, trial and error comes through again.
I drew little blotches of different shades of red (3 shades), and it looked BEAUTIFUL.
Can you send me a screenie, I can't seem to visualize what your talking about.
I'm ENRAGED.

BlitzPlus doesn't have Rand()!?! Whatta peice of crap!

What is this Rnd() garbage!??!

I want my Rand() back!



OMFG! t3h power of rand():
No need to blow an important blood vessel. Blitz plus DOES have Rand(). Let me explain. In blitz, Rand() returns an interger value, while Rnd() returns a float. I used Rnd() because it made the blood paterns come out in variety and not in lines.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

Super Sonic wrote:BTW, this is random and off-topic, but what of Timothy? Did he die? Too good to go to the forums? Has he not seen the beauty of your new creation?
He Has "band" as he excuse. So i dont think he will be joining us in our victorious moment.
1/8th time- 14secs
1/8th speed - 110mph
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

sine, cosine, tangent, cosine, cosecant, cotangent are trig functions.

Code: Select all

 |\
 | \
O|  \ H
 |   \
 |___x\
   A
O = 3
A = 4
H = 25
OAH is any triangle, x is any angle inside the triangle.
x is the angle you are referencing from. The sine of x is the opposite over the hypotenuse, or 3/25 units. The cosine of x is the adjacent over the hypotenuse, or 4/25 units. The tangent of x is the opposite over the adjacent, or 3/4. Cosine = 1/sine, cosecant = 1/secant, cotangent = 1/tangent. (Reciprocals).

how to remember which one's which -
SOHCAHTOA (so kah toe uh)

sine opposite hypotenuse cosine adjacent hypotenuse tangent opposite adjacent
or

Code: Select all

(read downwards)
sally oscar    (S O/H)
      has

can   a        (C A/H)
      hard

tell  on       (T O/A)
      always

Code: Select all

         90 (-270) degrees
           |
           |
+-180  ----+---- 0 degrees
           |
           |
         270 (-90) degrees
There's another relationship where if you draw a circle one unit in radius you have a number of relationships found by drawing triangles inside the one-unit circle (ie, all the triangles' hypotenuses are 1). Sine repeats between -90 & 90 degrees, (ie, all the sine values BETWEEN not including the 90, 270 degree range have the same as the 270, -90 degree range.) cosine repeats every 0, 180, (180, 360 are the same as 0, 180). i forget where tangent repeats. anyway, there's your nonsensical crash course in trigonometry. you usually use sine/cosine and stuff for angle trajectory (my terrain-destroying demo used to, maybe still, had so when i hold down m he rotates one degree at a time. the angle for which way the bullet shoots was calculated using trig)
Last edited by MarauderIIC on Sun Sep 26, 2004 12:55 am, edited 1 time in total.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply