NaaLaa
Platforms and ladders - Printable Version

+- NaaLaa (https://www.naalaa.com/forum)
+-- Forum: NaaLaa (https://www.naalaa.com/forum/forum-1.html)
+--- Forum: NaaLaa 7 Code (https://www.naalaa.com/forum/forum-4.html)
+--- Thread: Platforms and ladders (/thread-25.html)



Platforms and ladders - Marcus - 01-04-2024

This is a game that I started working on but abandoned because I didn't feel like drawing more enemy sprites (I even stole and NES:ified the two enemies there are from my n6 game Likker). It comes with a level editor.

[Image: platforms_and_ladders.jpg]


RE: Platforms and ladders - johnno56 - 01-04-2024

Gotta love the platformers.... Nicely done!

Question: Why use 'json' format for the level files? Smaller size? Easier to 'translate/interpret'? Not judging... just curious. I am so used to using the plain text 'grid' file... lol


RE: Platforms and ladders - Marcus - 01-05-2024

(01-04-2024, 10:49 PM)johnno56 Wrote: Gotta love the platformers.... Nicely done!

Question: Why use 'json' format for the level files? Smaller size? Easier to 'translate/interpret'? Not judging... just curious. I am so used to using the plain text 'grid' file... lol

The json library can convert any naalaa table to a json string and the other way around, so it's quite simple to use for saving an entire level structure to file, and you get files that are nice to look at in a text editor Smile

Code:
include "json.n7"

' Create a table.
foo = []
foo.position = []
foo.position.x = 10
foo.position.y = 35
foo.speed = []
foo.speed.x = 2.3
foo.speed.y = 1.27
foo.name = "dude"

' Convert table to a json string and print it.
fooAsJson = JSON_ToString(foo)
pln fooAsJson

' Create a new table from the json string - a copy of foo.
bar = JSON_FromString(fooAsJson)
pln bar.position.x + ", " + bar.position.y

system "pause"

Output:
Code:
{"position":{"x":10,"y":35},"name":"dude","speed":{"x":2.3,"y":1.27}}
10, 35
Press any key to continue . . .



RE: Platforms and ladders - johnno56 - 01-05-2024

Cool... Thank you.


RE: Platforms and ladders - 1micha.elok - 01-08-2024

(01-04-2024, 05:20 PM)Marcus Wrote: This is a game that I started working ...

The game's title as "Platforms and Ladders" inspired me to recreate a simplified version of "Snakes and LaddersBig Grin Big Grin Big Grin ... A player can climb the ladder and he should avoid the snake's tail....

.zip   Snakes_and_ladders.zip (Size: 30.42 KB / Downloads: 4)

[Image: images?q=tbn:ANd9GcTDtUHwscTSljDAG1mY52n...A&usqp=CAU]

This simplification is made just for fun only and as a way to make me easier to understand the logic behind it .... Oh, no, the Platforms and Ladders uses Object Oriented style   Confused ...
  Sprite, Item and Player are classes
  Item and Player inherit properties and methods/functions from Sprite
  vItem is an object of Item
  vPlayer is an object of Player ... etc.

However, the most important thing, it's very enjoyable to play around with Naalaa  Big Grin
It's Great !


RE: Platforms and ladders - johnno56 - 01-09-2024

Cool... Nicely done...


RE: Platforms and ladders - 1micha.elok - 01-13-2024

(01-04-2024, 10:49 PM)johnno56 Wrote: Gotta love the platformers.... Nicely done!

Question: Why use 'json' format for the level files? Smaller size? Easier to 'translate/interpret'? Not judging... just curious. I am so used to using the plain text 'grid' file... lol

Hi,

I'm gladly provide the map in a plain text grid file .... especially for you  Big Grin
Code:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 2 1 2 2 2 2 2 2 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0
0 0 2 2 2 2 2 2 2 1 2 2 2 2 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0
0 0 0 0 2 1 2 2 2 2 2 2 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

Oh, no...what are those ?  Big Grin You may translate this 0,1,2 with a Tilemap Editor  Big Grin Big Grin Big Grin

Actually, I challenged myself to rewrite the Platforms and Ladders using a Tilemap as an alternative to JSON map format.
This Tilemap version is made just for fun only and it serves as a proof of concept using Tilemap Editor
The most important thing, it's an awesome experience to play around with Naalaa
Added features :
- climb up a ladder easily (if stuck, just use LEFT and RIGHT keys)
- No more avoiding an enemy, you have automatic bullets to shot.

You may try the Platforms and Ladders in Tilemap version [ File : recreate_platforms_and_ladders.zip  ]

I thank a lot to Marcus for providing all the resources I need to learn the OOP style (wanna-be OOP  Big Grin ) which I used during the rewrite of the game. 
Code:
'----------------
' INITIALIZATION
'----------------
...
'load and setview map created with Tilemap Editor
TM_LoadMap("assets/map.txt");TM_SetView(0, 0, width(primary), height(primary))

'Sprite Class definition
Sprite =
    [
        '---Properties---
        'position (x,y) and size(w,h) are used in collision detection
        'dx and dy are movement direction in horizontal or vertical,baseCel refers to spritesheet
        img:0,x:0,y:0,w:0,h:0,dx:0,dy:0,baseCel:0,       
       
        '---Methods---
        SetDx       : function(deltax);this.dx=deltax;endfunc,
        SetDy       : function(deltay);this.dy=deltay;endfunc
    ]
   
visible Player = copy(Sprite)   'Player Class inherit properties and methods of Sprite Class
visible Coins = fill(Sprite,10) 'Coins Class has 10 objects, uses Sprite Class as a template
visible Bullet = copy(Sprite)   'Bullet Class uses Sprite Class as a template
visible Enemy = fill(Sprite,5)  'Enemy Class has 5 objects, uses Sprite Class as a template
...  

'--------------
' MAIN PROGRAM
'--------------
do
...
    PlayerMovement()
    UpdateCoins()
    UpdateBullet() 
    UpdateEnemies()
                                               
    foreach i in Coins draw image i.img, i.x, i.y, i.baseCel  'there are 10 coins
    foreach i in Enemy draw image i.img, i.x, i.y             'there are 5 enemies
    draw image Player.img, Player.x, Player.y, Player.baseCel 'only 1 player
    draw image Bullet.img, Bullet.x, Bullet.y                 'only 1 bullet
...
until keydown(KEY_ESCAPE,true)

Happy Weekend to everyone,


RE: Platforms and ladders - johnno56 - 01-13-2024

Cool. Many thanks for the map! Much appreciated.

J