News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Particle Effects- 3d starfield

Started by monkeybot, February 03, 2009, 08:53:42 AM

Previous topic - Next topic

kevin

#15
 Here's a bit of a tweak.

PlayBASIC Code: [Select]
; PROJECT : blob emiiter v 1.0
; AUTHOR : Monkeybot
; CREATED : 02/02/2009
; EDITED : 11/03/2009
; ---------------------------------------------------------------------

; ---------------------------------------------------------------------
;to do


explicit on
;screenvsync off
local num=1000
global width=getscreenwidth()
global height=getscreenheight()
constant border=0
constant xborder=50
Constant gravityVal#=0.5
global originX=width/2
global originY=height/2
global trailtimer=timer()
global gamespeed#=1
global offsetXVector#
global offsetYVector#
global offsetAngle=0

global hx,hy,h2x,h2y


type particle
x#
y#
ang
speed#
xVector#
yVector#
PathDistance#
gravityFlag
size#
TrailFlag
trailStartX#
trailStartY#
endtype
dim object(num) as particle
print "Working..............."
sync
local q,buttonflag,w
offsetXVector#=0
offsetYVector#=0

for q=0 to num-1
pokedata (q)
next



;initiate random stars
for w=0 to 100;000
;print w
; sync
for q=0 to num-1
doblobNoGfx(q)
next
next
; setfps(50)
setfps 0
repeat
cls 0
if (203=scancode()) then offsetAngle=offsetAngle-5;offsetXVector#
if (205=scancode()) then offsetAngle=offsetAngle+5

offsetXVector#=cos(offsetAngle)*5;object(index).speed#
offsetYVector#=sin(offsetAngle)*5;object(index).speed#
select mousebutton()
case 0
if gamespeed#>0.5 then gamespeed#=gamespeed#-0.01
case 1
if gamespeed#<6 then gamespeed#=gamespeed#+0.2
case 2
if gamespeed#>0.5 then gamespeed#=gamespeed#-0.2
endselect

ScreenViewport xborder,xborder,width-xborder,height-xborder

lockbuffer

global SpaceKeyDown =(34=scancode())
Global tKeyDown = (keystate(20))

;cls 0
for q=0 to num-1
doblob(q)
next
ScreenViewport 0,0,getscreenWidth(),GetScreenHeight()

ink $ffffff
box xborder,xborder,width-xborder,height-xborder,0
print "Num of particles "+str$(num)+" fps "+str$(fps())+" Speed "+str$(gamespeed#)
print "left/right mouse speed up/down "+str$(offsetAngle)
print "Key G - For grav effect // Key T for Warp // Q-Quit"
if timer()<trailtimer+500 then print "timer active"


local x1,y1,x2,y2,length=100
x1=cos(offsetAngle)*(length/2)
y1=sin(offsetAngle)*(length/2)
x2=cos(offsetAngle)*(length/2)
y2=sin(offsetAngle)*(length/2)
ink $ff
line (width/2)-x1,(height/2)-y1,(width/2)+x2,(height/2)+y2
circle (width/2),(height/2),4,2
circle(width/2)-x1,(height/2)-y1,4,2
circle(width/2)+x2,(height/2)+y2,4,2
unlockbuffer
sync
until (1=scancode()) or (16=scancode()) ;esc/q

waitnokey
; repeat
setfps(250);c
for q=0 to height/2 step 1
ink $fffffff
box 0+q+1,0+q+1,width-q-1,height-q-1,0
ink 0
box 0+q,0+q,width-q,height-q,0
sync

ink $fffffff
box 0+q+1,0+q+1,width-q-1,height-q-1,0
ink 0
box 0+q,0+q,width-q,height-q,0
sync
next

ink $ffffff
local size
setfps(30)
cls 0
sync
cls 0
for size=0 to 20
line (width/2)-size,(height/2),(width/2)+size,(height/2)
line (width/2),(height/2)-size,(width/2),(height/2)+size
sync
next
for size=20 to 0 step-1
cls 0
Login required to view complete source code



Makeii Runoru

I like it when you quit the game. The screen closes in on itself and displays a little star, much like an old television.
This signature is boring, and could be improved. However, the user of this signature doesn't need a fancy signature because he or she doesn't really care for one.

micky4fun

Hi monkeybot ,

Thanks for posting code , i will poke my nose in this as soon as possible , maths look very complicated , wish i was this good at maths , well done
looks very effective

mick :)

monkeybot

ahhhh ScreenViewport  thats what i was looking for

kevin


Oddly enough, the main bottleneck was the KeyState() functions really.  Which as it turns out to be slower than one would expect.


monkeybot

#20
100 fps difference just with that command change!
It would be nice to have a code profiler.... :)