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.

AppGameKit Classic Chat / Restart Level

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 2nd Jan 2015 13:54
Hi.

I want when the Player dead, Can Restart level. how can do it?
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 2nd Jan 2015 14:27 Edited at: 2nd Jan 2015 14:28
I usually initialize the variables in a function, and loads the levels in another function.

When the player die/loose, I call a "GameOverFunction" to show some info that you lost, and press a key to try again. Then i "restart" by calling the function that define all variables, again, and then I call the function that loads the level.

You have to put most things in functions, then you need a gamestate variable that tells you if the game is running/paused/over.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Jan 2015 14:36 Edited at: 2nd Jan 2015 14:37
if player.dead
levelclear(level)
levelload(level)
playerstart(player)
endif

using udts for storing data are useful

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 2nd Jan 2015 16:44
can you give me an example?
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 2nd Jan 2015 16:45
If you want to keep the progress of the player then consider twice the second and third step of Markus...
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 2nd Jan 2015 17:33
Check out the project "Santa's Bad Elf" in the examples that comes with AGK. It's very good at explaining a full game loop with gamestates / pause / restart. It's made by Lee Bamber, and I consider it a piece of art

Study it over and over, until you understand it all, then try to implement something similar to your game. You might need to rewrite parts of your game to fit, but you really need to understand how it works, before doing so.

Study it, tweak it, learn it

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 2nd Jan 2015 17:38
I think this game is relate to AppGameKit v2. I have AppGameKit v1.
Yodaman Jer
User Banned
Posted: 2nd Jan 2015 18:11
Santa's Bad Elf was made with AppGameKit 1, so anything you learn in it should be applicable to version 2.


It's back, baby!
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 2nd Jan 2015 18:22
Until the I learn somethings in AppGameKit I don't want buy Version 2.it should possible in AppGameKit v1.
Yodaman Jer
User Banned
Posted: 2nd Jan 2015 18:36
Right, so when I said
Quote: "Santa's Bad Elf was made with AppGameKit 1"
, then that really would be a good place to start!

Although you really should consider buying AppGameKit 2 as soon as possible, because it's a lot more stable, has a lot more features, and is a lot easier in the long run.


It's back, baby!
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 2nd Jan 2015 18:42
Quote: "Until the I learn somethings in AppGameKit I don't want buy Version 2.it should possible in AppGameKit v1. "


Like Yodaman said, Santa's Bad Elf is a V1 sample app so you can look through the code to study how events are handled. It is under "Projects\Basic\Examples\Games\SantasBadElf"

Of course restarting levels and resetting variables in possible in V1 and every programming language--it's just up to the programmer to develop a feasible solution.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Jan 2015 19:35
u need a better strategy.
if u read this short part of code think what u need.

if player.dead < thats using a udt it using a dot
means
type tplayer
dead
endtype
local player as tplayer

type tlevel
imgBackground
endtype

level=levelclear(level)
function levelclear(level as tlevel)

deleteimage(level.imgBackground)
level.imgBackground=0

endfunction level

level=levelload(level)
function levelload(level as tlevel)
level.imgBackground=loadimage("bg.png")
endfunction level

player=playerstart(player)
function playerstart(p as tplayer)
p.dead=0
endfunction p

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 5th Jan 2015 05:39
please Give me an example.
MikeHart
AGK Bronze Backer
20
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 5th Jan 2015 07:45
Lol duxe, you are prizeless. You have the example already. Read above what people had written and then you know where to find it.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 5th Jan 2015 09:39
Quote: "Lol duxe, you are prizeless. You have the example already. Read above what people had written and then you know where to find it."


This is similar to the practice of writing. write 100 times from each line.

Quote: "you are prizeless"


what? also you.

really AppGameKit Funniest engine that I worked.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jan 2015 10:03
You need some structure in your code.
You need to think about what a level is
You need to separate levels into functions of some sort
You need a way to initialise them
You need a way to finalise them
All these need to controlled by a menu

Draw it on paper before doing any coding

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Jan 2015 11:18
there is also a good online tool named mind map.
(be sure the save work there.)
http://mindmapfree.com/

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 5th Jan 2015 13:43 Edited at: 5th Jan 2015 13:44
Quote: "Draw it on paper before doing any coding"


Quote: "there is also a good online tool named mind map.
(be sure the save work there.)
http://mindmapfree.com/"


for some thing, i'ts correct that before doing any coding draw it on paper.
But for Now what I should draw on Paper? I want restart level and don't know how can do it.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jan 2015 14:03
You need to understand UDTs. These help a little towards the idea of objects.

Levels are like cardboard boxes. They contain the assets and the code for this level. For each box you must:

1. Setup - create the initial images etc
2. Run - run this until it hits an end condition (win/lose/play cancelled)
3. Clean up - delete images and sounds
4. Show a menu asking if the user wants to repeat this level
If they do, go to 1, else go to the main menu

You will need to study UDTs and Select... Case

-- Jim - When is there going to be a release?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Jan 2015 15:10 Edited at: 5th Jan 2015 15:11
AGK is not an engine as such, it is a programming language (please nobody contradict until you see the point I'm making it will just confuse matters).

There are 2 ways to do this. Either way you need to create your level within a function such as "CreateLevel(levelNum)"

1-Keep track of everything you create (sprite, text, arrays etc) and create a function to clear the level that deletes everything including the contents of the arrays ie "ClearLevel"

2-Use commands such as DeleteAllSprites

Then re-build the level by running your CreateLevel function.

These are really the basics of programming. You have to learn to track the data for objects you create so that they can be destroyed. AppGameKit is no different (other than being much simpler) than any other programming language when it comes to garbage collection. You have to make sure that when you create something you have a method to clear up after yourself.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jan 2015 16:36
It's unfortunate that AppGameKit for Pascal's elegant TAGKScene concept is hard to realise in T1 because of the lack of object-orientation.

It's much harder in linear code.

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Jan 2015 23:13
here is a level file i used in a game.
its just for look how i handle the level.



AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 6th Jan 2015 21:08 Edited at: 6th Jan 2015 21:45
Thanks Markus for example.

I wrote a code according to your example. but I need help to load level again. Please Help me to solve this Problem. I think this part is hardest part for me that I'm newbie. for better Understand I ask other question later.

Thanks.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Jan 2015 12:50
if i remember at home i will show u the mail loop too where this
functions are used.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Jan 2015 13:09
i would rename StartLevel() as Game() or GameLoop()

try using levelstart & levelstop as names

thats the normal flow

function Game()

levelstart()

do
if getpointerpressed() then exit
sync()
loop

levelstop()

endfunction

u want

function Game()

levelstart()

do
if getpointerpressed()
levelstop()
levelstart()
endif
sync()
loop

levelstop()

endfunction

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 7th Jan 2015 14:34 Edited at: 7th Jan 2015 14:35
Markus Please if you have any idea show me in my code that can see what's happen.

in this code I want when Press Enter remove level and if press Enter again, load level.

Thanks A LOT
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 7th Jan 2015 15:50 Edited at: 7th Jan 2015 16:00
Here you go:



That is a complete game right there!
You will need to flesh out the functions with code specific to your game but that will get things working for you.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jan 2015 17:42
Whenever you write a Create...() function, create the Delete...() function at the same time.

simple example, I create a HUD...



Now, I immediately write the Delete...



Now I can create and delete my Hud 1,000 times with 2 function calls.
IMPORTANT!!! Write the 2 functions at the same time, you will never go wrong this way.

Quidquid latine dictum sit, altum sonatur
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 7th Jan 2015 19:56
Thanks.my code can delete image aND sprites.but I want load it again.how can do it?
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 7th Jan 2015 23:14
Structure. See what everybody said above.

Onwards and sometimes upwards
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2015 09:08
Quote: "Structure. See what everybody said above."


above said delete sprite like my code. I want load it after delete sprites.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 8th Jan 2015 09:23
Did you somehow fail to see my post?
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2015 10:02
Quote: "Did you somehow fail to see my post?"


yes I see.but did you my post that said: "Please if you have any idea show me in my code that can see what's happen."

Everyone has a method, for this reason I wrote above example code that can delete sprites and images. now I want load it again in my code that see what's happen.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2015 10:56
I fix my code that work very well. mean when Press Enter key remove All Sprite and if Press Again, Remake them. I want know this way is correct? Later, the problem does not occur?

CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 8th Jan 2015 11:01
Why not run some tests and find out?

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2015 12:03
Quote: "Why not run some tests and find out?"


because I don't know more about this way. and don't know In my Project good work or no.I wrote code about 900 line and I should edit my code and want sure this way work.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 8th Jan 2015 13:09
Make an array of levels. Have a variable called CurrentLevel

Your menu will be level 1

Progress through the levels. To repeat one, do the setup for that level again and run it.

Got it?

Onwards and sometimes upwards
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2015 13:57
At first I have a question:

when delete sprites AppGameKit give an error. for fix this error should use :



there is any way that don't use GetSpriteExists()? because I have more that 50 sprite and I should use this command for all Sprites.


about levels:

First time I use Programming Language for make a game. My game have 50 levels and I don't think good Idea that wrote all levels in one Page.I want know how can write each level in separated page and how can load each when need?

Thanks.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Jan 2015 15:15
Quote: "there is any way that don't use GetSpriteExists()? because I have more that 50 sprite and I should use this command for all Sprites."


1. You should know what sprites you have created. If you don't know what sprites you have created, you need to write your program differently. See the examples already posted for tracking sprites in variables.

2. I always use getSpriteExists() on anything I delete, even if I'm sure it exists. It takes milliseconds and makes my program safer.

Quote: "My game have 50 levels and I don't think good Idea that wrote all levels in one Page"


1. You shouldn't be "writing" all of your levels, it makes it very hard, and is not good for expanding the game later.

2. Every level conforms to a set of rules. For example, there must be a floor, an enemy with strength and speed and an exit. You create the rules. Once you have the rules, you create a setup for each level. For example:

Level=1
LevelName="Enter the Dragon"
EnemyName="Eragon"
EnemyStrength=100
EnemySpeed=20
EnemySprite="eragon.png"
Exit.x=350
Exit.y=200


To set up a level, you read it's setup file and apply the rules. The programming effort for 1 level or 1,000 levels is the same.

Quidquid latine dictum sit, altum sonatur
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2015 18:01
Ok, but my mean is use sub-programs for each level and load them in main Program with use "#include filename$". I think this way make read code easier and decrease Mistake. What do you think?
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 8th Jan 2015 18:05
Quote: "What do you think?"

I think you don't understand what BatVink has just explained.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2015 18:26
I understood what said BatVink.but I think there is a Problem.

for example if I have a Function Like LoadImages() that load all images (All Levels) in this function I should load all images in each level even if I don't need use some them and this make usage memory.even may occur this happen for sprites.now what should I do?
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 8th Jan 2015 18:32
You need to to read and take notice of the help people are giving you.
If you read the code I gave you,you will see that you shouldn't load all images for all levels.
Greenwich
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location:
Posted: 8th Jan 2015 19:06
Behdadsoft, I think you would get many positive lessons from reading the Teach Yourself AppGameKit book, look for the forum thread about it.

Maybe it will help for me to say to you, a Programming Language does not work in the way you are trying. To use a programming language, you must change how you think about design and building games. Otherwise you will have much difficulty and mistakes.

For comparison here is a real world example. To get a house, you could buy a building made by someone else and then decorate it. That's what building a game with an Engine is like. You start at writing the beginning of the game and go to the end.

A different way to get a house, is to start with an empty spot of land, and build a building from scratch, and then decorate the building. That's what building a game with a Programming Language is like. (It is a LOT more work. You have to do 90% of the work before you can start writing the beginning of your game!)

To use a programming language, you have to learn lots of things about how a computer reads instructions, and how to build Structure in a computer program. Right now, your game program has very little Structure in it. This is causing you your problems and difficulty.

To learn how to make the Structure, so that you can use a Programming Language, you have to set aside your game ideas for a while and learn from how other people make games. It takes many lessons and much work.

You may notice that other people are concerned or frustrated by your questions. You may notice the answers they give you are confusing to you. It is because they are trying to explain to you the Structure you need, but the lesson is too complicated. You will want to start learning from a book like Teach Yourself AppGameKit so you can learn the elementary things before the complicated things.

Please let me know if there are any confusing sentences I said. I am writing in the style of Simple English to help with communication.

It's mean time. *averages*
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2015 20:57 Edited at: 8th Jan 2015 21:00
Thanks Greenwich for your help.

@Scraggle:

You need to to read and take notice of the help people are giving you.
If you read the code I gave you,you will see that you shouldn't load all images for all levels.

this is your code that you gave me:



I seen only Function name. I need see contain or show me how can load all level Images in one Function and load only used image in each level.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 8th Jan 2015 21:19
What I've given you there is a perfect (with one small error) template for a small game.
As I said in my original post; you now need to flesh out the functions with code specific to your game.
You can see from that where you need to place the code for loading sprites and you can see where you need to delete them. But you're going to have to do that yourself. I'm not going to write your game for you and I'm pretty sure nobody else wants to either.

<error fixed>
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 8th Jan 2015 23:07
I agree with Scraggle, though I might do it slightly differently.

Behdadsoft - You do not seem to understand the difference between data and code. In most simple games, like platform games, the only difference between levels is the platform data. the enemies, and the win and lose conditions.

The same code can be used for each level, once the level is loaded. The programming is in creating the code that can run any level. The design is in deciding what platforms and enemies go where. So, as a programmer, you can employ a level designer to create the levels.

Forget 50 levels. If you can't get two working you'll never have fifty.

You need to find a way of defining the assets for any level, create a function that will build the scene from that data and then run it.

Onwards and sometimes upwards
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 8th Jan 2015 23:34 Edited at: 8th Jan 2015 23:38
Just to add to that - think of a simple text adventure game.

Each room (location, level) consist of the following:

Static: description
\"You are on a sunny beach. The sea is calm. There\'s a beach-bar serving cocktails to the north.\"

Dynamic: anything there?
There is a beautiful WOMAN here. She is wearing a BIKINI and reading a BOOK.

Interactions: verbs and objects
(For example):
GET BIKINI
READ BOOK
KISS WOMAN
N

You do not write separate code for each of these rooms. Your code needs to handle the \"room\" by doing:

(1) Display description
(2) Display objects
(3) Handle interaction

The only complicated part here is defining the results of what the user types on the keyboard. But that too can be in the data.

Each object needs some response defined in your data for that room. For example:

Verb: KISS : object WOMAN
Response: \"The woman falls in love with you\"

Verb: READ : object WOMAN
Response: \"No man has ever understood a woman.\"

Verb: SWIM
Response: \"You try to swim in the sand. The woman walks away.\"

Verb: N : try to go to the North Node

Forget sprites - forget physics - make a simple text adventure work and you will understand what you need to know to get a framework working.

Onwards and sometimes upwards
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 9th Jan 2015 02:53 Edited at: 9th Jan 2015 03:05
i agree.... start with a text based game... even russian rollete would be a good start. completely text based and if you dont know what that is let me explain what you need to do.


[main loop]
ask the user to pick a number from 1-6
store that value in a variable
now use the random command to pick a number
if the number is not what the user picked then hes safe
if the number is exactly the same tell the user he died
now depending on the output of this game you can ask them to play again or quit
[loop if nessesary]

now i want to see if you can put this in code for me. If you can i will be suprized!

i will give you a hint on isolating it as a function:



try to put that into code for me and we will see where your coding skills are at. and i gave you allot of hints.

if you can write this game you will be able to tell me a few things about it.

how is this game able to loop and able to teminate?
do you know how to get input from the keyboard?
have you ever used the random number generator?
can you display text on the screen?
do you know about functions and what they are capable of?
do you know how to store variables or even what one is?
do you know what while,endwhile does and how it loops?
do you know how conditional statements work or what they even are?

www.sheldonscreations.com
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 9th Jan 2015 11:50
Behdadsoft seems to want a complete game, to look at. That's hard to find, since no one will give away their source code.

I suggest, NOT making a 50 level game, when you have not made any game before... Go back to learning programming, and then in a year or so, continue this game.

You can not expect us to hold your hand until this game is finished, you are really starting to annoy people on a level of wanting to crush their monitors now...

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.

Login to post a reply

Server time is: 2024-05-06 11:29:10
Your offset time is: 2024-05-06 11:29:10