rpg game map won't work
Author |
Message |
JB
|
Posted: Fri Apr 24, 2009 11:25 am Post subject: rpg game map won't work |
|
|
Here is my rpg game. The code for loading the 2D map won't load the map.
I've tried to change the arraay but that doesn't work.
Here is the code. The map is at the bottem.
Turing: |
%Cutthroat RPG! Started Wednesday, April 22.%
import GUI
View.Set ("graphics:600;400,nobuttonbar")
var name : string
var hp : real
var race : string
var power : int
var money : real := 0
var level: real:= 1
var weapon : string
var armour : string
var experience : real:= 0
var nextlevel : real
GUI.SetBackgroundColour (red)
procedure Start
GUI.Quit
end Start
procedure Instructions
end Instructions
procedure Load
end Load
var b1 := GUI.CreateButton (10, 250, 100, "Start Game", Start )
var b2 := GUI.CreateButton (130, 200, 100, "Instructions", Instructions )
var b3 := GUI.CreateButton (250, 250, 100, "Load Game", Load )
loop
exit when GUI.ProcessEvent
end loop
cls
proc Create_Character
cls
put "What is your characters name?"
get name
cls
loop
cls
put "Enter your Race."
put "Human - Can easily change its class."
put "Elf - They are known for their poetry, song, and magical arts. They also show great skil with weapons, and strategy."
put "Dwarf - They are known for their skill in warefare, their ability to withstand physical and nagical punishment, and their hard work."
put "Gnome - They are smaller than Dwaves, and make good alchenists, and technicians."
put "Halfling - They are clever, capable, and resouceful suvivers."
put "Half Elf - They get curiosity, and ambition from their human parent, and the love of poetry and song from their elf parent."
put "Alien - They are skilled in magic. They use very powerful magic that is too complicated for even the most powerful wizards to learn."
put "Half Orc - Half orc, half human. They like fighting more than argueing."
put "Demon - They don't have a living body, and are more ghost like, than human like."
get race
exit when race = "Human" or race = "Elf" or
race = "Dwarf" or race = "Gnome" or race = "Halfling" or
race = "Half Elf" or race = "Alien" or race = "Half Orc" or
race = "Demon"
end loop
cls
if race = "Human" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
if race = "Elf" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
if race = "Dwarf" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
if race = "Gnome" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
if race = "Halfling" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
if race = "Half Elf" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
if race = "Alien" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
if race = "Half Orc" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
if race= "Demon" then
hp: = 50
power := 7
level := 1
experience := 0
money := 500
end if
put "Character Name: ", name
put "Level: ", level
put "Race: ", race
put "hp: ",hp
put "power: ", power
put "Experience points: ", experience
put "money: ", money
delay (5000) %This delays the program to give you enough time to read your stats.%
end Create_Character
Create_Character
View.Set ("graphics:600;600,offscreenonly")
var tiles : array 0 .. 72, 0 .. 14 of int
var FileName : string := "map.txt"
var FileNo : int
open : FileNo, FileName, get
for decreasing y : 14 .. 0 % for every y
for x : 0 .. 72 %for every x
get : FileNo, tiles (x, y ) %get the tile type at (x,y)
end for
end for
close (FileNo )
procedure reDraw
for x : 0 .. 72
for y : 0 .. 14
if tiles (x, y ) = 1 then
Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, red) % the +10 is there because each tile is 10 by 10
else
Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, black)
end if
end for
end for
end reDraw
var key : array char of boolean
var px, py : int := 1 % we start off at grid 1,1
loop
reDraw
Input.KeyDown (key )
if key ('a') and tiles (px - 1, py ) = 0 then
px - = 1
end if
if key ('d') and tiles (px + 1, py ) = 0 then
px + = 1
end if
if key ('s') and tiles (px, py - 1) = 0 then
py - = 1
end if
if key ('w') and tiles (px, py + 1) = 0 then
py + = 1
end if
Draw.FillBox (px * 10, py * 10, px * 10 + 10, py * 10 + 10, yellow)
View.Update
delay (50)
end loop |
Mod Edit: Fixed syntax tags
Description: |
|
Download |
Filename: |
map.txt |
Filesize: |
1.08 KB |
Downloaded: |
69 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Zren
|
Posted: Fri Apr 24, 2009 1:44 pm Post subject: Re: rpg game map won't work |
|
|
Since most of you logic and stuff messed up.
You map is 72x15. You have x being from 0..72, which has 73 variables it'll look at and will throw an out of bounds error later when you fix the rest. The fact your starting from zero is great by the way.
Your whole filereading is messed up. You only got one thing right, and that's y being on the outside loop. Here's the logic you need.
code: |
Open File
for y 0 .. 71
Read line y of text file, store in temporary string
for x 0 .. 14
store value at character x in temporary string into map array
end for
end for
|
To find out the character in a string all you have to do is consider a string an array of characters.
Turing: | var blah :string := "lumppity doo"
put blah(1) |
In turing the first character starts at the value 1. So for your impletation which a for loop of x:0..14 you'll need to use
line(x+1)
You'll also have to convert the character to an integer, you can do this with strint()
|
|
|
|
|
|
|
|