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.

Author
Message
AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 5th May 2015 03:48
Well, I finished the AGK2 book and rather than re-read the entire book again I figured I would just dive in butt naked and see what I know versus what I don't. I suspect I will be having many sleepless nights trying to get my code working both correctly and efficiently. I'm doing a very basic beginner mode right now with 25 boxes, easy to win and just wanting to get the functionality going. I ran into my first conundrum today as I know there must be a better way to generate the following code:



As you can see, I had to make 5 separate blocks of code for each row. The AGK2 basic first 8 chapters or so really only goes into theory and how to do things on a basic level. My question, is there a better way to do this? I know in other languages I could write functions to do this so I don't have 500 lines of code in just creating one sprite only to have to do it again for mines and other images.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 5th May 2015 06:25
You could use a double for loop to place the sprites.

Example:

AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 5th May 2015 06:44 Edited at: 5th May 2015 06:45
I was thinking a function would do this well but the book doesn't cover that yet since it isn't finished. I'm trying to understand that logic there. I can understand most of it but the positioning is a bit weird. So it starts at 100,100 then becomes 100,115, then 100,130, and ....never mind I'm stupid I see now. Wouldn't I want to start y=7 to 35 step 7 or was that merely an example so I could see how it's done? By the way, thanks for the help, it's helping me learn this stuff.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 5th May 2015 07:01 Edited at: 5th May 2015 20:29
It is only an example. The way I wrote it is sort of confusing. Here's another way of writing the same function with a double for loop:

AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 5th May 2015 16:54
Thanks again. That last code snippet is much easier for me to read without going back, but then again it's good to get that experience anyways so I may try it both ways to just get my hands dirty to see which I prefer. Trying to be part of that minority that successfully builds a game
AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 6th May 2015 01:38 Edited at: 6th May 2015 01:54
Man that code was beating me down, but I finally figured it out. Everything makes sense now and here is the finished code without all the lines of garbage I didn't need.



Now that I don't have 80 lines of extra code I can work on setting depth and layer the sprites for bombs and numbers and such. I am trying to understand fully why we gave the global cells an integer value of 50? When I messed with it I would sometimes get out of bounds errors. The way I am reading this is cells as an array with one value of 50 which is then replaced by index. Why would this affect what is going on if it's just getting rewritten or am I missing something vital?


Edit:

Nevermind I'm stupid. I had to go back and re-read the arrays section. 50 indicates 51 values from 0-50. I set it to 25 since I'm only using 25 boxes. Good learning experience, hosing things up and then sitting around getting irritated figuring it out.
AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 6th May 2015 02:33 Edited at: 6th May 2015 03:03
My next issue is that I am trying to randomly pick numbers in specific increments so that I can place mines at each column and row. These mines will have a depth that is beneath the current sprite so when the user clicks on them they either show the bomb or don't.

I really wish the digital book was done, this is getting kind of frustrating to try to learn something that isn't complete for someone new to programming. Right now I am thinking an If statement might be the way to go or generate a random value and if it is "x number" place sprite?

Edit:

Got it to work:

IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 6th May 2015 04:55
Looks like you grasp it pretty well. Although, I have to ask, wouldn't it be simpler just to use Random(0,1) instead of Mod()?

Also, I was thinking about dynamic arrays and wrote this to illustrate resizing them in case you don't understand how.

AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 6th May 2015 05:50 Edited at: 6th May 2015 05:53
I'm stealing that code for reference and study Yeah, your right Random(0,1) would be easier, never thought of that. I kinda wanted to use Mod anyways since I rarely get to play with it in code. I will probably change it though just to clean it up a bit. I have to put the Sprite delete and get pointer click in at some point but I need to make graphics for numbers to indicate how close bomb is which at the moment seems like it will be difficult but I will figure it out. I try to post thoughts as I go on here as a kind of mental note of what I went through to get to the conclusion and result I have. I'm also thinking I want to limit the amount of mines and may increase the numbers and use Random after all.
AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 13th May 2015 06:31
Either I've run into a roadblock or am not thinking this through but since the variables within the functions are not usable outside I am having the issue of changing the depth of the mines after the function has been called. My other issue is, I'm trying to use GetPointerClick() = 1 with the x and y coordinates but nothing is happening when I click. My assumption is this falls in line with my first problem of not being able to adjust the sprite depth due to the variables being locked int the function. Am I understanding this correctly and what are some alternatives? Sorry if I keep asking questions but this stuff is just getting harder and harder for me to grasp and is why I have been taking some days off out of frustration.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 13th May 2015 06:36
Show me some code and explain how you want this function to behave.
AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 14th May 2015 04:34 Edited at: 14th May 2015 04:45


So basically, with your help from earlier I generated a second function to place mines under the existing sprites. I'm having a hard time figuring out how to manipulate those sprites since they are locked into that function, at least with my minimal knowledge they are. Before when I had 100 lines of code I could manipulate them but that made the code huge and unmanageable. Right now I got the mines on top just so I could see them generate.

How can I interact with those functions outside? I was going to place the manipulations inside the functions but that doesn't seem to work. I'm going to have to think about it a bit more because this has me at a halt.

Edit after some thoughts:
The way I am looking at this, the functions runs and bam it's done. Anything I do after that will be ignored. So this brings me full circle back to how do I modify the sprite after it's been drawn up? The specific part of the code is:


I am getting rid of the x# to that if statement and moving it back outside the function where it belongs until I can figure this out.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 14th May 2015 04:50
What kind of manipulations? If you are wanting to setup a way to interact with them, pressing a button, you will have to use the do loop.
AAChaoshand
8
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 14th May 2015 05:00 Edited at: 14th May 2015 05:17
Hmm, so generate the cells and mines with a loop and then from there I can do as I need? Basically, it's minesweeper, I want it to pop when I click either either a mine or an empty cell.


Edit: Modified code:



So now the next problem is me figuring out why it only lets me execute one mine reveal and not multiple. I also need to tell it to only reveal where I clicked and not some random mine.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 17th May 2015 01:55 Edited at: 17th May 2015 07:38
After re-reading the last few posts I realized that I wasn't helping much. As I have never made a minesweeping type game I didn't really know how to go about it. So I started my own little project.

If you want, I'll post the code or I could make a tutorial or something.

I don't have a finished, polished game really but I think I have a working prototype, so to speak.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 20th May 2015 20:43
Here is my project so far. You can download and do what you want with it. Don't get too excited though, it's really basic.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-29 10:33:48
Your offset time is: 2024-03-29 10:33:48