Game creation questions...

Find quick help here to get you started with Hollywood
Post Reply
User avatar
Tuxedo
Posts: 344
Joined: Sun Feb 14, 2010 12:41 pm

Game creation questions...

Post by Tuxedo »

Hi ALL!
I'm working on some sort of programming exercise atm...
I'm trying to make a metroidvania like game but have some questions to ask before start coding, sorry in advance if something was already discussed...
The questions(in simple random order):

- To Fix the fps to a certain rate(basically 60, not the monitor refresh rate that maybe was too high, ther'es a standard method?
- Since my goal was to make 1080p, to switch to upper resolutions(for example 2560 x1440), I can use simply the scaling engine togheter RebelSDL or there was a different way? Same thing if to switch to lower.
- To put tiled background on screen the best and fast option was the DisplayBrushPart command?
- If understood correctly I cant use layers with RebelSDL that seems to me the best plugin to uses to make a 2D platfrom/shooter, so I have to blit the brushes with alpha channel simply over the other background/objects/whatever and make a my personal layers management putting one over the other?
- There was any recommendation to follow to avoid basic errors?

ATM that was my concerns...but for sure more to come....

Thank you all in advance and sorry to ask probably weird/stupid things!
Simone"Tuxedo"Monsignori, Perugia, ITALY.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: Game creation questions...

Post by Bugala »

"To Fix the fps to a certain rate"

With SetInterval Function you can lock FPS rate. In SetInterval you tell how often, in MilliSeconds, the Function is to be executed, since 1 Second is 1000 Milliseconds, for example to get max 60 FPS rate, you would use 1000/60 = 16.666... = 17 Ms to lock it at about 60 FPS.

"- Since my goal was to make 1080p, to switch to upper resolutions(for example 2560 x1440), I can use simply the scaling engine togheter RebelSDL or there was a different way? Same thing if to switch to lower."

Yes.

"- If understood correctly I cant use layers with RebelSDL that seems to me the best plugin to uses to make a 2D platfrom/shooter, so I have to blit the brushes with alpha channel simply over the other background/objects/whatever and make a my personal layers management putting one over the other?"

There are couple of different approaches to this. One way is to "paint" everything each cycle and from pieces.

As in, first paint the background, then paint the stuff that is on top of background, and when painting background etc. use tiles.

But, there could be other options too, like if background isn't too big, then you could at beginning of level create a big picture from those tiles, and instead of dealing with tiles, keep just painting that one big picture. It is good method to do this way, but it can also create some problems. Like lets say you decide to make Original Super Mario Bros style. You could make Background as one big picture, and then all those walls as another big picture, then first paint bg picture, then on top of that all those wall tiles picture. But what if you break one of the tiles? Now you either need to recreate the Wall Tiles picture, or you need to paint to that specific location something that looks like there was no tile ever, which could be for example that you copy part of background picture to that specific location where that tile was or make it transparent or something.

It depends upon what you plan to do. Like if you plan that some explosion leaves a mark to the super Mario wall tiles, then it might be easier to use a big picture instead of remaking from tiles each cycle.
User avatar
Tuxedo
Posts: 344
Joined: Sun Feb 14, 2010 12:41 pm

Re: Game creation questions...

Post by Tuxedo »

Hi again!
I managed to work on a routine that dispalys the game screen from tiles 16 x 16 to a 1920 x 1080 screen/window but noticed that wasnt so speedy as I expected with tiles...
The attached example was also weird since When I sue DisplayBrushPart(that on RebelSDL documenation wasnt described as hw accelerated), and also call another routine from the main one I get roughly the double of the speed than using DisplayBrush(that was described as hw accelerated in RebelSDL documentation) and also using less commands...The first one gives me 7ms to be drawn the second 17ms...

If you need also the assets to try the code tell me...

Dunno if I use too tiny tiles or waht...

Anyone can help me?

Code: Select all

/* sPLATFORM */

; VARIABILI DI BASE

MapW		= 0	; Larghezza mappa in tiles
MapH		= 0	; Altezza mappa in tiles
MaptileW	= 0	; larghezza tile mappa
MaptileH	= 0	; Altezza tile mappa
MapOrientation	= ""	; orientamento mappa ("right-down" di default)
InfiniteMap	= ""	; Controllo se la mappa è infinita
Infinite	= 0	; Così so se la mappa è settata come infinita o no
LayersNo	= 0	; Numero di layers attivi in questa mappa
TileS1		= 0
BaseTT		= 0	; questo è il tile "ZERO" del tileset utilizzato correntemente per disegnare lo sfondo
salta  = 0

/********************************************** DEBUG ********************************************************/
@OPTIONS {EnableDebug = true} ; ATTIVO L'OUTPUT DI DEBUG PER CONTROLLARE EVENTUALI ERRORI!!!!!!!!!
/********************************************** DEBUG *********************************************************/

@REQUIRE "rebelsdl"

@DISPLAY {Width = 1920, Height = 1080, Color = $444444}

;OpenResourceMonitor()

map$ , mapbyte = FileToString("MAPPA/mappa5.json")	; carico la mia mappa

Function p_LoadResources()	; carico le risorse
	HERO_ATTACK		= LoadBrush(Nil, "MAPPA/DATA/HERO/ATTACK_6X5.png", {LoadAlpha = True, Hardware = True})
	HERO_DEAD		= LoadBrush(Nil, "MAPPA/DATA/HERO/DEAD_5x5.png", {LoadAlpha = True, Hardware = True})
	HERO_IDLE		= LoadBrush(Nil, "MAPPA/DATA/HERO/IDLE_4X5.png", {LoadAlpha = True, Hardware = True})
	HERO_JUMP		= LoadBrush(Nil, "MAPPA/DATA/HERO/JUMP_4X4.png", {LoadAlpha = True, Hardware = True})
	HERO_JUMPHIGH		= LoadBrush(Nil, "MAPPA/DATA/HERO/JUMPHIGH_4X4.png", {LoadAlpha = True, Hardware = True})
	HERO_RUN		= LoadBrush(Nil, "MAPPA/DATA/HERO/RUN_5X5.png", {LoadAlpha = True, Hardware = True})
	MAP_BACKGROUND		= LoadBrush(Nil, "MAPPA/DATA/MAP/Background.png", {LoadAlpha = True, Hardware = True})
	MAP_BACKGROUNDNOHW	= LoadBrush(Nil, "MAPPA/DATA/MAP/Background.png", {LoadAlpha = True})
	MAP_BUILDINGS		= LoadBrush(Nil, "MAPPA/DATA/MAP/Buildings.png", {LoadAlpha = True, Hardware = True})
	MAP_GREENTREE		= LoadBrush(Nil, "MAPPA/DATA/MAP/Green-Tree.png", {LoadAlpha = True, Hardware = True})
	MAP_INTERIOR01		= LoadBrush(Nil, "MAPPA/DATA/MAP/Interior-01.png", {LoadAlpha = True, Hardware = True})
	MAP_TILES		= LoadBrush(Nil, "MAPPA/DATA/MAP/Tiles.png", {LoadAlpha = True, Hardware = True})
	MAP_TREEASSETS		= LoadBrush(Nil, "MAPPA/DATA/MAP/Tree-Assets.png", {LoadAlpha = True, Hardware = True})
	MAP_TREEBACKGROUND	= LoadBrush(Nil, "MAPPA/DATA/MAP/TreeBackground.png", {LoadAlpha = True, Hardware = True})
	BEE_ATTACK		= LoadBrush(Nil, "MAPPA/DATA/MOB/BEE_ATTACK_4X4.png", {LoadAlpha = True, Hardware = True})
	BEE_FLY			= LoadBrush(Nil, "MAPPA/DATA/MOB/BEE_FLY_4X4.png", {LoadAlpha = True, Hardware = True})
	BEE_HIT			= LoadBrush(Nil, "MAPPA/DATA/MOB/BEE_HIT_4X4.png", {LoadAlpha = True, Hardware = True})
	BOAR_HIT		= LoadBrush(Nil, "MAPPA/DATA/MOB/BOAR_HIT_3X2.png", {LoadAlpha = True, Hardware = True})
	BOAR_IDLE		= LoadBrush(Nil, "MAPPA/DATA/MOB/BOAR_IDLE_3X2.png", {LoadAlpha = True, Hardware = True})
	BOAR_RUN		= LoadBrush(Nil, "MAPPA/DATA/MOB/BOAR_RUN_3X2.png", {LoadAlpha = True, Hardware = True})
	BOAR_WALK		= LoadBrush(Nil, "MAPPA/DATA/MOB/BOAR_WALK_3X2.png", {LoadAlpha = True, Hardware = True})
	OBJ_BOX			= LoadBrush(Nil, "MAPPA/DATA/OBJ/BOX_2x2.png", {LoadAlpha = True, Hardware = True})
	OBJ_COIN		= LoadBrush(Nil, "MAPPA/DATA/OBJ/COIN_1x1.png", {LoadAlpha = True, Hardware = True})
	OBJ_KEY			= LoadBrush(Nil, "MAPPA/DATA/OBJ/KEY_1x1.png", {LoadAlpha = True, Hardware = True})
	OBJ_POTION33		= LoadBrush(Nil, "MAPPA/DATA/OBJ/POTION33_1x1.png", {LoadAlpha = True, Hardware = True})
	OBJ_POTION100		= LoadBrush(Nil, "MAPPA/DATA/OBJ/POTION100_1x1.png", {LoadAlpha = True, Hardware = True})
	OBJ_SPAWNBEE		= LoadBrush(Nil, "MAPPA/DATA/OBJ/SPAWN_BEE_2x3.png", {LoadAlpha = True, Hardware = True})
EndFunction

Function p_MapData()	; imposto le variabili di base della mia mappa prendendle dal file .JSON salvato da Tiled
	MapW		= map.width		; Larghezza mappa in tiles
	MapH		= map.height		; Altezza mappa in tiles
	MaptileW	= map.tilewidth		; larghezza tile mappa
	MaptileH	= map.height		; Altezza tile mappa
	MapOrientation	= map.orientation	; orientamento mappa ("right-down" di default)
	InfiniteMap	= map.infinite		; Controllo se la mappa è infinita
	Infinite	= 0			; Così so se la mappa è settata come infinita o no
	LayersNo	= TableItems(map.layers); Numero di layers attivi in questa mappa
EndFunction

Function p_TileToLoad(tt) ; quì calcolo quali Tiles caricare dall'immagine di partenza
	srcx = tt - BaseTT

	IF srcx < 0
		salta = 1
	else
		salta = 0
	EndIF

	deltaTT = Int(srcx/30)

	IF srcx < 30
		srcx = srcx
		srcy = srcy
	Else
		srcx = srcx - (30 * deltaTT)
		srcy = deltaTT
	EndIF

EndFunction


Function p_DrawTiles() ; scrivo a schermo le mie tiles
	srcx, srcy  = 0, 0
	destx, desty = 0,0
	BaseTT = 8447
	deltaMAP = 0

	For LOCAL x = 0 to 8040

	IF (x <> 0) AND Frac(x/120) = 0
		desty = desty + 16
		destx = destx - 1920
		deltaMAP = deltaMAP + 36
	EndIF

;		p_TileToLoad(map.layers[1].data[(x+deltaMAP)])										; UNCOMMENT that....
;		If salta = 0 THEN DisplayBrushPart(MAP_BACKGROUND, srcx*16, srcy*16, destx+(x*16), desty, 16, 16)			; ...AND THAT to see the speed differeces....
		If map.layers[1].data[(x+deltaMAP)] <> 0 THEN DisplayBrush(map.layers[1].data[(x+deltaMAP)], destx+(x*16), desty)	; ...AND COMMENT HERE
	Next

;DisplayBrush(MAP_BACKGROUND, 0, 0, {Width = 1920, Height = 1080, SmoothScale= 1})

EndFunction

Function p_CreateTiles() ; quì dentro creo le tile HW dall'immagine di partenza
 LOCAL TileW, TileH, ttnum, ttcnt, ttcol, srcx, srcy = 16, 16, 8447, 510, 30, 0 , 0
 LOCAL ttrow = ttcnt/ttcol

	CreateBrush(0, 16, 16 , 0)

	LOCAL deltaTT = 0

	For i = ttnum to (ttnum + ttcnt - 1)
		deltaTT = Int((i - ttnum)/30)
		SelectBrush(0)

		If (i - ttnum) < 30
			srcx = i - ttnum
			srcy = srcy
		Else
			srcx = (i - ttnum) - (deltaTT * 30)
			srcy = deltaTT
		EndIF

		DisplayBrushPart(MAP_BACKGROUNDNOHW, srcx*16, srcy*16, 0, 0, 16, 16)
		EndSelect()

		CopyBrush(0, i, {Hardware = true})
	Next

FreeBrush(0)

EndFunction


SetSerializeMode(#SERIALIZEMODE_NAMED) 	; imposto come va serializzata il file JSON che ho caricato...
map = DeserializeTable(map$)		; ...e lo Deserializzo in una TABELLA Hollywood con nomi invece di numeri.

StartTimer(2)
p_LoadResources()	; carico tutto quello che mi serve
p_MapData()		; Controllo i imposto i parametri della mia mappa dal file .JSON
p_CreateTiles()		; Ora creo le Tiles per poterle scrivere in hw con DisplayBrush()


DebugPRint("TIMER PRE....", GetTimer(2))

BeginDoubleBuffer(True)

Repeat

StartTimer(1)

DisableLineHook()
p_DrawTiles()
EnableLineHook()

timer = GetTimer(1)

Flip()

DebugPrint("TEMPO..........", timer)

	WaitEvent
Forever
Simone"Tuxedo"Monsignori, Perugia, ITALY.
Post Reply