This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-10-28 08:40:38

Dangerstevey
Scratcher
Registered: 2009-10-28
Posts: 5

Gun Jamming

I am working on a top down shooter game, and I have most of the game working, except the gun. Sometimes the gun fires perfectly, and sometimes it doesn't fire at all. my code is below, please help me get it working.

[blocks]
<when green flag clicked>
<go to x sad  0 )y sad  0
<hide>
<set{ pistol ammo }to( 10
<forever>
<if><mouse down?>
<if> <( <{ Pistol ammo }> <>> 0 )>
<broadcast[ Mouse click
<end>
<end>
<end>


<when I receive[ Mouse click
<if> Costume # of Player = 2
<show>
<go to[ player
<point towards( mouse pointer
<repeat( 80
<move( 10 )steps>
<end>
<end>
[/blocks]

Last edited by Dangerstevey (2009-10-28 08:40:57)

Offline

 

#2 2009-10-28 09:00:59

deathlordIX
Scratcher
Registered: 2009-10-22
Posts: 1

Re: Gun Jamming

Repeat moving 10 steps until touching edge. Then go to Player. Tell me iif it works.

Offline

 

#3 2009-10-28 09:10:41

Dangerstevey
Scratcher
Registered: 2009-10-28
Posts: 5

Re: Gun Jamming

It still doesn't work

Offline

 

#4 2009-10-28 20:57:55

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Gun Jamming

Here are my assumptions based on what you have posted so far...
1) all the script you posted goes into the "bullet" sprite's script.
2) there is more script you haven't posted
    (because... I don't see any code to change the players costume?)

Anyway, I made 2 sprites. Sprite 1 was my player/gun and sprite 2 was the bullet. I put all your script into sprite 2. When run and the mouse was clicked, nothing happened because of the "if player costume = 2" line. I changed the "2" to a "1" and it fired the bullet every time.

You should upload what you have done so far so we can provide better help!  smile
Peace.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#5 2009-10-29 08:05:55

Dangerstevey
Scratcher
Registered: 2009-10-28
Posts: 5

Re: Gun Jamming

Yes you were right in assuming that it is all in the bullet sprite, but the changing of the player's costume is in the player sprite, and the reason i have it is because i have multiple weapons and need to change costume to access them. What you asked me to change does not affect the bullet's firing at all.

Offline

 

#6 2009-10-29 16:37:09

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Gun Jamming

Ok, I downloaded your project and it seems to work great, ie.. I can't get it to repeat your intermittent problem of the gun not firing.

But then again, you have completely changed the code from what you posted above, you don't even have any variables in use at the moment. So I guess all I can say is congrats, you fixed it!?! The new code seems to be working fine to me but I'll be glad to help if you have any more questions. Peace!

edit:
Whoops, spoke too soon. That super fast bullet looks great but I can see you've already found a common limitation in Scratch. You got around it cleverly with Sprite 3's "If distance to Sprite 2 < 80" but that creates another problem. If you fire just under (or potentially over) Sprite 2, it is destroyed even though you didn't hit it. If you can live with that, cool! Otherwise the first thing that comes to my mind is checking not only for distance<80 but also Sprite 3's y value compared to Sprite 2's y value. Then if Sprite 2 was flying too low or too high, no instant death explosion  smile  Cool workaround though!!

Last edited by Locomule (2009-10-29 16:44:36)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#7 2009-10-30 08:16:09

Dangerstevey
Scratcher
Registered: 2009-10-28
Posts: 5

Re: Gun Jamming

You downloaded my platformer trial. The game i am working on is a top down shooter, and i didn't upload it because It is nowhere near being done.

Offline

 

#8 2009-10-30 09:50:10

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Gun Jamming

Ahhh, ok sorry. Well in that case, it is gonna be harder to help. I'm not at home at the moment so I'm kind of limited as far as what I can do. But at home, I made a project using your script and once I changed the "if player costume = 2" line from a "2" to a "1", it fired every time. I suspect that the problem lies somewhere else but since you won't post the project until it is finished, who knows.

Just making sure that you know this though... you can post the incomplete project so people can help with it, then every time you re-post it (with the same name) it will overwrite the last version. Otherwise I can only say again that the script you posted above (with the "2" to a "1" change) is working like a charm. I can only help as much as you let me! Unless I'm just missing something and if so, I'm very sorry.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#9 2009-10-31 14:53:46

Dangerstevey
Scratcher
Registered: 2009-10-28
Posts: 5

Re: Gun Jamming

The costumes are the different weapons that the player can use, and costume number 2 is the one with the pistol. I tried changing the number of the costume and the number on the script and the problem remained. I did notice, however that the gun does seem to fire more often when the player is moving.

PS: I decided to upload what i have now so that the problem can be seen easier.

Last edited by Dangerstevey (2009-10-31 14:57:37)

Offline

 

#10 2009-10-31 21:36:24

Ssbrawl700
Scratcher
Registered: 2009-02-11
Posts: 100+

Re: Gun Jamming

Check this out it might help

http://scratch.mit.edu/projects/Ssbrawl700/699305


Can you beat the ever-so challenging Keyboard Khaos?

Offline

 

#11 2009-11-02 01:57:29

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Gun Jamming

Ok. The bullet issue that you initially described, "not firing", is a two part problem. 1) Once fired, no matter whether it hits something or not, it is gonna "Move 10 steps 80 times" every single time and cannot be fired again until it completes its flight. Hence some of the times that it seems to just not fire. 2) Sometimes it seems to fire but disappears. This has to do with the multiple simultaneous collision detections that are going on, along with problem 1) I just mentioned. What is happening is that when you mouse click, even though the bullet is still in that 80 times loop, it jumps back to the start position. In the meantime, it is also in the "If touching (wall/barrier) color" loop and so it appears to begin to fire but disappears because that color loop is telling it to hide. This was tricky to figure out!

Want to see it fire correctly? Remove that "If touching (wall/barrier) color block and will stop disappearing. Now this is not practical though because now the bullet flies through the walls and the barrier. I created several different fixes for this but before deciding on exactly what to do, you must first decide what else you plan to add to this game. More monsters? Scrolling backgrounds? Nothing? etc... because the best remedy for one of these situations is different than the others. Almost every game made in Scratch runs into this problem. If your background will not be scrolling, you could modify your current "If touching color" system and it will work fine. Add many more monster sprites and it becomes impractical. Although one partial solution to that is to decide the maximum number of monsters you want to possibly have on the screen at the same time (ie.. how many sprites) and then use multiple costumes so that each monster sprite can be used for many different monsters. Another solution is to replace the "If touching color" system by making the 4 walls and barrier into a single sprite. Then you can use an "If touching sprite" system for both the walls and the creatures. Another thing to add (and yes, there are multiple ways to do this too) is a way to tell if a bullet has reached the edge of the screen or hit something, and actually stop it's flight instead of just hiding the bullet. Then your player can fire again as soon as the bullet is done instead of having to wait for it to float invisibly around the edge of the screen while finishing that "Repeat 80 times: Move 10 Steps" loop.

So let me know what your future plans are and I'll make my best recommendation. I also wanted to say that this is very cool and I have been inspired by it and learned some new ways of doing things. For example, at first I didn't realize that the player could walk around. Once I tried it, it was freaking me out! In my short time here, I have used directional walking and point-at-mousing but never both at the same time. So what started out as weird quickly became very cool and easy to manage. Now I definitely want to use that movement style in some game!

And of course, I realize that you may not really intend to do much more to this game so all my rambling here may be overkill. Regardless, I recommend using this information and changing your script yourself, if this information has made any sense and helped you map out which direction you want to go with this cool game. I will continue to provide any support if you want it. Even if you just want me to upload a working script, I will, as long as you tell me what else you plan to add, if anything. Thanks a lot for being patient. That is one of the biggest requirements for doing any programing, imho. Now I'm off to work on a scrolling race car track for someone else. Keep up the good work!


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

Board footer