Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Snake game like code AGK

Author
Message
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 27th Jun 2015 02:20
Hey All

Brand new to the world of AppGameKit about, ohhhhhhhhhhhhhh, 5 hours ago thanks to the Steam Sale - I downloaded the demo, it reminded me of AMOS, I know I'm not alone as I've seen the little emoticon thingy now I'm on the forum - And, well, here I am. After briefly being distracted by "Her Story"...

Anyways...

Just sitting down with it to have a little play, I'm not new to the world of coding but for the past 9 years or so I've been living in a world of VBA (Visual Basic for Applications) and doing mostly bespoke business like internal stuff (AKA the boring stuff).

Years ago, using AMOS, I wrote a little Snake like game where you had to navigate a maze (think those little maze games in puzzle books where you have to reach treasure) - So, to get me used to things I thought I'd have a go at that.

I've hit a little snag and can't figure out the basics

What I want to do, is draw a line that keeps on going - A snake, but I can't work out which Command to use, I've looked for a "Plot", "Ink", "Pixel" or a "Draw" or, something...

The closest I got was DrawLine;



Can anyone point me in the right direction for the right Command?

This is very much a n00b question but I've been in the 'Help' for about an hour now and I've either over thought this or I'm missing something so stunningly simple I'm going to be kicking myself for a week

Thanks in advance for any help
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Jun 2015 10:01
Hi JazzSPX, and welcome to the forums. As you're new you won't have realised this but posts don't show up for a while (when a moderator has checked it) until you have passed initial moderation (to weed out the spambots).

You've come to the right place TGC's financial director Rick Vanner headed up STOS and AMOS long before joining the TGC team

There are lots of ways to do this sort of game and a snake game is even in the example projects that come in the AppGameKit install "App Game Kit 2\Projects\Games\SnakeSnacker". A good place to start is in the help files (press F1 in the IDE).

Personally I would look at this example as the best way to use AppGameKit is using sprites. Once you get used to using them it opens up a lot more possibilities.

Using AppGameKit V2 Tier 1
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 29th Jun 2015 20:14
Hey baxslash, thanks for the welcome!

I've been lurking through the forum looking for more help off people who wanted to do something similar, I've seen a lot of references to AMOS - Good to see :')

I did know what there was going to be a delay after I'd posted, but wasn't sure how much.

I've since been on an adventure through the examples and have indeed seen that game and have also realised there is no command like I was originally asking for - Ha!

I was hoping to avoid using sprites as I can't particular use Painting programmes very well beyond the basics, I once made my own Graphics for another game I did back on the C64 using SEUCK (I would have been a teenager) and while I was kind of proud of some of those I don't think I've really come on any from there LOL

I've actually been messing round with a few other ideas since I posted this and have made some basic, basic, basic sprites to work with - Perhaps I'll get a game running and then worry about the graphics later

Again, thanks for the welcome - Hoping I'll become a fixture around these parts
SpecTre
Developer
16
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 30th Jun 2015 11:41
Quote: "Perhaps I'll get a game running and then worry about the graphics later"


Thats not a bad way of doing things and a method a lot of people use. Just use some simple gfx with the right size you want and they can be changed to look good later.

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 30th Jun 2015 11:56
Quote: "Just use some simple gfx with the right size you want and they can be changed to look good later."


Ha. They don't get much simpler than a solid white box with "Mole" written on it

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 30th Jun 2015 18:00
I'm not sure exactly what the command is that you were looking for but did you try DrawBox?

Using AppGameKit V2 Tier 1
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 30th Jun 2015 21:18
Quote: "I'm not sure exactly what the command is that you were looking for but did you try DrawBox?"


Yeah, I did - Tried all the draw commands, just couldn't find one that would let me plot one pixel and draw with it :/

I got round it last night, made myself a little sprite and then cloned it when it was moving so it "drew" behind it. At least then I could use GetSpriteHit to see if it hit itself as well, but I'm a little worried that I'll end up with so many Sprites I'll eventually end up with it slowing down so not exactly happy with that method.

But, trial and error and all that

BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Jul 2015 00:49
If you are trying to achieve the original snake look and feel, the I would suggest starting with an array of sprites - let's say 10 pixels square for the sake of an example. Make the array more than big enough - 100 elements, each representing a sprite.

Start the snake off with 3 body sections (3 sprites). On each move take the last (tail) sprite and move it to the front, based on the direction the user presses. When you eat an apple, add one of the array of sprites to the tail. And Repeat...

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 1st Jul 2015 03:04
Quote: "If you are trying to achieve the original snake look and feel"


Hey BatVink

Thanks for the reply, and the advice but unfortunately, no; That's not what I'm trying to achieve.

What I want to do is get an ever growing 'Snake' to navigate a maze to an end point, thinking about it - More like a 'Tron Bike' game than 'Snake', the idea of the game being that the 'Snake' continually moves and grows, you've to avoid your trail, and obstacles, to get to the exit point.

Hope that makes sense now?

In my original AMOS game I had it plotting a pixel and drawing a path, I'd also detect the colour in front of the current X,Y to see if it was something that made my 'Snake' crash or, well, whatever - I based bonuses, deaths and other such things on certain colour values.

When I first came across AppGameKit it was the first thing I thought about doing with it as it seemed so similar.

The original game, I did, "Lionel", was the last game I wrote on AMOS. I never got the chance to release it (I used to publish Public Domain through 17-Bit Software) for one reason or another, but I honestly used to enjoy playing it myself. It was a simple game with a simple concept, but it just kind of worked in it's own way.

I learnt a lot from doing it. Looking back I've probably got rose coloured glasses on - It had an intro screen with "LIONEL" coming down from above, one letter at a time with a kind of glow surrounding it when complete, my friend at the time was good with Pro Tracker so he made me a music file to use. The game would start with an arrow bouncing down to show the start position of Lionel and then you where off on your adventure.

Even though I was the practically the only person to ever see it, I used to try and game my own game and get high scores late at night... The sign of a good game, or a good 'tester' - I never worked that out

The reason I never released it? - Well, it was a memory hog LOL - I went over the top or got sloppy with the code and it only worked on memory expanded A1200's :/

"Things" happened and the next thing I knew a year or so had passed and I as sitting in front of a PC, no AMOS and no sign of a PCOS - My game was lost to history.

AHEM - Sorry, went on a bit there - Guess this is kind of more important to me than I thought

Hmmmmmmmmmmmmmmmmmmmmmm
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Jul 2015 13:06
You could replicate this using a memblock which you turn into an image. I'm not sure how slow that would be but we could be talking about a pretty small image scaled up here?

That being the case all you'd have to do is create a 2D array that you can set values in for the game engine to check and change values in and have a function that edits the image before the end of your game loop. Then you just need to assign the image to a single sprite that fills the screen.

I guess I could write something like that pretty quick but you might need to study the memblock commands to get an idea what is involved.

I have some functions for changing individual pixels in an image that I could dig out and share with you if you decide to go that route and get stuck.

Maybe you should revive Lionel using AppGameKit too?

Using AppGameKit V2 Tier 1
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 1st Jul 2015 18:34
I like this use of these phrases...

Quote: "all you'd have to do"

Quote: "Then you just need to"

Quote: "I could write something like that pretty quick"


Just make it sound simple why don't you?! LOL

I've been doing some more tinkering around and researching and I'm not so sure that the amount of Sprites will be a problem, they're only 1 x 1 and not animated - I might be able to get away with it.

(I'm all up for advice if you think that's the wrong way to go about it)

I can't seem to think of a way I can define the 'Map' that needs to be followed.

I've mocked a screen up (time to show off my afore mentioned mad graphics skills )



The idea is that the black background is off the maze, and therefore death, and you've to get to the yellow block to win.

Is there a way I can check to see if the X,Y of my sprite is on a black pixel or a yellow one?
SpecTre
Developer
16
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 1st Jul 2015 21:06
Here is how to read the 4 byte integer value of a memblock once loaded in to obtain the value of the pixel for RGBA:



This will set the memBlock 4 byte value to set the colour of the pixel but only if the colour value of the pixel is one you want to change.



Idea how to use them.




Not on AGK2 to check this and writing from memory on my tablet (my memBlock lol ) so hopefully this is correct

Hope this makes sense and can help.

Here are a couple of my threads which might help as Paint Pot uses memblocks and I had trouble initially trying to get stuff working at first as I too were looking for some commands as in Amos

http://forum.thegamecreators.com/?m=forum_view&t=213305&b=48

http://forum.thegamecreators.com/?m=forum_view&t=213459&b=41


Quote: "Maybe you should revive Lionel using AppGameKit too?"


I think you should too, really good getting some of your old code working on AppGameKit to learn it

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
SpecTre
Developer
16
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 1st Jul 2015 21:17 Edited at: 1st Jul 2015 21:18
Nice attempt JazzSPX, didn't see that before as I typed the above stuff

If you can do it with sprites though I think you might be better off because the Get Image from MemBlock is a slow command to use in a loop to display the image to the screen. Unless you are using a small image and scaling up I guess.

I initially started using ways of programming like I used to in Amos re double buffering screens and using memBlocks for pixel effects etc, however I am going to change to using sprites more for my new stuff once I have finished my current program as they work much much faster and you can have loads on screen at once as long as they are not all massive

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
SpecTre
Developer
16
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 1st Jul 2015 21:21
Quote: "Is there a way I can check to see if the X,Y of my sprite is on a black pixel or a yellow one?"


You could set up an array for your map, e.g.:

0 = Black
Y = Yellow
X = Course

[0.X.X.0.0.0]
[0.0.X.0.X.Y]
[0.0.X.0.X.0]
[0,0,X,X,X,0]
[0,0,0,0,0,0]

Then all you have to do is check your array and if you are on a 0 then lose life and if you hit Y then you win

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 2nd Jul 2015 19:49
Quote: "Here are a couple of my threads which might help as Paint Pot uses memblocks and I had trouble initially trying to get stuff working at first as I too were looking for some commands as in Amos "


I'd actually heard of Paint Pot before I found AppGameKit! - No idea it was done in this though - Nice one!

Yeah, it's weird that it's so close to AMOS but some of the features / commands I used aren't here - Good though, get's your brain working on what you need to do to achieve what you want

Tell you what else I'm missing as well the AND / OR operators - Hard to believe that they've not been included

Quote: "If you can do it with sprites though I think you might be better off because the Get Image from MemBlock is a slow command to use in a loop to display the image to the screen. Unless you are using a small image and scaling up I guess."


Yeah, I was doing more reading on Sprites and then some on Memblocks and pretty much came to the same conclusion, nice to have a little verification though

Quote: "You could set up an array for your map"


Pretty much along the lines of what I've been thinking about today, even working out if I could make an editor to help me with it - Getting cocky about these things already

Quote: "Then all you have to do"


... And there it is again LOL - Arrays though, I can only make sense of those at 2am after high doses of coffee :/ - They're like my nemesis in any programming language! Quite often at work (VBA) I come across things and think "An array would be perfect here so, how else can I do it?" :/
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 2nd Jul 2015 19:51
Quote: "Nice attempt JazzSPX, didn't see that before as I typed the above stuff"


Oh! - And, probably wasn't there - I'm still a n00b and getting my posts vetted.

Hopefully won't be too long before I can SPAM you with links to making $30,000 dollars a month though
SpecTre
Developer
16
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 3rd Jul 2015 23:16
Quote: "Yeah, it's weird that it's so close to AMOS but some of the features / commands I used aren't here - Good though, get's your brain working on what you need to do to achieve what you want"


Similar but strange sometimes as it takes a bit to get used to the different way of doing things which I am still struggling with now
Can't seem to get my head around the full screen method and %age system yet but I might give that a go on the next project after Doodle Draw as I have a music app in mind.

Quote: "I'd actually heard of Paint Pot before I found AppGameKit! - No idea it was done in this though - Nice one!"


Haha cool
Like you it was an old program I released with Amos back in the 90's so thought it would help me learn AppGameKit but I also had DBPro before too which helped.

Quote: "even working out if I could make an editor to help me with it"


Seems to be one of the first things people start off with. If you have a look through the forums you will see lots of people who have done level editors Might help.

Then all you have to do............ lol, will have to stop saying that.
I know when people put it in my posts it leaves me thinking for a couple of days, this all I have to do is hard lol

Quote: "Hopefully won't be too long before I can SPAM you with links to making $30,000 dollars a month though"


Don't forget us when you are on that much


Good luck with your program and look forward to seeing it develop

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jul 2015 16:01 Edited at: 5th Jul 2015 16:05
Quote: "Tell you what else I'm missing as well the AND / OR operators - Hard to believe that they've not been included"


They are there.



Regarding your problem of detecting if you are on the path. I would create the path from square sprites and perform Sprite collision to see if you are on track. You can put sprites in collision groups i.e path sprites in one group and non-path sprites in another.

By the way, first game I ever wrote at 12 years old in 1982 - Tron Lightcycles on a Dragon 32! I used the same logic as you described earlier - checking point colours.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 6th Jul 2015 19:58
Quote: "Good luck with your program and look forward to seeing it develop"


Weird, thought I'd replied to this once - But, thanks! - No doubt you'll be seeing a lot of me!

Quote: "They are there."


So they are :/ - Must have been something else that wasn't working as I thought when I originally tried to use them... Must remember to double check that in the future, thanks, I'd have been in a nested IF hell!

Quote: "Regarding your problem of detecting if you are on the path. I would create the path from square sprites and perform Sprite collision to see if you are on track. You can put sprites in collision groups i.e path sprites in one group and non-path sprites in another."


That's not a bad shout at all. I've been thinking about how to do this most of the weekend while tinkering away with other bits and pieces.

Quote: "By the way, first game I ever wrote at 12 years old in 1982 - Tron Lightcycles on a Dragon 32! I used the same logic as you described earlier - checking point colours."


Great minds think alike and all that! - Oooooooooooooh for the lack of being able to use a simple command to get a colour value eh?

I spent yesterday evening trying to use GetImage from the "background" sprite and then use GetSpriteColorAlpha but I seemed to be getting nowhere with it, think what was my last ditch attempt at using colour on this one
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jul 2015 11:10
Getting point data is notoriously slow. Behind the scenes the screen data has to be locked to prevent changes and then unlocked which slows things down. This problem is usually solved by copying screen pixel data to a memblock which can be referenced much quicker.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 8th Jul 2015 01:34
Quote: "Getting point data is notoriously slow. Behind the scenes the screen data has to be locked to prevent changes and then unlocked which slows things down. This problem is usually solved by copying screen pixel data to a memblock which can be referenced much quicker."


Interesting, thanks for that - I'll have to do some more reading on graphics, it's not something I've worked with a lot in the past 10+ years of programming, I don't know if you saw earlier but I've been mainly working with VBA - So, while I can make Microsoft Office sing and dance to my tune, calling sprites and detecting collisions don't often get needed

Anyways, I've been having a play with what I need to do to get my maze, I've uhhmed and ahhhed and I've come up with this method.

Please excuse the rough code, this is a test I'm working with to generate the maze, I'll worry about code placement when I integrate it

So, my game area is going to be 1024 x 768, split into blocks of 32. To draw the map I was thinking about using a text string with different letters to represent where a block should go. Keeping the same theme as above, I've two different coloured brown tiles, a black tile for the death zone and a yellow goal.

In a FOR loop I read the string one letter at a time, create a new sprite based on that letter and position it accordingly, here is the code;



The idea being that I could make an editor to draw the maze (BG$) and save it as a text file, calling the new maze for a new level.

My main concern with this method is the number of sprites I'm going to have to create, there are 768 generated on this alone - My method of drawing Lionel is by drawing him a pixel at a time, again using sprites.

These sprites are soon going to add up :/

Can anyone with experience advise if that's going to become an issue, or advice on how this can be done better and or differently?

Thanks in advance for any help!

I promise I'll go away with these questions once I'm on the right path LOL
SpecTre
Developer
16
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Jul 2015 03:31
Hmmm, thinking about this, you could create your maps as an image file in PGN format using just a few colours. This wouldn't be a big file at 1024 x 768.

You could have an image for each level. Created using a map editor or even Windows Paint.

You could then create one large sprite as the screen sprite displaying this image and also load this image into a memBlock to check the pixel data for the colour using my examples above for memBlocks.
This checking of the the pixel colour in the memBlock would be fast and would allow you to check for being off the map, etc.

The next part then would be how to display the snake.

Get image from memBlock is not very fast if plotting pixels to the memBlock.
You could however create some Render images from the background and plot the snake to that using double buffering and scaling the image up to then put/replace the screen sprite.

I confess I am not an expert with Render images and they have their own problems especially at the moment when using them on Android but they work well on other formats like PC, MAC and iOS.

I have had some help with Render images from the developer Paul regarding my Doodle Draw app I am currently doing if you want to check the threads out here to help with that part:

http://forum.thegamecreators.com/?m=forum_view&t=214589&b=48

http://forum.thegamecreators.com/?m=forum_view&t=214648&b=41

Probably not the best way of doing as Sprites is maybe the way to go but just a thought.
Hopefully some others will come to the rescue.

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 8th Jul 2015 17:02
Quote: "Probably not the best way of doing as Sprites is maybe the way to go but just a thought.
Hopefully some others will come to the rescue. "


I got the impression from what was being said above that Sprites where the way to go on this - Which is why I went that way in the end

I could be wrong :/

I've been back burner thinking today, after re-reading what BatVink said, I don't think I actually need to draw the "black" sprite - I can use the lack of sprite collision as a detector... That'd save me quite a few on screen...

Though, the original goal was going to be to create graphics for the area outside of the maze...

I can do without though...
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Jul 2015 17:43
Quote: "These sprites are soon going to add up :/"


One thing that AppGameKit is very good at is handling lots of sprites. If you want to know just how good, download 1982 and be amazed

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 8th Jul 2015 20:52
Quote: "One thing that AppGameKit is very good at is handling lots of sprites. If you want to know just how good, download 1982 and be amazed "


Crikey. That looks kind of mental. I'll have some of that!
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 9th Jul 2015 01:03 Edited at: 9th Jul 2015 01:03
Quote: "One thing that AppGameKit is very good at is handling lots of sprites."


Yeaaaaaaaaaaaaah. Not *that* many though - Just did a test run with my Sprite Maze and there was noticeable slow down before Lionel got very far.

To be fair, I did take the Michael a little bit with them. It did hang in there, I had 768 32x32 px and 10,000+ 1x1 px at one point and it was still moving.

I guess I'm looking at these Memblock things after all

Ohhhhhhhhhhhhhh for the lack of a Plot(x, y) and a GetColour(x, y) [sigh]
SpecTre
Developer
16
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 9th Jul 2015 01:42
Quote: "I guess I'm looking at these Memblock things after all

Ohhhhhhhhhhhhhh for the lack of a Plot(x, y) and a GetColour(x, y) [sigh]"


Lol, well it won't do any harm giving it a go for your first project in order to recreate your game and then you can think more about sprites for all the new games etc


The code above effectively lets you do the Plot and GetColour using the memBlocks

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 9th Jul 2015 02:05
Quote: "Lol, well it won't do any harm giving it a go for your first project in order to recreate your game"


Nah, you're right - It's all a learning thing, and that's never a bad thing (as I keep telling my kids).

Quote: "you can think more about sprites for all the new games etc"


Already on it

Quote: "The code above effectively lets you do the Plot and GetColour using the memBlocks"


Handy! Though. Your use of the word "effectively" might come in to question soon
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Jul 2015 17:45
I wish I could find my signature app. It was a very efficient way to sign your name on a touch screen, and was essentially a dot-to-dot line drawing exercise.
If I find it, I'll post it.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
JazzSPX
4
Years of Service
User Offline
Joined: 26th Jun 2015
Location:
Posted: 10th Jul 2015 20:52
Quote: "I wish I could find my signature app. It was a very efficient way to sign your name on a touch screen, and was essentially a dot-to-dot line drawing exercise.
If I find it, I'll post it."


Oh, please - Be very interested in looking at that

Login to post a reply

Server time is: 2019-10-17 13:32:54
Your offset time is: 2019-10-17 13:32:54