summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Default.ppinchbin0 -> 60 bytes
-rw-r--r--designer.bmx94
-rw-r--r--level.bmx34
-rw-r--r--main.bmx2
4 files changed, 109 insertions, 21 deletions
diff --git a/Default.ppinch b/Default.ppinch
new file mode 100644
index 0000000..260e8b7
--- /dev/null
+++ b/Default.ppinch
Binary files differ
diff --git a/designer.bmx b/designer.bmx
index 7546823..b6f12de 100644
--- a/designer.bmx
+++ b/designer.bmx
@@ -33,43 +33,76 @@ Type Designer
Global gui:TGUIHandler
- Global fname_lab:TLabel
Global fname_txt:TText
+ Global fname_load:TButton
+ Global fname_save:TButton
- Global setname_lab:TLabel
Global setname_txt:TText
- Global levname_lab:TLabel
Global levname_txt:TText
+ Global levadd_but:TButton
+ Global levins_but:TButton
+ Global levdel_but:TButton
+ Global levinv_check:TCheckbox
+ Global levnum:TNumberInt
Global hide_check:TCheckbox
Global validbut:TButton
Global helpbut:TButton
Global quitbut:TButton
+
+ Global mdialog:TGUIHandler
+ Global md_panel:TPanel
+ Global md_friendly:TCheckbox
+ Global md_invert:TCheckbox
+ Global md_mass:TText
+ Global md_ok:TButton
+ Global md_cancel:TButton
+
+ Global pdialog:TGUIHandler
+ Global pd_panel:TPanel
+ Global pd_gap:TNumberInt
+ Global pd_vx:TText
+ Global pd_vy:TText
+ Global pd_ok:TButton
+ Global pd_cancel:TButton
Function Initialise()
If Not init
+ Local l:TLabel
+
TGUIFont.font = GameGFX.guifont
levelset = New TLevelSet
level = New TLevel
levelsetfname = "Default.ppinch"
- done = False
levelindex = 0
gui = TGUIHandler.Create()
- fname_lab = TLabel.Create(gui,0,0,"File")
+ 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)
- setname_lab = TLabel.Create(gui,0,10,"Levelset name")
+ TLabel.Create(gui,0,10,"Levelset name")
setname_txt = TText.Create(gui,TEXTX,10,"",32)
- levname_lab = TLabel.Create(gui,0,20,"Level name")
+ 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
- hide_check = TCheckbox.Create(gui,700,0,"Hide GUI",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)
@@ -78,6 +111,7 @@ Type Designer
init=True
EndIf
+ done = False
fname_txt.text = levelsetfname
setname_txt.text = levelset.name
levname_txt.text = level.name
@@ -95,6 +129,7 @@ Function DoDesigner()
While Not Designer.done
Cls
Designer.gui.EventLoop()
+ SetColor(255,255,255)
DrawImage(GameGFX.pointer,MouseX(),MouseY())
Flip
FlushMem
@@ -127,3 +162,46 @@ End Function
Function CheckCallback(w:TWidget)
End Function
+
+Function LoadCallback(w:TWidget)
+ Try
+ Local load:TLevelSet=TLevelSet.Load(Designer.fname_txt.text)
+ Designer.levelset=load
+ Catch e:TLevelException
+ GUINotify("Failed to load '" + Designer.fname_txt.text + "'||"+e.message,GameGFX.pointer)
+ EndTry
+End Function
+
+Function SaveCallback(w:TWidget)
+ If Not Designer.levelset.Save(Designer.fname_txt.text)
+ GUINotify("Failed to save '" + Designer.fname_txt.text + "'",GameGFX.pointer)
+ EndIf
+End Function
+
+Function InvertPlacedCallback(w:TWidget)
+ Local c:TCheckbox=TCheckbox(w)
+ Designer.level.invmass=c.checked
+End Function
+
+Function LevelNumberCallback(w:TWidget)
+ Local c:TNumberInt=TNumberInt(w)
+ SaveLevel()
+ Designer.levelindex=c.value
+ LoadLevel()
+End Function
+
+Function AddLevelCallback(w:TWidget)
+End Function
+
+Function InsertLevelCallback(w:TWidget)
+End Function
+
+Function DeleteLevelCallback(w:TWidget)
+ If Designer.levelset.level.Count()<2
+ GUINotify("Must have at least one level!",GameGFX.pointer)
+ Return
+ EndIf
+
+ If GUIYesNo("Delete this level:|"+Designer.levname_txt.text,GameGFX.pointer)
+ EndIf
+End Function \ No newline at end of file
diff --git a/level.bmx b/level.bmx
index 50411a1..ba0ea40 100644
--- a/level.bmx
+++ b/level.bmx
@@ -7,9 +7,10 @@
Strict
Import noddybox.vector
Import noddybox.bitmapfont
+Import noddybox.algorithm
Import "types.bmx"
-Const MAGIC:String="$Version$"
+Const MAGIC:String="PPINCH0.0"
Const MAX_GRAV:Int=10
Const MAX_POINT:Int=1000
@@ -17,9 +18,6 @@ Const MAX_POINT:Int=1000
Const GRAV_ATTRACT:Int=0
Const GRAV_REPEL:Int=0
-Const LINE_EVEN:Int=0
-Const LINE_RAND:Int=1
-
Type TLevelException
Field message:String
@@ -74,12 +72,11 @@ Type TGravPoint
End Type
Type TPointLine
- Field mode:Int
Field x1:Float
Field y1:Float
Field x2:Float
Field y2:Float
- Field num:Int
+ Field gap:Int
Field v:TVector
Method New()
@@ -87,28 +84,41 @@ Type TPointLine
End Method
Method CreatePoints(l:TList)
+ Local line:TList=DoLine(x1,y1,x2,y2)
+ Local n:Int=line.Count()
+ Local i:Int=0
+
+ For Local p:TAlgoPoint=EachIn line
+ If (i Mod gap)=0
+ Local tp:TPoint=New TPoint
+ tp.x=p.x
+ tp.y=p.y
+ tp.v.x=v.x
+ tp.v.y=v.y
+ l.AddLast(tp)
+ EndIf
+ i:+1
+ Next
End Method
Function FromStream:TPointLine(s:TStream)
Local o:TPointLine=New TPointLine
- o.mode=s.ReadInt()
o.x1=s.ReadFloat()
o.y1=s.ReadFloat()
o.x2=s.ReadFloat()
o.y2=s.ReadFloat()
- o.num=s.ReadInt()
+ o.gap=s.ReadInt()
o.v.x=s.ReadInt()
o.v.y=s.ReadInt()
Return o
End Function
Method ToStream(s:TStream)
- s.WriteInt(mode)
s.WriteFloat(x1)
s.WriteFloat(y1)
s.WriteFloat(x2)
s.WriteFloat(y2)
- s.WriteInt(num)
+ s.WriteInt(gap)
s.WriteInt(v.x)
s.WriteInt(v.y)
End Method
@@ -192,7 +202,7 @@ Type TLevelSet
name="Untitled"
End Method
- Function FromStream:TLevelSet(file:String)
+ Function Load:TLevelSet(file:String)
Local s:TStream=ReadStream(file)
If s=Null
@@ -221,7 +231,7 @@ Type TLevelSet
Return o
End Function
- Method ToStream:Int(file:String)
+ Method Save:Int(file:String)
Local s:TStream=WriteStream(file)
If s=Null
diff --git a/main.bmx b/main.bmx
index 2d0e539..1e02371 100644
--- a/main.bmx
+++ b/main.bmx
@@ -30,7 +30,7 @@ Incbin "GFX/COLLECTOR.png"
' Initialise graphics
'
SetGraphicsDriver GLMax2DDriver()
-Graphics 800,600',32,60
+Graphics 800,600,32,60
HideMouse
SetBlend(ALPHABLEND)