Car racing game --- mapping system help
Author |
Message |
lil_mickey

|
Posted: Sat Apr 30, 2005 3:20 pm Post subject: Car racing game --- mapping system help |
|
|
Hi, im currently working on my final project, which is an overhead view car racing game. I have a few questions about the mapping system...
I'm going to have it like in most RPg's, where the character ( or in this case, the car), stays in the middle of the screen, while the map moves. I'm having a few problems implementing this. How would you do this, so that you dont draws the whole track( which is going to be huge) at one time, but draws it screen by screen ,without hard-coding??? Im sorry if this is confusing, it if is, tell ne, and ill try to explain it what i mean.
Heres what i have so far....its doesn't work too well.
code: | % What is this? My attempt at our (Dejan and I) mapping system...it stinks, but it's a start!
% setting the screen
setscreen ("graphics:640;480,nobuttonbar,nocursor,position:top;center,offscreenonly")
% yes these variables are global...get over it!!
% half of these variables im not even using yet
% static variables (variables that will change depending on what track is chosen)
var TrackWidth : int := 10 % number of screens wide a track is
var TrackHeight : int := 5 % number of screens high a track is
var screenHieght : int := 480 % hieght of one screen
var screenWidth : int := 640 % width of one screen
var screenDirectory : string := "screens1/"
var NumberofScreens : int := 10 % number of screen files for that particular track
% other variables
var TrackData : int % text File with the data for that particular track
var ScreenImages : array 1 .. NumberofScreens of int
var MapX : int := 1 % x co-ordinate of map
var MapY : int := 1 % y co-ordinate of map
var chars : array char of boolean % for input.KeyDown
var MoveSpeed : int := 5 % amount of pixels map will move each time
var car := Pic.FileNew ("bmw-325.bmp")
Pic.SetTransparentColor (car, 13)
car := Pic.Scale (car, Pic.Width (car) div 1.5, Pic.Height (car) div 1.5)
var mainMap : int
var count := 1
%%%%%%%%%procedures%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% procedure readData % read data about specific track
procedure LoadScreens % for loading maps
put "Loading Maps..."
for i : 1 .. NumberofScreens
ScreenImages (i) := Pic.FileNew (screenDirectory + intstr (i) + ".bmp") %Load every image, in order, from the file folder that holds the screens
end for
end LoadScreens
procedure DrawCar % drawing the car
Pic.Draw (car, 320 - (Pic.Width (car) div 2), 240 - (Pic.Height (car) div 2), picMerge) % Draws car at center
end DrawCar
procedure DrawMap % long and inefficient mapping system...currently under construction!
cls
if MapX > Pic.Width (mainMap) or MapY > Pic.Height (mainMap) then
mainMap := ScreenImages (count)
end if
if MapX > 1 then % drawing new maps...needs fixing!!!
if ScreenImages (count) = mainMap then % basically, when main map moves right, it draws another map to the left of it
count -= 1
end if
Pic.Draw (ScreenImages (count), MapX - Pic.Width (mainMap), MapY, picCopy)
end if
if MapX < 1 then % when main map moves right, draws another map to the right of main map
if ScreenImages (count) = mainMap then
count += 1
end if
Pic.Draw (ScreenImages (count), MapX + Pic.Width (mainMap), MapY, picCopy)
end if
if MapY > 1 then % when main map moves up, draws another map underneath
if ScreenImages (count) = mainMap then
count += 1
end if
Pic.Draw (ScreenImages (count), MapX, MapY - Pic.Height (mainMap), picCopy)
end if
if MapY < 1 then % when the main map moves down, dras another one above it
if ScreenImages (count) = mainMap then
count -= 1
end if
Pic.Draw (ScreenImages (count), MapX, MapY + Pic.Height (mainMap), picCopy)
end if
Pic.Draw (mainMap, MapX, MapY, picCopy)
if MapX > 1 and MapY > 1 then % when map moves up AND left, draws a map at lower left corner
if ScreenImages (count) = mainMap then
count += 1
end if
Pic.Draw (ScreenImages (count), MapX - Pic.Width (mainMap), MapY - Pic.Height (mainMap), picCopy)
end if
if MapX < 1 and MapY < 1 then % when map moves down and right, draws map at upper right corner
if ScreenImages (count) = mainMap then
count -= 1
end if
Pic.Draw (ScreenImages (count), MapX + Pic.Width (mainMap), MapY + Pic.Height (mainMap), picCopy)
end if
if MapX < 1 and MapY > 1 then % when map moves up and right, draws map at lower right corner
if ScreenImages(count) = mainMap then
count += 1
end if
Pic.Draw (ScreenImages (count), MapX + Pic.Width (mainMap), MapY - Pic.Height(mainMap), picCopy)
end if
if MapX > 1 and MapY < 1 then % when map moves down and left, draws a map at upper left corner
if ScreenImages(count) = mainMap then
count -= 1
end if
Pic.Draw (ScreenImages (count), MapX - Pic.Width (mainMap), MapY + Pic.Height(mainMap), picCopy)
end if
end DrawMap
procedure Move % moving the map!
if chars (KEY_UP_ARROW) then % depending on what you press, the co-ordinates of the map will change
MapY -= MoveSpeed
end if
if chars (KEY_DOWN_ARROW) then
MapY += MoveSpeed
end if
if chars (KEY_LEFT_ARROW) then
MapX += MoveSpeed
end if
if chars (KEY_RIGHT_ARROW) then
MapX -= MoveSpeed
end if
% self explanitory
end Move
%%%%%%%%%% main program %%%%%%%%%%%%
LoadScreens
mainMap := ScreenImages (5)
loop
View.Update
DrawMap % loads map
DrawCar % draws car in middle, over the map
Input.KeyDown (chars)
Move % determines new co-ordinates for the next loop
end loop
|
i keep getting errors with my arrays..any help would be appreciated!
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
jamonathin

|
Posted: Mon May 02, 2005 5:50 am Post subject: (No subject) |
|
|
Well, next time throw everything into a zip file, because we cant run it properly without the images.
I'm guessing that its one simple image of a track, that you're going to draw twice. What you can do is assign two x, y and pic variables to the images.
Turing: | var x, y, pic: array 1 .. 2 of int
pic (1) := Pic.FileNew ("map.jpg")
pic (2) := pic (1)
x (1) := 0
x (2) := 0
y (1) := 0
y (2) := Pic.Height ( pic (1) ) %Starts at the very tip of the picture.
|
Now what you can do is just make a procedure that checks if the map needs to be moved back to where it started.
Turing: |
procedure move_back
for i : 1 .. 2 %Checking if that picture is too low to be shown
if y (i ) + Pic.Height (pic (1)) <= 0 then
y (i ) := Pic.Height (pic (1))
end if %Moving it back up to the tip of the other picture
end for
end move_back |
You can use the same concept if the player is moving backwards. Just use y(i) >=maxx and y (i) := -Pic.Height.
|
|
|
|
|
 |
lil_mickey

|
Posted: Mon May 02, 2005 10:04 pm Post subject: (No subject) |
|
|
hey sorry, ill put it in a zip file next time...i wasnèt really thinkin when i posted this Thats not exactly what i was trying to do, but what you explained did give me a couple of ideas on how i could cut down on some lines of code if i did have to draw the same picture over and over again.
Right now, the way i have it,i have to make every screen a different picture( even if some of the screens, especially on straight-aways, are exactly the same). That seems like it will take up alot of space and im trying to find a better, more effecient way , so that making multiple maps wont be such a chore. I was thinking that it could read info from a text file and map it like that (similar to many tile engines ),but im pretty unfamiliar with working with text files in turing.
But anyways thanks for the help, ill keep what you said in mind. I posted it in a zip file so you can see how it works. Any other suggestions will be greatly appreciated
Description: |
first attempt at car scrolling, mapping system. |
|
 Download |
Filename: |
maping.zip |
Filesize: |
767.39 KB |
Downloaded: |
165 Time(s) |
|
|
|
|
|
 |
|
|