Can't get my sprite moving.
| Author |
Message |
DemonWasp
|
Posted: Wed Feb 25, 2009 1:54 pm Post subject: Re: Can't get my sprite moving. |
|
|
Design
Normally I'd do most of this in my head, but instead I'll do a walkthrough here.
Thinking about your game world, we see that you have a World, which is composed of multiple Areas, which is composed of grid squares. Overall, your world is just one rather large grid, but it's segmented into discrete units called "Areas" that you travel to and from.
So we have a basic design now: the World is composed of Areas. Areas are composed of a two-dimensional array of grid squares (at the moment, this is a variable called "map", and each grid square is represented as a character. At the moment, it's loaded from a fairly simple file - which we'll need to change.
Another feature that we'll start with right off-the-bat is the ability to have different worlds. Each time you run the program, you'll have only one World loaded (as well as its multiple areas) - by default, you'd give out the World for Evermore, but if I wanted I could make a world for The Lord of the Rings or whatever else and load that instead. If that sounds complicated, don't worry, that's one of the easy parts.
What do Area and World look like?
Now we need to determine which properties our World and Area have. I'll start with the most basic implementations for the moment.
Worlds have:
- name
- an array of Areas
Areas have:
- a name
- a 2d array of grid squares
- some way of identifying which area the player goes to if they leave via N/S/E/W edge.
So what we'll do is have a world file (example: Evermore.world). In that file, we'll have something like this (everything after a # is a comment and won't appear in the file):
| code: |
Demonstration # The world name
2 # The number of areas in the world
1 West Side # The area number, the area name
XXXXX... # (put the map in here...)
-1 # Area to go to if we exit to the (direction);
2 # negative one (-1) means "nowhere"
-1 # Order is North, East, South, West
-1
2 East Side
XXXXX... (put the map in here...)
-1
-1
-1
1
|
So we see that we have a simple world with an East Side and a West Side. You can go from one to the other, but you can't leave in any other direction. The reason that we number each area is so that it's easier for the human writing that file to figure out which area is which number (because once you have more than about 20 areas, you'd be forced to count every time you wanted to link one side of an area into the next area...)
The Implementation
The above leads to the following for our data structure:
[syntax="Turing]
const MAX_AREAS : int := 64 % This is whatever we want, we just need a number at the moment (we can get around this later with flexible arrays...)
const AREA_SIZE : int := 40 % This is what we've already got, it's just a constant now.
const AREA_NONE : int := -1 % This is for the -1 in the file for the area. This is the flag for "can't go that way!"
type Area:
record
name : string
map : array 1..AREA_SIZE, 1..AREA_SIZE of char % This is just like the existing map variable; the only difference is that we can have more than one of them now.
n, e, s, w : int % The index (in the 'areas' array in World) of the area to move to.
end record
type World:
record
name : string
areas : array 1..MAX_AREAS of Area
end record
[/syntax]
Of course, just having the data structure is unhelpful, as we'll need methods to deal with the data. I'll give you a chance to implement these; if you run into problems I can give you a hand
| Turing: |
function loadArea ( stream : int ) : Area
% This is a helper function for loadWorld below.
% It will receive the input stream from loadWorld and will create a new Area variable and return it, after loading its contents.
% Most of the work for this method has already been done. Look at the code for loading maps in the existing Evermore.t file.
end loadArea
function loadWorld ( worldName : string ) : World
% This is the main loading function. It will open the named file (note: worldName should be something like "Evermore", but we need to read from "Evermore.world", so you'll have to add ".world".
% When it comes to loading areas, this method should make use of loadArea, above
end loadWorld
|
To test your implementations, you can use the attached sample and the following call:
| Turing: |
var sampleWorld : World := loadWorld ("sample")
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
saltpro15

|
Posted: Wed Feb 25, 2009 2:00 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
| I vote for someone to sticky this thread, DemonWasp just covered more about games than I learned all year in gr10 CS *claps |
|
|
|
|
 |
DemonWasp
|
Posted: Wed Feb 25, 2009 2:10 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
re: sticky - fine by me. I'd move the pertinent sections to a walkthrough, but I'm having trouble seeing where a proper tutorial would start and stop. I'll put in some thought and see if I come up with anything tutorial-worthy.
Also, mods: if you could correct the missing quote in one of my [ syntax ] tags above, I'd be grateful.
Edit: Took a quick look, seems the topic of 2d grid-movement and collision detection is actually already covered by a tutorial by CodeMonkey2000. If you were meaning the whole "multiple areas" thing, then I could probably come up with a tutorial on how to design simple programs (Is there actually any demand for that? Are people likely to use it?). |
|
|
|
|
 |
Razgriz

|
Posted: Wed Feb 25, 2009 7:47 pm Post subject: Re: Can't get my sprite moving. |
|
|
DemonWasp @ 25th February 2009 wrote: Design
| code: |
Demonstration # The world name
2 # The number of areas in the world
1 West Side # The area number, the area name
XXXXX... # (put the map in here...)
-1 # Area to go to if we exit to the (direction);
2 # negative one (-1) means "nowhere"
-1 # Order is North, East, South, West
-1
2 East Side
XXXXX... (put the map in here...)
-1
-1
-1
1
|
So I would do that in notepad? |
|
|
|
|
 |
saltpro15

|
Posted: Wed Feb 25, 2009 7:51 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
| you can, any text editor should work I believe |
|
|
|
|
 |
DemonWasp
|
Posted: Wed Feb 25, 2009 7:55 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
| Any text editor that doesn't add formatting information or similar garbage. Notepad works fine. |
|
|
|
|
 |
Razgriz

|
Posted: Thu Feb 26, 2009 6:52 am Post subject: RE:Can\'t get my sprite moving. |
|
|
Re:Sticky
Yeah, I think it'd be good there for any others who've had my problem..
plus my first thread would become a sticky. (Woo!)
;D |
|
|
|
|
 |
Razgriz

|
Posted: Sun Feb 07, 2010 10:34 am Post subject: Re: Can't get my sprite moving. |
|
|
Ahem; if I may ressurect the dead..
I forget all of my turing coding! I'm just now getting back into Turing because I was so intensely bored one day. I want to make a game [much like the one I started here a year ago]. Problem is, after a year of inactivity, I don't remember a thing. Anyone who could give some refreshers and some advice would be a personal hero.
Thanks.
Also, I seem to ahve lost the code of the game I was working on. I don't know if I ever gave anyone on here the full version, but in the event that I did, if you could send it to me, greatly appreciated. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
SNIPERDUDE

|
Posted: Sun Feb 07, 2010 2:00 pm Post subject: Re: Can't get my sprite moving. |
|
|
Quick summary:
Check up on the Turing Walkthrough for more.
| Turing: | var x : int
const y : real := 1. 3
var c : char
var s : string := "Hello World!"
var a : array 1 .. 5 of int
setscreen ("graphics:450;450, nobuttonbar, offscreenonly, title:TEST!")
fcn adds (x1 : int, x2 : real) : real
result x1 + x2
end adds
proc prints
put s
end prints
loop
for i : 0 .. 20 by 2
if i mod 8 = 0 then
put "GO"
elsif i = 18 then
put "QWERTY"
else
put "GONE"
end if
end for
end loop |
Hopefully that'll jog your memory somewhat. |
|
|
|
|
 |
Razgriz

|
Posted: Sun Feb 07, 2010 3:09 pm Post subject: Re: Can't get my sprite moving. |
|
|
| And it has. Thank you very much. I'll likely post some new code from my new one when I have some progress, thanks. |
|
|
|
|
 |
SNIPERDUDE

|
Posted: Sun Feb 07, 2010 3:18 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
| No problem |
|
|
|
|
 |
|
|