Open Source Tile based game

BlitzMax Forums/BlitzMax Beginners Area/Open Source Tile based game

julias0(Posted 2016) [#1]
Hello Everyone!

I was wondering if there was any open source tiled game written in blitzmax available anywhere.
I wanted to read a few examples before writing something.

Cheers :D


dw817(Posted 2016) [#2]
.


dw817(Posted 2016) [#3]


Seems you're not the only one interested in this. However I'm not seeing any small source code examples so I can certainly write one to get you started.

I need this code for myself later (as I'm revamping my game mapper) so you may have a few extra features, Julias. :)

UPDATED 02/01/16





For those of you teaching me things in here, I am now discovering the CreateTimer() routine and yes, it gives very smooth timing.


julias0(Posted 2016) [#4]
Thanks dw817! :D :D :D

I owe you a pizza :D


dw817(Posted 2016) [#5]


A pizza ? Wow, hmm ... Extra mushroom, that's the ticket.

Glad to help. :)


TomToad(Posted 2016) [#6]
Here's a little something I whipped up. Might not be the best way to do things, but might give you some ideas.



dw817(Posted 2016) [#7]
Hi Tom. Long day. Trying out your game. This is really neat !

Suggestion: How about a CAT that travels 2x the speed randomly in the maze ?

That is, the player moves one space (one grid square), cat moves two spaces - and waits until player moves again.

If player grabs cheese, increase score, randomly place all existing cats. Add another cat also random position.

So by grabbing two cheese, there will be 2-active cats. No cat at all for first level.

Random placement of cats should also be a distance of at least 25% the full distance of a map from the player to give the player a chance to maneuver around them.

This will be a bonus if a cat is hot on the heels of the mouse. As soon as mouse touches cheese, player is guaranteed all cats are relocated at least 25% of entire map away from player. Their reward, and then they must maneuver around the cats again to find the newly placed random cheese.

Cheese can be relocated no less a distance of at least 10% of the map so it doesn't just drop in the player's lap.


julias0(Posted 2016) [#8]
@TomToad:

I owe you a pizza too B)

Thanks a lot!


dw817(Posted 2016) [#9]
I'm having a problem that ONLY appears when I compile without debug mode. See this picture:



I found the solution. I am not using GrabImage() for the first tile. Now you would think that by using CreateImage() which already defines the size of the image, that it would default to BLACK. Apparently not.

So before I started drawing the other tiles I used, GrabImage img_tile[0],0,0 and that fixed it. Apparently you need GrabImage() even if there is no image to grab.

And yes, Tom, if I didn't state it earlier, I really like your circular arrow find. I'm playing a game called Strider Reboot and they use a 'distance' to target meter. It would be a lot more helpful if they had your arrow pointer additionally.

As for games that already use this, look to Camp Lazlo Leaky Lake Games to see a demonstration of an arrow pointing to a remote target.

https://youtu.be/XjumxTuShNQ?t=60


Derron(Posted 2016) [#10]
After creating a new Image you should clear the contained pixmap's pixels.

LockImage(img).ClearPixels(0)

Else you end up with a new image consisting of a pixmap containing garbage (what was left in the memory block at that moment).

This is similar to relying on existing backbuffer content (what we talked about in another thread).


bye
Ron


dw817(Posted 2016) [#11]
Hi Ron. I'm not using a TPixMap in this program at all, however. Can you use ClearPixels() for Timages ?


Midimaster(Posted 2016) [#12]
To manipulate an image, you have to convert it into a pixmap. Long version looks like this:
Graphics 800,600
Global Img:TImage=CreateImage(200,100)

Local Pix:TPixmap=LockImage(Img)
	Pix.ClearPixels($FF000000)
UnlockImage Img

SetClsColor( 255,0,0 )
Cls 
DrawImage Img,100,100
Flip 0
WaitKey()


Also this is possible:

SuperStrict

Graphics 800,600
Global Img:TImage=CreateImage(100,100)

Local Pix:TPixmap=LockImage(Img)
SetClsColor( 111,0,0 )
Cls 

 Pix:TPixmap=LockImage(Img)
 	For Local I%=0 To 1000
		Pix.WritePixel(Rand(99),Rand(99),$FF0000FF)
	Next
UnlockImage Img
DrawImage Img,100,100

Flip 0
WaitKey()

The HexString represent the color in AARRGGBB


markcw(Posted 2016) [#13]
Komiga (formerly Plash) wrote a set of modules for bmx called duct (as in ductile/flexible) which seems to be for 2d games. There is a tilemap module HERE which may be worth checking out. The license is MIT but Komiga is not supporting it.

For something simple, JazzieB made a Scrolling tilemap demo in Bmx HERE.

Spacerat has a tile engine with map writer/loader HERE but no examples I could find.

Planiax has Ignition Max still for sale HERE which has a basic tile system and editor. That became Ignition X for MonkeyX and now Pyro.


Derron(Posted 2016) [#14]
dw817:
Can you use ClearPixels() for Timages ?


LockImage(img).ClearPixels(0)
 |              |
 '-- returns the pixmap used by "img"
                |
                '-- calls "ClearPixels" method
                    of the returned pixmap

'long
local p:TPixmap = LockImage(img)
p.ClearPixels(0)
UnlockImage(img) 'does "nothing" (stub), so you _could_ skip it


So my line should be "enough". Of course you could use other colors than "0" (eg. $FF000000).


bye
Ron


dw817(Posted 2016) [#15]
Since you're only initializing your images one time and never again, MidiMaster, you could also use this:
Graphics 640,480
' Cls is not needed since graphics above already clears the screen
Global img:Timage=CreateImage(200,100)
GrabImage img,0,0
It's no big. :)


Derron(Posted 2016) [#16]
@ leaving out CLS

His code was
SetClsColor( 111,0,0 )
Cls 


With SetClsColor() being important, because the Cls then does not result in a black screen but a slightly (dark) red one.
If you draw something (not fully opaque) on that screen, you will see the difference.


bye
Ron


Midimaster(Posted 2016) [#17]
The difference between the "Clear"-Method in...
Global Img:TImage=CreateImage(200,100)
LockImage(img).ClearPixels(0)

...or also...
Global Img:TImage=CreateImage(200,100)

Local Pix:TPixmap=LockImage(Img)
	Pix.ClearPixels($00000000)
UnlockImage Img


..and the "Grab"-Method...

Global img:Timage=CreateImage(200,100)
GrabImage img,0,0

... is, that "Grabbing" results in a black opaque rectangle and "Clear" results in a defined transparent rectangle (without garbage).

to dw817:
Your question was, how to clear images instead of pixmaps. But derron'way exactly showed this in one line code. My code demonstrated the "long" way with locking and unlocking. To manipulate an image quickly and easy, you need to convert it temporary into a pixmap.


dw817(Posted 2016) [#18]
Derron's way is small. I'm concerned about locking pixels that aren't later unlocked, can that cause a problem in the future ?


Derron(Posted 2016) [#19]
Unlockimage is an empty function for years now... if unsure just append that command too.

Bye
Ron


dw817(Posted 2016) [#20]
Derron. Oh ? Okay, well, yours is certainly the smallest - that's the kind of code I like. Easy to debug later.

Ok, thanks. I know before I knew about SetGraphicsDriver GLMax2DDriver(),0 not unlocking an image could cause your code to crash later with a D3DD error saying you could not draw to the screen.

The SetGraphicsDriver() routine has changed all that now though.