Author Topic: Platformer  (Read 899 times)

johnno56

  • Guest
Platformer
« on: October 26, 2014 »
Is it possible to have a platformer-type tutorial? How to use the tile map application and how to incorporate the map data into a basic game? I have always liked the old classics and would like to make one of my own.

Many thanks

J

kcfb

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Platformer
« Reply #1 on: October 26, 2014 »
Hi Johnno, did you look at this- I found it very useful when I first looked at that lib: https://www.youtube.com/watch?v=T4R8n9URiWU

johnno56

  • Guest
Re: Platformer
« Reply #2 on: October 26, 2014 »
I should have remembered that one. Many thanks. Apart from the very first part of the video being a bit fuzzy, and the cheesy player graphics, I should be able to get the gist of the methods. Don't expect a Super Mario Bros-type game in the future. My graphics talents aren't THAT good. Better than Mr. Cheesy, but not Mario good. Thanks for the tip.

J

johnno56

  • Guest
Re: Platformer
« Reply #3 on: October 26, 2014 »
I have had a look at the map editor in the past and have a question. I have an idea for a level that is bigger than the screen size. If I make the map that I have drawn, will the entire map be displayed on the screen, or will the screen "scroll". Am I making sense?

J

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 549
    • View Profile
Re: Platformer
« Reply #4 on: October 26, 2014 »
I have had a look at the map editor in the past and have a question. I have an idea for a level that is bigger than the screen size. If I make the map that I have drawn, will the entire map be displayed on the screen, or will the screen "scroll". Am I making sense?

J

You can make the map as big as you like and scroll it.

Let's say your map is 640x480 pixels and the window is 320x240. If you call 'proc TM_SetCamera 0, 0', you will se the top left part of the map next time you call 'TM_Render'. If you call 'proc TM_SetCamera 320, 0', you will see the top right part of the map. And 'proc TM_SetCamera 320, 240' will show you the bottom right part.

I suggest you have a look at the Tilemap library exampels, I think John made them pretty step-by-step:ish.



.\\\opz

johnno56

  • Guest
Re: Platformer
« Reply #5 on: October 26, 2014 »
Cool. Thanks for that. As soon as I have had my morning caffeine fix, I will get right onto it....

J

johnno56

  • Guest
Re: Platformer
« Reply #6 on: October 30, 2014 »
Marcus,

Fired up those TM examples 1 to 4 and they all crashed. "Line 248: Array index out of range".  Do you think they may have been created using the N5 version of TM?

J

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 549
    • View Profile
Re: Platformer
« Reply #7 on: October 30, 2014 »
That sounds really weird. The biggest example (scrolling stuff) has only got 130 lines :)

Does the fourth one look like this:

Code: [Select]
rem ==================================================================
rem Tilemap library example 4.
rem
rem We extend the platform game (example 3) with a map larger than the
rem screen and a parallax effect.
rem
rem By John Master.
rem ==================================================================

import "Tilemap.lib"
import "Keycodes.lib"

rem Load map created with TM Editor.
if not TM_LoadMap("assets/map4.txt")
wln "Could not load map!"
wln "Press any key to exit ..."
wait keydown
end
endif

rem Load player image.
load image 1, "assets/smiley.png"
rem Load background image.
load image 2, "assets/bg.png"

rem Turn on double buffering.
set redraw off

rem Set render view. Usually you want to use the entire window, like
rem this.
proc TM_SetView 0, 0, width(primary), height(primary)

rem The map has one loader flag set, value 1, which we let represent
rem the player's starting position. There's only one element in the
rem array returned from 'TM_GetLoaderFlags', but let's still search
rem for it and set the player position.
playerX = 0
playerY = 0
flags[][] = TM_GetLoaderFlags()
for i = 0 to sizeof(flags, 0) - 1
if flags[i][TM_FLAG] = 1
rem The flags use map coordinates, so we need to convert them to
rem world (and in this case also screen) coordinates. The cels
rem in the map image are of the size 32x32, so the conversion is
rem quite simple.
playerX = flags[i][TM_X]*32
playerY = flags[i][TM_Y]*32
endif
next

rem This time the player needs a variable for it's vertical speed
rem and a flag indicating if it's on the ground or not. We also use
rem a counter, 'playerGravityTimer' to increase the player's
rem vertical speed every now and then (yes, integer gravity).
playerDY = 0
playerOnGround = false
playerGravityTimer = 0

rem Count the jewels in the map. They're using image cel 1 in the map
rem image.
jewelCount = 0
for y = 0 to TM_MapHeight() - 1
for x = 0 to TM_MapWidth() - 1
if TM_GetCel(x, y) = 1 then jewelCount = jewelCount + 1
next
next

rem Game loop.
do
rem Update.
rem Move player.
dx = 0
if keydown(VK_LEFT) then dx = -4
if keydown(VK_RIGHT) then dx = 4
rem Only jump if player's on ground.
if keydown(VK_UP) and playerOnGround
rem Set vertical speed.
playerGravityTimer = 0
playerDY = -7
endif
rem Increase vertical speed every time 'playerGravityTimer' is zero.
playerGravityTimer = (playerGravityTimer + 1)%5
if playerGravityTimer = 0
playerDY = min(playerDY + 1, 6)
endif
rem Move.
newPos[] = TM_Move(1, playerX, playerY, dx, playerDY)
playerX = newPos[TM_X]
playerY = newPos[TM_Y]
rem Update the 'playerOnGround' flag.
if TM_CollisionDown()
playerOnGround = true
else
playerOnGround = false
endif
rem If the player hits the ceiling, the vertical speed should be
rem set to zero.
if TM_CollisionUp() then playerDY = 0

rem Check if player is on a jewel.
pos[] = TM_ToTile(playerX + 16, playerY + 16)
if TM_GetCel(pos[TM_X], pos[TM_Y]) = 1
proc TM_SetCel pos[TM_X], pos[TM_Y], -1
jewelCount = jewelCount - 1
endif

rem Center camera around player.
proc TM_SetCamera playerX - width(primary)/2 + 16, playerY - height(primary)/2 + 16

rem Draw parallax background.
set color 255, 255, 255
x = -(TM_CameraX()/2)%640
y = -(TM_CameraY()/2)%480
draw image 2, x, y
draw image 2, x + 640, y
draw image 2, x, y + 480
draw image 2, x + 640, y + 480
rem Let library draw the map.
proc TM_Render
rem Draw player. We now need to convert its coordinates from
rem world to screen.
draw image 1, TM_ToScreenX(playerX), TM_ToScreenY(playerY)
rem Write instructions.
set caret 320, 8
center "Pick up all the jewels to finish the level."
center "Press Esc to quit ..."

redraw
wait 16
until jewelCount = 0 or keydown(VK_ESC, true)
.\\\opz

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 549
    • View Profile
Re: Platformer
« Reply #8 on: October 30, 2014 »
Have a look at the attached example (new), hope it helps :)

You know how you mark tiles as obstacles in the tilemap editor, right? In the "Tiles" window, double click on a tile and it will get a white outline indicating that it's now an obstacle.

« Last Edit: October 30, 2014 by John »
.\\\opz

johnno56

  • Guest
Re: Platformer
« Reply #9 on: October 30, 2014 »
In reference to your previous post, yes, the listing is exactly the same.

That being said, I fear I have wasted your time. I believe I have found the source of the problem. It was me. I realize that the tilemap example is 130 lines long and the error message made no sense. The error message was generated by the TM Editor because I was trying to load the example.txt file... That loud noise you should be hearing is the sound of the palm of my hand hitting my forehead. Running the example, using N6, ran just fine...  :-[ My bad. Sorry for the trouble.

J

(ps: I like the monochromatic look of your example...)

John

  • Sr. Member
  • ****
  • Posts: 362
    • View Profile
Re: Platformer
« Reply #10 on: October 31, 2014 »
I've done the same thing a couple of times. Let's blame Marcus for not doing any file checkings at all ;)

The third example is a blank file here, even in the istaller build. I wonder how that happened ...

Jusy ask if you run into any  problems with the library, I've used it a lot.