Can try, here is some stripped out code with just the tilemap and the problem call from player.main this is the example where using Field gives me the cannot access from here error and Global works
Mapping.Monkey - Contains the code for drawing a tilemap, pretty much a clone of the diddy example
'Loads up a tiled map for use as the playfield, code uses the diddy module for its tileset loading
'Layer one should be called "Tile Layer 1" The collisions Layer should be called "Collisions Layer 1"
Import mojo
Import diddy
Const ScreenWidth = Int 640
Const ScreenHeight:Int = 480
Public Class ClassTiles
' Field TileMap:MyTileMap
Field str:String
Field TileMap:MyTileMap
Field OffSetX:Int
Field OffSetY:Int
'Call me to load up a new tileset for the background map
Method Initialise(TileSetFile:String, MapFile:String)
diddyGame.images.LoadAnim(TileSetFile, 20, 20, 21, Null, True, False)
Local reader:MyTiledTileMapReader = New MyTiledTileMapReader
Local tm:TileMap = reader.LoadMap("maps/"+MapFile)
TileMap = MyTileMap(tm)
End Method
Method DrawTiles()
TileMap.RenderMap(OffSetX, OffSetY, ScreenWidth, ScreenHeight)
End Method
'Code in original example file, no idea what it does but it is called on exit. Code brings up an error if used
Method UpdateTiles()
' TileMap.UpdateAnimation(dt.frametime)
End Method
End Class
Class MyTiledTileMapReader Extends TiledTileMapReader
Method CreateMap:TileMap()
Return New MyTileMap
End
End
Class MyTileMap Extends TileMap
Method PreRenderLayer:Void(tileLayer:TileMapLayer)
SetAlpha(tileLayer.opacity)
End
End
Player.Monkey - This has the player and shooting functions normally
this line beings up the error
If BulletX[CounterA] > ScreenWidth Or BulletY[CounterA] > ScreenHeight Or BulletX[CounterA] < 0 Or Game.Mapping.TileMap.CollisionTile(BulletX[CounterA]+Game.Mapping.OffSetX, BulletY[CounterA]+Game.Mapping.OffSetY, "Collisions Layer") > 0 Then
Import Mojo
Import diddy
Import Main
Const ScreenHeight:Int = 480
Const ScreenWidth:Int = 640
Class ClassPlayer
Field X:Int = 200
Field Y:Int = 300
Field Speed:Int = 5
Field BulletX:Float[100]
Field BulletY:Float[100]
Field BulletSpeed:Float[100]
Field BulletAngle:Float[100]
Field BulletCount:Int = 0
Field BulletTimer:Float = Millisecs()
Method SortBulletsArray()
Local CounterA:Int
Local CounterB:Int
'If the bullet has gone off the screen do something about it (remove it from the array and then sort the rest)
For CounterA = 0 To BulletCount
If BulletX[CounterA] > ScreenWidth Or BulletY[CounterA] > ScreenHeight Or BulletX[CounterA] < 0 Or Game.Mapping.TileMap.CollisionTile(BulletX[CounterA]+Game.Mapping.OffSetX, BulletY[CounterA]+Game.Mapping.OffSetY, "Collisions Layer") > 0 Then
'Move all the bullets after the null one down the array, then reduce the counter
For CounterB = CounterA To BulletCount-1
BulletX[CounterB] = BulletX[CounterB+1]
BulletY[CounterB] = BulletY[CounterB+1]
BulletSpeed[CounterB] = BulletSpeed[CounterB+1]
BulletAngle[CounterB] = BulletAngle[CounterB+1]
Next
BulletCount -= 1 'Remove the bullet from the count
End If
Next
End Method
End Class
Main.Monkey - Main game loop, initialises maps etc
'language imports
Import mojo
Import diddy
'Project imports
Import input 'contains keys for rebinding
Import player
Import mapping
Function Main()
New Game()
End Function
Class Game Extends DiddyApp
Field Player:ClassPlayer
Field Input:ClassInput
Field Mapping:ClassTiles 'Causes error switching field for global makes it work
Method OnCreate()
SetUpdateRate(120)
Player = New ClassPlayer
Mapping = New ClassTiles
Mapping.Initialise("tileslostgarden.png", "map.xml")
Player.Initialise()
End Method
Method OnRender()
Cls(0, 0, 0)
Mapping.DrawTiles
End Method
Method OnUpdate()
CheckInput
Player.UpdateBullets
End Method
Method CheckInput()
If KeyDown(C_KEY_DOWN) And Mapping.TileMap.CollisionTile(Player.X+Mapping.OffSetX, Player.Y+11+Mapping.OffSetY, "Collisions Layer") < 1 Then Mapping.OffSetY += 1
If KeyDown(C_KEY_UP) And Mapping.TileMap.CollisionTile(Player.X+Mapping.OffSetX, Player.Y-1+Mapping.OffSetY, "Collisions Layer") < 1 Then Mapping.OffSetY -= 1
If KeyDown(C_KEY_LEFT) And Mapping.TileMap.CollisionTile(Player.X-1+Mapping.OffSetX, Player.Y+Mapping.OffSetY, "Collisions Layer") < 1 Then Mapping.OffSetX -= 1
If KeyDown(C_KEY_RIGHT) And Mapping.TileMap.CollisionTile(Player.X+11+Mapping.OffSetX, Player.Y+Mapping.OffSetY, "Collisions Layer") < 1 Then Mapping.OffSetX += 1
If KeyHit(C_KEY_SHOOT) Then Player.Shoot("") 'Check is the player is shooting, use keyhit so it doesnt try to spam bullets
If MouseDown(MOUSE_LEFT) And MouseOnUI = False Then Player.Shoot("")
'Test code for player collisions with map
If MouseHit(MOUSE_RIGHT) Then Print Mapping.TileMap.CollisionTile(Player.X+Mapping.OffSetX, Player.Y+Mapping.OffSetY, "Collisions Layer")
End Method
End Class
|