Screen Scrolling from Text File
Author |
Message |
DrummaBoyFB
|
Posted: Sat Jun 05, 2010 8:28 pm Post subject: Screen Scrolling from Text File |
|
|
Ok so it's the end of the school year practically and I have this assignment for class.
I gotta make a game. I'm fairly good at programming so I'm have no troubles for the most part.
I'm just stuck on the screen scrolling part of it. I know how to do screen scrolling when you import a picture file (I've done it in turing and C++ before) but the teacher said we have to draw out the map in a text file and import it into a 2d array which will display it on the screen.
I've done that part already. But I really don't know how to make it scroll. I've asked my teacher several times and he won't give me a decent answer all he says is that I need 2 more variables which doesn't help me much. So can you please help me out?
( Note : i'm not asking you to do my homework for me , just to help me out - steer me in the right direction )
Also I have already added the 2 new variables to my procedure , I just don't know what to do with them
Note: the way I want it to scrolling, is when my character gets to a certain part of the screen I want the screen to scroll.
(I'm not putting the whole code, cause it's an uncommented disaster right now, so I'm only going to put the map drawing part
to see if you can help me
(map dimensions are 15 (row) and 22 (col)
Turing: |
setscreen ("graphics: 800, 600") % 4 by 3
var BlockWidth : int := (maxx + 1) div 20
var BlockHeight : int := (maxy + 1) div 15
proc drawmap (map : array 1 .. *, 1 .. * of int, NumRow, NumCol : int, HomeRow, HomeCol : int)
var chars : array char of boolean
var x, y : int
for row : 1 .. NumRow % positions in the array
for col : 1 .. NumCol % positions in the array
Input.KeyDown (chars )
x := (col - 1) * BlockWidth
y := maxy + 1 - (row * BlockHeight )
drawfillbox (x, y, x - BlockWidth - 1, y + BlockHeight - 1, map (HomeRow + row - 1, HomeCol + col - 1))
end for
end for
end drawmap
var file, row, col : int
var map : array 1 .. 30, 1 .. 40 of int
open : file, "2d array game.txt", get
if file > 0 then
get : file, row
get : file, col
end if
for rows : 1 .. row
for cols : 1 .. col
get : file, map (rows, cols )
end for
end for
drawmap (map, row, col, 1, 1)
|
Please specify what version of Turing you are using
Newest |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Sat Jun 05, 2010 9:21 pm Post subject: RE:Screen Scrolling from Text File |
|
|
I think the two variables your teacher is talking about is an offset in the x and y axis which you would add to the position when you draw it. Unfortunately I don't think Turing has has a way to move the origin, so you will have to do that for every draw call. Anyway, you just change the offset when the player gets near the screen. Something like this:
Turing: | View.Set ("graphics:500;500,offscreenonly,nobuttonbar")
type Point :
record
x : real
y : real
end record
function NewPoint (newX : real, newY : real) : Point
var tempPoint : Point
tempPoint.x := newX
tempPoint.y := newY
result tempPoint
end NewPoint
var viewOffset : Point := NewPoint (0, 0)
var maxSize : Point := NewPoint (500, 500)
var playerPos : Point := NewPoint (100, 100)
var keys : array char of boolean
loop
% Update Logic
Input.KeyDown (keys )
if (keys ('w')) then
playerPos.y + = 10
end if
if (keys ('a')) then
playerPos.x - = 10
end if
if (keys ('s')) then
playerPos.y - = 10
end if
if (keys ('d')) then
playerPos.x + = 10
end if
viewOffset.x + = ((maxx / 2 - viewOffset.x ) - playerPos.x ) / 5
viewOffset.y + = ((maxy / 2 - viewOffset.y ) - playerPos.y ) / 5
% Draw Logic
cls
Draw.Box (round (viewOffset.x ), round (viewOffset.y ), round (maxSize.x + viewOffset.x ), round (maxSize.y + viewOffset.y ), black)
Draw.Oval (round (playerPos.x + viewOffset.x ), round (playerPos.y + viewOffset.y ), 5, 5, black)
View.Update ()
Time.DelaySinceLast (33)
exit when keys (KEY_ESC)
end loop
|
Hope that helps. |
|
|
|
|
|
Cezna
|
Posted: Sun Jun 06, 2010 10:55 am Post subject: RE:Screen Scrolling from Text File |
|
|
If you make all the objects positions realtive to a certain point on the screen, then all you would have to do to make it scroll is move the reference point using x and y offsets (that would be those two variables).
These offsets would be what you change when you want to move the screen.
By the way, I know it dosn't help, but your teacher seems to be asking you to draw the level in a very inefficient way.... though I'm sure you already know this. |
|
|
|
|
|
DrummaBoyFB
|
Posted: Tue Jun 08, 2010 8:13 am Post subject: RE:Screen Scrolling from Text File |
|
|
thanks you to for your reply's but I don't quite grasp what you mean by offsets but I'm sure I can figure that out on my own. Anyways TerranceN I'm not familiar wit what records do so could you fill me in on that? |
|
|
|
|
|
TerranceN
|
Posted: Tue Jun 08, 2010 2:50 pm Post subject: RE:Screen Scrolling from Text File |
|
|
They just allow you to put multiple variables into one (like a struct in C/C++). I could have created an x and y variable for each value that needed it (viewOffset, maxSize, playerPos) but instead I defined a new type of variable that contains two real type varaibles. For more on records, click here.
Offsets are just a way to turn game co-ordinates into screen co-ordinates. If you add the offset to every draw call then its like the origin moved to (offset, offset). If you change the offset when a character moves you can make it look the screen is scrolling.
Hope that helps. |
|
|
|
|
|
|
|