scratch sprite not registering hit consistently - sprite

This simple shooter game is supposed to result in the sprite shattering and disappearing when hit. It will work maybe 40% of the time. Here's the link to the project and the relevant code block:
https://scratch.mit.edu/projects/524150880/editor

So turns out that by simplifyingthe sprite's movements from:
to:
fixed the problem. Sprite consistently breaks up and disappears when hit. So it was just a matter of streamlining I guess?

If you are going to make a shooter game, you probably want to use create clone of [myself] block and then do this:
when i start as a clone
show
repeat until < <touching [YOUR TARGET SPRITE HERE]> or <touching [edge]> >
|| point in direction (DIRECTION OF YOUR SHOOTER)
|| move (ADD YOUR NUMBER HERE)
start sound (meow)
change [score] by (1)
repeat (5)
|| change [mosaic] effect by (2)
delete this clone
For the bullet, you would need this script:
when green flag clicked
forever
if <key [ANY KEY YOU WOULD LIKE TO USE TO SHOOT] pressed> then
|| create clone of myself
However if you would like to add a cooldown to the bullets, make a new variable called cooldown and reduce it by 0.1 every millisecond (0.1 second), but do make sure that when cooldown is 0 it doesn't go into the negatives, and when cooldown is 0, you can shoot and it resets the cooldown to the number of seconds you want it to be, if you want it your code should look like this:
when green flag clicked
forever
if <key [ANY KEY YOU WOULD LIKE TO USE TO SHOOT] pressed> then
|| if cooldown < 0.1
|| || create clone of myself
The reason it is || if cooldown < 0.1 and not || if cooldown = 0 is because if you screw up and accidentally make it 4.25 instead of 4.2 the bullet would still shoot

Related

How can i make python return a window that will be soon used to put stuff on? python 3

Currently trying to make a alarm clock, but not sure how to return a seperate window that will soon have numbers on it for the time. Thanks. This is what i currently got right now.
#square interface
#adjustable hour/minute/seconds
#choose stopwatch(stops at a certain time)
#choose timer(counts down from timer)
#a start button
Have not tried anything because i don't know what to type

How can I make a variable dynamically change while on console python3

I am working on a program and it needs to display the number of seconds that passed since it started. The variable is inside input() like this:
while True:
something = input(str(x) + "seconds have passed. Please input the number in 60 seconds:")
if x == 60:
break
Is there any way to make the x change dynamically while on screen? So it raises every second and also updates on screen without the need to press enter.
If yes, is there also a way to add an if statement that checks when the variable reached 60 and break the loop.

I am trying to make an image stay put longer after an if statement occurs

I am trying to edit my game so that when an if statement occurs an image appears, but the if statement only happens when the object hits the wall and the ball bounces off, so the image only appears for the amount of time the if statement is active. I tried to make a delay command but after the if statement occurs it freezes the entire game for the given time.
Does anyone know how to isolate a delay command or make the image stay visible for an extra second after the if statement expires/after the ball hits the wall and bounces off???
Here are the lines of code that has to do with this:
image_set = pygame.display.set_mode()
image = pygame.image.load("image.png")
def image():
image_set.blit(image,(600,90))
if object.left == (COLLISION_RANGE) or object.right == (WINDOWWIDTH COLLISION_RANGE):
DisplayOoface()
Oof.play()
Put the code to "hide" the image into a separate function, Use the Threading package to create a new thread and pass that function in to be executed.
Within the function you can add a delay to the start of the code. When you start the additional thread within the if statement, you will have the delay you need, and then the function can hide the image.
If you do not thread this task, then python simply processes one line of code at a time. By passing off the task of waiting and hiding the image to a secondary thread, your main thread (the game) can continue functioning as needed.
https://docs.python.org/3/library/threading.html

MEL Script Button deletes object if it exists

My MEL knowledge isn't great and I have created a small script that duplicates your object and brings it next to your main one. I want to make it like when you click the MEL button the object appears but when you click it again the object gets deleted (if exists). Any help would be great as I'm almost at the point where I'm gonna start hitting my head on the wall.
Thanks
Here's a bit of code that will delete an object if its found:
if (objExists("YOUR_OBJECT_NAME_HERE"))
{
delete("YOUR_OBJECT_NAME_HERE");
}
Let's create our test object. It's a nurbsSphere1:
sphere -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360 -r 1 -d 3;
if...else statement in MEL is quite simple. Use the following code to select and delete a nurbsSphere1 if it exists in your scene:
if(`objExists nurbsSphere1`) {
select nurbsSphere1;
delete nurbsSphere1;
} else {
warning("No NURBS Sphere exists");
}
To execute just several lines of MEL code (not all) in Script Editor, select all the lines you need and press ctrl+enter on a keyboard for execution.

too much error correction made the code more worse

This is my first time with python and I have written this program to simulate a node trying to find mobile phones in an area.
first i am taking the distance converting them to RSS and based on that deciding the direction of the node to find all mobile phones.
the code worked fine till 2 days ago but when i expanded to area and no of nodes, some errors started to come and i kept correcting them.
now it doesn't run and I have made it more worse:
is there any hint or guidance I can get from the experts?
and yes I have overwritten the code without saving it to some other place.
Or maybe someone can really help me by having a look at it.
its really messy though.
thanks
Here is a part of the code i am having the most trouble with.
def pos_y(uav_current_cord,area,uav_step_size,flag):
detected_y = 0
detected_nodes_pos_y = 0
if flag == 1:
span = area+uav_step_size - uav_current_cord[1]
#print(span)
for y in range(uav_current_cord[1],area+uav_step_size,uav_step_size):
global distance_covered
distance_covered += uav_step_size
UAV_new = [uav_current_cord[0],y]
y_last_pos = UAV_new
plot((*UAV_new), marker='o', color='r', ls='')
distance_new=[]
for i in nodes:
temp_x_axis = euclid_dist(UAV_new,node_cord[i])
ss_x_axis = dist_to_ss(temp_x_axis)
if (ss_x_axis > threshold):
detected_nodes_pos_y += 1
detected_y = (detected_nodes_pos_y)
if y >= area+uav_step_size:
uav_current_cord = UAV_new
flag = 1
keep_moving = neg_x(uav_current_cord,span,uav_step_size,flag,y_last_pos)
uav_current_new = keep_moving[0]
distance_covered_back = keep_moving[1]
nodes_detected_final = keep_moving[2]
uav_current_new = keep_moving[3]
#return [uav_current_new, distance_covered, nodes_detected_final, uav_current_new]
#uav_current_new = y_last_pos
return [y_last_pos, distance_covered, detected_y, y_last_pos]
if flag == 1:
area1 = area*2
for y in range(uav_current_cord[1],area,uav_step_size):
UAV_new = [uav_current_cord[0],y]
#print('Pos_Y movement of UAV',UAV_new)
#print('ye loop chal raha hai')
y_last_pos = UAV_new
plot((*UAV_new), marker='o', color='g', ls='')
distance_new=[]
for i in nodes:
temp_x_axis = euclid_dist(UAV_new,node_cord[i])
ss_x_axis = dist_to_ss(temp_x_axis)
if (ss_x_axis > threshold):
detected_nodes_pos_y += 1
detected_y = (detected_nodes_pos_y)
#print('nodes detected in pos Y ',detected_y)
#print('last position in pos y =', y_last_pos)
for y in range(UAV_new[1],uav_current_cord[1],-uav_step_size):
# print('ab ye chala hai')
UAV_new=[uav_current_cord[0],y]
plot((*UAV_new), marker='o', color='g', ls='')
distance_covered_back = area*2
return [UAV_new, distance_covered_back, detected_y, y_last_pos]
As others have said, use git, but know the alternatives.
If you're brand new to revision control, starting with Git will either be a big help or hindrance in the time being, but learning Git will be valuable down the line regardless.
If you have an MSDN account, you can also use Visual Studio's built-in revision control. It's good for rapid prototyping, but has no real edge over git.
Another common choice that is pretty simple would be TortoiseSVN. It's very easy to use.
Alternatively, if you don't mind your code being public for a free account or a small monthly fee for private, you can do all your commits via browser using GitHub. This is hand's down the simplest option for revision control newbies. It's major downside is limited flexibility for multi-file commits.
I have little to no meaningful experience with BitBucket and some other common alternatives to GitHub.
I'm sorry, but we cannot help you... You're not the first with this problem and unfortunately not the last.
To help prevent this kind of problems, software like Git exists. It let's you do the following (image reference):
The root file is the master. This is your working script. If you want to change/add/remove something, you make a so-called branch where you do whatever you want. If you have tested it, you can commit the changes (that is, store this as a new version of the script with a comment) and merge it with the master (that is, add the changes to the master script). If something seems to be wrong, you can always go back to a previous version of your script.
The documentation of Git is very good: read it and use it wisely!

Resources