![]() ![]() move ( 25 ) Sprite Commands Simple commands foreach_sprite ( tag = 'player-missile' ) async def propel_missile ( missile ): missile. foreach_sprite ( player1, player2, player3, player4 ) async def animate_player ( player ): next_frame ( player ) await nyan. Should be used in conjunction with and decorators. when_event_recieved ( 'marco' ) def do (): print ( 'polo' ) a script to each sprite passed or in the case a tag is passed, for each sprite that has the given tag. broadcast ( 'marco' ) run code in response to a broadcasted event, use like this. You can use nyan.broadcast() to broadcast an event that can be picked up by an event listener. This will make the cat turn upside down instantly when the program starts, wait 2 seconds, then turn back up again. when_program_starts async def do (): cat. To run code after a waiting period, you can use the await nyan.sleep() command like this: cat = nyan. This will make the cat turn upside down instantly when the program starts. make some code run just at the beginning of your project, use like this: cat = nyan. Sprites have other commands that you can see in the next section called Sprite Commands. The above code will make the cat turn around forever. Animation and Control Commands make things move around, you can start by using like this: cat = nyan. set_backdrop (( 255, 255, 255 ))Īnywhere you can set a color in Nyan, you can do it using a named color like 'red' or an RGB value above like (255, 255, 255) or even an RGBA value like (0, 0, 0, 127) (the fourth number is transparency from 0 to 255). Additionally, if you want to set colors by RGB (Red Green Blue) values, you can do that like this: # Sets the background to white. There are lots of named colors to choose from. You can change the background color with the t_backdrop() command: nyan. This will put a black circle in the middle of the screen. new_circle ( color = 'black', x = 0, y = 0, radius = 100, border_color = "light blue", border_width = 10 ) You can find font files at sites like DaFont. Then you can change font=None to font='Arial.ttf'. If you want to change the font, you'll need a font file (usually named something like Arial.ttf) in your assets folder. new_text ( text = 'hi there', x = 0, y = 0, font = None, font_size = 50, color = 'black' ) You can find images online at sites like OpenGameArt, or you can make your own using an online sprite editor like Piskel. Make sure you have a file named character.png in a folder named assets inside your project for the code above to work. This will place an image in the middle of the screen. new_image ( image = 'character.png', x = 0, y = 0, size = 100 ) You can also change the color by changing 'black' to another color name, like 'orange'. Likeswise, increasing y moves the image up and decreasing y moves the image down. Increasing x moves the image right and decreasing x moves the image left. Just like Scratch, the middle of the screen is x=0, y=0. If you want to change where the image is on the screen, try changing x=0 (horizontal position) and y=0 (vertical position). This will put a tall, black Rectangle in the middle of the screen. new_rect ( color = 'black', x = 0, y = 0, width = 100, height = 200, border_color = "light blue", border_width = 10 ) (Copy and paste the code below to try it out.) nyan.new_rect() box = nyan. To get images or text on the screen, use the following commands. Packaging Nyan Programs - Creating an executable that can be shared with other people. ![]() Other Useful Commands - General commands.Audio Commands - Playing sounds and music.Keyboard Commands - Detecting keyboard actions.Mouse Commands - Detecting mouse actions (clicks, movement).Animation and Control Commands - Animating and controlling graphics, shapes, and text.Basic Commands - Getting graphics, shapes, and text on the screen.The rest of this document is divided into the following sections: start_program () # this is the last line in the programĪll other commands go between those two commands. Run the following command in your terminal: pip install nyanĪll Nyan programs start with import nyan and end with nyan.start_program(), like this: import nyan # this is the first line in the program nyan. Make sure that you have Python 3.7 or greater. It was designed to have similar commands and simplicity to MIT's Scratch and is distinguished from such projects as Pygame, Arcade, or Pygame Zero because of its lack of boiler plate code, its easy-to-understand plain-english commands, and intuitive API. Nyan is an excellent choice for beginner programmers to get started with graphics programming. The code above makes a game where you have to click the cat to win: repeat_forever async def move_cat (): cat. Here's the code to make a simple game using Nyan: import nyan cat = nyan. Nyan - a fork of Python Play - is an open-source code library for the Python programming language that makes it as easy as possible to start making games. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |