diff options
-rw-r--r-- | Default.ppinch | bin | 60 -> 60 bytes | |||
-rw-r--r-- | designer.bmx | 361 | ||||
-rw-r--r-- | level.bmx | 11 |
3 files changed, 337 insertions, 35 deletions
diff --git a/Default.ppinch b/Default.ppinch Binary files differindex 260e8b7..529588e 100644 --- a/Default.ppinch +++ b/Default.ppinch diff --git a/designer.bmx b/designer.bmx index b6f12de..a29a19e 100644 --- a/designer.bmx +++ b/designer.bmx @@ -8,6 +8,7 @@ Strict Import noddybox.vector Import noddybox.bitmapfont Import noddybox.simplegui +Import noddybox.algorithm Import "types.bmx" Import "level.bmx" Import "game.bmx" @@ -18,13 +19,235 @@ End Function Private +' **** Types +' +Type TDesObj Abstract + Const SELSIZE:Int=3 + + Function Create:TDesObj(x:Int, y:Int) Abstract + Function CreateFromLevel:TDesObj(o:Object) Abstract + Method Draw() Abstract + Method DrawSelect() Abstract + Method MouseOver:Int(x:Int, y:Int) Abstract + Method Drag(x:Int, y:Int) Abstract + Method Edit() Abstract + Method Save(l:TLevel) Abstract + + Method DrawSelBox(x:Int, y:Int) + Local x1:Int=x-SELSIZE + Local y1:Int=y-SELSIZE + Local x2:Int=x+SELSIZE + Local y2:Int=y+SELSIZE + + SetColor(255,255,255) + DrawLine(x1,y1,x2,y1) + DrawLine(x2,y1,x2,y2) + DrawLine(x2,y2,x1,y2) + DrawLine(x1,y2,x1,y1) + End Method + + Method InSelBox(px:Int, py:Int, x:Int, y:Int) + Local x1:Int=x-SELSIZE + Local y1:Int=y-SELSIZE + Local x2:Int=x+SELSIZE + Local y2:Int=y+SELSIZE + + Return px>=x1 And px<=x2 And py>=y1 And py<=y2 + End Method +End Type + +Type TDesGrav Extends TDesObj + Field g:TGravPoint + + Function Create:TDesObj(x:Int, y:Int) + Local o:TDesGrav=New TDesGrav + + o.g=New TGravPoint + o.g.x=x + o.g.y=y + o.g.friendly=False + o.g.mass=25 + o.g.repel=False + + Return o + End Function + + Function CreateFromLevel:TDesObj(o:Object) + Local lp:TGravPoint=TGravPoint(o) + Local no:TDesGrav=New TDesGrav + + no.g=New TGravPoint + no.g.x=lp.x + no.g.y=lp.y + no.g.friendly=lp.friendly + no.g.mass=lp.mass + no.g.repel=lp.repel + + Return no + End Function + + Method Draw() + If g.friendly + SetColor(0,255,0) + Else + SetColor(255,0,0) + EndIf + + DrawOval(g.x-MASSRAD,g.y-MASSRAD,MASSSIZE,MASSSIZE) + End Method + + Method DrawSelect() + DrawSelBox(g.x,g.y) + End Method + + Method MouseOver:Int(x:Int, y:Int) + Return InSelBox(x,y,g.x,g.y) + End Method + + Method Drag(x:Int, y:Int) + g.x=x + g.y=y + End Method + + Method Edit() + Designer.md_friendly.checked = g.friendly + Designer.md_invert.checked = g.repel + Designer.md_mass.text = g.mass + + If GUIDialog(Designer.mdialog,Designer.md_ok,Designer.md_cancel,GameGFX.pointer) + g.friendly = Designer.md_friendly.checked + g.repel = Designer.md_invert.checked + g.mass = Designer.md_mass.text.ToFloat() + EndIf + End Method + + Method Save(l:TLevel) + l.grav.AddLast(g) + End Method + +End Type + +Type TDesPoint Extends TDesObj + Field l:TPointLine + Field over_p1:Int + + Function Create:TDesObj(x:Int, y:Int) + Local o:TDesPoint=New TDesPoint + + o.over_p1=False + + o.l=New TPointLine + o.l.x1=x + o.l.y1=y + o.l.y2=y + + If x<GraphicsWidth()/2 + o.l.x2=x+50 + Else + o.l.x2=x-50 + EndIf + + o.l.gap=1 + o.l.v.x=0 + o.l.v.y=0 + + Return o + End Function + + Function CreateFromLevel:TDesObj(o:Object) + Local lp:TPointLine=TPointLine(o) + Local no:TDesPoint=New TDesPoint + + no.l=New TPointLine + no.l.x1=lp.x1 + no.l.y1=lp.y1 + no.l.x2=lp.x2 + no.l.y2=lp.y2 + no.l.gap=lp.gap + no.l.v.x=lp.v.x + no.l.v.y=lp.v.y + + Return no + End Function + + Method Draw() + Local lp:TList=DoLine(l.x1,l.y1,l.x2,l.y2) + Local i:Int=0 + + SetColor(0,255,0) + DrawLine(l.x1,l.y1,l.x1+l.v.x*10,l.y1+l.v.y*10) + DrawLine(l.x2,l.y2,l.x2+l.v.x*10,l.y2+l.v.y*10) + + For Local p:TAlgoPoint=EachIn lp + If (i Mod l.gap)=0 + SetColor(255,255,255) + Else + SetColor(200,0,0) + EndIf + Plot(p.x,p.y) + i:+1 + Next + End Method + + Method DrawSelect() + If over_p1 + DrawSelBox(l.x1,l.y1) + Else + DrawSelBox(l.x2,l.y2) + EndIf + End Method + + Method MouseOver:Int(x:Int, y:Int) + If InSelBox(x,y,l.x1,l.y1) + over_p1=True + Return True + EndIf + If InSelBox(x,y,l.x2,l.y2) + over_p1=False + Return True + EndIf + Return False + End Method + + Method Drag(x:Int, y:Int) + If over_p1 + l.x1=x + l.y1=y + Else + l.x2=x + l.y2=y + EndIf + End Method + + Method Edit() + Designer.pd_gap.text = l.gap + Designer.pd_vx.text = l.v.x + Designer.pd_vy.text = l.v.y + + If GUIDialog(Designer.pdialog,Designer.pd_ok,Designer.pd_cancel,GameGFX.pointer) + l.gap = Designer.pd_gap.text.ToInt() + l.v.x = Designer.pd_vx.text.ToFloat() + l.v.y = Designer.pd_vy.text.ToFloat() + EndIf + End Method + + Method Save(l:TLevel) + l.point.AddLast(l) + End Method + +End Type + ' **** Globals ' +' This type acts as a namespace for global variables +' Type Designer Const TEXTX:Int=100 Global init:Int=False + Global obj:TList + Global levelset:TLevelSet Global level:TLevel Global levelsetfname:String @@ -53,7 +276,6 @@ Type Designer Global quitbut:TButton Global mdialog:TGUIHandler - Global md_panel:TPanel Global md_friendly:TCheckbox Global md_invert:TCheckbox Global md_mass:TText @@ -61,8 +283,7 @@ Type Designer Global md_cancel:TButton Global pdialog:TGUIHandler - Global pd_panel:TPanel - Global pd_gap:TNumberInt + Global pd_gap:TText Global pd_vx:TText Global pd_vy:TText Global pd_ok:TButton @@ -71,42 +292,66 @@ Type Designer Function Initialise() If Not init Local l:TLabel + Local p:TPanel + + obj = CreateList() TGUIFont.font = GameGFX.guifont - levelset = New TLevelSet - level = New TLevel - levelsetfname = "Default.ppinch" - levelindex = 0 + levelset = New TLevelSet + level = New TLevel + levelsetfname = "Default.ppinch" + levelindex = 0 - gui = TGUIHandler.Create() + gui = TGUIHandler.Create() TLabel.Create(gui,0,0,"File") - fname_txt = TText.Create(gui,TEXTX,0,"",32) - fname_load = TButton.Create(gui,fname_txt.x+fname_txt.w+10,0,50,12,"Load",LoadCallback) - fname_save = TButton.Create(gui,fname_load.x+fname_load.w+10,0,50,fname_load.h,"Save",SaveCallback) + fname_txt = TText.Create(gui,TEXTX,0,"",32) + fname_load = TButton.Create(gui,fname_txt.x+fname_txt.w+10,0,50,12,"Load",LoadCallback) + fname_save = TButton.Create(gui,fname_load.x+fname_load.w+10,0,50,fname_load.h,"Save",SaveCallback) TLabel.Create(gui,0,10,"Levelset name") - setname_txt = TText.Create(gui,TEXTX,10,"",32) + setname_txt = TText.Create(gui,TEXTX,10,"",32) TLabel.Create(gui,0,20,"Level name") - levname_txt = TText.Create(gui,TEXTX,20,"",32) - levadd_but = TButton.Create(gui,levname_txt.x+levname_txt.w+10,levname_txt.y,50,12,"Add",AddLevelCallback) - levins_but = TButton.Create(gui,levadd_but.x+levadd_but.w+10,levname_txt.y,50,12,"Insert",InsertLevelCallback) - levdel_but = TButton.Create(gui,levins_but.x+levins_but.w+10,levname_txt.y,50,12,"Delete",DeleteLevelCallback) - - levinv_check = TCheckbox.Create(gui,0,35,"Invert placed masses",InvertPlacedCallback) - l=TLabel.Create(gui,levinv_check.w+50,35,"Level:") - levnum = TNumberInt.Create(gui,l.x+l.w+10,35,LevelNumberCallback) - levnum.value=0 - levnum.minval=0 - levnum.maxval=0 + levname_txt = TText.Create(gui,TEXTX,20,"",32) + levadd_but = TButton.Create(gui,levname_txt.x+levname_txt.w+10,levname_txt.y,50,12,"Add",AddLevelCallback) + levins_but = TButton.Create(gui,levadd_but.x+levadd_but.w+10,levname_txt.y,50,12,"Insert",InsertLevelCallback) + levdel_but = TButton.Create(gui,levins_but.x+levins_but.w+10,levname_txt.y,50,12,"Delete",DeleteLevelCallback) + + levinv_check = TCheckbox.Create(gui,0,35,"Invert placed masses",InvertPlacedCallback) + l = TLabel.Create(gui,levinv_check.w+50,35,"Level:") + levnum = TNumberInt.Create(gui,l.x+l.w+10,35,LevelNumberCallback) + levnum.value = 0 + levnum.minval = 0 + levnum.maxval = 0 - hide_check = TCheckbox.Create(gui,750,0,"Hide",HideCallback) + hide_check = TCheckbox.Create(gui,750,0,"Hide",HideCallback) - validbut = TButton.Create(gui,650,570,49,29,"Check",CheckCallback) - helpbut = TButton.Create(gui,700,570,49,29,"Test",TestCallback) - quitbut = TButton.Create(gui,750,570,49,29,"Quit",QuitCallback) + validbut = TButton.Create(gui,650,570,49,29,"Check",CheckCallback) + helpbut = TButton.Create(gui,700,570,49,29,"Test",TestCallback) + quitbut = TButton.Create(gui,750,570,49,29,"Quit",QuitCallback) + + mdialog = TGUIHandler.Create() + p = TPanel.Create(mdialog,-1,-1,400,100) + md_friendly = TCheckbox.Create(mdialog,p.x+5,p.y+10,"Friendly (scores for player)?") + md_invert = TCheckbox.Create(mdialog,p.x+5,p.y+30,"Inverse gravity?") + l = TLabel.Create(mdialog,p.x+5,p.y+50,"Mass:") + md_mass = TText.Create(mdialog,p.x+l.w+10,p.y+50,"",30,TText.NUMERIC|TText.POSITIVE) + md_ok = TButton.Create(mdialog,p.x+5,p.y+p.h-25,p.w/2-10,20,"OK",Null) + md_cancel = TButton.Create(mdialog,p.x+p.w/2+5,p.y+p.h-25,p.w/2-10,20,"Cancel",Null) + + pdialog = TGUIHandler.Create() + p = TPanel.Create(pdialog,-1,-1,400,100) + l = TLabel.Create(pdialog,p.x+5,p.y+10,"Gap per point:") + pd_gap = TText.Create(pdialog,p.x+90,p.y+10,"",30,TText.NUMERIC|TText.INTEGER|TText.POSITIVE) + l = TLabel.Create(pdialog,p.x+5,p.y+30,"Initial dx:") + l = TLabel.Create(pdialog,p.x+5,p.y+50,"Initial dy:") + pd_vx = TText.Create(pdialog,p.x+90,p.y+30,"",30,TText.NUMERIC) + pd_vy = TText.Create(pdialog,p.x+90,p.y+50,"",30,TText.NUMERIC) + pd_ok = TButton.Create(pdialog,p.x+5,p.y+p.h-25,p.w/2-10,20,"OK",Null) + pd_cancel = TButton.Create(pdialog,p.x+p.w/2+5,p.y+p.h-25,p.w/2-10,20,"Cancel",Null) + levelset.level.AddLast(level) init=True EndIf @@ -126,11 +371,71 @@ Function DoDesigner() Designer.done=False + Local sel:TDesObj=Null + Local drag:Int=False + While Not Designer.done Cls - Designer.gui.EventLoop() + + If Not drag + Designer.gui.EventLoop() + EndIf + + Local x:Int=MouseX() + Local y:Int=MouseY() + + If Not drag + sel=Null + EndIf + + For Local o:TDesObj=EachIn Designer.obj + o.Draw() + + If sel=Null And o.MouseOver(x,y) + sel=o + EndIf + Next + + If sel<>Null + sel.DrawSelect() + EndIf + + If drag + sel.Drag(x,y) + EndIf + + If KeyHit(KEY_MOUSERIGHT) + If sel<>Null + Select GUIMenu("Object Menu",["Edit","Delete"],x,y,GameGFX.pointer) + Case 0 + sel.Edit() + Case 1 + Designer.obj.Remove(sel) + End Select + Else + Select GUIMenu("Create Menu",["Create Gravity Point","Create Particle Line"],x,y,GameGFX.pointer) + Case 0 + Designer.obj.AddLast(TDesGrav.Create(x,y)) + Case 1 + Designer.obj.AddLast(TDesPoint.Create(x,y)) + End Select + EndIf + sel=Null + EndIf + + If Not drag + If KeyDown(KEY_MOUSELEFT) And sel<>Null + drag=True + EndIf + Else + If Not KeyDown(KEY_MOUSELEFT) + drag=False + EndIf + EndIf + SetColor(255,255,255) DrawImage(GameGFX.pointer,MouseX(),MouseY()) + Flip FlushMem Wend @@ -15,9 +15,6 @@ Const MAGIC:String="PPINCH0.0" Const MAX_GRAV:Int=10 Const MAX_POINT:Int=1000 -Const GRAV_ATTRACT:Int=0 -Const GRAV_REPEL:Int=0 - Type TLevelException Field message:String @@ -29,7 +26,7 @@ Type TLevelException End Type Type TGravPoint - Field mode:Int + Field repel:Int Field friendly:Int Field x:Float Field y:Float @@ -49,12 +46,12 @@ Type TGravPoint m.x=x m.y=y - m.inverse=(mode=GRAV_REPEL) + m.inverse=repel End Method Function FromStream:TGravPoint(s:TStream) Local o:TGravPoint=New TGravPoint - o.mode=s.ReadInt() + o.repel=s.ReadInt() o.friendly=s.ReadInt() o.x=s.ReadFloat() o.y=s.ReadFloat() @@ -63,7 +60,7 @@ Type TGravPoint End Function Method ToStream(s:TStream) - s.WriteInt(mode) + s.WriteInt(repel) s.WriteInt(friendly) s.WriteFloat(x) s.WriteFloat(y) |