Scrolling maze game
Blitz3D Forums/Blitz3D Beginners Area/Scrolling maze game
| ||
Hi, I want to program a maze game like pacman with a scrolling map. The map needs to be two screens in size X and Y and my sprite needs to be able to scroll along with the map. I can't seem to find any commands for drawing scrolling maps in Blitz 3D or a program to create maps. Can anyone help? Dean Sharples |
| ||
Since you're using Blitz3D, I assume you want to create a 3D game? In that case, there are no scrolling maps, instead there is a camera pointing at objects in 3D space called "entities". You'll want to keep the player (in this case Pacman) in view of the camera. This can be done using PointEntity. Something like this: Graphics3D 1600, 900 Local camera = CreateCamera() MoveEntity(camera, 0, 20, 0) Local pacman = CreateSphere() EntityColor(pacman,255,255,0) PositionEntity(pacman,10,0,10) Local maxX=40 Local maxY=30 Dim wall(maxX,maxY) Local x,y For x=0 To maxX-1 For y=0 To maxY-1 If x=0 Or x=maxX-1 Or y=0 Or y=maxY-1 Then wall(x,y) = CreateCube() PositionEntity(wall(x,y),x,0,y) EntityColor(wall(x,y),100,100,100) EndIf Next Next While Not KeyHit(1) Local speed# = 0.1 If KeyDown(30) MoveEntity(pacman,-speed,0,0) ElseIf KeyDown(17) MoveEntity(pacman,0,0,speed) ElseIf KeyDown(31) MoveEntity(pacman,0,0,-speed) ElseIf KeyDown(32) MoveEntity(pacman,speed,0,0) EndIf PointEntity(camera,pacman) UpdateWorld RenderWorld Text 10,10,"WASD to move pacman" Flip() Wend You can play around with commands CameraProjMode and CameraZoom to give it more of a "2D" feeling. As for creating maps: I would use Tiled or even Microsoft Excel to "draw" your levels and then load them into your program: do not create a wall on empty cells, do create a wall on cells filled with a certain number. You'll need collisions, enemies (AI) and so forth as well of course. |
| ||
You can also use the ORIGIN command in BlitzBasic. It adds an (negativ) offset value to all drawing commands. So you can use a playground wider than the screen, and dont have to think about the coordinates and visible viewport. Here is a sample with 1600x1200 pixels on a 800x600 screen. You can use all coordinates like on a 1600x1200 screen. But the ORIGIN commans will only show a "window" of 800x600. I wrote you 3 possibilities of scrolling. You can check them with Key <S>: Graphics 800,600 SetBuffer BackBuffer() Global PlayerX%=400, PlayerY%=400 Global PlayWidth%=1600, PlayHeight%=1200 Global OriginX%,OriginY% Global Method$="Center" Repeat Cls ; painting of the scene with an offset Origin -OriginX%, -OriginY% For x%=0 To PlayWidth/100-1 For y%=0 To PlayHeight/100-1 Color 0,111,0 Rect x*100+1,y*100+1,98,98,False Color 111,111,111 Text x*100+50,y*100+50, x+"/" +y,True, True Next Next Color 255,0,0 Oval PlayerX,PlayerY,9,9 ;reset offset to paint something neutral Origin 0,00 Color 255,255,255 Text 20,0, "Use Cursor to move the red Player" Text 20,20, " PLAYER = " +PlayerX+" / " +PlayerY Text 20,40, "Use <S> to swap control method: " +Method Text 20,60, " SCROLL = " +OriginX+" / " +OriginY ; user inputs If KeyHit(31) If Method="Static" Method="Center" ElseIf Method="Dynamic" Method="Static" ElseIf Method="Center" Method="Dynamic" EndIf EndIf If KeyDown(203) PlayerX=PlayerX-5 If PlayerX<5 PlayerX=5 EndIf If KeyDown(205) PlayerX=PlayerX+5 If PlayerX>PlayWidth-5 PlayerX=PlayWidth-5 EndIf If KeyDown(200) PlayerY=PlayerY-5 If PlayerY<5 PlayerY=5 EndIf If KeyDown(208) PlayerY=PlayerY+5 If PlayerY>PlayHeight-5 PlayerY=PlayHeight-5 EndIf ; offset calculations If Method="Center" ; Method 1 Player is always in the center OriginX = PlayerX - GraphicsWidth()/2 OriginY = PlayerY - GraphicsHeight()/2 ElseIf Method="Dynamic" ; Dynamic scroll OriginX = (PlayerX) * GraphicsWidth() / PlayWidth OriginY = (PlayerY) * GraphicsHeight() / PlayHeight ElseIf Method="Static" ; Scrolls only when necessary If Abs(PlayerX-OriginX)>GraphicsWidth()-100 OriginX=originX+5 ElseIf Abs(PlayerX-OriginX)<100 OriginX=originX-5 EndIf If Abs(PlayerY-OriginY)>GraphicsHeight()-100 OriginY=originY+5 ElseIf Abs(PlayerY-OriginY)<100 OriginY=originY-5 EndIf EndIf ;offset border checks If OriginX>GraphicsWidth() OriginX=GraphicsWidth() If OriginX<0 OriginX=0 If OriginY>GraphicsHeight() OriginY=GraphicsHeight() If OriginY<0 OriginY=0 Flip 1 Until KeyHit(1) |
| ||
Ok thanks for that, will look into it. |
| ||
You can also create a 2d game by using 3d, for example moving the character only on x and z (for top down view), or only on x and y (for side view). |