Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain the game, and then the goal, Your goal is to try to defeat these aliens, and then the keys press F to attack, and

Explain the game, and then the goal, "Your goal is to try to defeat these aliens," and then the keys "press F to attack," and " Press arrow keys to move" but when I program it, it will only show two when I press the spacebar to switch each time. I also want the text to disappear when I press x.

import pgzrun
from pgzero.actor import Actor
from random import randint
#from pgzero.clock import clock

WIDTH = 800
HEIGHT = 600

player_health = 100
enemy_health = 50

# add the images/shapes
player = Actor("alien.png")
player.pos = (300, 300)

enemy = Actor("alien2.png")
enemy2 = Actor("alien3.png")

background = Actor('space.png')

enemy.pos = (randint(0, WIDTH), randint(0, HEIGHT))
enemy2.pos = (randint(0, WIDTH), randint(0, HEIGHT))

# a variable to keep track of the player's score
score = 0

enemies = [enemy, enemy2]

#goal_text = "Your goal is to try to defeated these aliens. "
#goal_text_display = True

current_text = "Your goal is to try to defeated these aliens."

def draw():
   screen.clear()
   background.draw()
   #if goal_text:
   screen.draw.text(current_text, (WIDTH/2, HEIGHT/2), color="white", fontsize=20, align="center")
   for e in enemies:
       e.draw()
       if enemy_health <= 0:
           screen.draw.text("Enemy Defeated", (e.x, e.y), color="white", fontsize=20, align="center")
       player.draw()
       if player_health <= 0:
           screen.draw.text("Game Over", (WIDTH/2, HEIGHT/2), color="white", fontsize=30, align="center")
   
   screen.draw.text("Score: " + str(score), (700, 10), color="white")
   screen.draw.text("Player Health: " + str(player_health), (10, 10), color="white")
   screen.draw.text("Enemy Health: " + str(enemy_health), (10, 30), color="white")

def update():
   global score, player_health, enemy_health, current_text
   
   if keyboard.space:
       if current_text == "Your goal is to try to defeated these aliens.":
           current_text = "Press F to attack"
           current_text = "Press arrow keys to move"
       else:
           current_text = "Your goal is to try to defeated these aliens."
   
   #if current_text and keyboard.x:
   #    current_text = False
   
   if player_health <= 0:
       pgzrun.quit()
   for e in enemies:
       e.x += 1
       if enemy_health <= 0:
           pgzrun.quit()
       if e.x > WIDTH:
           e.x = 0
       if player.colliderect(e):
           player_health -= 10
           score += 1
           e.pos = (randint(0, WIDTH), randint(0, HEIGHT))
           if keyboard.F:
               enemy_health -= 10
     
   if keyboard.left:
       player.x -= 5
   if keyboard.right:
       player.x += 5
   if keyboard.up:
       player.y -= 5
   if keyboard.down:
       player.y += 5
   if player.x < 0:
       player.x = 0
   #if player.x > WIDTH - player.width:
   #    player.x = WIDTH - player.width
   #if player.y < 0:
   #    player.y = 0
   #if player.y > HEIGHT - player.height:
   #    player.y = HEIGHT - player.height
       
pgzrun.go()

 

Step by Step Solution

3.30 Rating (147 Votes )

There are 3 Steps involved in it

Step: 1

Solution The code you have provided is a basic game where the player controls an alien to defeat oth... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Explain how to handle conflict effectively.

Answered: 1 week ago

Question

What are some of the features of the Unified Process (UP)?

Answered: 1 week ago

Question

26. Name at least two ways a gene could influence alcoholism.

Answered: 1 week ago