From 44f5889373f05d53a94a052fedffbd7d6c0f21e0 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 26 Nov 2005 01:39:40 +0000 Subject: Initial mainly working version --- SFX/pop.wav | Bin 9112 -> 2328 bytes game.bmx | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++ gametypes.bmx | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- hardwire.bmx | 38 +++++----- pieces.sxc | Bin 0 -> 6075 bytes types.bmx | 30 ++++---- 6 files changed, 450 insertions(+), 40 deletions(-) create mode 100644 pieces.sxc diff --git a/SFX/pop.wav b/SFX/pop.wav index e9a4523..b67fa1b 100644 Binary files a/SFX/pop.wav and b/SFX/pop.wav differ diff --git a/game.bmx b/game.bmx index 0df53c5..606c014 100644 --- a/game.bmx +++ b/game.bmx @@ -6,15 +6,211 @@ ' Strict Import "types.bmx" +Import "particle.bmx" +Import "sounds.bmx" Import "gametypes.bmx" Type TGame + Field level:Int Field score:Int Field gm:TGameMap + Field timer:Int + Field alpha:Double + Field alphainc:Double + Field count:Int + Field block:TPiece + Field nextblock:TPiece + Field drop:Int Method New() score=0 gm=New TGameMap + level=1 + Particles.Clear() + alpha=0.7 + alphainc=0.01 + count=0 + nextblock=TPiece.Create() + drop=False + CreateNext() + End Method + + Method SetInitLevel(l:Int) + level=l + SetTimer() + End Method + + Method SetTimer() + If drop + timer=5 + Else + timer=Max(HERTZ/5,(16-level)*HERTZ/5) + EndIf + End Method + + Method LevelUp() + level:+1 + count=0 + End Method + + Method CreateNext() + block=nextblock + block.y=-4 + block.x=Pit.WIDTH/2 + nextblock=TPiece.Create() + nextblock.x=Pit.WIDTH+3 + nextblock.y=1 + drop=False + End Method + + Method Pause() + Local i:Timage=CreateImage(GraphicsWidth(),GraphicsHeight(),1,MASKEDIMAGE|DYNAMICIMAGE|FILTEREDIMAGE) + + GrabImage(i,0,0) + MidHandleImage(i) + SetColor(255,255,255) + + FlushKeys() + + Local a:Int[]=[0,0,0,0,0,0,0,0] + Local ac:Int[]=[7,6,5,4,3,2,1,0] + + While Not KeyHit(GameConfig.kpause) + Cls + + Local al:Double=0.3 + + For Local f:Int=0 Until a.length + SetAlpha(al) + SetRotation(a[f]) + SetScale(al,al) + DrawImage(i,GraphicsWidth()/2,GraphicsHeight()/2) + If ac[f]>0 + ac[f]:-1 + Else + a[f]:+1 + EndIf + al:+0.1 + Next + + SetRotation(0) + SetScale(1,1) + GameGFX.large.Centre("PAUSED",GraphicsHeight()/2-16) + + Flip + Wend + + SetAlpha(1) + SetRotation(0) + SetScale(1,1) + + FlushKeys + End Method + + Method Play:Int() + Local playing:Int=True + + Cls + + GameGFX.large.DrawColoured("SCORE",0,0,255,255,0) + GameGFX.large.Draw(score,0,20) + + GameGFX.large.DrawColoured("LEVEL",0,100,255,255,0) + GameGFX.large.Draw(level,0,120) + + GameGFX.large.DrawColoured("NEXT",Pit.X(Pit.WIDTH+2),Pit.Y(-1),255,255,0) + nextblock.Draw() + + If Not gm.overflow + If KeyHit(KEY_ESCAPE) + playing=False + EndIf + + If Not gm.BlockInteract() + timer:-1 + + If timer<=0 + SetTimer() + block.y:+1 + + If block.Collides(gm) + block.y:-1 + block.AddToMap(gm) + count:+1 + If count>10 + LevelUp() + EndIf + + If Not gm.overflow + CreateNext() + EndIf + EndIf + EndIf + + If KeyHit(GameConfig.kleft) + block.x:-1 + If block.Collides(gm) + block.x:+1 + EndIf + EndIf + + If KeyHit(GameConfig.kright) + block.x:+1 + If block.Collides(gm) + block.x:-1 + EndIf + EndIf + + If KeyHit(GameConfig.krotright) + block.RotateRight() + If block.Collides(gm) + block.RotateLeft() + EndIf + EndIf + + If KeyHit(GameConfig.krotleft) + block.RotateLeft() + If block.Collides(gm) + block.RotateRight() + EndIf + EndIf + + If KeyDown(GameConfig.kdrop) + timer=0 + 'drop=True + EndIf + EndIf + + block.Draw() + + score:+gm.Draw()*level*10 + Else + gm.Draw() + + SetAlpha(alpha) + SetColor(255,255,255) + DrawImage(GameGFX.gameover,GraphicsWidth()/2,GraphicsHeight()/2) + SetAlpha(1) + alpha:+alphainc + If alpha<=0.7 Or alpha>=1.0 + alpha=Max(0,Min(1,alpha)) + alphainc=-alphainc + EndIf + + If KeyHit(KEY_ENTER) Or KeyHit(KEY_ESCAPE) + playing=False + EndIf + EndIf + + Particles.Draw() + + If KeyHit(GameConfig.kpause) And Not gm.overflow + Pause() + EndIf + + Flip + + Return playing End Method End Type diff --git a/gametypes.bmx b/gametypes.bmx index b12972b..8866f5e 100644 --- a/gametypes.bmx +++ b/gametypes.bmx @@ -69,9 +69,9 @@ Type TWire t=Rand(0,6) End Method - Function Create:TWire(t:Int) + Function Create:TWire(t:Int[]) Local o:TWire=New TWire - o.t=t + o.t=t[Rand(0,t.length-1)] Return o End Function @@ -104,6 +104,221 @@ Type TWire End Function End Type +Type TPiece Abstract + Field x:Int + Field y:Int + Field ox:Int + Field oy:Int + Field map:TWire[4,4] + Field rot:Int + Field offx:Int[4] + Field offy:Int[4] + + Function Create:TPiece() + Local o:TPiece + + Select Rand(0,5) + Case 0 + o=TPiece(New TPiece_S_Left) + Case 1 + o=TPiece(New TPiece_S_Right) + Case 2 + o=TPiece(New TPiece_L_Left) + Case 3 + o=TPiece(New TPiece_L_Right) + Case 4 + o=TPiece(New TPiece_Square) + Case 5 + o=TPiece(New TPiece_Bar) + End Select + + o.BaseInit() + + Return o + End Function + + Method Init() Abstract + + Method BaseInit() + Init() + rot=0 + ox=offx[rot] + oy=offy[rot] + End Method + + Method Draw() + For Local px:Int=0 Until 4 + For Local py:Int=0 Until 4 + If map[px,py] + Local gx:Int=Pit.X(x-ox+px) + Local gy:Int=Pit.Y(y-oy+py) + SetColor(255,255,255) + DrawImage(GameGFX.tile,gx,gy) + SetColor(128,128,128) + DrawImage(map[px,py].Image(),gx,gy) + EndIf + Next + Next + End Method + + Method RotateLeft() + If rot=0 + rot=3 + Else + rot:-1 + EndIf + + ox=offx[rot] + oy=offy[rot] + + Local m:TWire[4,4] + + For Local px:Int=0 Until 4 + For Local py:Int=0 Until 4 + If map[px,py] + map[px,py].RotateLeft() + EndIf + m[py,3-px]=map[px,py] + Next + Next + + map=m + End Method + + Method RotateRight() + rot=(rot+1) Mod 4 + + ox=offx[rot] + oy=offy[rot] + + Local m:TWire[4,4] + + For Local px:Int=0 Until 4 + For Local py:Int=0 Until 4 + If map[px,py] + map[px,py].RotateRight() + EndIf + m[3-py,px]=map[px,py] + Next + Next + + map=m + End Method + + Method Collides:Int(gm:TGameMap) + For Local px:Int=0 Until 4 + For Local py:Int=0 Until 4 + If map[px,py] + Local gx:Int=x-ox+px + Local gy:Int=y-oy+py + + If gx<0 Or gx>=Pit.WIDTH Or gy>=Pit.HEIGHT + Return True + EndIf + + If gy>=0 And gm.map[gx,gy] + Return True + EndIf + EndIf + Next + Next + + Return False + End Method + + Method AddToMap(gm:TGameMap) + For Local px:Int=0 Until 4 + For Local py:Int=0 Until 4 + If map[px,py] + Local gx:Int=x-ox+px + Local gy:Int=y-oy+py + + If gy<0 + gm.overflow=True + Else + gm.map[gx,gy]=map[px,py] + Particles.AddDust(Pit.X(gx)+16,Pit.Y(gy)+32) + EndIf + EndIf + Next + Next + Sound.Click() + gm.CheckWires() + End Method +End Type + +Type TPiece_S_Right Extends TPiece + Method Init() + map[1,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_RIGHT]) + map[2,0]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.BOTTOM_LEFT,TWire.LEFT_RIGHT]) + map[0,1]=TWire.Create([TWire.CROSS,TWire.TOP_RIGHT,TWire.BOTTOM_RIGHT,TWire.LEFT_RIGHT]) + map[1,1]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT]) + offx=[1,2,2,0] + offy=[1,1,2,2] + End Method +End Type + + +Type TPiece_S_Left Extends TPiece + Method Init() + map[0,0]=TWire.Create([TWire.CROSS,TWire.TOP_RIGHT,TWire.BOTTOM_RIGHT,TWire.LEFT_RIGHT]) + map[1,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_LEFT]) + map[1,1]=TWire.Create([TWire.CROSS,TWire.TOP_RIGHT]) + map[2,1]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.BOTTOM_LEFT,TWire.LEFT_RIGHT]) + offx=[1,2,2,0] + offy=[1,1,2,2] + End Method +End Type + + +Type TPiece_L_Right Extends TPiece + Method Init() + map[0,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_RIGHT]) + map[1,0]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.BOTTOM_LEFT,TWire.LEFT_RIGHT]) + map[0,1]=TWire.Create([TWire.CROSS,TWire.TOP_BOTTOM]) + map[0,2]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.TOP_RIGHT,TWire.TOP_BOTTOM]) + offx=[0,2,3,1] + offy=[1,0,2,3] + End Method +End Type + + +Type TPiece_L_Left Extends TPiece + Method Init() + map[0,0]=TWire.Create([TWire.CROSS,TWire.TOP_RIGHT,TWire.BOTTOM_RIGHT,TWire.LEFT_RIGHT]) + map[1,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_LEFT]) + map[1,1]=TWire.Create([TWire.CROSS,TWire.TOP_BOTTOM]) + map[1,2]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.TOP_RIGHT,TWire.TOP_BOTTOM]) + offx=[1,2,2,1] + offy=[1,1,2,2] + End Method +End Type + + +Type TPiece_Square Extends TPiece + Method Init() + map[0,0]=TWire.Create([TWire.CROSS]) + map[1,0]=TWire.Create([TWire.CROSS]) + map[0,1]=TWire.Create([TWire.CROSS]) + map[1,1]=TWire.Create([TWire.CROSS]) + offx=[0,2,2,0] + offy=[1,1,3,3] + End Method +End Type + + +Type TPiece_Bar Extends TPiece + Method Init() + map[1,0]=TWire.Create([TWire.CROSS,TWire.BOTTOM_LEFT,TWire.BOTTOM_RIGHT,TWire.TOP_BOTTOM]) + map[1,1]=TWire.Create([TWire.CROSS,TWire.TOP_BOTTOM]) + map[1,2]=TWire.Create([TWire.CROSS,TWire.TOP_BOTTOM]) + map[1,3]=TWire.Create([TWire.CROSS,TWire.TOP_LEFT,TWire.TOP_RIGHT,TWire.TOP_BOTTOM]) + offx=[1,1,2,1] + offy=[1,1,1,2] + End Method +End Type + + Type TFallingBlock Field w:TWire Field x:Int @@ -132,6 +347,7 @@ Type TFallingBlock End Method End Type + Type TWireListEnt Field w:TWire Field x:Int @@ -146,6 +362,7 @@ Type TWireListEnt End Function End Type + Type TWireList Field list:TList Field col:Int @@ -271,7 +488,7 @@ Type TGameMap x:+TWire.DirX(dir) y:+TWire.DirY(dir) - If x=ox And y=oy + If x=ox And y=oy And dir=TWire.DIR_LEFT Return True EndIf @@ -464,9 +681,6 @@ Type TGameMap EndIf EndIf - SetColor(trode_col,trode_col,0) - DrawImage(GameGFX.cursor,Pit.X(cx),Pit.Y(cy)) - trode_col:+trode_coli If (trode_col=255 And trode_coli>0) Or (trode_col=200 And trode_coli<0) diff --git a/hardwire.bmx b/hardwire.bmx index 61a1180..7a9a8a5 100644 --- a/hardwire.bmx +++ b/hardwire.bmx @@ -42,7 +42,7 @@ Else EndIf ? -Graphics 800,600,32,60 +Graphics 800,600,32,HERTZ HideMouse SetBlend(ALPHABLEND) @@ -71,6 +71,12 @@ Global quit:Int=False Menu() While Not quit + Local game:TGame=New TGame + game.SetInitLevel(GameConfig.start_level) + + While game.Play() + Wend + Menu() Wend @@ -124,21 +130,10 @@ Function Menu() Local tx1:Int=(GraphicsWidth()-GameGFX.large.TextWidth("START LEVEL 1"))/2 Local tx2:Int=tx1+GameGFX.large.TextWidth("START LEVEL ") - Local gm:TGameMap=New TGameMap - While Not done - If gm.overflow - SetClsColor(128,0,0) - Else - SetClsColor(0,0,0) - EndIf - Cls DrawImage(GameGFX.title,0,0) - gm.Draw() - Particles.Draw() - sel=menu.Render(defkey>0) If defkey>0 @@ -159,15 +154,15 @@ Function Menu() GameGFX.large.DrawColoured("Left",250,180,c1,c1,0) GameGFX.large.DrawColoured("Right",250,210,c2,c2,0) - GameGFX.large.DrawColoured("Up",250,240,c3,c3,0) - GameGFX.large.DrawColoured("Down",250,270,c4,c4,0) - GameGFX.large.DrawColoured("Rotate",250,300,c5,c5,0) + GameGFX.large.DrawColoured("Rotate Right",250,240,c3,c3,0) + GameGFX.large.DrawColoured("Rotate Left",250,270,c4,c4,0) + GameGFX.large.DrawColoured("Drop",250,300,c5,c5,0) GameGFX.large.DrawColoured("Pause",250,330,c6,c6,0) GameGFX.large.DrawColoured(KeySym(GameConfig.kleft),500,180,c1,c1,0) GameGFX.large.DrawColoured(KeySym(GameConfig.kright),500,210,c2,c2,0) - GameGFX.large.DrawColoured(KeySym(GameConfig.kup),500,240,c3,c3,0) - GameGFX.large.DrawColoured(KeySym(GameConfig.kdown),500,270,c4,c4,0) - GameGFX.large.DrawColoured(KeySym(GameConfig.krot),500,300,c5,c5,0) + GameGFX.large.DrawColoured(KeySym(GameConfig.krotright),500,240,c3,c3,0) + GameGFX.large.DrawColoured(KeySym(GameConfig.krotleft),500,270,c4,c4,0) + GameGFX.large.DrawColoured(KeySym(GameConfig.kdrop),500,300,c5,c5,0) GameGFX.large.DrawColoured(KeySym(GameConfig.kpause),500,330,c6,c6,0) @@ -191,11 +186,11 @@ Function Menu() Case 2 GameConfig.kright=k Case 3 - GameConfig.kup=k + GameConfig.krotright=k Case 4 - GameConfig.kdown=k + GameConfig.krotleft=k Case 5 - GameConfig.krot=k + GameConfig.kdrop=k Case 6 GameConfig.kpause=k End Select @@ -223,7 +218,6 @@ Function Menu() done=True FlushKeys() Case MENU_SCORES - gm.AddRow() FlushKeys() Case MENU_KEYS FlushKeys() diff --git a/pieces.sxc b/pieces.sxc new file mode 100644 index 0000000..dde0de0 Binary files /dev/null and b/pieces.sxc differ diff --git a/types.bmx b/types.bmx index 62d08dd..42cb2bd 100644 --- a/types.bmx +++ b/types.bmx @@ -25,6 +25,7 @@ Incbin "GFX/copper.png" Incbin "GFX/copperslice.png" Incbin "GFX/dust.png" Incbin "GFX/title.png" +Incbin "GFX/gameover.png" Incbin "GFX/cursor.png" Incbin "TILES/tile.png" @@ -44,6 +45,8 @@ Incbin "TILES/top_right.png" Incbin "TILES/bottom_left.png" Incbin "TILES/bottom_right.png" +Const HERTZ:Int=60 + Type Lookup Global si:Double[] Global co:Double[] @@ -66,6 +69,7 @@ Type GameGFX Global large:TBitmapFont Global title:TImage + Global gameover:TImage Global pointer:TImage Global copper:TImage @@ -106,6 +110,8 @@ Type GameGFX large=TBitmapFont.Load("incbin::GFX/large.bmf",0) title=LoadImage("incbin::GFX/title.png",0) + gameover=LoadImage("incbin::GFX/gameover.png",0) + MidHandleImage(gameover) pointer=LoadImage("incbin::GFX/pointer.png",0) @@ -148,9 +154,9 @@ End Type Type GameConfig Global kleft:Int Global kright:Int - Global kup:Int - Global kdown:Int - Global krot:Int + Global krotright:Int + Global krotleft:Int + Global kdrop:Int Global kpause:Int Global start_level:Int @@ -160,9 +166,9 @@ Type GameConfig If s=Null kleft=KEY_LEFT kright=KEY_RIGHT - kup=KEY_UP - kdown=KEY_DOWN - krot=KEY_SPACE + krotright=KEY_UP + krotleft=KEY_DOWN + kdrop=KEY_SPACE kpause=KEY_P start_level=1 Return @@ -172,9 +178,9 @@ Type GameConfig kleft=s.ReadInt() kright=s.ReadInt() - kup=s.ReadInt() - kdown=s.ReadInt() - krot=s.ReadInt() + krotright=s.ReadInt() + krotleft=s.ReadInt() + kdrop=s.ReadInt() kpause=s.ReadInt() start_level=s.ReadInt() @@ -192,9 +198,9 @@ Type GameConfig s.WriteInt(kleft) s.WriteInt(kright) - s.WriteInt(kup) - s.WriteInt(kdown) - s.WriteInt(krot) + s.WriteInt(krotright) + s.WriteInt(krotright) + s.WriteInt(kdrop) s.WriteInt(kpause) s.WriteInt(start_level) -- cgit v1.2.3