BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Basic Asteroids demo code"
, by darkeagle
Some quick demo code which shows the physics of an Asteroids game. This code will be editited and messed around with for use in my upcoming tutorial :D
Code
AppTitle "Asteroids Physics" Graphics 800, 600 SetBuffer BackBuffer() Global KM# = 100 ;constant of mass Global KAf# = 0.01 ;constant of air friction Global tX#, tY# ;thrust Global aX#, aY# ;acceleration Global vX#, vY# ;velocities Global pX#=800, pY#=600 ;position Global afX#, afY# ;air friction Global pitch# Global speed# While Not KeyHit(1) Cls pitch# = pitch# - KeyDown(203) + KeyDown(205) If KeyDown(200) speed# = speed# + 0.1 ElseIf KeyDown(208) speed# = speed# - 0.1 Else speed# = speed# * 0.99 End If If pitch# < 0 pitch# = pitch# + 360 If pitch# > 360 pitch# = pitch# -360 If speed# > 10 speed# = 10 If speed# < -10 speed# = -10 Text 10, 10, pitch Text 10, 20, speed Text 10, 30, "aX is: " + aX + ", aY is: " + aY Text 10, 40, "X velocity is: " + vX + ", Y velocity is: " + vY Text 10, 50, "X position is: " + pX + ", Y position is: " + pY dophysics() Rect pX/2, pY/2, 10, 10, 1 Line (pX/2)+5, (pY/2)+5, (pX/2)+(Cos(pitch#)*20)+5, (pY/2)+(Sin(pitch#)*20)+5 Flip Wend Function dophysics() tX#= Cos(pitch#)*speed# tY#= Sin(pitch#)*speed# aX = tX/KM aY = tY/KM AfX# = KAF# * vX# AfY# = KAF# * vY# aX# = aX# - AfX# aY = aY# - AfY# vX = vX + aX vY = vY + aY pX = pX + vX pY = pY + vY If pX < 0 pX = 1600 If pY < 0 pY = 1200 If pX > 1600 pX = 0 If pY > 1200 pY = 0 End Function
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations