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 DBPro Corner / how do I do "wait" without halting the program?

Author
Message
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 15th Oct 2011 23:21 Edited at: 15th Oct 2011 23:22
I need to do a wait before changing attacking to false. (Ya know, so you cant move while attacking) But it just freezes the whole program. (Mainly cause its in playerinput() function, which is in the main loop.) Is there anyway to stop this. (Without using any outside subroutines/functions.(Ill do it if thats the only way but im trying to keep it clean)) Heres the code if it helps, (SEE: playerinput(), if Rshift)



"Insert funny coding-related joke here"
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Oct 2011 23:27 Edited at: 15th Oct 2011 23:28
Prevent the user from moving whilst an attack is progress. I'd store the length of the attack in a variable like this

MoveAllowed= Timer() + 1000

And place movement commands in a conditional branch like this:



Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 16th Oct 2011 00:13
Well I did it, and its not working, its not freezing anymore, but the player can move directly after hitting. Look through it please.
the only thing it did is make it so the player cant hit while moving, which I didnt want.



"Insert funny coding-related joke here"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th Oct 2011 00:57 Edited at: 16th Oct 2011 01:11
I think you're are going down a bad path trying to learn to program this way. You are having problems and questions for nearly every line of code you add. I have tried to both help and pursuade you to utilize the great resources here (tutorials, code snippets, forum searches etc...), to gain a solid foundation on both general coding concepts as well as dbpro specific principles.

If your first post would have stated, "I have a game idea, can someone code it for me." it would have been flame-bait and eventually locked. But that is essentially what you are doing when looking at your posts and other thread. It's a bit outrageous to me.

- You've chosen to learn by coding a game far beyond your knowledge level.
That's fine

- You have questions
That's fine

But to pose questions for nearly ever step along the way, mainly because of your personal decision to not put in the time and work required to give yourself the the experience and knowledge needed... is not fine IMHO.

Two quotes come to mind...

"Give a man a fish and he eats for a day. Teach a man to fish and he eats for a lifetime."

"You can lead a horse to water, but you can't make it drink."

So, for me. I'd rather teach you how to fish. Please reconsider my suggestion of studying some tutorials and code snippets to see how things work. TDK's Tutorials are great for building that foundation. There's the water...

In general response....
Your question showed you were trying to build what is termed a (Finite State Machine), it's a good thing to learn, and it would have, with a bit of work, given you the result you desire. The answer you got was essentially timer based handler, which is another good concept, but would require a bit more to implement to get your required results. Eventually you will use both concepts, but I would have stayed with your "state machine" for now.

Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 16th Oct 2011 01:08
Not really, Im doing the code myself, im mainly asking for help because of bugs, at first maybe, but my main problem is the bugs.
Like I coded the attacking system, but it was freezing the whole program so I asked for help.

Its not above my level. Ive learned the syntax, im only trying to learn a system of doing it, no tutorial will have that.

"Insert funny coding-related joke here"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th Oct 2011 01:16
Quote: "Not really, Im doing the code myself, im mainly asking for help because of bugs, at first maybe, but my main problem is the bugs.
Like I coded the attacking system, but it was freezing the whole program so I asked for help.

Its not above my level. Ive learned the syntax, im only trying to learn a system of doing it, no tutorial will have that."


Plenty of tutorials will have the answer to your question which is essentially a finite state machine to control actions. You missed my edit at the end of my post. I still stick with my opinion of your approach. It's not bugs. It's the fact that you don't have the experience, and/or haven't studied enough code to see "what needs to be done" and "how those whats are implemented".

Feel free to have a different opinion.

Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 16th Oct 2011 01:40
ok. I just feel you earn better by doing, ive already learned so much in the past 3-4 days. A week ago I didnt know how to position a sprite. Lol. But ok, ill go read up in the code base/20 line code forums. And maybe some tutorials, and obviously some practice.

"Insert funny coding-related joke here"
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 16th Oct 2011 09:24
I would like to make a suggestion, if I may. That is that you make something small first. Try doing a remake of Galaxion or something first. By doing, you'll learn (as you yourself said). But dont make the mistake of thinking that simply learning syntax will help anymore than saving you from pressing F1 a few times. As a self-taught programmer I can say that you need to UNDERSTAND programming before you can call yourself a programmer. Don't just 'hit the books', comprehend them too. When someone shows you how to do something don't be happy with 'oh that's how it's done' but actually dissect it and try to work out why its done like that. For this reason you should stay away from the 20 line challenge for now as you will struggle to grasp code that's been truncated to that level. Once you've gotten a better understanding of coding, then go study the 20 liners (some of them are REALLY impressive!). I suppose this whole paragraph could be summarised as 'crawl before you can walk, walk before you can run, run before you can fly!'

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 16th Oct 2011 17:55
I don't think I should be attempting anything at this point, I just mess it up, I actually was doing something like that, attempting to use sprite sheets, but the playerinput was messing up, and the background always went over the images despite pasting the spaceship after the background. So I stopped cause it was annoying me. I guess what I should do is dont make a background, and just color it black and do a dot command, use get image on it, sprite it, and paste it everywhere (about 2000) then when the player reaches about x=>700
(Im going to make it 800x600, its a sizeable resolution) then instead of the player moves, the screen scrolls (by that I mean the enemies and stars scroll to make it look like its scrolling)
But as always I guarentee ill run into a bug Ive never encountered in about 10 or less minutes of coding. *sigh*

"Insert funny coding-related joke here"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Oct 2011 00:50 Edited at: 17th Oct 2011 02:44
Quote: "But as always I guarentee ill run into a bug Ive never encountered in about 10 or less minutes of coding. *sigh*"


This comes with the territory of learning to program. We have all been throught it, and we all continue to go through it all along our progression. No one just gets it right from day one, year one, decade one. There is always a lot of trial by error.

But, it's not just blind luck. Eventually you build some sort of foundation and experience to logically work through problems. In the beginning it feels more like guess-work and more things seem to not work the way we expect, than things working correctly. As you work around each hurdle, your experience will grow.

I wish it were as simple as learning syntax and commands. But it's not. Putting together commands in a working, logical, efficient structure to accomplish tasks takes a lot of work, patience, experience, knowledge etc. There are so many concepts and disciplines that one must become reasonably proficient in, in order to have a vision become reality. There is a lot of complexity in even what may appear to be a simple game. One must be able to break down that complexity into smaller manageable tasks.

As one becomes proficient in the smaller building blocks, combining that experience to build more complex building blocks opens the door to being able to work one's way through problems he/she may not have encountered before, or perhaps, even thought of. It's the small building blocks that everything else rests on. Without that core foundation, programming feels like a chaotic game of chance.

It just like any other discipline that requires skill. Playing an instrument, such as guitar is a "somewhat good" analogy. If one studies musical theory, and understands how musical notes were derived, then how scales are built on those notes, how keys are related to those notes/scales, then how chords are built up from notes within those scales, then how modes are built by altering the starting and ending note of a particular scale and understanding the patterns of the steps between notes in those scales, how chord progressions are derived etc...etc...etc...

From a good foundation, musicians can adapt to numerous circumstances. Composing songs, evoking moods/tones, developing harmonies, and deciding on chord progressions isn't completely random. That musician can compose/play songs written/learned in one key, and transpose them to another key very naturally. A lead guitartist can know what scales, and modes work in what keys and over what notes/chord progressions. Unfortunately in this analogy, all of that studying, knowledge, experience can't guarantee that one will be a great player . And sometimes in music, as well as game creation, natural talent and creativity plays a large role in the equation... but that's a whole other discussion.

Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 17th Oct 2011 06:26
Completely correct. Lol. Well I don't know if this is harder, or much easier, but I figured a turn based, tile based game would be much easier, so thats what im doing.
It just seems more in my level. Plus tile based has a easier system to manage. ESPECIALLY in collision.

"Insert funny coding-related joke here"
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 17th Oct 2011 11:21
in answer to why above code does not work, once the timer is greater than MoveAllowed then there no reset of MoveAllowed.

Dark Physics makes any hot drink go cold.
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 17th Oct 2011 12:30
Quote: "I don't think I should be attempting anything at this point, I just mess it up, I actually was doing something like that, attempting to use sprite sheets, but the playerinput was messing up, and the background always went over the images despite pasting the spaceship after the background..."


Have you been through the DBPro help and looked through ALL the sprite commands? When I hit a problem it's the first place I look. Even the programming Gods still hit F1 or go back to the books now and then. This should solve your problem:



That's why you need to schlep through the tutorials. Type "Set Sprite Priority" in your editor and press F1. It will explain about drawing priority which you can think of as "layers".

BTW, if you want to program long term, prepare to battle through it because programming has no boundaries other than hardware and imagination. It's something you'll be learning the rest of your life. Arthur Rubinstein, one of the world's greatest pianists once said in his old age that if he could live longer, he would "love to learn the piano". Basically he was saying that there is always so much left to learn and improve, in despite of how much you know.

If you don't like this prognosis, there are plenty of really great software packages out there that involve minimal coding. TGC even has some so check out their products. If you don't like those, go to sourceforg or softpedia for a large array (pardon the pun) of FREE game-making software.

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Oct 2011 16:32
@ Darkzombies

Just a few things I'd like to say (I haven't read everything in this thread):

1) I have nothing to complain about your code structure. You have a decent understanding of how to use functions and subroutines, and you indent your code correctly. The only thing missing is comments... In the future, try to comment your code whenever you can.

2) Start with something simpler. You're attempting games that are too difficult.

TheComet

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 17th Oct 2011 18:27
Is tile-based, turn-based, top down dungeon crawler type thing to hard? Whats the easiest 2d game I can do?

"Insert funny coding-related joke here"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Oct 2011 19:00 Edited at: 17th Oct 2011 19:07
Quote: "Is tile-based, turn-based, top down dungeon crawler type thing to hard? Whats the easiest 2d game I can do?"


tile-based,turn-based,top down dungeon crawlers ar quite difficult. There is a lot of things to handle and concepts to understand. Generally multidimensional arrays for the world map, smooth-scrolling, multiple movements going on (sometimes the character is moving, sometimes the world is moving below the character, sometimes both are moving), setting up enemy ai, battle sequences, items, weapons, all the other logic states that must be processed.

Any full game has it's particular problems to overcome. But possibly some manageable ones...
Tic-Tac-Toe:
Don't be fooled. While appearing very simple with pen and paper. there is a lot that goes into coding a tic-tac-toe game. Usually including a 2dimensional array, a small decision tree. If the game was played to fill the entire grid (rather than stopping on a win condition) there would be 362,880 different games possible.

Pong like games: Have you deal with projectiles and trajectories.

A snake or lazer cycle type game: It has it's own hurdles, especially lazer cycle, which would generally include a computer oponent, so some basic AI needs to be implemented. If one prefers they could stick with a multiplayer version (not networked) but two users sharing one keyboard

Then there are more complex games that involve a larger decision tree and thus more "logical states", like space invaders (now you also deal with projectiles, collision handling, timers.

Pac-Man: A simple AI but now you introduce multiple behavior types, and other states like evade.


I would start with tic-tac-toe. You may think it's silly, but once you get into it, it has a lot to offer as far as learning goes, and it's not as easy as one may think. Then I would do something like a snake game or lazer cycle. Then perhaps a space invaders or pac-man. These games build on top of eachother and gradually grow in complexity. It's sort of hard determine which is more difficult between tic-tac-toe and pong.

If you can get through the above, then perhaps you would have a lot of what you need tackling a tile-map scrolling dungeon crawler.

Your signature has been erased by a mod please reduce it to 600 x 120.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Oct 2011 21:19 Edited at: 18th Oct 2011 00:39
I very quickly slapped together a tic_tac_toe game. I didn't feel like thinking much about the check win condition, so the method I used here is very ugly and could easily be reworked. In fact the entire program could be done a lot better, but not bad for an hours work.

The code contains no comments, but it should be easy figure out what is going on. (I may comment the code, and clean it up... If I have time later.)

After a win press any key to restart

version 1.3 (fixed some logical errors adding comments)


The media (a simple "X" "O" .png file is attached)

Your signature has been erased by a mod please reduce it to 600 x 120.

Attachments

Login to view attachments
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 18th Oct 2011 05:36 Edited at: 18th Oct 2011 06:13
Ok, seems simple enough.

CHALLENGE ACCEPTED!

EDIT: Ok so, get image really confuses me, I did this (Look in begin: ) and it says illegal image number, can someone just make it clear to me what it means by "left, top, right, bottom" I think thats the only problem. (Im getting illegal area number, so I probally put it in wrong)



And the image is ATTACHED.

"Insert funny coding-related joke here"

Attachments

Login to view attachments
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Oct 2011 07:46
It's not an illegal image it's an illegal area. The problem is with the last 70 on the second image. The image is 70x35 so if you go beyond 35 on the y coordinate it'll be outside of the bitmap. Using 1's for both image numbers won't work (the second time you use image number 1 the first image is overwritten with the new image number 1). And always use a texture flag of 1 at the end of all get images so that it grabs it without blurring it.

It's like this:

GET IMAGE ImageNumber, x1, y1, x2, y2, TextureFlag

ImageNumber = Image number used to store the image
x1 = Upper left corner x coordinate
y1 = Upper left corner y coordinate
x2 = Lower right corner x coordinate
y2 = Lower right corner y coordinate
TextureFlag = How the image is grabbed 0=blurred slightly 1=not blurred



Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 18th Oct 2011 07:58
Ok I see, I just switched up the last two by accident. Thanks!

"Insert funny coding-related joke here"
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Oct 2011 08:04 Edited at: 18th Oct 2011 08:05
Here's what Grog said graphically:



TheComet

Attachments

Login to view attachments
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 19th Oct 2011 05:59
Ok so, I am working on my tic tac toe game, and again, and I got an error I have NO idea what it means.

in the init() function I am getting "Cannot find structure in 'init :x' in local declaration at line 44. Never seen this before, im guessing from "local declaration" it didnt return the boxes array right. But I still have no idea.



"Insert funny coding-related joke here"
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 19th Oct 2011 11:48
Structural error. Program still runs on my machine after error msg.

Dim boxes(10) at the beginning of your code. You init() function is pointless.



Refer to my code snippet re X's and O's on this thread:
http://forum.thegamecreators.com/?m=forum_view&t=190469&b=7

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 19th Oct 2011 11:54
Code correction (Sorry I was doing two things at once):


My brain doen't do multi-tasking well XD

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 19th Oct 2011 12:08 Edited at: 19th Oct 2011 12:25
You don't have to have 'global dim boxes(10)' at the beginning of your code. Regardless that's not your problem here.

(And it wouldn't run on my version with default editor here)

Here is your issue.

You have a Global X at the top of your code. Then inside your function you try to use x (lowercase) as a variable for your for loop. They wind up being treated as the same variable becuase DBpro isn't case sensative...,, and the function doesn't declare it own local variable x becuase it's already a global as the following snippet will show.



I'm not 100% sure why the compiler errors when you go to change that variable (as in your for loop),, though in this case in turned out to be a good thing... since it probably wasn't your intention to effect the value of global X inside the init function. Somone else may be able remark on that. Look what could have happened:



So you have a couple of choices.
- Don't use the same variable name regardless of case.
- force a declaration of a new local variable x that differs from the global variabl X:


You are going to have an issue with currentsprite not being set to anything, in case you weren't aware you never initialize it

Your signature has been erased by a mod please reduce it to 600 x 120.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Oct 2011 12:23 Edited at: 19th Oct 2011 12:27
Edit: Woah, NonZero and Zenassem beat me by a long shot... guess I should learn to refresh the thread before posting.

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 19th Oct 2011 12:32 Edited at: 19th Oct 2011 12:34
@Grog
Why is it converting the x to a 1 causing for 1=1 to 10? It's not a #constant? Unless I am mising something I disagree.

I think you are on to something though (see my post above yours if you haven't). Because the error only shows up when using x in the for-loop,, but I can show many instances where a variable has a value and then it is reset by the for-loop. In fact, any time you use the same variable as an index, it has a value when you have another for loop using that same variable.

And i pulled my example snippet from above


So it's not as though it's a constant and being converted at compile time.

Your signature has been erased by a mod please reduce it to 600 x 120.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Oct 2011 12:38
Sorry I edited it out of my last message but yeah it's treating it like a constant for some unknown reason.

Try this init() function:


Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 19th Oct 2011 18:50 Edited at: 19th Oct 2011 19:16
Oh, ok, I hate it when I forget stuff like that. But anyways, whats wrong with this line?



(P.S. I declared mx=mousex() : my=mousey() : mc=mouseclick()
blah blah earlier. I also fixed the boxes(x) thingy)

Also, on the starfighter project thingy im doing, I need help, its not pasting random stars everywhere. (I made an image, because dot and get image werent working too well, its attached)



t is s gnat re h as ben destro ed by A m d

Attachments

Login to view attachments
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 20th Oct 2011 16:02
@zenassem:

Quote: "...You have a Global X at the top of your code..."


Nice Catch!
Can't believe I didn't even notice that.

Quote: "(And it wouldn't run on my version with default editor here)"


Really? I knew something strange was up on my end. It's not the first time I've been able to run despite error messages. (Insert eerie music)

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 20th Oct 2011 18:10 Edited at: 20th Oct 2011 18:31
Fixed the other post. NOTE TO SELF: Dont use the same number for every coordinate on get image lol

EDIT: Ok, I looked everywhere, how can you do a loading box? This is for my starfighter game, it just loads the stars. (I know I can do it instantly, it looks cooler this way )



EDIT TWO: Never mind, im an idiot, I put both y coords the same.

EDIT THREE: Ok, so yeah... it doesnt change, but at least it shows.



t is s gnat re h as ben destro ed by A m d
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 21st Oct 2011 03:57
Ok, just one more question, so im getting illegal image number, so ive tried setting it to crazy number that I could not possibly have ever set and that didnt work either so im not sure lol.

Maybe someone with more careful eyes will notice something i didnt (P.S. Its at line 60)



t is s gnat re h as ben destro ed by A m d
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 21st Oct 2011 10:28
It's prolly coz you didn't declare "ship" as a Global Variable. Then You used it in a function. In this case DBP treats it as local meaning that its default value is 0. Also it's MAKE OBJECT PLAIN, not "Make Object Plane" at line 32.



Add that to the top of your code instead of "ship = 5000" and hopefully it works.

PS: Please post the exact error message next time as knowing what line the error was at helps in speeding up diagnosis.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 22nd Oct 2011 03:06 Edited at: 22nd Oct 2011 19:06
I think I should stop posting these lol, they usually just turn out to make me seem like an idiot, how could I forget the global lol.

EDIT: Ok, finally ran into a real bug (Not an error, a bug)
The space area is done, it has static stars, and moving ones. But the player isnt showing up for some reason now.



Also, the spaceship is attached if you need to test it.

EDIT TWO: Also, do this if you want it to run right



EDIT THREE: Still havent really figured it out, but Im trying to do some AI, I just wanted to post it here to ask if Im going in the right track, or getting into some bad habits. This is what I have.



EDIT FOUR: Ok, now I have a question.
How would I make a multi-dimensional array within a type, and use it to detect which tile a person is on, and if an enemy is a couple tiles (Or on the tile, for a battle to start) from the player?



t is s gnat re h as ben destro ed by A m d

Attachments

Login to view attachments
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 23rd Oct 2011 00:47
No ones going to answer? *Sobs*

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 23rd Oct 2011 01:26
For the player not showing up, try using the command DRAW SPRITES LAST early in the code.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 23rd Oct 2011 01:39 Edited at: 23rd Oct 2011 01:44
Duh! I forgot about sprite priority, thanks!

EDIT: Still not working

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Oct 2011 02:33
It's because you overwrite image 1 (ship) with the image for the stars on line 34. You may want to use something like IMG to show the variable is an image number, SPR to show the variable stands for a sprite number, and OBJ to show the variable stands for object number.

PlayerIMG = Image number for players ship
PlayerSPR = Sprite number for players ship
StarIMG = Image number for star field
StarOBJ = Object number for star field

What I generally do is have a long list at the top of the code to tell me at a glance what image numbers are used so I don't forget and/or use an image number that's already used.



And don't be afraid to add debugging code that you can leave in there while you create the game. If you make it a switch you can easily turn it off at will when you want to see the game without the debugging area.



The reason why your sprite doesn't move is because you use the variables player.x and player.y but you don't actually change their values so they always stay zero. Try using INC and DEC on those variables instead.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 23rd Oct 2011 03:44 Edited at: 23rd Oct 2011 04:19
Well ok, but I did this for moving

if leftkey()=1
if player.x =< 100
oldx = sprite x(player.id)
oldy = sprite y(player.id)
sprite player.id, oldx, oldy, ship
endif
else
sprite player.id, player.x - 2, player.y, ship
player.x = sprite x(player.id)
endif


So why shouldnt that work?

EDIT: Nevermind, Fixed! (Though the image is pasted to the top right of the screen as well for some reason, but I can figure that out myself, Its probally something stupid that ill regret posting)

Also, is there any good AI tutorials out there?

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Oct 2011 19:05
Just to let you know. It's really better to place the player sprite in only one SPRITE command. That way it's efficient and if there's a problem you know exactly where to look. The same is true of enemies.



Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 23rd Oct 2011 19:26 Edited at: 24th Oct 2011 02:02
I guess I always need to learn better ways of doing stuff, thanks, though Im trying to learn everything I need to know, then perfect my strategies.

EDIT: Ok, that doesnt work, but this does.



(Note: I did this one for the space game, thus note the up and down as well, Ill work on the other one.)

EDIT: I was experimenting with a fade in system, and it works well, but it can only handle one sprite at a time :/

So I do this:



And heres the function.



So can anyone tell me how to have it affect multiple sprites at a time, and keep the rest of the program running whilst doing it. (I could probally just include everything from the main loop in there, but I dont want to take the chance, unless it will actually work)

EDIT TWO: Ive been working ALOT on this. Is there a better way to do image numbers? (Im getting illegal image number, its probally from my lack of organization)



Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 23rd Oct 2011 19:27 Edited at: 23rd Oct 2011 19:30
OOPS DOUBLE POST!

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 24th Oct 2011 04:27
OOPS TRIPLE POST, IM SORRY, PLEASE DELETE, LOOK AT FIRST ONE!

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Oct 2011 18:34 Edited at: 24th Oct 2011 18:36
Quote: "Ok, that doesnt work, but this does."


It does but since you define player.x and player.y already there's no need to repeat the "player.x = sprite x(player.id)" every time the player moves. You only need the SPRITE X() and SPRITE Y() commands when you don't already know where the player is.

Quote: "I was experimenting with a fade in system, and it works well, but it can only handle one sprite at a time :/"


It only does one at a time because you make it fade till it's done fading all the way with a REPEAT/UNTIL loop. The only way it'll work for multiple sprites is if you change that fade function to only change the alpha level one step per function call. The function call probably should be within a FOR/NEXT loop going through all the sprites. It'll probably require an array to store the current fade levels (and if the sprite is going to fade). Unfortunately I have to go soon so I can't post an example of what I mean right now.


Quote: "Im getting illegal image number"


Just glancing at your code it looks like it's because your grabbing images with an array. It would work if the array had numbers in it but when you dimensionalize an array everything in it starts at zeros. Image number zero and sprite number zero cannot be used.

This is what an array looks like (also there's no need to add GLOBAL since arrays are GLOBAL by default):


If you need help with arrays check out TDK's Tutorials:
http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 25th Oct 2011 03:14 Edited at: 25th Oct 2011 03:26
Hmm, okay, (Guess the array thing was common sense, im an idiot forgetting to set them) But is there any other way to get the fade working, like is it possible to keep the main loop going while the repeat-until is going?

EDIT: Ok, ive organized it a bit better, and fixed it, now its displaying nothing...



Though don't hold me to it, its probally something stupid lol.

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 25th Oct 2011 07:38
You needed a SYNC placed just before the end of your DO - LOOP. You also needed the mousex(), mousey(), etc. to be in the DO-LOOP. I edited it a little bit so that the first sprite flashes when you mouse over it:


Also, I never put in DISABLE ESCAPEKEY until I am almost done with a game. I had to get out of it the hard way.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 25th Oct 2011 08:30 Edited at: 26th Oct 2011 08:30
I HATE forgetting stuff so little. Then not even noticing it to a point where I have to ask for help.

EDIT: Hmm, the buttons dont show up, I had them displayed over the image, but they still dont show, I think it may be something with the get image, ill attach the image, maybe you can look it over.



EDIT TWO: Still not working, but ive worked on the code, bullets and enemies still arent working, despite it being much better, If someone can look it over and tell me what im doing wrong that would help me alot.



EDIT THREE: Ok, I also have a problem with my space game, it either doesnt place an enemy every 20 seconds, or just doesnt move them.



Still need help with my other problem as well.

Attachments

Login to view attachments
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 26th Oct 2011 06:47 Edited at: 26th Oct 2011 06:47
Oops double post!!

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 26th Oct 2011 17:20
There was a lot wrong with your code and I have listed the comments that I have regarding it. I fixed your main menu so it at least works. You need to write the corresponding subroutines.


You should work on one game at a time until you have a better understanding of how to code. If I am going to help you, I want to be able to press ESC and get out of your game. Going to a pause routine is something you do later on anyway.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 26th Oct 2011 18:27 Edited at: 26th Oct 2011 19:02
I colored the backdrop because I dont like the blue screen (I know I couldve just turned it off) Load and save functions im going to create when I have enemies and shooting working. The MM's stand for main menu, and since my images and sprites have different numbers, I used MMS to signify that, (Though it is true I couldve used a type with spr and img) I grabbed the text as an image because only sprites work with my fadeIn function, which when the player died, just text appearing on the screen is boring, I wanted it to fade in. I didnt mean to do global arrays. I offsetted the images because they were appearing on the top left (or bottom right, I dont remember) of the screen lol.

And I think thats all you asked me, right?

I know I do some things in some bad ways, everyone probally has at some point, But most of the things you asked were for a point, the goto's though. I know not to use them. I was being an idiot. This is just for learning, but thanks for the advice.

EDIT: I tried deleting the images for the menu before entering the game, but it didnt work



Login to post a reply

Server time is: 2024-11-22 12:39:44
Your offset time is: 2024-11-22 12:39:44