Adventures of AGK!

Started by Dabz, June 11, 2019, 15:55:35

Previous topic - Next topic

Dabz

Well, real good second bout at AGK Classic, and, yeah, I'm pretty pleased with the handle on things... There are a few irks, but, they are workable really, I dont really like the way you pass values back from functions, seems a bit half baked if you ask me, another is how they seem to have got rid of DATA statements, which is such a shame, because they are really handy to store static information in, yes, you can use other things, but I find them neat and tidy.

Another is there seems to be no line continuation symbol, so, when you have, say, tilemap data in an array, you've got to plonk it all on one line, I mean, its not a biggy, but, again, something would of been nice to keep it all tidy.

I havent played with sound yet, but, its sound, though I've delved into quite a bit on how certain aspects of the engine works, and, yeah, I've had fun with the amount of time I've played with it, so, the fruits of my little shenanigans is this:-

http://www.dabzy.co.uk/test/agk/

(Left/Right arrow keys, Space to jump)

A little platformer setup, okay, its nowhere near anywhere yet, but, I've used the Dizzy character for the mechanics, I like how Dizzy platforming goes, so, its based on that, I think the general "feel" of Dizzy is in, which is nice, but to expand it more, I'll need to build a lot more stuff, so, as I'm going along, I can plonk info here, it'll probably be an intermittent project with AFK stuff going on, but, when I can, I'll be poking at this with a stick! :D

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Qube

Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Dabz

Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Qube

Oy! Dabz, get ya arse back in here ya twat ;D ( we're both ginger so we can insult each other )

So... This is way way better than I first thought. When I played it I kinda got giddy with the whole retro Dizzy thing but something was niggling at me. So I took a close look and you have pixel perfect platform walking going on here :o

As I'm about to redo my map editor what was your approach to this?

1.. Actually checking each foot against pixels
2.. Adding each pixel to the tile map so it knows to increase / decrease on the y pos
3.. Via math, like a cos / sin radius or angle based on tile symmetry

Something else?

What was your approach and what's the performance like?

Personally I was aiming for the point 2 method as that would be the fastest but if you've come up with a simpler / faster way then super smashing great..... And go!
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Dabz

#4
lol, basically, many moons ago, aka BlitzBasic, I used to use ReadPixelFast on the backbuffer, then modern graphics kicked in and all that was tucked out of the way, but, it was my preferred way, so I sorta had to invent a way to find if a point was on a "solid", then obviously store that result somewhere to check later on, and obviously use it like I did in days gone by... I didnt want to see if I could get the pixel info using shaders, because, well, I dont know if you can, I know you can set them, and quite frankly, I wanted something simple to use, so I came up with this:-


Global screenWidth As Float = 1024
Global screenHeight As Float = 576

SetWindowTitle( "First run" )
SetWindowSize( screenWidth, screenHeight, 0 )
SetWindowPosition( ( GetMaxDeviceWidth() - GetWindowWidth() ) / 2, ( ( GetMaxDeviceHeight() - GetWindowHeight() ) / 2 ) )
SetWindowAllowResize( 0 )
SetVirtualResolution( screenWidth, screenHeight )
SetDisplayAspect( screenWidth / screenHeight )
SetOrientationAllowed( 0, 0, 1, 1 )
EnableClearColor( 1 )
SetVsync( 1 )
SetClearColor( 0, 0, 0 )
UseNewDefaultFonts( 1 )

#constant TILE_WIDTH 32
#constant TILE_HEIGHT 32
#constant TILE_AMOUNT 48

type TTileCollisionsInfo
id as integer
units as integer [TILE_HEIGHT]
endtype

global tileCollisionsBank as TTileCollisionsInfo [TILE_AMOUNT]
global tiles as integer [TILE_AMOUNT]

for loopTile = 0 to TILE_AMOUNT-1
tiles[loopTile] = LoadImage(str(loopTile)+".png")
CreateSprite(loopTile+1, tiles[loopTile])
SetSpriteVisible(loopTile+1,0)
next

CalculateCollisionUnits()

#constant MAP_WIDTH 23
#constant MAP_HEIGHT 12
#constant WORLD_WIDTH 17
#constant WORLD_HEIGHT 6

#constant MAP_TILE_AMOUNT 276

global currentWorldScreenX as integer = 0
global currentWorldScreenY as integer = 0

global map as integer [MAP_WIDTH,MAP_HEIGHT] //,WORLD_WIDTH,WORLD_HEIGHT] //17,6

LoadMap()

Local mx, my, xGrid, yGrid, pointInTileX, pointInTileY as integer
Local mapOffsetX, mapOffsetY as integer
Local currentTile, yTileUnit, clonedSprite as integer

text = createText("Collide")
SetTextPosition(text,0,30)
SetTextSize(text,20)
SetTextVisible(text,0)
do
    ClearScreen()
   
    Print( ScreenFPS() )
    mx = GetPointerX()
    my = GetPointerY()
   
    xGrid = (mx - mapOffsetX) >> 5
yGrid = (my - mapOffsetY) >> 5
pointInTileX = (mx - mapOffsetX) - (xGrid << 5)
pointInTileY = (my - mapOffsetY) - (yGrid << 5)

If xGrid => 0 And xGrid < MAP_WIDTH
If yGrid => 0 And yGrid < MAP_HEIGHT
currentTile = map[xGrid,yGrid]
If currentTile <> 0
If tileCollisionsBank[currentTile].units[pointInTileX] =< pointInTileY
SetTextVisible(text,1)
else
SetTextVisible(text,0)
EndIf
else
SetTextVisible(text,0)
EndIf
EndIf
EndIf
   
    for loopy = 0 to MAP_HEIGHT-1
for loopx = 0 to MAP_WIDTH-1
//if map[loopx,loopy] <> 0
SetSpriteVisible(map[loopx,loopy]+1,1)
SetSpriteX(map[loopx,loopy]+1,loopx << 5)
SetSpriteY(map[loopx,loopy]+1,loopy << 5)
DrawSprite(map[loopx,loopy]+1)
//endif
next
next
    Sync()
loop

function CalculateCollisionUnits()
local loopx as integer
local loopy as integer
local tilePixels as integer [TILE_WIDTH,TILE_HEIGHT]

for loopTile = 0 to TILE_AMOUNT-1
tileCollisionsBank[loopTile].id = loopTile
tilePixels = ImageToArray(tiles[loopTile])

for loopx = 0 to TILE_WIDTH-1
for loopy = 0 to TILE_HEIGHT-1
if tilePixels[loopx,loopy] <> 0xff00ff
tileCollisionsBank[loopTile].units[loopx] = loopy
exit
endif
next
next
next
endfunction

function LoadMap()
local staticMap as integer [MAP_TILE_AMOUNT] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,22,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,22,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,22,23,0,0,0,0,0,0,0,0,0,0,0,1,2,2,3,0,0,0,0,0,0,22,23,0,0,0,0,0,0,0,0,0,0,0,14,15,15,13,0,0,0,0,0,0,22,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,0,0,22,23,0,0,0,4,5,2,2,8,9,0,0,0,0,0,0,0,0,0,0,0,0,22,23,0,4,5,6,10,10,10,10,7,8,9,18,19,30,9,0,0,0,0,1,2,22,17,2,6,10,10,10,10,10,10,10,10,7,6,10,10,7,2,2,2,2,2,2,16]

local tileID as integer
local mapTileCounter as integer
for loopy = 0 to MAP_HEIGHT-1
for loopx = 0 to MAP_WIDTH-1
tileID = staticMap[mapTileCounter]
if  tileID <> 0
map[loopx,loopy] = tileID
endif
mapTileCounter = mapTileCounter + 1
next
next
endfunction

function ImageToArray(imageID as integer)
memblock = CreateMemblockFromImage(imageID)

width = GetMemblockInt(memblock, 0)
height = GetMemblockInt(memblock, 4)
size = GetMemblockSize(memblock)

local imageArray as integer [TILE_WIDTH,TILE_HEIGHT]

loopx as integer = 0
loopy as integer = 0

for loopMemBlock = 12 to size-1 step 4
rgb = 0

r = GetMemblockByte(memblock, loopMemBlock)
g = GetMemblockByte(memblock, loopMemBlock+1)
b = GetMemblockByte(memblock, loopMemBlock+2)

rgb = r
rgb = (rgb << 8) + g
rgb = (rgb << 8) + b

imageArray[loopx,loopy] = rgb

loopx = loopx + 1
if loopX = TILE_WIDTH
loopx = 0
loopy = loopy + 1
endif
next
SetImageTransparentColor(imageID,255,0,255 )
endfunction imageArray


Basically, I scan each tile for a solid colour, I move along the x-axis, scanning down on the y until I hit something, then I store that point in the tile, hop along to the next column, rinse repeat.

So with all the info stored, "ingame" I check what tile a point is on in the tilemap (the above code the point is the mouse location) when I know that tile, I then work out where within the tile that point is, check it against the info I stored earlier:-


If tileCollisionsBank[currentTile].units[pointInTileX] =< pointInTileY


And obviously if I'm on or past the "solid" marker, then, I act accordingly, that part of the code is now wrapped up in a function, so, now, to check Dizzys, say, right foot (Actually, its his left, but right to us, lol), I just use:-


If CheckCollision(player.x+36,player.y+46) <> 0
player.y = player.y - 2
EndIf


You can see the collision points I use on Dizzy in the attachment.

The only thing with this way, is that the collision detection works from top to bottom, if you just had a line through the centre of the a tile and nothing more, then, it would work as expecting coming down, but if you were coming up, you'd collide as soon as it knew you were on the tile, so basically, the reaction would be miles away from the line itself. This is no biggy, as I can expand that if I need to later on, but I dont actually need it, so...

Performance wise, I have no idea, but it should be okay as your not accessing actual image pixel data when checking, which can be a killer, its just a simple array your checking.

But, its been an ideal little thing to learn a bit about how AGK works as you have to use a bit of stuff to get it motoring, which was the whole idea really, and well, it went a charm! :D

Dabz



Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

GaborD

The jumping animation is pure greatness!

I hope you make a full game out of this. Love a fun jump'n'run.

Derron

What are the white dots on the "dizzyCol.png" for?

bye
Ron

Qube

Ah right, you went for the way I thought would be fastest ;D - nice work and thanks for sharing. Yeah, real shame the good old ReadPixel isn't really a thing anymore :(
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Steve Elliott

Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Dabz

@Ron, that's just highlighting where in pixels on the Sprite I'm checking collisions that's all, it sorta helped as a placeholder just see if the collisions were acting accordingly, nowt major really!

@Qube, I did realise when writing it that all the info is there so if you need to rotate the Sprite to match the ground, then it should be easy enough as you can compare them both pretty easily, so that's a bonus too!

@Steve cheers matey :)

@GaborD, I'll have a go, wont be done in a month but I can chop away, the programming part will be nothing, it'll be the sprites that'll bottleneck it for me! Give me a pencil and a bit of paper, and I'm pretty good at drawing, give me a mouse and monitor and the stuff I knock up is terrible!!!
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Derron

Maybe you should try to draw with a digitizer / drawing tablet. Pressure steps allow for a natural drawing look (less alpha to full alpha, small pencil tip to bigger tip...)

If you own a reasonable fast tablet you could even try first steps there. Some prefer drawing "indirect" (similar to a mouse) and some "direct" (drawing on the display - so to have a direction connection of drawing device and painting stroke).

If done properly - eg in a vector program, you even do not have to worry about antialiasing you will just receive pure vectors, ready to get resized to the desired resolution (aka "draw bigger and scale down later").


@ pixel dots
Thought that already (as they were "kind of" symmetrized). Thanks for the clarification.


bye
Ron

Dabz

#11
I've tried a few things Ron matey, but, for whatever reasons, I just cannot replicate what I can do with a pencil and paper... And its got to be plain old graphite pencils as well, I can do shading in grey absolutely lovely, chuck colour pencils in my hand and, again, I lose aspect of it and can never get it right... Seems like colour goes in, but once it gets processed, runs down my arm into my hands it gets converted to greyscale! :D

I havent done any drawing for years now though, again, mostly just time, the last one I was working on was a tiger when I was working away, but a bottle of shampoo decided to leak in my bag and ruin him, and since then, I've never felt like starting anything else, which is a shame when I think, because its in me!

Dabz

EDIT: I've attached the last picture of my tiger, I nearly had him finished when the shampoo decided to run out, but even half finished he still looks pretty cool!
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Qube

Nice drawing you got there :) - I always preferred drawing with just a pencil rather than colour and would often have my art work at school ruined by the teacher writing "Use more colour!" over it.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Coder Apprentice

Quote from: Qube on June 12, 2019, 22:33:55
Nice drawing you got there :) - I always preferred drawing with just a pencil rather than colour and would often have my art work at school ruined by the teacher writing "Use more colour!" over it.

Those who can't do teach...

Qube

QuoteThose who can't do teach...
Yeah, I spent hours on those drawings and the teacher happily wrote that over the top ruining it. Another teacher ( IT and Design ) loved my drawings but I think the art teacher was just so fixated with having to use colour she couldn't appreciate a pencil drawing.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.