Sep-24-2019, 03:25 PM
This pysynth looks interesting, but which file am I supposed to download? The only module I've ever installed is pygame, and with that I had to enter a command in my computer's command prompt.
As for game files, honestly, I prefer everything to be contained within the code of the game. For instance, my sprite function draws a sprite from a list of values (simply put, each value indicates a color, while its placement in the list is used to determine where its drawn on the screen). Here's the code I came up with that does this (I'm planning on making it into a custom class so I don't have to copy-paste all of this into each program):
Anyway, as we see all the code for the sprite itself is stored within the program itself. I would also prefer to be able to synthesize music from within my programs themselves. When I do get around to making a sprite and music maker, honestly I'll probably have them output the files as a list that I can copy-paste into my programs, rather than having them make actual files.
Oh, and for the record, I've since learned to use set a framerate without using the time.delay command. I haven't bothered to do it with this program though since I only made it to learn how to draw sprites; I don't intend to actually use any of this in a program.
As for game files, honestly, I prefer everything to be contained within the code of the game. For instance, my sprite function draws a sprite from a list of values (simply put, each value indicates a color, while its placement in the list is used to determine where its drawn on the screen). Here's the code I came up with that does this (I'm planning on making it into a custom class so I don't have to copy-paste all of this into each program):
import pygame pygame.init() mainWindow=pygame.display.set_mode((500,500)) x=200 y=250 pixel=10 row1=[0,0,0,1,1,0,0,0] row2=[0,0,1,1,1,1,0,0] row3=[0,1,1,1,1,1,1,0] row4=[1,1,0,1,1,0,1,1] row5=[1,1,1,1,1,1,1,1] row6=[0,0,1,0,0,1,0,0] row7=[0,1,0,1,1,0,1,0] row8=[1,0,1,0,0,1,0,1] sprite=row1+row2+row3+row4+row5+row6+row7+row8 def makeSprite(): pixelx=x pixely=y r=0 g=0 b=0 for a in sprite: if a==1: r=255 g=255 b=255 pygame.draw.rect(mainWindow, (r,g,b),(pixelx,pixely,pixel,pixel)) pixelx=pixelx+pixel if (pixelx-x)%(8*pixel)==0: pixelx=x pixely=pixely+pixel def main(): global x global y while True: pygame.time.delay(100) for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() quit() key=pygame.key.get_pressed() if key[pygame.K_UP]: y=y-pixel if key[pygame.K_DOWN]: y=y+pixel if key[pygame.K_RIGHT]: x=x+pixel if key[pygame.K_LEFT]: x=x-pixel mainWindow.fill((0,0,0)) makeSprite() pygame.display.update() main()Of course, this is an overly simplified version I made trying to figure out how to do this. I plan to have the thing be able to display more than 2 different colors, and also for the final version it will be possible to adjust both the dimensions of a sprite in pixels, and the exact dimensions of each pixel. Essentially, the class will be able to take 6 values: the x and y coordinates, the width and height of the sprite, and the width and height of the pixels. In my example program, the pixels are 10 screen pixels square, and the sprite is made up of an 8x8 grid of these. Doing this btw, I found that the pixel dimensions of the aliens in space invaders apparently aren't all 8x8 (one of them is 11x8), which is what inspired me to make it so that you can actually customize the dimensions of each sprite.
Anyway, as we see all the code for the sprite itself is stored within the program itself. I would also prefer to be able to synthesize music from within my programs themselves. When I do get around to making a sprite and music maker, honestly I'll probably have them output the files as a list that I can copy-paste into my programs, rather than having them make actual files.
Oh, and for the record, I've since learned to use set a framerate without using the time.delay command. I haven't bothered to do it with this program though since I only made it to learn how to draw sprites; I don't intend to actually use any of this in a program.