Fizz!
Super Easy 2D Physics with Newton
Fizz! is a set of very easy to use functions that allows you to have real world physics in your 2D games with Newton.
Screenshots
Videos
Explosion - 700kb
Grenade - 500kb
Catapult - 150kb
Mario - 450kb (mov)
Mario & Luigi - 350kb (mov)
Code
function MakeStaticBox( xLength#, yLength#, xPos#, yPos#, Angle# )
FizzBox = NDB_NewtonCreateBox( xLength# / 100, yLength# / 100, 0.5, 0)
StaticBox = NDB_NewtonCreateBody( FizzBox )
NDB_BuildMatrix 0, 0, Angle#, xPos# / 100, yPos# / 100, 0
NDB_NewtonBodySetMatrix StaticBox
NDB_NewtonBodySetMaterialGroupID StaticBox, Objects( 0 )
endfunction
function MakeStaticOval( xDiameter#, yDiameter#, xPos#, yPos#, Angle# )
FizzOval = NDB_NewtonCreateSphere( xDiameter# / 200, yDiameter# / 200, 0.5 / 2, 0)
StaticOval = NDB_NewtonCreateBody( FizzOval )
NDB_BuildMatrix 0, 0, Angle#, xPos# / 100, yPos# / 100, 0
NDB_NewtonBodySetMatrix StaticOval
NDB_NewtonBodySetMaterialGroupID StaticOval, Objects( 0 )
endfunction
function MakeMovingBox( xLength#, yLength#, xPos#, yPos#, Angle#, Mass#, SpriteNumber, ImageNumber )
sprite SpriteNumber, -1000, -1000, ImageNumber
set sprite priority SpriteNumber, 1
FizzBox = NDB_NewtonCreateBox( xLength# / 100, yLength# / 100, 0.49, 0)
MoveableBox = NDB_NewtonCreateBody( FizzBox )
NDB_BuildMatrix 0, 0, Angle#, xPos# / 100, yPos# / 100, 0
NDB_NewtonBodySetMatrix MoveableBox
NDB_BodySetGravity MoveableBox, 1
NDB_NewtonBodySetMassMatrix MoveableBox, Mass#, 1, 1, 1
NDB_NewtonBodySetMaterialGroupID MoveableBox, Objects( 0 )
NDB_NewtonBodySetAutofreeze MoveableBox, 0
NDB_SetVector 0, 0, 1
UpVector = NDB_NewtonConstraintCreateUpVector( MoveableBox )
NDB_NewtonUpVectorSetPin UpVector
make object triangle SpriteNumber, 0, 0, 0, 1, 0, 0, 0, 1, 0
hide object SpriteNumber
NDB_BodySetDBProData MoveableBox, SpriteNumber
NDB_SetVector 0, 0, 0
NDB_NewtonBodySetOmega MoveableBox
NDB_NewtonBodySetVelocity MoveableBox
TotalObjects( 0 ) = TotalObjects( 0 ) + 1
SpriteNumbers( TotalObjects( 0 ) ) = SpriteNumber
endfunction
function MakeMovingOval( xDiameter#, yDiameter#, xPos#, yPos#, Angle# Mass#, SpriteNumber, ImageNumber )
sprite SpriteNumber, -1000, -1000, ImageNumber
set sprite priority SpriteNumber, 1
FizzOval = NDB_NewtonCreateSphere( xDiameter# / 200, yDiameter# / 200, 0.49 / 2, 0)
MoveableOval = NDB_NewtonCreateBody( FizzOval )
NDB_BuildMatrix 0, 0, Angle#, xPos# / 100, yPos# / 100, 0
NDB_NewtonBodySetMatrix MoveableOval
NDB_BodySetGravity MoveableOval, 1
NDB_NewtonBodySetMassMatrix MoveableOval, Mass#, 1, 1, 1
NDB_NewtonBodySetMaterialGroupID MoveableOval, Objects( 0 )
NDB_NewtonBodySetAutofreeze MoveableOval, 0
NDB_SetVector 0, 0, 1
UpVector = NDB_NewtonConstraintCreateUpVector( MoveableOval )
NDB_NewtonUpVectorSetPin UpVector
make object triangle SpriteNumber, 0, 0, 0, 1, 0, 0, 0, 1, 0
hide object SpriteNumber
NDB_BodySetDBProData MoveableOval, SpriteNumber
TotalObjects( 0 ) = TotalObjects( 0 ) + 1
SpriteNumbers( TotalObjects( 0 ) ) = SpriteNumber
endfunction
function StartFizz()
`This function sets up the Fizz world ready for use.
dim SpriteNumbers( 10000 )
dim Walls( 0 )
dim Objects( 0 )
dim Players( 1 )
dim TotalObjects( 0 )
dim Screen( 4 )
dim Players#( 100, 7 )
NDB_NewtonCreate
NDB_SetVector 0, 30, 0
NDB_SetStandardGravity
Walls( 0 ) = NDB_NewtonMaterialCreateGroupID()
Objects( 0 ) = NDB_NewtonMaterialCreateGroupID()
Players( 0 ) = NDB_NewtonMaterialCreateGroupID()
NDB_NewtonMaterialSetDefaultFriction Walls( 0 ), Objects( 0 ), 0, 0
NDB_NewtonMaterialSetDefaultFriction Walls( 0 ), Players( 0 ), 0, 0
NDB_NewtonMaterialSetDefaultFriction Objects( 0 ), Players( 0 ), 0, 0
NDB_NewtonMaterialSetDefaultElasticity Objects( 0 ), Players( 0 ), 0.1
xPixels# = screen width()
yPixels# = screen height()
xCentre# = xPixels# / 2
yCentre# = yPixels# / 2
FizzBox = NDB_NewtonCreateBox( 500, 500, 1, 0 )
FrontWall = NDB_NewtonCreateBody( FizzBox )
NDB_BuildMatrix 0, 0, 0, xCentre# / 100, yCentre# / 100, -0.5
NDB_NewtonBodySetMatrix FrontWall
NDB_NewtonBodySetMaterialGroupID FrontWall, Walls( 0 )
BackWall = NDB_NewtonCreateBody( FizzBox )
NDB_BuildMatrix 0, 0, 0, xCentre# / 100, yCentre# / 100, 0.5
NDB_NewtonBodySetMatrix BackWall
NDB_NewtonBodySetMaterialGroupID BackWall, Walls( 0 )
endfunction
function UpdateFizz()
`This function must be called every loop, it gets all the new objects positions
`from Newton and then draws the sprites in their new positions.
TimeElapsed# = NDB_GetElapsedTimeInSec()
NDB_NewtonUpdate TimeElapsed#
for Object = 1 to TotalObjects( 0 )
SpriteNumber = SpriteNumbers( Object )
ImageNumber = sprite image( SpriteNumber )
xPos# = object position x( SpriteNumber )
yPos# = object position y( SpriteNumber )
Angle# = object angle z( SpriteNumber )
sprite SpriteNumber, xPos# * 100 - Screen( 1 ), yPos# * 100 - Screen( 2 ), ImageNumber
Width# = sprite width( SpriteNumber )
Height# = sprite height( SpriteNumber )
offset sprite SpriteNumber, Width# / 2, Height# / 2
rotate sprite SpriteNumber, Angle#
next Object
`Player control
for PlayerNumber = 1 to Players( 1 )
NDB_NewtonBodyGetVelocity NDB_GetBody( Players#( PlayerNumber, 0 ) )
xVelocity# = NDB_GetVector_X()
yVelocity# = NDB_GetVector_Y()
Force# = ( Players#( PlayerNumber, 1 ) - xVelocity# ) * 10
NDB_SetVector 1, 0, 0, 0
NDB_SetVector 2, Force#, 0, 0
NDB_BodyAddForceGlobal NDB_GetBody( Players#( PlayerNumber, 0 ) )
NDB_SetVector 2, 0, 0 - Players#( PlayerNumber, 2 ), 0
NDB_BodyAddForceGlobal NDB_GetBody( Players#( PlayerNumber, 0 ) )
Players#( PlayerNumber, 2 ) = 0
if ABS( yVelocity# ) < 0.5 and Players#( PlayerNumber, 3 ) > 0 then Players#( PlayerNumber, 3 ) = Players#( PlayerNumber, 3 ) - 1
if ABS( yVelocity# ) > 0.5 then Players#( PlayerNumber, 3 ) = 5
SpriteNumber = Players#( PlayerNumber, 4 )
xPos# = object position x( SpriteNumber )
yPos# = object position y( SpriteNumber )
Angle# = object angle z( SpriteNumber )
sprite SpriteNumber, xPos# * 100 - Screen( 1 ), yPos# * 100 - Screen( 2 ), Players#( PlayerNumber, 5 )
offset sprite SpriteNumber, Players#( PlayerNumber, 6 ), Players#( PlayerNumber, 7 )
rotate sprite SpriteNumber, Angle#
next PlayerNumber
endfunction
function AddExplosion( xPos#, yPos#, Force# )
NDB_SetVector 1, xPos# / 100, yPos# / 100, 0
for Object = 1 to TotalObjects( 0 )
xObject# = object position x( SpriteNumbers( Object ) )
yObject# = object position y( SpriteNumbers( Object ) )
xDifference# = xObject# - ( xPos# / 100 )
yDifference# = yObject# - ( yPos# / 100 )
Length# = xDifference# ^ 2 + yDifference# ^ 2
xVector# = ( xDifference# / Length# ) * Force#
yVector# = ( yDifference# / Length# ) * Force#
NDB_SetVector 2, xVector#, yVector#, 0
NDB_BodySetForceGlobal NDB_GetBody( SpriteNumbers( Object ) )
next Object
endfunction
function MakePlayer( PlayerNumber, xDiameter#, yDiameter#, xPos#, yPos#, xOffset, yOffset, SpriteNumber )
Players#( PlayerNumber, 0 ) = SpriteNumber
sprite SpriteNumber, -1000, -1000, 1
set sprite priority SpriteNumber, 2
NDB_StartCompoundCollision
FizzOval = NDB_NewtonCreateSphere( xDiameter# / 200, yDiameter# / 200, 0.49 / 2, 0)
NDB_AddCollisionToArray FizzOval
FizzBox = NDB_NewtonCreateBox( xDiameter# / 100, yDiameter# / 200, 0.49, 0)
NDB_AddCollisionToArray FizzBox
FizzPlayer = NDB_NewtonCreateCompoundCollision()
MoveableOval = NDB_NewtonCreateBody( FizzPlayer )
NDB_BuildMatrix 0, 0, Angle#, xPos# / 100, yPos# / 100, 0
NDB_NewtonBodySetMatrix MoveableOval
NDB_BodySetGravity MoveableOval, 1
NDB_NewtonBodySetMassMatrix MoveableOval, 100, 1, 1, 1
NDB_NewtonBodySetMaterialGroupID MoveableOval, Players( 0 )
NDB_NewtonBodySetAutofreeze MoveableOval, 0
NDB_SetVector 0, 1, 0
UpVector = NDB_NewtonConstraintCreateUpVector( MoveableOval )
NDB_NewtonUpVectorSetPin UpVector
make object triangle SpriteNumber, 0, 0, 0, 1, 0, 0, 0, 1, 0
hide object SpriteNumber
NDB_BodySetDBProData MoveableOval, SpriteNumber
TotalObjects( 0 ) = TotalObjects( 0 ) + 1
Players( 1 ) = Players( 1 ) + 1
SpriteNumbers( TotalObjects( 0 ) ) = SpriteNumber
Players#( PlayerNumber, 4 ) = SpriteNumber
Players#( PlayerNumber, 6 ) = xOffset
Players#( PlayerNumber, 7 ) = yOffset
endfunction
function MouseScroll( Speed )
if mousex() < 10 then Screen( 1 ) = Screen( 1 ) - Speed
if mousex() > 1014 then Screen( 1 ) = Screen( 1 ) + Speed
if mousey() < 10 then Screen( 2 ) = Screen( 2 ) - Speed
if mousey() > 758 then Screen( 2 ) = Screen( 2 ) + Speed
endfunction
function BuildWorld( Filename$ )
dim Size( 0 )
load array Filename$ + "Size.Fizz", Size( 0 )
Size = Size( 0 )
dim World( Size, 5 )
load array Filename$ + ".Fizz", World( Size, 5 )
for Cell = 1 to Size
Length = World( Cell, 1 )
Height = World( Cell, 2 )
xPos = World( Cell, 3 )
yPos = World( Cell, 4 )
Angle = World( Cell, 5 )
MakeStaticBox( Length, Height, xPos, yPos, Angle )
next Cell
endfunction
function MakeJoint( xPixel#, yPixel#, ChildSpriteNumber, ParentSpriteNumber )
`This function will make a joint for an object to rotate around.
`If you want the joint to be pinned in space, use "0" as the ParentNumber
NDB_SetVector 1, xPixel# / 100, yPixel# / 100, 0
NDB_SetVector 2, 0, 0, 1
BodyNumber = NDB_GetBody( ChildSpriteNumber )
if ParentSpriteNumber > 0
ParentBodyNumber = NDB_GetBody( ParentSpriteNumber )
else
ParentBodyNumber = 0
endif
FizzJoint = NDB_NewtonConstraintCreateHinge( BodyNumber, ParentBodyNumber )
endfunction
How to Install
Copy & Paste the code from above into DBPro
File -> Save Source As... -> Saved it in your project directory, named
"Fizz.dba"
In your project click the
"Files" tab (bottom right)
Click
"Browse", double click
"Fizz.dba"
File -> Save All
Your done installing!
How to Use
WHEN USING FIZZ! ALL LENGTHS AND POSITIONS ARE IN PIXELS
You need to call the command
StartFizz() at the top of your program, then you need to call
UpdateFizz() every loop.
If you want to create an invisible, static object (such as a wall) you use these commands:
MakeStaticBox( Width, Height, xPos, yPos, Angle )
MakeStaticOval( Width, Height, xPos, yPos, Angle )
If you want to create a moving object you need to use these commands:
MakeMovingBox( Width, Height, xPos, yPos, Angle, Mass, SpriteNumber, ImageNumber )
MakeMovingOval( Width, Height, xPos, yPos, Angle, Mass, SpriteNumber, ImageNumber )
The
SpriteNumber is like an object number, it must be unique to that object.
The
ImageNumber is the number of the image which the sprite will use (the picture of the object). This must be loaded beforehand with
load image
To make an explosion use this function:
AddExplosion( xPos, yPos, Force )
The force should be somewhere around 1000.
To scroll the screen you need to adjust the variables
Screen( 1 ) and
Screen( 2 ). These are the x and y positions of the camera.
For example:
if leftkey() = 1 then Screen( 1 ) = Screen( 1 ) - 10
if rightkey() = 1 then Screen( 1 ) = Screen( 1 ) + 10
if upkey() = 1 then Screen( 2 ) = Screen( 2 ) - 10
if downkey() = 1 then Screen( 2 ) = Screen( 2 ) + 10
MouseScroll( Speed ) - Call this every loop to use the mouse to scroll the screen (like an RTS)
To make a controllable player use the following command:
MakePlayer( PlayerNumber, xDiameter, yDiameter, xPos, yPos, xOffset, yOffset, SpriteNumber )
The player is an oval. For best results make is a bit
smaller than your player sprite so you get a bit of overlap.
To move the player you need to adjust the
Players#( Number, x ) array.
Players#( Number, 1 ) is the x speed.
Players#( Number, 2 ) should be set to about 350 when you want to jump.
Players#( Number, 3 ) tells you whether you can jump. If it is 0 then it is OK to jump.
To set what image to use for the player set
Players#( Number, 5 ). You can do this dynamically to animate the player.
To build your level very easily you need to use this command:
BuildWorld( "Filename" )
To add a joint to your level use this command
MakeJoint( xPos, yPos, ChildSprite, ParentSprite )
You need to make the object you want to be jointed beforehand, in it's starting position, then you need to use this command to 'pin' it in place. If the object is connected to nothing, use ParentNumber of 0, if you want to make a chain you can specify a parent object to connect to.
Chains of three can be erratic.
You can make a
Fizz! World with this editor:
dim World( 1000, 5 )
set image colorkey 255, 0, 128
load image "Block.bmp", 1, 1
load image "Axis.bmp", 2, 1
Length = 100 : Height = 100
sync on
do
`====================================
`====================================
`Put your code for making your level in here.
`Use sprite numbers 3 - 1000
`Remember to say "- xScreen" and "- yScreen" on all your sprite commands.
`=====================================
`====================================
Speed = 1
if shiftkey() = 1 then Speed = 5
if upkey() = 1 then Height = Height + Speed
if downkey() = 1 and Height > Speed then Height = Height - Speed
if rightkey() = 1 then Length = Length + Speed
if leftkey() = 1 and Length > Speed then Length = Length - Speed
Angle = Angle + ( mousemovez() / 20 )
if mouseclick() <> 1 then Mouse = 0
if mouseclick() = 1 and Mouse = 0
ObjectNumber = ObjectNumber + 1
World( ObjectNumber , 1 ) = Length
World( ObjectNumber , 2 ) = Height
World( ObjectNumber , 3 ) = mousex() + xScreen
World( ObjectNumber , 4 ) = mousey() + yScreen
World( ObjectNumber , 5 ) = Angle
World( 0, 0 ) = World( 0, 0 ) + 1
Mouse = 1
endif
sprite 1, mousex(), mousey(), 1
size sprite 1, Length, Height
offset sprite 1, Length / 2, Height / 2
rotate sprite 1, Angle
set sprite alpha 1, 100
sprite 2, -15 - xScreen, -15 - yScreen, 2
for Object = 1 to World( 0, 0 )
sprite Object + 1000, World( Object, 3 ) - xScreen, World( Object, 4 ) - yScreen, 1
size sprite Object + 1000, World( Object, 1 ), World( Object, 2 )
offset sprite Object + 1000, World( Object, 1 ) / 2, World( Object, 2 ) / 2
rotate sprite Object + 1000, World( Object, 5 )
next Object
if mousex() < 5 then xScreen = xScreen - 20
if mousex() > 1020 then xScreen = xScreen + 20
if mousey() < 5 then yScreen = yScreen - 20
if mousey() > 765 then yScreen = yScreen + 20
if spacekey() = 1 then xScreen = 0 : yScreen = 0
set cursor 0, 0
print scancode()
if controlkey() = 0 or keystate( 44 ) = 0 then Undo = 0
if controlkey() = 1 and keystate( 44 ) = 1 and Undo = 0
delete sprite World( 0, 0 ) + 1000
World( 0, 0 ) = World( 0, 0 ) - 1
ObjectNumber = ObjectNumber - 1
Undo = 1
endif
if controlkey() = 1 and keystate( 31 ) = 1
Size = World( 0, 0 )
dim Save( Size, 5 )
dim Size( 0 )
Size( 0 ) = Size
for aCell = 0 to World( 0, 0 )
for bCell = 1 to 5
Save( aCell, bCell ) = World( aCell, bCell )
next bCell
next aCell
Save( 0, 0 ) = World( 0, 0 )
input "Filename? ", Filename$
save array Filename$ + ".Fizz", Save( Size, 5 )
save array Filename$ + "Size.Fizz", Size( 0 )
center text screen width() / 2, screen height() / 2 - 50, "SAVED!!!"
sync
suspend for key
endif
sync
loop
Get the media
here (about 5 kb)
Mouse click - place block
Mouse wheel - rotate
Arrow keys - change dimensions
Shift - speed up resizing
Space - reset camera to 0,0
Control + z - undo
Control + s - Save
You just need to make it show your level (without any players, objects or enemies), and then you can cover over the walls etc. with blocks.
When you are done press control + s, put in a filename.
Then you just need to put the files that are made in your project folder and call
BuildWorld() with the right filename.
Sample Programs
Here are some sample programs to test out
Fizz!
You need to use the media attached to this post (9kb)
Press 1 - 6 to make objects.
StartFizz()
set image colorkey 255, 0, 128
load image "Crate.bmp", 1, 1
load image "Beans.bmp", 2, 1
load image "Package.bmp", 3, 1
load image "Girder.bmp", 4, 1
load image "BowlingBall.bmp", 5, 1
load image "DinosaurEgg.bmp", 6, 1
load image "Floor.bmp", 30, 1
color backdrop rgb( 0, 128, 255 )
MakeStaticBox( 1100, 300, 512, 800, 0 )
sprite 1000, 0, 600, 30
`Main loop.
sync rate 60
sync on
do
if keystate( 2 ) = 0 then One = 0
if keystate( 2 ) = 1 and One = 0
Number = Number + 1
MakeMovingBox( 120, 120, rnd( 800 ) + 100, rnd( 100 ), rnd( 45 ), 80, Number, 1 )
One = 1
endif
if keystate( 3 ) = 0 then Two = 0
if keystate( 3 ) = 1 and Two = 0
Number = Number + 1
MakeMovingBox( 44, 53, rnd( 800 ) + 100, rnd( 100 ), rnd( 45 ), 20, Number, 2 )
Two = 1
endif
if keystate( 4 ) = 0 then Three = 0
if keystate( 4 ) = 1 and Three = 0
Number = Number + 1
MakeMovingBox( 100, 180, rnd( 800 ) + 100, rnd( 100 ), rnd( 45 ), 40, Number, 3 )
Three = 1
endif
if keystate( 5 ) = 0 then Four = 0
if keystate( 5 ) = 1 and Four = 0
Number = Number + 1
MakeMovingBox( 356, 60, rnd( 800 ) + 100, rnd( 100 ), rnd( 45 ), 40, Number, 4 )
Four = 1
endif
if keystate( 6 ) = 0 then Five = 0
if keystate( 6 ) = 1 and Five = 0
Number = Number + 1
MakeMovingOval( 80, 80, rnd( 800 ) + 100, rnd( 100 ), rnd( 90 ), 100, Number, 5 )
Five = 1
endif
if keystate( 7 ) = 0 then Six = 0
if keystate( 7 ) = 1 and Six = 0
Number = Number + 1
MakeMovingOval( 100, 150, rnd( 800 ) + 100, rnd( 100 ), rnd( 90 ), 60, Number, 6 )
Six = 1
endif
UpdateFizz()
sprite 1000, 0, 600, 30
sync
loop
Use the mouse to place objects:
StartFizz()
hide mouse
set image colorkey 255, 0, 128
load image "Crate.bmp", 1, 1
load image "Beans.bmp", 2, 1
load image "Package.bmp", 3, 1
load image "Girder.bmp", 4, 1
load image "BowlingBall.bmp", 5, 1
load image "Bang.bmp", 6, 1
load image "Floor.bmp", 30, 1
color backdrop rgb( 0, 128, 255 )
MakeStaticBox( 1100, 300, 512, 800, 0 )
sprite 1000, 0, 600, 30
ObjectType = 1
`Main loop.
sync rate 60
sync on
do
zMouseMove# = mousemovez()
Angle# = Angle# + zMouseMove# / 20
if mouseclick() <> 1 then aMouse = 0
if mouseclick() = 1 and aMouse = 0
Number = Number + 1
if ObjectType = 1
MakeMovingBox( 118, 118, mousex() + Screen( 1 ), mousey() + Screen( 2 ), Angle#, 80, Number, 1 )
endif
if ObjectType = 2
MakeMovingBox( 42, 52, mousex() + Screen( 1 ), mousey() + Screen( 2 ), Angle#, 5, Number, 2 )
endif
if ObjectType = 3
MakeMovingBox( 98, 178, mousex() + Screen( 1 ), mousey() + Screen( 2 ), Angle#, 60, Number, 3 )
endif
if ObjectType = 4
MakeMovingBox( 354, 58, mousex() + Screen( 1 ), mousey() + Screen( 2 ), Angle#, 20, Number, 4 )
endif
if ObjectType = 5
MakeMovingOval( 78, 78, mousex() + Screen( 1 ), mousey() + Screen( 2 ), Angle#, 20, Number, 5 )
endif
if ObjectType = 6
AddExplosion( mousex(), mousey(), 900 )
endif
aMouse = 1
endif
if mouseclick() <> 2 then bMouse = 0
if mouseclick() = 2 and bMouse = 0
ObjectType = ObjectType + 1
bMouse = 1
endif
if ObjectType > 6 then ObjectType = 1
sprite 1001, mousex(), mousey(), ObjectType
offset sprite 1001, sprite width( 1001 ) / 2, sprite height( 1001 ) / 2
rotate sprite 1001, Angle#
set sprite alpha 1001, 80
UpdateFizz()
sprite 1000, 0 - Screen( 1 ), 600 - Screen( 2 ), 30
if leftkey() = 1 then Screen( 1 ) = Screen( 1 ) - 10
if rightkey() = 1 then Screen( 1 ) = Screen( 1 ) + 10
if upkey() = 1 then Screen( 2 ) = Screen( 2 ) - 10
if downkey() = 1 then Screen( 2 ) = Screen( 2 ) + 10
sync
loop
Wheel - Rotate
Left Click - Place / Explode!
Right Click - Change Object
Arrows - Scroll
Player Control:
StartFizz()
hide mouse : color backdrop rgb( 0, 128, 255 )
LoadImages()
MakeStaticBox( 1100, 300, 512, 800, 0 )
MakePlayer( 1, 110, 200, 600, 500, 500, 3 )
MakePlayer( 2, 110, 200, 400, 500, 501, 3 )
sync rate 60
sync on
do
sprite 1000, 0 - Screen( 1 ), 600 - Screen( 2 ), 30
if returnkey() = 1
Number = Number + 1
MakeMovingBox( 118, 118, rnd( 1000 ), 100 + rnd( 200 ), rnd( 90 ), 120, Number, 1 )
endif
UpdateFizz()
Players#( 1, 1 ) = 0
if keystate( 38 ) = 1 then Players#( 1, 1 ) = 7
if keystate( 36 ) = 1 then Players#( 1, 1 ) = -7
if keystate( 37 ) = 1 and Players#( 1, 3 ) = 0 then Players#( 1, 2 ) = 400
Players#( 2, 1 ) = 0
if keystate( 32 ) = 1 then Players#( 2, 1 ) = 7
if keystate( 30 ) = 1 then Players#( 2, 1 ) = -7
if keystate( 31 ) = 1 and Players#( 2, 3 ) = 0 then Players#( 2, 2 ) = 400
sync
loop
function LoadImages()
set image colorkey 255, 0, 128
load image "Crate.bmp", 1, 1
load image "BowlingBall.bmp", 2, 1
load image "Dude.bmp", 3, 1
load image "Floor.bmp", 30, 1
endfunction
A, S, D - Player 1
J, K, L - Player 2
Enter - Make crates (be careful!)
Please note that the girder object sometimes has some problems, if you want to use long thin objects with
Fizz! then make sure you place them carefully when setting up the level, otherwise Newton can get confused.
If the programs above look too complicated here is a much simpler one:
StartFizz()
set image colorkey 255, 0, 128
load image "Crate.bmp", 1, 1
MakeStaticBox( 1100, 300, 512, 800, 0 )
MakeMovingBox( 120, 120, 500, 100, 30, 80, 1, 1 )
`Main loop.
sync rate 60
sync on
do
UpdateFizz()
sync
loop
Updates coming...
- More shapes!