Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Help: Learning coding 2d games via remaking Ninja Gaiden NES

Author
Message
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 9th Feb 2017 07:34
Hi..im still learning on doing 2d game and i picked to remake Ninja Gaiden(NES) since it most appealling to me to learn other than mario. So here is all the code and media but here are the things that i want to know:

1.Im loading the collision data via CSV .For the level background,i use png and plan to use several pngs untill the end of the loading from tileset(which i dont know how).Is this method is right?
2.For the character, im using raycast from sprite mid offset, but i notice that something im a little bit above collision tiles and sometimes a little bit inside the collision tiles
3.Can someone give me a good jumping code instead the one that im using?

Thanks


Attachments

Login to view attachments
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Feb 2017 13:23
What generates your collision data in the CSV? Where is that coming from?

You probably don't need to raycast the character movement given the style of game. For an old NES game, typically a simple tile-based collision system will work. A few simple checks can tell you what side of a tile the player collided with, which you can use that info to determine if the ninja should stick onto a wall or not.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 14th Feb 2017 17:24
Yay! Finally a reply. haha. CSV is generated in Tiled application. Regarding to your reply, that is what im asking on normally how things is done in 2d games. Actually i dont know what is tilebase collision and grid base system,completely clueless. Hope i can be steer to a right direction.

Thanks
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Feb 2017 18:57
I'd say you chose a rather in-depth project for a beginner. You should do some searching on the forums (or google really) for tilemaps.

Essentially, the majority (if not all) old games were tile-based. Even the games that have no visible square patterns in design were likely tile-based. What this means is the map is drawn from a series of blocks (tiles). A tile might be water, grass, a rock, whatever. Some are passable, others are not possible. Imagine your character as a separate layer on top of the map. It can not go over the non-passable tiles. When the player tries to move the character, look ahead at the target destination (where it would be at after the move). You can easily check what kind of tile it would hit by keeping your map data stored in 2D array. This array represents your map tiles and thus forms an invisible grid over the map.

For instance, say your character is at location [160,78]. The map is made up of tiles 32x32 pixels. By dividing your location by the tile size, you can figure out what tile in the array you're at. (or spot on the grid)

5 = 160 / 32
2 = 78 / 32

Just do integer division, drop the fraction. If your map array is zero-based (the first tile is at 0,0) then the location [160,78] is at array[5,2]. A very simple array would be filled with 1s and 0s, passable or non-passable. So just look at the value at that array position to determine if you can move forward or not.

Some examples I found quickly for further reading.
https://developer.mozilla.org/en-US/docs/Games/Techniques/Tilemaps
https://gamedevelopment.tutsplus.com/tutorials/an-introduction-to-creating-a-tile-map-engine--gamedev-10900

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 15th Feb 2017 02:23
Maybe i get it wrong. But does it mean that the player is not moving with any speed that i want but move from tile to tile. E.G increment of 32 for 32px tile. And i have to check on which tile my player is currently on and always check the next tile is walkable or not.Look hard and im quite suprised if it is true.

Thanks
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Feb 2017 16:10
You can do either or. You can move your character 2px at a time or jump 32px at a time. And yes, every time you update the character position you need to recheck which tile it occupies. It's not hard at all, here's some pseudo-code.



For smooth gameplay, what you'd really want to do when the player hits an impassable tile is rather than not move at all, you move as close to the tile as you can without going onto it. Say a wall is 4px away, but your speed is 6px each step. If you move forward, you'd be in the wall. But if you do nothing, there appears an invisible barrier of 4px standing between you and the wall. So you move 4px up to the wall instead rather than the full 6px. It allows you to move right up to the wall but not going beyond it.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 16th Feb 2017 12:34 Edited at: 16th Feb 2017 12:39
Thanks for the psedocode.. Ill study it.
How about loading the map then. Do you mean we need to load the level image from the "palette" or "tileset" tile by tile and NOt from the finished image of the drawn tile? I really tot we need level data for collision only and that explain why the tile drawn in tiled application give different number in CSV.


Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Feb 2017 15:51 Edited at: 16th Feb 2017 15:52
I've written a TMX importer, and Clonex has expanded on it. For performance, I suggest only using it to export the data back out into a binary format and include only the data you need. The file will be smaller and it will load much much faster. (XML parsing is slow with native string commands).

Here's a tileset I made (and never finished). It's 5 x 13 tiles.


Example of using that tileset to build a map: (ok, this appears to use an updated version of my tileset I can't find right now)



For AppGameKit, here's what I do. I create 1 sprite and load the tilemap image. Create an animated sprite, which turns each tile into a frame. You only need to do this for a single sprite, this is your master sprite. Every tile on the map will be a clone of that sprite, thus sharing the image data and saving memory. Set the frame of each sprite to the tile you want. For collision data, make a file to associate with each tilemap you use. Animated sprites build their frames from left to right going from top to bottom. So all you need to do is associate a frame number with it's collision data. There are several ways to do this, depending on how much data you need to know about a tile. For simplicity we'll just go with passable and impassable, 0 or 1.

Your data could look like a simple CSV file:
1,0,2,0,3,0,4,0,5,1,6,0,7,1,8,1

First the frame number (tile number) then followed by it's passable state.

If you want to get more technical, you could save up to 8 flags in a single byte using binary and bit-shifting. I can go over that later if you need me to. But really, this collision data format is entirely up to you.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 17th Feb 2017 23:00
Ok. Thanks. It might get time for me to digest this one but atleast i know the right concept Try and Report Back later

Login to post a reply

Server time is: 2024-03-28 15:45:10
Your offset time is: 2024-03-28 15:45:10