QuestionQuestion

Graphical User Interface
Task description: Cannon games
You will use a variation of the code from Exercise 9 to create a cannonball game. The player should put strength and angle to the cannon to hit an object on the ground a distance away from the cannon. Use the techniques from practice 9 to calculate the trajectory of the cannonball. There should be an option box for whether the game will use air resistance or not.
To be able to render the results of the integrator as an animation instead of a regular plot, is one alternative integrator added to the exercise. This integrator returns its results through repeated calls to the next () method. So every time you update the animation, call next () to get out next value from the integrator.
An example of the GUI is shown below. The cannon is at the bottom left. The red square is the goal the player must hit. The black balls are cannonballs the player shoots. The white box is an obstacle which the player must shoot over to hit the target.
Volunteer: Wind can be a voluntary additional task, the wind is random for each shot and should be shown to the player so that the player can compensate. The goal is to hit the target with as few shots as possible.
Voluntary: Create terrain that the bullet cannot get through so the player has to shoot more upwards to hit (must shoot over the terrain).

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import tkinter as tk
import numpy as np
import matplotlib.pyplot as plt
import math

class Basis:                                        # Class with gravity - without air-resistance
    def __init__(self, tyng):
       self.tyng = tyng                            # tyng = gravitaional acceleration
   
    # Function for gravity class. tidspunkt = time, tilstandsvektor = vector (used as parameter)
    def evaluate(self, tidspunkt, tilstandsvektor):
       x_pos = 0                           # x acceleration
       y_pos = self.tyng                   # y acceleration
       x_fart = tilstandsvektor[2]         # x_fart = x_velocity
       y_fart = tilstandsvektor[3]         # y_fart = y_velocity
       endring = np.array([x_fart, y_fart, x_pos, y_pos])*tidspunkt       # endring = change
       return endring                                                      # returning [new_x, new_y, new_xDot, new_yDot] vector


class Luft:                                  # Class where drag is applied. Luft = Air (with air resistance)

    def __init__(self, tyng, luftm):                         # luftm = drag (parameter - air resistance)
       self.tyng = tyng
       self.luftm = luftm

    def evaluate(self, tidspunkt, tilstandsvektor):             #   function for drag
       x_fart = tilstandsvektor[2]                            #   same as in the previous class function
       y_fart = tilstandsvektor[3]
       F = math.sqrt(x_fart**2 + y_fart**2)                   # F = V for velocity
       x_pos = -(self.luftm * x_fart * F)                      # x position
       y_pos = self.tyng - (self.luftm...
$93.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats