01-04-2024, 05:20 PM
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.
(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
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"
{"position":{"x":10,"y":35},"name":"dude","speed":{"x":2.3,"y":1.27}}
10, 35
Press any key to continue . . .
(01-04-2024, 05:20 PM)Marcus Wrote: [ -> ]This is a game that I started working ...
(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
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
'----------------
' 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)