From 5a8cc026cb6fc591795b8b8e0abec245771889bb Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 12 Oct 2007 23:01:07 +0000 Subject: Updates --- GFX/PNG/BULLET.png | Bin 0 -> 224 bytes GFX/PNG/MOUSE.png | Bin 0 -> 338 bytes GFX/PNG/PLAYER.png | Bin 0 -> 343 bytes GFX/PNG/PLAYERDEAD.png | Bin 0 -> 949 bytes GFX/PNG/PLAYERHAPPY.png | Bin 0 -> 357 bytes GFX/backdrop.bmp | Bin 1440054 -> 0 bytes GFX/backdrop.c4d | Bin 106459 -> 0 bytes GFX/button.png | Bin 0 -> 5483 bytes GFX/earth.c4d | Bin 0 -> 106459 bytes GFX/earth.png | Bin 0 -> 324058 bytes GFX/font.bmf | Bin 84480 -> 83712 bytes GFX/font_shadow.bmf | Bin 84480 -> 83712 bytes GFX/layer1.png | Bin 0 -> 10110 bytes GFX/layer2.png | Bin 0 -> 15450 bytes GFX/sprites.bms | Bin 0 -> 15062 bytes font_fade.bmx | 18 +-- main.bmx | 340 +++++++++++++++++++++++++++++++++++------------- menu.bmx | 76 +++++++++++ players.bmx | 123 ++++++++++++++++++ sprite.bmx | 94 +++++++++++++ 20 files changed, 555 insertions(+), 96 deletions(-) create mode 100644 GFX/PNG/BULLET.png create mode 100644 GFX/PNG/MOUSE.png create mode 100644 GFX/PNG/PLAYER.png create mode 100644 GFX/PNG/PLAYERDEAD.png create mode 100644 GFX/PNG/PLAYERHAPPY.png delete mode 100644 GFX/backdrop.bmp delete mode 100644 GFX/backdrop.c4d create mode 100644 GFX/button.png create mode 100644 GFX/earth.c4d create mode 100644 GFX/earth.png create mode 100644 GFX/layer1.png create mode 100644 GFX/layer2.png create mode 100644 GFX/sprites.bms create mode 100644 menu.bmx create mode 100644 players.bmx create mode 100644 sprite.bmx diff --git a/GFX/PNG/BULLET.png b/GFX/PNG/BULLET.png new file mode 100644 index 0000000..374e7ae Binary files /dev/null and b/GFX/PNG/BULLET.png differ diff --git a/GFX/PNG/MOUSE.png b/GFX/PNG/MOUSE.png new file mode 100644 index 0000000..a860d90 Binary files /dev/null and b/GFX/PNG/MOUSE.png differ diff --git a/GFX/PNG/PLAYER.png b/GFX/PNG/PLAYER.png new file mode 100644 index 0000000..81c3a3e Binary files /dev/null and b/GFX/PNG/PLAYER.png differ diff --git a/GFX/PNG/PLAYERDEAD.png b/GFX/PNG/PLAYERDEAD.png new file mode 100644 index 0000000..cea2717 Binary files /dev/null and b/GFX/PNG/PLAYERDEAD.png differ diff --git a/GFX/PNG/PLAYERHAPPY.png b/GFX/PNG/PLAYERHAPPY.png new file mode 100644 index 0000000..eb4218d Binary files /dev/null and b/GFX/PNG/PLAYERHAPPY.png differ diff --git a/GFX/backdrop.bmp b/GFX/backdrop.bmp deleted file mode 100644 index 7e4a969..0000000 Binary files a/GFX/backdrop.bmp and /dev/null differ diff --git a/GFX/backdrop.c4d b/GFX/backdrop.c4d deleted file mode 100644 index 4183fe7..0000000 Binary files a/GFX/backdrop.c4d and /dev/null differ diff --git a/GFX/button.png b/GFX/button.png new file mode 100644 index 0000000..6e97350 Binary files /dev/null and b/GFX/button.png differ diff --git a/GFX/earth.c4d b/GFX/earth.c4d new file mode 100644 index 0000000..4183fe7 Binary files /dev/null and b/GFX/earth.c4d differ diff --git a/GFX/earth.png b/GFX/earth.png new file mode 100644 index 0000000..6abc6fe Binary files /dev/null and b/GFX/earth.png differ diff --git a/GFX/font.bmf b/GFX/font.bmf index 373086f..897024b 100644 Binary files a/GFX/font.bmf and b/GFX/font.bmf differ diff --git a/GFX/font_shadow.bmf b/GFX/font_shadow.bmf index 1867516..97992e3 100644 Binary files a/GFX/font_shadow.bmf and b/GFX/font_shadow.bmf differ diff --git a/GFX/layer1.png b/GFX/layer1.png new file mode 100644 index 0000000..c0313da Binary files /dev/null and b/GFX/layer1.png differ diff --git a/GFX/layer2.png b/GFX/layer2.png new file mode 100644 index 0000000..603017a Binary files /dev/null and b/GFX/layer2.png differ diff --git a/GFX/sprites.bms b/GFX/sprites.bms new file mode 100644 index 0000000..8a10e53 Binary files /dev/null and b/GFX/sprites.bms differ diff --git a/font_fade.bmx b/font_fade.bmx index 62f5e82..0c9cd1b 100644 --- a/font_fade.bmx +++ b/font_fade.bmx @@ -3,12 +3,14 @@ ' ' $Id$ ' -Type FontFade +Import noddybox.bitmapfont + +Type TFontFade Field list:TList - Field font:BitmapFont + Field font:TBitmapFont - Function Create:FontFade(f:BitmapFont) - Local ff:FontFade=New FontFade + Function Create:TFontFade(f:TBitmapFont) + Local ff:TFontFade=New TFontFade ff.list=New TList ff.font=f @@ -16,7 +18,7 @@ Type FontFade Return ff End Function - Method Add(s:String, x:Float, y:Float, col:Int, a:Float, ai:Float, dx:Float, dy:Float) + Method Add(s:String, x:Float, y:Float, col:Int, a:Float=1.0, ai:Float=0.02, dx:Float=0.0, dy:Float=0.0) Local f:FontFadeEnt=New FontFadeEnt f.s=s @@ -34,7 +36,7 @@ Type FontFade list.AddLast(f) End Method - Method Centre(s:String, y:Float, col:Int, a:Float, ai:Float, dy:Float) + Method Centre(s:String, y:Float, col:Int, a:Float=1.0, ai:Float=0.02, dy:Float=0.0) Local f:FontFadeEnt=New FontFadeEnt f.s=s @@ -74,9 +76,9 @@ Type FontFade SetAlpha(f.a) If f.centre - font.CentreColoured(f.s,f.y,f.r,f.g,f.b) + font.Centre(f.s,f.y,f.r,f.g,f.b) Else - font.DrawColoured(f.s,f.x,f.y,f.r,f.g,f.b) + font.Draw(f.s,f.x,f.y,f.r,f.g,f.b) EndIf f.a:+f.ai diff --git a/main.bmx b/main.bmx index f360e90..4b91516 100644 --- a/main.bmx +++ b/main.bmx @@ -6,95 +6,240 @@ Strict Import noddybox.bitmapfont +Import noddybox.vector ' Includes ' -Include "font_fade.bmx" +Import "font_fade.bmx" +Import "menu.bmx" +Import "sprite.bmx" +Import "players.bmx" ' Included binaries ' Incbin "GFX/font.bmf" Incbin "GFX/font_shadow.bmf" -Incbin "GFX/backdrop.bmp" +Incbin "GFX/earth.png" +Incbin "GFX/layer1.png" +Incbin "GFX/layer2.png" +Incbin "GFX/button.png" +Incbin "GFX/PNG/PLAYER.png" +Incbin "GFX/PNG/PLAYERHAPPY.png" +Incbin "GFX/PNG/PLAYERDEAD.png" +Incbin "GFX/PNG/MOUSE.png" +Incbin "GFX/PNG/BULLET.png" + +' Initialise graphics +' SetGraphicsDriver GLMax2DDriver() Graphics 800,600,32,60 HideMouse SetBlend(ALPHABLEND) +' Consts +' +Const SPEED:Float=0.1 +Const MAX_SPEED:Float=2.0 + ' Globals ' -Global font:BitmapFont=BitmapFont.Load("incbin::GFX/font.bmf",0) -Global font_shadow:BitmapFont=BitmapFont.Load("incbin::GFX/font_shadow.bmf",0) -Global quit:Int=True -Global fade:FontFade=FontFade.Create(font) -Global fade_shadow:FontFade=FontFade.Create(font_shadow) -Global bdrop:TImage=LoadImage("incbin::GFX/backdrop.bmp",0) +Global quit:Int=False +Global music:Int=True +Global sfx:Int=True + +' Global images +' +Global font:TBitmapFont=TBitmapFont.Load("incbin::GFX/font.bmf",0) +Global font_shadow:TBitmapFont=TBitmapFont.Load("incbin::GFX/font_shadow.bmf",0) +Global fade:TFontFade=TFontFade.Create(font) +Global fade_shadow:TFontFade=TFontFade.Create(font_shadow) +Global layer1:TImage=LoadImage("incbin::GFX/layer1.png",FILTEREDIMAGE) +Global layer2:TImage=LoadImage("incbin::GFX/layer2.png",FILTEREDIMAGE) +Global buttonimg:TImage=LoadImage("incbin::GFX/button.png",0) + +AutoMidHandle True +Global earthimg:TImage=LoadImage("incbin::GFX/earth.png",0) +AutoMidHandle False -SetImageHandle(bdrop,400,300) +' Load sprites +' +AutoMidHandle True +Global mouse_cursor:TImage=LoadAnimImage("incbin::GFX/PNG/MOUSE.png",16,16,0,3,0) +Global player_image:TImage=LoadAnimImage("incbin::GFX/PNG/PLAYER.png",16,16,0,2,0) +Global bullet_image:TImage=LoadAnimImage("incbin::GFX/PNG/BULLET.png",8,8,0,2,0) +AutoMidHandle False -Intro() +Global bdropx#=0 +Global bdropy#=0 +Global mouse:TSprite=TSprite.Create(mouse_cursor,5,True,False,0) +Global actor:TPlayer=TPlayer.Create(player_image,bullet_image,3,False,True,1) + +' ---------------------------------------------- +' MAIN +' ---------------------------------------------- +' MainMenu() While Not quit MainMenu() Wend +EndGraphics End -Function StartPage(bground:Int=True,sx:Float=1,sy:Float=1) +' ---------------------------------------------- +' UTILS +' ---------------------------------------------- +' +Function StartPage(bground:Int=False,dx:Float=0,dy:Float=0) Cls If bground - Local x:Float,y:Float,r:Float,a:Float - a=GetAlpha() - r=GetRotation() - GetScale(x,y) - - SetAlpha(2) - SetTransform(0,sx,sy) - DrawImage(bdrop,400,300) - SetAlpha(a) - SetTransform(r,x,y) + bdropx:+dx + bdropy:+dy + TileImage(layer2,bdropx/2,bdropy/2) + TileImage(layer1,bdropx,bdropy) EndIf End Function Function EndPage(flush:Int=True) - If flush Then FlushMem + SetTransform(0,1,1) + mouse.x=MouseX() + mouse.y=MouseY() + mouse.Update() + 'If flush Then FlushMem Flip End Function -Function Intro() - Local c=20 +' ---------------------------------------------- +' PLAYER CODE +' ---------------------------------------------- +' +Function InitPlayer() + actor.sprite.ChangeImage(player_image,1) + actor.NewGame() +End Function + + +Function MovePlayer() + If KeyDown(KEY_DOWN) + actor.sprite.v.y:+SPEED + ElseIf KeyDown(KEY_UP) + actor.sprite.v.y:-SPEED + ElseIf (actor.sprite.v.y<>0) + If (Abs(actor.sprite.v.y)>SPEED) + actor.sprite.v.y:-Sgn(actor.sprite.v.y)*SPEED + Else + actor.sprite.v.y=0 + EndIf + EndIf + + If KeyDown(KEY_RIGHT) + actor.sprite.v.x:+SPEED + ElseIf KeyDown(KEY_LEFT) + actor.sprite.v.x:-SPEED + ElseIf (actor.sprite.v.x<>0) + If (Abs(actor.sprite.v.x)>SPEED) + actor.sprite.v.x:-Sgn(actor.sprite.v.x)*SPEED + Else + actor.sprite.v.x=0 + EndIf + EndIf + + actor.sprite.v.y=Min(MAX_SPEED,Max(actor.sprite.v.y,-MAX_SPEED)) + actor.sprite.v.x=Min(MAX_SPEED,Max(actor.sprite.v.x,-MAX_SPEED)) + + actor.AddBullet(MouseX(),MouseY()) +End Function + + + +' ---------------------------------------------- +' MENU +' ---------------------------------------------- +' +Function MainMenu() Local a$ - Local f:FontFade=fade_shadow + Local txt$ + Local f:TFontFade=fade_shadow + Local ang:Float=0 + Local tx:Int=0 + Local done:Int=False + + Local menu:TMenu=TMenu.Create(font,buttonimg,100) - SetTransform(0,2,2) + menu.Add("PLAY!") + menu.Add("HOW TO PLAY") + menu.Add("EFFECTS ON/OFF") + menu.Add("MUSIC ON/OFF") + menu.Add("QUIT") RestoreData intro_data - While Not KeyHit(KEY_SPACE) - StartPage() + ReadData a$ + + While a$<>"XXX" + txt:+a$ + ReadData a$ + Wend + + While Not done + StartPage(True,0.2,0.5)'Sin(ang),Cos(ang*2)) - c:-1 + SetTransform(0,1,1) - If c=0 - c=20 - - ReadData a$ - - If a$="XXX" - RestoreData intro_data - c=200 - Else - f.Centre(a$,500,$ffff80,0,0.008,-2) - EndIf + font_shadow.Centre("NUTTER SHOOT",0) + font_shadow.Centre("(C) IAN C 2005",30) + + Select menu.Render() + Case "PLAY!" + done=True + Case "HOW TO PLAY" + HowToPlay() + Case "MUSIC ON/OFF" + music=Not music + Case "EFFECTS ON/OFF" + sfx=Not sfx + Case "QUIT" + done=True + quit=True + EndSelect + + If KeyDown(KEY_ESCAPE) + done=True + quit=True EndIf - f.Process() + ang:+0.5 + + SetTransform(0,2,2) + + If music + font.Draw("a",0,0) + Else + font.Draw("b",0,0) + EndIf + + If sfx + font.Draw("c",40,0) + Else + font.Draw("d",40,0) + EndIf + + SetTransform(0,2,2) + + font_shadow.Draw(txt$,tx,550,255,255,100) + + tx:-3 + + If tx<-font.TextWidth(txt[0..1]) + tx:+font.TextWidth(txt[0..1]) + txt=txt[1..]+txt[0..1] + EndIf EndPage() Wend @@ -102,66 +247,85 @@ Function Intro() End Function -Function MainMenu() -End Function - - -Rem -sc=10 -t$="THIS IS SOME VERY, VERY, *VERY* ~~LARGE SCROLLING TEXT....." -x#=0 -ang#=0 -angi#=0.2 - -While Not KeyHit(KEY_ESCAPE) - Cls - - For f=0 Until NO - st[f].Update() - Next +Function HowToPlay() + Local txt$ + Local col:Int + Local f:TFontFade=fade_shadow + Local done:Int=False + Local y:Int + Local menu:TMenu=TMenu.Create(font,buttonimg,530) - SetTransform(ang,sc,sc) + SetTransform(0,1,1) + InitPlayer() - ang:+angi + actor.sprite.y=80 + + f.Clear() - If ang<=-10 Or ang>=10 Then angi=-angi - - fnt.DrawColoured(t$,x,0,255,255,255)'128,128) + menu.Add("BACK") - If Not KeyDown(KEY_P) - x:-5 + While Not done + StartPage() + + MovePlayer() - If x<-fnt.TextWidth(t[0..1]) - x:+fnt.TextWidth(t[0..1]) - t=t[1..]+t[0..1] + actor.Update() + + If f.IsEmpty() + RestoreData tutor_data + ReadData txt$ + y=100 + + While txt$<>"XXX" + ReadData col + f.Centre(txt$,y,col,0.02,0.02) + ReadData txt$ + y:+20 + Wend EndIf - EndIf - FlushMem - - Flip + f.Process() + + Select menu.Render() + Case "BACK" + done=True + EndSelect + + If KeyDown(KEY_ESCAPE) + done=True + quit=True + EndIf + + EndPage() + Wend -Wend + f.Clear() +End Function -End Rem ' PROGRAM DATA ' #intro_data - DefData "NUTTER SHOOT" - DefData " " - DefData "(C) IAN C 2005" - DefData " " - DefData "THIS IS FREE SOFTWARE." - DefData "SEE THE GNU GENERAL" - DefData "PUBLIC LICENSE FOR" - DefData "DETAILS." - DefData " " - DefData " " - DefData "PRESS SPACE TO PLAY" - DefData " " - DefData " " + DefData " " + DefData " " + DefData "SAVE THE EARTH FROM " + DefData "THE PERIL OF BADLY DRAWN SPRITES " + DefData "AFTER THE BLOOD OF THEIR FORMER MASTERS..." + DefData " " DefData "DEVELOPED WITH BLITZMAX" - DefData "HTTP://WWW.BLITZBASIC.COM" + DefData " " + DefData "XXX" + +#tutor_data + DefData "THIS LITTLE SPRITE IS YOU...",$ff0000 + DefData "IT RUNS AROUND WHEN YOU PRESS THE CURSOR KEYS",$ff0000 + DefData "AIM WITH THE MOUSE",$ff0000 + DefData " ",$ff0000 + DefData "TRY IT NOW!",$ffff00 + DefData " ",$ff0000 + DefData "SHOOT THINGS. DON'T RUN INTO THINGS.",$ff0000 + DefData "DON'T GET SHOT. DON'T FORGET TO FLOSS.",$ff0000 + DefData "THESE ARE THE RULES!",$ffff00 + DefData " ",$ff0000 DefData "XXX" diff --git a/menu.bmx b/menu.bmx new file mode 100644 index 0000000..b441a0f --- /dev/null +++ b/menu.bmx @@ -0,0 +1,76 @@ +' +' Provides simple menus +' +' $Id$ +' +Import noddybox.bitmapfont + +Type TMenu + Field list:TList + Field img:TImage + Field font:TBitmapFont + Field ypos:Int + Field xpos:Int + Field yoff:Int + Field w:Int + Field h:Int + Field count:Int + Field mbdown:Int + + Function Create:TMenu(f:TBitmapFont, img:TImage, y:Int) + Local menu:TMenu=New TMenu + + menu.list=New TList + menu.img=img + menu.font=f + menu.ypos=y + menu.w=ImageWidth(img) + menu.h=ImageHeight(img) + menu.xpos=GraphicsWidth()/2-menu.w/2 + menu.yoff=menu.h/2-f.TextHeight("X")/2 + menu.mbdown=False + Return menu + End Function + + Method Add(s:String) + list.AddLast(s) + End Method + + ' Returns the selected item, or "" for none + ' + Method Render:String() + Local y:Int=ypos + Local in:String="" + Local mx:Int=MouseX() + Local my:Int=MouseY() + Local any:Int=False + + For Local s:String=EachIn list + If (mx>xpos And mxy And my50) + m_bullets.RemoveFirst() + EndIf + + Local s:TSprite=TSprite.Create(m_bullet,2,False,False,0) + + s.x=sprite.x + s.y=sprite.y + + s.v.x=dx + s.v.y=dy + + s.v.Normalise() + s.v.Scale(m_bullet_speed) + + m_bullets.AddLast(s) + Else + m_bullet_del:-1 + EndIf + End Method +End Type + + +Type TPlayer Extends TActor + ' These fields are public + ' + Field lives:Int + + Function Create:TPlayer(img:TImage,bullet:TImage,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int) + Local p:TPlayer=New TPlayer + + p.InitActor(img,bullet,10,4,anim_speed,ping_pong,anim_with_delta,col_mask) + p.lives=3 + + Return p + End Function + + Method NewGame() + Centre() + lives=3 + m_bullets.Clear() + m_bullet_del=m_init_del + End Method + + Method ResetPosition() + sprite.x=GraphicsWidth()/2 + sprite.y=GraphicsHeight()/2 + sprite.v.x=0 + sprite.v.y=0 + End Method +End Type + +Type TEnemy Extends TActor + Function Create:TEnemy(img:TImage,bullet:TImage,bullet_del:Int,bullet_speed:Float,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int) + Local p:TEnemy=New TEnemy + + p.InitActor(img,bullet,bullet_del,bullet_speed,anim_speed,ping_pong,anim_with_delta,col_mask) + + Return p + End Function +End Type + diff --git a/sprite.bmx b/sprite.bmx new file mode 100644 index 0000000..94ab084 --- /dev/null +++ b/sprite.bmx @@ -0,0 +1,94 @@ +' +' Provides sprite wrappers routines +' +' $Id$ +' +Import noddybox.vector + +Type TSprite + Field x:Float + Field y:Float + Field v:TVector + + ' These fields are private + ' + Field img:TImage + Field frames:Int + Field pong:Int + Field fr:Int + Field colmask:Int + Field aninmove:Int + Field animspeed:Int + Field animframe:Int + Field animframeinc:Int + + Function Create:TSprite(i:TImage,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int) + Local s:TSprite=New TSprite + + s.img=i + s.frames=i.frames.length-1 + s.fr=0 + s.colmask=col_mask + s.animframe=0 + s.animframeinc=1 + s.pong=ping_pong + s.aninmove=anim_with_delta + s.animspeed=anim_speed + + s.v=TVector.Create(0,0,0) + + s.x=0 + s.y=0 + s.v.x=0 + s.v.y=0 + + Return s + End Function + + Method ChangeAnim(anim_speed:Int,ping_pong:Int,anim_with_delta:Int) + pong=ping_pong + aninmove=anim_with_delta + animspeed=anim_speed + End Method + + Method ChangeImage(i:TImage,col_mask) + img=i + frames=i.frames.length-1 + colmask=col_mask + animframe=0 + animframeinc=1 + End Method + + Method Update() + x:+v.x + y:+v.y + + DrawImage(img,x,y,animframe) + + If (colmask<>0) + CollideImage(img,x,y,animframe,0,colmask,Self) + EndIf + + fr:+1 + + If (frames>0 And ((Not aninmove) Or v.x<>0 Or v.y<>0)) + + If (fr>animspeed) + fr=0 + + animframe:+animframeinc + + If (pong) + If (animframe=0 Or animframe=frames) + animframeinc=-animframeinc + EndIf + Else + If (animframe>frames) + animframe=0 + EndIf + EndIf + EndIf + EndIf + End Method + +End Type \ No newline at end of file -- cgit v1.2.3