Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » Python programming language
- MountainMan00
- Scratcher
28 posts
Python programming language
Very Simple Dodge Game
import pygame as pg
import random
import pygame.midi as MID
MID.init()
pg.font.init()
try:
myfont = pg.font.SysFont("comic sans", 20)
except:
myfont = pg.font.SysFont(pg.font.get_default_font(), 20)
highscore = 0
Win_height,Win_len = 600,800
Win = pg.display.set_mode((800,600))
pg.display.set_caption("Very Simple Dodge Game - Python Version")
WHITE = (255,255,255)
YELLOW = (255,255,0)
GREEN = (0,255,0)
BLACK = (0,0,0)
LIGHTRED = (255,100,100)
FPS = 60
PLAYER_HIT = pg.USEREVENT + 1
HARDER = pg.USEREVENT + 2
TIME_PASSED = pg.USEREVENT + 3
icon = pg.Surface((10,10))
pg.draw.circle(icon,GREEN,(5,5),5)
icon.set_colorkey((0,0,0))
pg.display.set_icon(icon)
clock = pg.time.Clock()
midi = MID.Output(1) #37,28 7,75
bad_width = 20
def stop_all_sounds():
for x in range(127):
midi.note_off(x)
def handle_bad(badstuff,player,speed):
for x in badstuff:
x.y += speed
if x.colliderect(player) and x.width != 1:
pg.event.post(pg.event.Event(PLAYER_HIT))
x.width = 1
if x.y > Win_height+20:
badstuff.remove(x)
def spwan_badstuff(badstuff,prob):
#MM00
if random.randint(0,prob) == 1:
midi.set_instrument(118)
midi.write([[[0x90,60,70],200]])
badstuff.append(pg.Rect(random.randint(0, Win_len), 0, bad_width , bad_width))
def set_pos(rect):
rect.x, rect.y = pg.mouse.get_pos()[0] - 5 , pg.mouse.get_pos()[1] - 5
def make_text(score,highscore):
if score > highscore:
highscore = score
mystr = "Score : {} Highscore : {}"
return str.format(mystr.format(score,highscore))
def draw_win(rect,badstuff,text,hardmode):
texter = myfont.render(text,1,(LIGHTRED if hardmode else WHITE))
Win.fill(BLACK)
Win.blit(myfont.render("MountainMan00",True,(30,30,30)),(640,10))
pg.draw.circle(Win,GREEN,(rect.x+5,rect.y+5),5)
for x in badstuff:
pg.draw.circle(Win, YELLOW, (x.x+bad_width/2, x.y+bad_width/2), bad_width/2)
Win.blit(texter,(10,10))
pg.display.update()
def main():
global highscore
brokeH = False
difficulty = 100
running = True
score = 0
player_rect = pg.Rect(200,200,10,10)
max_speed = 15
bad_speed = 5
bad_stuff = []
pg.time.set_timer(HARDER,2000,8)
pg.time.set_timer(TIME_PASSED, 100)
hardmode = False
while running:
clock.tick(FPS)
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
if event.type == PLAYER_HIT:
highscore = score if score > highscore else highscore
midi.set_instrument(55)
midi.write([[[0x90,64,100],200]]) #Losing
stop_all_sounds()
main()
if event.type == HARDER:
difficulty -= 10
midi.set_instrument(55)
midi.write([[[0x90, 20, 100], 2000]])
bad_speed +=1
if difficulty < 50:
bad_speed = max_speed
if event.type == TIME_PASSED:
score += 0.1
score = round(score,3)
# Hardmode ON
if bad_speed == max_speed and not hardmode:
hardmode = True
midi.set_instrument(126)
midi.write([[[0x90, 10, 100], 2000]])
if score > highscore and not brokeH and highscore != 0: # Highscore broken
midi.set_instrument(10)
out = []
midi.write([[[0x90,60,100],200]])
brokeH = True
spwan_badstuff(bad_stuff, round(difficulty/12))
draw_win(player_rect, bad_stuff, make_text(score, highscore),hardmode)
handle_bad(bad_stuff, player_rect, bad_speed)
set_pos(player_rect)
pg.quit()
if __name__ == '__main__':
main()
#MM00
Last edited by MountainMan00 (April 5, 2024 14:25:51)
- MountainMan00
- Scratcher
28 posts
Python programming language
There is a Python library called Panda3d; you can make 3d games with it!
It's also available for C++.
However, the community is relatively small and it has a bit of a steep learning curve.
It's also available for C++.
However, the community is relatively small and it has a bit of a steep learning curve.
- mrcoat
- Scratcher
100+ posts
Python programming language
(decode with base64)
Why'd you encode it?
My cartoon
Watch My Show!
I was gonna put an image of the studio but it didn't work.
Cool thing I made
when [Awesomeness v] > (100)
forever
play sound [Victory v] until done
set rotation style [The best style v]
go to [The party v]
end
- zaid1442011
- Scratcher
500+ posts
Python programming language
(#999)Use w3schools for learning. It only teaches you the language and nothing else. I learned Python from there.
I'm just starting to learn Python. Any tips?
I am a guy who codes weird stuff. Don’t check my GitHub only if you want stupid HTML pages (or something to host them). Check my platformer if you want to see something to see.
Profiles: GitHub.
You won't understand stuff in my signature because I talk about stuff in the ATs (Advanced Topics).
Check out this song for @griffpatch https://scratch.mit.edu/projects/887382049/
- mumu245
- Scratcher
1000+ posts
Python programming language
(#1000)I suggest you try to make some simple text-only projects for your first months to learn the language, then take your time and start making an app you love, for example I was working on the same app for 4 months, because I love both the app I will make and the coding activity.make stuff on your own, even if its dead simple like a calculator or a todo list or a calendar or a game or anything simple, DO NOT fall into tutorial hell and only make stuff you see in tutorials, use them for only learning the syntax and its features and how you structure your code. first thing to do after learning the basics is make your own scripts/projects that you can benefit from or show off to friends/family I'm just starting to learn Python. Any tips?
- mumu245
- Scratcher
1000+ posts
Python programming language
(#1002)Ursina is a full-blown game engine based on it (still text-only, but really good).
There is a Python library called Panda3d; you can make 3d games with it!
It's also available for C++.
However, the community is relatively small and it has a bit of a steep learning curve.
- BlauHourglass
- Scratcher
1000+ posts
Python programming language
Ah, Python… My greatest friend and enemy! Currently working on making my art gallery in Python, and I'm struggling xD ChatGPT isn't making sense and I need to redo EVERYTHING and flush things out. Anyone experienced with key inputs and image displaying?
。 ゚。⋆☾ Did I ask? ☽ ⋆。 ゚☁︎。 ⋆。 ゚☾ But sleep's a part of the job, y'know. ☽ ⋆。 ゚☁︎。 ⋆。 ゚☾ If everyone were smart, no one would be. ☽ ⋆。 ゚。
——
Retired founder of Soundwave Productions ← click me, fufu~
Co-owner of The Glow Shop ← click me, fufu~
Co-owner of Ville de L'Art ← click me, fufu~
♕ Classical SSC May '24 ♕
⸙ Epistolary SWC March '24 ⸙
Co-owner of The Glow Shop ← click me, fufu~
Co-owner of Ville de L'Art ← click me, fufu~
——
ı|ı|ı Script SWC July '24 ı|ı|ı♕ Classical SSC May '24 ♕
⸙ Epistolary SWC March '24 ⸙
- mumu245
- Scratcher
1000+ posts
Python programming language
(#1007)Send code
Ah, Python… My greatest friend and enemy! Currently working on making my art gallery in Python, and I'm struggling xD ChatGPT isn't making sense and I need to redo EVERYTHING and flush things out. Anyone experienced with key inputs and image displaying?
- BlauHourglass
- Scratcher
1000+ posts
Python programming language
The one that CGPT gave me or the one that I'm thinking about coding?(#1007)Send code
Ah, Python… My greatest friend and enemy! Currently working on making my art gallery in Python, and I'm struggling xD ChatGPT isn't making sense and I need to redo EVERYTHING and flush things out. Anyone experienced with key inputs and image displaying?
。 ゚。⋆☾ Did I ask? ☽ ⋆。 ゚☁︎。 ⋆。 ゚☾ But sleep's a part of the job, y'know. ☽ ⋆。 ゚☁︎。 ⋆。 ゚☾ If everyone were smart, no one would be. ☽ ⋆。 ゚。
——
Retired founder of Soundwave Productions ← click me, fufu~
Co-owner of The Glow Shop ← click me, fufu~
Co-owner of Ville de L'Art ← click me, fufu~
♕ Classical SSC May '24 ♕
⸙ Epistolary SWC March '24 ⸙
Co-owner of The Glow Shop ← click me, fufu~
Co-owner of Ville de L'Art ← click me, fufu~
——
ı|ı|ı Script SWC July '24 ı|ı|ı♕ Classical SSC May '24 ♕
⸙ Epistolary SWC March '24 ⸙
- TheElephantCoder
- Scratcher
33 posts
Python programming language
cool_half = awesome!
print(“Scratch is ” + cool_half)
This combines to make, Scratch is awesome!
print(“Scratch is ” + cool_half)
This combines to make, Scratch is awesome!
TheElephantCoder
- mumu245
- Scratcher
1000+ posts
Python programming language
(#1009)The one you wrote.The one that CGPT gave me or the one that I'm thinking about coding?(#1007)Send code
Ah, Python… My greatest friend and enemy! Currently working on making my art gallery in Python, and I'm struggling xD ChatGPT isn't making sense and I need to redo EVERYTHING and flush things out. Anyone experienced with key inputs and image displaying?
- BlauHourglass
- Scratcher
1000+ posts
Python programming language
import tkinter as tk
import os
import cv2
import pyautogui
from PIL import Image, ImageTk
x = 1920*2
y = 1080*2
pictures = []
# path = "art/"
for x in os.listdir():
if x.endswith(".png"):
# print(x) # testing
pictures.append(x)
class SlideshowApp:
def __init__(self, images):
self.root = tk.Tk()
self.root.title("Slideshow")
self.images = images
self.current_index = 0
self.canvas = tk.Canvas(self.root, width=x, height=y)
self.canvas.pack()
self.display_image()
self.root.bind("<Left>", self.prev_image)
self.root.bind("<Right>", self.next_image)
def display_image(self):
self.canvas.delete("all")
image_path = self.images[self.current_index]
try:
self.current_image = cv2.imread(image_path)
if self.current_image is None:
raise FileNotFoundError(f"Unable to read image: {image_path}")
image_pil = Image.fromarray(cv2.cvtColor(self.current_image, cv2.COLOR_BGR2RGB))
self.current_image_tk = ImageTk.PhotoImage(image=image_pil)
x_center = (x - self.current_image) // 2
y_center = (y - self.current_image) // 2
self.canvas.create_image(x_center, y_center, anchor="nw", image=self.current_image_tk)
except Exception as e:
print(f"Error displaying image: {e}")
def next_image(self):
self.current_index = (self.current_index + 1) % len(self.images)
self.display_image()
def prev_image(self):
self.current_index = (self.current_index - 1) % len(self.images)
self.display_image()
def run(self):
self.root.mainloop()
if __name__ == "__main__":
images = pictures
app = SlideshowApp(images)
app.run()
This actually has a Tkinter bug in it that I'm currently also trying to figure out. This is also a mix of CGPT and my code; unfortunately I'm not the best at documentation, and I…really need to fix that. But anyways, here.
Last edited by BlauHourglass (Feb. 17, 2024 19:26:16)
。 ゚。⋆☾ Did I ask? ☽ ⋆。 ゚☁︎。 ⋆。 ゚☾ But sleep's a part of the job, y'know. ☽ ⋆。 ゚☁︎。 ⋆。 ゚☾ If everyone were smart, no one would be. ☽ ⋆。 ゚。
——
Retired founder of Soundwave Productions ← click me, fufu~
Co-owner of The Glow Shop ← click me, fufu~
Co-owner of Ville de L'Art ← click me, fufu~
♕ Classical SSC May '24 ♕
⸙ Epistolary SWC March '24 ⸙
Co-owner of The Glow Shop ← click me, fufu~
Co-owner of Ville de L'Art ← click me, fufu~
——
ı|ı|ı Script SWC July '24 ı|ı|ı♕ Classical SSC May '24 ♕
⸙ Epistolary SWC March '24 ⸙
- MountainMan00
- Scratcher
28 posts
Python programming language
Because Scratch replaces the normal quotes with the fancy ones(decode with base64)
Why'd you encode it?
- Ricky-Jan_test
- Scratcher
21 posts
Python programming language
print('welcome, you can post or discuss python code here')
- Hai1-2-37
- Scratcher
39 posts
Python programming language
secret_number = 8
guesses = 0
guess_limit = 3
while guesses < guess_limit:
int(input('guess: ‘))
guesses = guesses + 1
if guesses == secret_number:
print(’You win! ‘)
else:
print(’You lose')
guesses = 0
guess_limit = 3
while guesses < guess_limit:
int(input('guess: ‘))
guesses = guesses + 1
if guesses == secret_number:
print(’You win! ‘)
else:
print(’You lose')
- Hai1-2-37
- Scratcher
39 posts
Python programming language
This is my number guessing game! secret_number = 8
guesses = 0
guess_limit = 3
while guesses < guess_limit:
int(input('guess: ‘))
guesses = guesses + 1
if guesses == secret_number:
print(’You win! ‘)
else:
print(’You lose')
- Ricky-Jan_test
- Scratcher
21 posts
Python programming language
This is my number guessing game!
Cool! but there is a little bug…
You need to save the input in the variable:guess = int(input('guess: '))In this way, the user's input will be saved in the variable.
And adjust these lines to:if guess == secret_number:
print('You Win!')
break # to stop the loop
Here is the little challenge! Can you make the secret number of the number random?
Here is how to get the random value:import random
random_value = random.randint(0, 10)
print(random_value)
Last edited by Ricky-Jan_test (March 20, 2024 06:25:17)
- Hai1-2-37
- Scratcher
39 posts
Python programming language
Here is my new codeThis is my number guessing game!
Cool! but there is a little bug…
You need to save the input in the variable:guess = int(input('guess: '))In this way, the user's input will be saved in the variable.
And adjust these lines to:if guess == secret_number:
print('You Win!')
break # to stop the loop
Here is the little challenge! Can you make the secret number of the number random?
Here is how to get the random value:import random
random_value = random.randint(0, 10)
print(random_value)
import random
secret_number = random.randint(0, 10)
print(secret_number)
guesses = 0
guess_limit = 3
while guesses < guess_limit:
guess = int(input('guess: ‘))
guesses = guesses + 1
if guess == secret_number:
print(’You win! ‘)
else:
print(’You lose')
- Ricky-Jan_test
- Scratcher
21 posts
Python programming language
Here is the letter pyramid, hahaha
def letterPyramid(letter):
if len(letter) % 2 == 1:
row = len(letter) // 2
for i in range(row + 1):
for j in range(row - i):
print(' ‘, end=“”)
for j in range(2 * i + 1):
print(letter, end=’'")
print()
else:
print('please input odd number of characters')
letter = input('Input Letters: ')
letterPyramid(letter)
Last edited by Ricky-Jan_test (March 20, 2024 06:36:27)
- Discussion Forums
- » Things I'm Making and Creating
- » Python programming language