This is interesting..
I coded it this afternoon because I was trying to create a platform collision space editor then found it to be more
dynamic than I realized at first.. since I coded it in this way o.0
Anyone have any ideas on how I can expand this into some kind of mini-function set? I'm on the right track..
[pbcode]
size=12
x_size=getscreenwidth()/size
y_size=getscreenheight()/size
dim grid_array(x_size, y_size)
do
sync
cls rgb(255,255,255)
draw_the_grid(size, 1, 1)
loop
function draw_the_grid(size, flag, number)
for tempx=1 to getscreenwidth()/size
for tempy=1 to getscreenheight()/size
if grid_array(tempx, tempy)=0
boxc (tempx-1)*size, (tempy-1)*size, tempx*size, tempy*size, 0, rgb(0, 20, 0)
else
boxc (tempx-1)*size, (tempy-1)*size, tempx*size, tempy*size, 1, rgb(0, 0, 0)
endif
select flag
case 1
check_grid(mousex(), mousey(), tempx, tempy, size, number)
endselect
next tempy
next tempx
endfunction
function check_grid(mx, my, tempx, tempy, size, number)
if mouseinbox( (tempx-1)*size, (tempy-1)*size, tempx*size, tempy*size )
if leftmousebutton()
action_number(number, tempx, tempy)
endif
if rightmousebutton()
action_number(2, tempx, tempy)
endif
endif
endfunction
function action_number(number, tempx, tempy)
select number
case 1
grid_array(tempx, tempy)=1
case 2
grid_array(tempx, tempy)=0
endselect
endfunction
[/pbcode]
I find it funny how there's 15 views yet no one had any comments. Kind of dissapointing actually... was hoping for more input.
Oh well.. it's the internet.
Quote from: LemonWizard on October 03, 2011, 11:30:26 PM
I find it funny how there's 15 views yet no one had any comments. Kind of dissapointing actually... was hoping for more input.
Oh well.. it's the internet.
Probably because people can't make head nor tails of what you're trying to do from your first post..
I think you're trying to make a map library.. ie..
[pbcode]
Type TMap
Xpos
Ypos
BlockWidth
BlockHeight
ArrayHandle
EndType
Dim Maps(0) as Tmap
For lp=1 to 16
CreateImage lp,32,32
rendertoimage lp
cls rndrgb()
rendertoscreen
next
; make some maps
For lp =1 to 10
Width=rndrange(5,10)
Height=rndrange(5,10)
index=New_Map(Width,height)
if Index
For Ylp=0 to Height
For Xlp=0 to Width
ImageIndex=rndrange(1,15)
Set_Map_Tile(Index,Xlp,Ylp,ImageIndex)
next
next
EndIF
next
do
cls
For lp=1 to GetArrayElements(Maps())
if Maps(lp)
Draw_Map(lp)
endif
next
Sync
loop
Function New_Map(Width,Height)
if WIdth>1 and Height>1
Index=GetFreeCell(Maps())
if Index
Maps(Index).Xpos=rnd(400)
Maps(Index).Ypos=rnd(300)
Maps(Index).BlockWidth=32
Maps(Index).BlockHeight=32
Maps(Index).ArrayHandle=Make2DIntegerArray(Width,Height)
endif
endif
EndFunction Index
Function Set_Map_Tile(Index,X,Y,ImageIndex)
if Index>0 and Index<= GetArrayElements(Maps())
if Maps(index)
MakeArray Buffer()
BUffer()=Maps(Index).ArrayHandle
Buffer(x,y)=IMageIndex
endif
endif
EndFunction
Function Draw_Map(Index)
if Index>0 and Index< GetArrayElements(Maps())
if Maps(index)
MakeArray Buffer()
BUffer()=Maps(Index).ArrayHandle
Xpos=Maps(Index).XPos
Ypos=Maps(Index).YPos
Width=Maps(Index).BlockWidth
for ylp=0 to GetArrayElements(Buffer(),2)
Xpos2=Xpos
for Xlp=0 to GetArrayElements(Buffer(),1)
ThisImage=Buffer(xlp,ylp)
if ThisIMage
drawimage ThisIMage,xpos2,ypos,false
endif
Xpos2+=Width
next
Ypos+=Maps(Index).BlockHeight
next
boxc Maps(Index).XPos,Maps(Index).YPos,xpos2-Width-1,Ypos-Height-1,false,$ffffff
text Maps(Index).XPos,Maps(Index).YPos,"Map #"+Str$(Index)
Maps(Index).XPos++
if Maps(Index).XPos>GetScreenWidth()
Maps(Index).XPos=-(Xpos2-Maps(Index).XPos)
endif
endif
endif
endfunction
Function Make2DIntegerArray(Width,Height)
Dim Array(Width,Height)
EndFunction Array()
[/pbcode]
Nope. I was trying to make a collision editor.
Basically in my game engine i'm working on which uses 2d box collision I am trying to integrate a "platform" ontop which
has a slope array.
It's for x to length, value =height
This grid is supposed to be the first steps towards an editor that lets me draw the slope for the top of that platform.
So you have two things. A: a box with an obvious hitbox range. B: The top or slope of the box. Which gets taken into account on collision if the boxe's flag is set to 1.
All of this is theoretical.. and it's just expandable code. The reason I think it's expandable is because how the functions are communicating with eachother... but it didn't really have a set purpose... the idea was to work on expandability o.o see what people can turn it into.. that's why I made this post.
The main part that I feel is impressive about it is the way I call the action_number with
function check_grid(mx, my, tempx, tempy, size, number)
if mouseinbox( (tempx-1)*size, (tempy-1)*size, tempx*size, tempy*size )
if leftmousebutton()
action_number(number, tempx, tempy)
You could write new functions that also call that same function.. and that same function just does different actions based on the flags you send it... like action_number(38, param1, param2, param3) etc..
it's the start of an event based interpreter if you use it that way.
the other reason it's impressive and expandable is because if you change the size variable at start up the program automatically handles everything including the array allocation for the grid item..
It could be turned into a pixel based image editor.. with the right code to.
THe mouse stuff is already coded into the draw grid function but one might want to seperate the draw grid function from the actual mouse click checks that way the coder can better define how input is handled..
>.> uhm basically..
I see it as having infinite potential just because of how it's built to start with. and I thought others would pick up on it..
erm.. well if that makes sense to you, then ok.. but if what you want to do is call an action, then you really don't need to set Select statements to fall through, either us Jump Tables or call the functions directly.
[pbcode]
Setfps 100
BaseIndex =FunctionIndex("Action_1")
Do
CallFunction BaseIndex+mode
if SpaceKey()
Mode+=1
If Mode>2 then Mode =0
FlushKeys
endif
Sync
loop
Function Action_1()
cls
ink $ffffffff
c1=rgb(10,20,30)
c2=rgb(30,50,90)
shadebox 0,0,800,600,c1,c1,c2,c2
Print "Action #1"
EndFunction
psub Action_2()
cls
ink $ffffffff
centertext 400,50, "Action #2"
xpos=mod(Xpos+1,800)
Circle Xpos,100,30,true
Endpsub
psub Action_3()
cls
centertext 400,300,"Action #3"
Time--
if time<=0
SpeedX1=rndrange(-5,5)
SpeedX2=rndrange(-5,5)
SpeedY1=rndrange(-5,5)
SpeedY2=rndrange(-5,5)
Time=rndrange(50,200)
endif
x1+=SpeedX1
y1+=SpeedY1
x2+=SpeedX2
y2+=SpeedY2
if X1<0 then X1=0 : SpeedX1*=-1
if X2<0 then X2=0 : SpeedX2*=-1
if X1>800 then X1=800 : SpeedX1*=-1
if X2>800 then X2=800 : SpeedX2*=-1
if y1<0 then y1=0 : Speedy1*=-1
if y2<0 then y2=0 : Speedy2*=-1
if y1>600 then y1=600 : Speedy1*=-1
if y2>600 then y2=600 : Speedy2*=-1
line x1,y1,x2,y2
Endpsub
[/pbcode]