So I am making a game like the commonly know games pyro sand, and powder game. But I'm making one that will actually be educational, and realistic. What I'm just trying to do currently is make an effective system that draws the particals. keep in mind it isnt done.
Turing: |
/**
*Version 0.24
*Copthesaint
*/
View.Set ("Graphics:400;400,Title: Chemical Reaction,NoButtonBar,OffScreenOnly")
%The Property of the type of partical
type partTypeProperty :
record
clr : int
mass : real
name : string
end record
var partTypeProperties : flexible array 1 .. 0 of partTypeProperty
%The identifier that holds what values have been freed.
type freeValue :
record
iD : int
end record
var freePartValues : flexible array 1 .. 0 of freeValue
var freeBlockValues : flexible array 1 .. 0 of freeValue
%The partical values
type partical :
record
x, y, rotate, yPrev : real
partType, rotateWay : int
end record
var particals : flexible array 1 .. 0 of partical
%The block values
type block :
record
x, y : real
partType : int
end record
var blocks : flexible array 1 .. 0 of block
%Frees a current partical
proc destroyPartical (particalIndex : int)
var freedAvalible : boolean := false
for i : lower (freePartValues ) .. upper (freePartValues )
if freePartValues (i ).iD = 0 then
freePartValues (i ).iD := particalIndex
freedAvalible := true
end if
exit when freedAvalible
end for
if not freedAvalible then
new freePartValues, succ (upper (freePartValues ))
freePartValues (upper (freePartValues )).iD := particalIndex
end if
end destroyPartical
%Creates a new partical
proc newPartical (x, y, brushSize, partType : int)
for j : (brushSize * - 1) .. brushSize
for p : (brushSize * - 1) .. brushSize
var freedAvalible : boolean := false
for i : lower (freePartValues ) .. upper (freePartValues )
if freePartValues (i ).iD ~ = 0 then
particals (freePartValues (i ).iD ).x := x + j + Rand.Int (- 1, 1)
particals (freePartValues (i ).iD ).y := y + p
particals (freePartValues (i ).iD ).partType := partType
particals (freePartValues (i ).iD ).rotate := 270
particals (freePartValues (i ).iD ).rotateWay := (Rand.Int (0, 1) * 2) - 1
freedAvalible := true
freePartValues (i ).iD := 0
end if
exit when freedAvalible
end for
if not freedAvalible then
new particals, succ (upper (particals ))
particals (upper (particals )).x := x + j + Rand.Int (- 1, 1)
particals (upper (particals )).y := y + p
particals (upper (particals )).partType := partType
particals (upper (particals )).rotate := 270
particals (upper (particals )).rotateWay := (Rand.Int (0, 1) * 2) - 1
end if
end for
end for
end newPartical
%Translates each particle due to gravity
proc translateGravity (fps : real)
for i : lower (particals ) .. upper (particals )
particals (i ).yPrev := particals (i ).y
particals (i ).y := particals (i ).y - (partTypeProperties (particals (i ).partType ).mass * fps )
if particals (i ).yPrev - particals (i ).y ~ = 0 then
particals (i ).rotate := particals (i ).rotate + (particals (i ).rotateWay * partTypeProperties (particals (i ).partType ).mass * fps )
particals (i ).x := particals (i ).x + (cosd (particals (i ).rotate ) * fps )
if particals (i ).rotate < 225 or particals (i ).rotate > 315 then
particals (i ).rotate := 270
particals (i ).rotateWay := (Rand.Int (0, 1) * 2) - 1
end if
end if
end for
end translateGravity
%Loads The Partical Values
proc loadTypes (fileName : string)
var streamID : int
open : streamID, fileName, get
loop
exit when eof (streamID )
new partTypeProperties, succ (upper (partTypeProperties ))
get : streamID, partTypeProperties (upper (partTypeProperties )).name
get : streamID, partTypeProperties (upper (partTypeProperties )).clr
get : streamID, partTypeProperties (upper (partTypeProperties )).mass
end loop
close (streamID )
end loadTypes
loadTypes ("Partical_Types.txt")
var x, y, b1, b2 : int := 0
var brushSize : int := 1
var partType : int := 1
var hit : boolean := false
var fpsCurrent, fpsPrevious : real := 30
loop
fpsCurrent := Time.ElapsedCPU - fpsCurrent
fpsPrevious := 30 / (1000 / fpsCurrent )
fpsCurrent := Time.ElapsedCPU
Mouse.Where (x, y, b1 )
if b1 = 0 and hit = true then
hit := false
end if
if b1 = 1 and hit ~ = true then
hit := true
b2 := 1
end if
if hit = true and b2 = 1 then
newPartical (x, y, brushSize, partType )
end if
b2 := 0
translateGravity (fpsPrevious )
for i : lower (particals ) .. upper (particals )
drawdot (round (particals (i ).x ), round (particals (i ).y ), partTypeProperties (particals (i ).partType ).clr )
end for
View.Update
cls
end loop
|
I want to focus specifically on lines 91-96. There is no runtime problems, but I need help developing a formula that will more realistically show the particals moving at different velocities to different angles.
Turing: |
particals (i ).rotate := particals (i ).rotate + (particals (i ).rotateWay * partTypeProperties (particals (i ).partType ).mass * fps )
particals (i ).x := particals (i ).x + (cosd (particals (i ).rotate ) * fps )
if particals (i ).rotate < 225 or particals (i ).rotate > 315 then
particals (i ).rotate := 270
particals (i ).rotateWay := (Rand.Int (0, 1) * 2) - 1
end if
|
Save this text in a new text file as Partical_Types.txt:
code: | hydrogen 22 -1.9 hellium 0 0 lithium 0 0 beryllium 0 0 boron 0 0 carbon 0 0 nitrogen 0 0 oxygen 0 0 fluorine 0 0 neon 0 0 sodium 0 0 magnesium 0 0 aluminium 0 0 silicon 0 0 phosphorus 0 0 sulfur 0 0 chlorine 0 0 argon 0 0 |
I havnt givin elements proper values yet. |