News:

Function Finder  Find all the functions within source code files

Main Menu

Small Sprite Control Engine. Keeps track of # of specific sprites and renders.

Started by LemonWizard, January 15, 2009, 09:28:14 PM

Previous topic - Next topic

LemonWizard

This is another demo, I wrote up as part of testing the PB runtime.
Took me about half an hour. It's nifty.. I think.

Try it for yourself!!
It basically demonstrates how to hard render sprites.. it's more useful if you want to avoid Pb's built in sprite and map systems. Or quickly test stuff out. ^_^
Plus, I'm further demonstrating exactly how to control large number of sprites using an array.
To add different properties to the array you just basically add a new value to the second array dimension.
The squares are different colors and they stay those colors so you can see them animated!
Squares can be changed to anything though. The array values stay the same!

Question: What would I have to do to make them rotate circularely around the mouse? I'm thinking if I set 12 points based on the mousex and y, and make it like a clock... but then how would.. I... do that? 0_0 Somone help? ^^ I'm thinking I could also maybe just.. make a temp loop that rotates them, from 1 to 360, and plot the degrees using a formulae... any ideas?
I'm going to be using effects like this in games and what not and I"d rather program parts of the engine's array stuff first.
90% of what I post array wise will be used in my project in some way.



; PROJECT : Squares
; AUTHOR  : JO
; CREATED : 1/15/2009
; EDITED  : 1/15/2009
; ---------------------------------------------------------------------
sw=getscreenwidth()
sh=getscreenheight()
mx=mousex()
my=mousey()
clickswitch=1
squares=40
dim squares(squares,5)
tempscreen=newimage(sw, sh)
speed=1
temp=0

Drawn:
wait 30
sync
mx=mousex()
my=mousey()
if leftmousebutton()
squares(temp,3)=rnd(255)
squares(temp,4)=rnd(255)
squares(temp,5)=rnd(255)
ink rgb(squares(temp,3), squares(temp,4), squares(temp,5))
box mx, my, mx+8, my+8, 1
squares(temp,1)=mx
squares(temp,2)=my
temp=temp+1
if temp=squares then goto main
endif
goto drawn

Main:
sync
gosub Drawsquares
gosub Movesquares
gosub followsquares
wait 30
goto Main

Drawsquares:
rendertoimage tempscreen
cls rgb(0,0,0)
for temp=1 to squares
ink rgb(squares(temp,3), squares(temp,4), squares(temp,5))
box squares(temp,1), squares(temp,2), squares(temp,1)+8, squares(temp,2)+8, 1
next
rendertoscreen
drawimage tempscreen, 0, 0, 0
return

Movesquares:
for temp=1 to squares
move=rnd(4)
if move=1 then squares(temp,1)=squares(temp,1)-speed
if move=2 then squares(temp,1)=squares(temp,1)+speed
if move=3 then squares(temp,2)=squares(temp,2)-speed
if move=4 then squares(temp,2)=squares(temp,2)+speed

next
return

Followsquares:
mx=mousex()
my=mousey()
for temp=1 to squares
if squares(temp,1) <mx then squares(temp,1)=squares(temp,1)+1
if squares(temp,1) >mx then squares(temp,1)=squares(temp,1)-1
if squares(temp,2) <my then squares(temp,2)=squares(temp,2)+1
if squares(temp,2) >my then squares(temp,2)=squares(temp,2)-1
next
return


reno

Hi LemonWizard ,

I used a routine for this a long time ago. It was for the my game "Alice and the golden coins". It was coded in BLITZ PLUS.

I reopened the source code and I think you can use some lines for your work.

I was making some spheres turning around a point.

I hope it could help you.


;energie
Dim Dec30v00#(9);position X
Dim Dec30v01#(9);position Y

Dim Dec31v00#(9);angle pour la rotation

Dim Dec32v00%(9);image du bloc a afficher

Dec32v00(0)=4
Dec32v00(1)=3
Dec32v00(2)=2
Dec32v00(3)=1
Dec32v00(4)=0
Dec32v00(5)=9
Dec32v00(6)=8
Dec32v00(7)=7
Dec32v00(8)=6
Dec32v00(9)=5

Global Dec33v00#=0.0;position X global de l'energie
Global Dec33v01#=0.0;position Y global de l'energie
Global Dec33v02#=0.0;ecartement des 2 boules d'energie


-----------------------
;INIT

;energie
Dec31v00(0)=000.0
Dec31v00(1)=012.8
Dec31v00(2)=025.6
Dec31v00(3)=038.4
Dec31v00(4)=051.2
Dec31v00(5)=180.0
Dec31v00(6)=192.8
Dec31v00(7)=205.6
Dec31v00(8)=218.4
Dec31v00(9)=231.2

Dec33v00#=768.0
Dec33v01#=256.0
Dec33v02#=064.0


-----------------------

;MAIN LOOP

;dessin, energie
For Dec00v00=0 To 9

;mise a jour
Dec31v00(Dec00v00)=(Dec31v00(Dec00v00)+8.0)

;position X
Dec30v00(Dec00v00)=((Cos(Dec31v00(Dec00v00))*Dec33v02)+Dec33v00)
;position Y
Dec30v01(Dec00v00)=((Sin(Dec31v00(Dec00v00))*Dec33v02)-Dec33v01)
Dec30v01(Dec00v00)=(-Dec30v01(Dec00v00))

;dessin
DrawImage(Ima00v00(0),Ceil#(Dec30v00(Dec00v00)),Ceil#(Dec30v01(Dec00v00)),Dec32v00(Dec00v00))

Next
More games ? Go to my website :)
http://www.thereeteam.com/

reno

More games ? Go to my website :)
http://www.thereeteam.com/