Hello.
I have been struggling with trying to implement a " camera " like functionality in my game I am making. More like I am struggling on how to implement it. Here is my code so far. The types are in seperate files and also my main loop is.
My questions are probly simple or obvious but I am new to this and am not sure which I should do and don't want to code it one way and find out I should have done it another way.
With my Maps type code, is the tiled map larger then my screen x,y and I just cant see it because of no camera type yet? I know its not wider because I don't want it to be, but is the Y height go beyond the upper or lower portion of my viewing area? And if it does go beyond my screen how do I move my player along it to make a camera in 2D, should I use the tiled map index somehow or should I use the screen X&Y to somehow do it? I don't want to code it one way and then later on find out I should have done it another way. The map sizes in my game will remain the same size for all levels.
If I do need to use the arrays index could someone be so kind as to show how you index the array because the help files doesn't show much on how to do it.
Another question related to this is I used another image to draw some foliage on the map using a .bmp and didn't put it into the array, just used drawtext and drew over my tiled map or on top of it.This slowed my game down terribly, the bullets out of my players gun looked like slow motion..LoL , is there a better way to do this or a reason why it slowed it down?
Being a newbie to this I will appreciate any help in this and any criticism of my code sofar, such as making the array part of the list in the create function( i think it is anyhow). I am copying the structure as best as possible from the "make asteroids in an hour" tutorial posted by Wave in the tutorial section. Also I already know the trig is wrong for the 2D vectoring but I needed it to face north or up at the start as this is going to be a top down viewed shooter that Yscrolls only.Nonetheless let me know what you all think of the structure and such please. Thank You in advance.
I have been struggling with trying to implement a " camera " like functionality in my game I am making. More like I am struggling on how to implement it. Here is my code so far. The types are in seperate files and also my main loop is.
Strict Include"TGameObjects.BMX" Include"TMaps.BMX" Include"TPlayers.BMX" Include"TFire.BMX" Global ScreenW = 1024, ScreenH = 768,Depth = 0 Graphics ScreenW,ScreenH,Depth SetMaskColor 244,21,241' Magenta TPlayers.Create() TMaps.Create() While Not KeyDown(KEY_ESCAPE) Cls TMaps.UpdateAll() TPlayers.UpdateAll() TFire.UpdateAll() SetScale 1,1 SetRotation 0 DrawText " memory allocated ..."+ MemAlloced(), 0,0 DrawText " memory used ..." + MemUsage(),0,14 'DrawText " mapx size is " + TMaps.X,0,28 'DrawText " mapy size is " + TMaps.Y,0,42 Flip FlushMem Wend End Type TMaps Extends TGameObjects Global Image:TImage Global List:TList Global bush:TImage Const TileSize% = 32 Field TileMap% Function Create() Local TileMap:TMaps = New TMaps If List = Null List = CreateList() List.AddLast TileMap If Not Image Image = LoadAnimImage("gfx/Grass.bmp",TileSize,TileSize,0,1,FILTEREDIMAGE) EndIf EndFunction Method New() X=0 Y=0 End Method Method Draw() End Method Method Update() Local i%,j% Local MyMap%[32,50] For i =0 To 31 For j =0 To 49 X = i * TileSize Y = j * TileSize TileMap = MyMap[i,j] SetRotation 0 SetScale 1,1 DrawImage Image,X,Y,TileMap Next Next End Method Function UpdateAll() Local TileMap:TMaps For TileMap:TMaps = EachIn List TileMap.Update() Next End Function Method Destroy() End Method End Type Type TFire Extends TGameObjects Global List:TList Global Image:TImage Function Fire(X,Y,Direction,XSpeed,YSpeed) Local Bullet:TFire = New TFire If List = Null List = CreateList() List.AddLast Bullet If Not Image Bullet.Image = LoadImage("gfx/bullet.bmp") MidHandleImage(Bullet.Image) End If Local BulletSpeed#= 8 Bullet.X = X Bullet.Y = Y Bullet.Direction = Direction 'Add Shot Start Speed Bullet.XSpeed= +Sin(Direction)*BulletSpeed + XSpeed Bullet.YSpeed= -Cos(Direction)*BulletSpeed + YSpeed End Function Method Draw() SetRotation( Direction ) SetScale .8,.6 DrawImage( Image,X,Y ) End Method Method Update() Draw() X:+ XSpeed Y:+ YSpeed If X > 1024 Or Y > 768 Or X < 0 Or Y < 0 Destroy() End Method Function UpdateAll() If Not List Return Local Bullet:TFire For Bullet = EachIn List Bullet.Update() Next End Function Method Destroy() List.Remove( Self ) End Method EndType Type TPlayers Extends TGameObjects Global List:TList Global Image:TImage Field Direction = 0 Function Create() Local player1:TPlayers = New TPlayers If List = Null List = CreateList() List.AddLast player1 If Not Image Image = LoadImage("gfx/player1.bmp") End If EndFunction Method New() X=512 Y=668 End Method Rem End Function End Rem Method Draw() SetScale .4,.4 SetRotation(Direction) DrawImage(Image,X,Y) MidHandleImage (Image) EndMethod Method Update() Draw() Local movespeed# =3.0 Local turnspeed# =2.0 If KeyDown(KEY_LEFT)&KeyDown(KEY_MOUSERIGHT) X:-Sin(Direction-90*movespeed) Y:+Cos(Direction-90*movespeed) Else If KeyDown(KEY_LEFT) Direction:- turnspeed If Direction<0 Then Direction:+360 'stay within 0 to 360 End If If KeyDown(KEY_RIGHT)&KeyDown(KEY_MOUSERIGHT) X:-Sin(Direction+90*movespeed) Y:+Cos(Direction+90*movespeed) ElseIf KeyDown(KEY_RIGHT) direction:+ turnspeed If Direction>360 Then Direction:-360 End If If KeyDown(KEY_UP) X:+ Sin(Direction)*movespeed Y:- Cos(Direction)*movespeed End If If KeyDown(Key_Down) X:- Sin(Direction)*movespeed Y:+ Cos(Direction)*movespeed End If If KeyHit(KEY_MOUSELEFT) TFire.Fire( X, Y, Direction, XSpeed, YSpeed ) End If End Method Function UpdateAll() Local player1:TPlayers For player1:TPlayers = EachIn List player1.Update() Next End Function Method Destroy() End Method End Type Type TGameObjects Abstract Field X#,Y# Field Direction# Field XSpeed# Field YSpeed# Function Create() End Function '///////////////////' Function UpdateAll() End Function '//////////////////' Method New() End Method '/////////////////' Method Update() End Method '/////////////////' Method Draw() End Method '/////////////////' Method Destroy() End Method End Type
My questions are probly simple or obvious but I am new to this and am not sure which I should do and don't want to code it one way and find out I should have done it another way.
With my Maps type code, is the tiled map larger then my screen x,y and I just cant see it because of no camera type yet? I know its not wider because I don't want it to be, but is the Y height go beyond the upper or lower portion of my viewing area? And if it does go beyond my screen how do I move my player along it to make a camera in 2D, should I use the tiled map index somehow or should I use the screen X&Y to somehow do it? I don't want to code it one way and then later on find out I should have done it another way. The map sizes in my game will remain the same size for all levels.
If I do need to use the arrays index could someone be so kind as to show how you index the array because the help files doesn't show much on how to do it.
Another question related to this is I used another image to draw some foliage on the map using a .bmp and didn't put it into the array, just used drawtext and drew over my tiled map or on top of it.This slowed my game down terribly, the bullets out of my players gun looked like slow motion..LoL , is there a better way to do this or a reason why it slowed it down?
Being a newbie to this I will appreciate any help in this and any criticism of my code sofar, such as making the array part of the list in the create function( i think it is anyhow). I am copying the structure as best as possible from the "make asteroids in an hour" tutorial posted by Wave in the tutorial section. Also I already know the trig is wrong for the 2D vectoring but I needed it to face north or up at the start as this is going to be a top down viewed shooter that Yscrolls only.Nonetheless let me know what you all think of the structure and such please. Thank You in advance.