gamebox
play

GAMEBOX CS 1111 NOVEMBER 2019 GAMEBOX - PowerPoint PPT Presentation

GAMEBOX CS 1111 NOVEMBER 2019 GAMEBOX https://cs1110.cs.virginia.edu/gamebox-summary.html Save gamebox.py into every folder that uses gamebox Gamebox is a simple game library built on top of Pygame It supports Animation


  1. GAMEBOX CS 1111 NOVEMBER 2019

  2. GAMEBOX • https://cs1110.cs.virginia.edu/gamebox-summary.html • Save gamebox.py into every folder that uses gamebox • Gamebox is a simple game library built on top of Pygame • It supports • Animation • Collision Detection • Simply physics • More

  3. IMPORT STATEMENTS • Always start with: import pygame import gamebox camera = gamebox.Camera(800, 600) # you can change these # dimensions to change the window size

  4. CLICKING_EXAMPLE.PY • http://cs1110.cs.virginia.edu/files/cs1111_19fa/clicking_example.py • Let’s take a look at some of the mechanisms:

  5. TIME LOOP • At the core of gamebox is the passage of time: gamebox.timer_loop(30, tick) • This tells gamebox to call the function “ tick ” 30 times per second. def tick(keys): • This defines the tick function to take in any pressed keys

  6. TIME LOOP if pygame.K_UP in keys: • This detects if the “UP” arrow is being hit on the keyboard. • List of keys: https://www.pygame.org/docs/ref/key.html if camera.mouseclick: • Detects if the mouse is pressed (could be true several times in a row) camera.draw(logo) • Draws the logo as it’s current stored location camera.display() • Draws everything the camera “drew”

  7. CAMERA Point of Origin (0,0) Y increases X increases

  8. GAMEBOXES • A gamebox is a rectangle • You can draw images or color the rectangles • They can move • They support collision detection • They can change appearance • See 2. gameboxes on http://cs1110.cs.virginia.edu/gamebox-summary.html

  9. GAMEBOXES MOVEMENT b1 = gamebox.from_color(50, 100, "red", 20, 40) # x, y, color, width, height b1.move(5, 6) b1.x -= 5 b1.center(50, 100)

  10. EXAMPLES – SIMPLE ANIMATION • Starfield – Simple starfield animation https://cs1110.cs.virginia.edu/files/cs1111_19fa/starfield.py • Gangnam Style – Sprite images https://cs1110.cs.virginia.edu/files/cs1111_19fa/animation.py • Timer https://cs1110.cs.virginia.edu/files/cs1111_19fa/pygame_demo.py

  11. COLLISION DETECTION print(b1.touches(b2)) • If b1 touches b2, return true print(b1.bottom_touches(b2)) • If the bottom of b1 touches b2, return true b1.move_to_stop_overlapping(b2) b1.move_both_to_stop_overlapping(b2)

  12. EXAMPLES • Arrow-Keys: [movement, images, keyboard controls] https://cs1110.cs.virginia.edu/files/cs1111_19fa/arrow_keys.py • Infinite_jumper: [movement, jumping, collision detection, panning] https://cs1110.cs.virginia.edu/files/cs1111_19fa/infinite_jumper.py • Healthbar: [rudimentary AI, health bar, game_over screen] https://cs1110.cs.virginia.edu/files/cs1111_19fa/health_bar.py • Basic Carry Demo (Carrying an item) https://cs1110.cs.virginia.edu/files/cs1111_19fa/basic_carry_stuff.py

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend