Hello there! In class, I have been learning how to use python in processing. However, I have learned barely anything in processing, and I now have a project to complete. I am trying to make a simple game where you control a spaceship and have to shoot this big alien, but I have absolutely no idea how to test for collisions between a rectangle and an image. And Google hasn’t really helped either, because it seems like almost no one uses processing.py. Can someone please help me? I have put my code below (very bad code lol, I really have no idea what I’m doing) along with two images (the player and the enemy). Thank you!
x = 750
y = 900
xspeed = 0
bossx = 500
bossy = 100
bxspeed = 10
bosshealth = 200
gunx = x + 50
guny = 900
velocity = 100
xxspeed = 0
liney = bossy
bgunx = bossx + 50
bguny = 100
def setup():
global ship, alien
ship = loadImage("ship.png")
alien = loadImage("alien.png")
imageMode(CORNERS)
size(1500, 1000)
frameRate(60)
def draw():
global x, y, bgunx, bguny, xspeed, ship, alien, bossx, bxspeed, gunx, guny, xxspeed, linex, bossy
background(0)
textSize(32)
text(bosshealth, 750, 30)
fill(255)
image(ship, x, y)
bullet = rect(gunx, guny, 15, 15)
danger = rect(bgunx, bguny, 30, 30)
if keyPressed:
if key == "d":
xspeed = 10
xxspeed = 10
if key == "a":
xspeed = -10
xxspeed = -10
else:
xspeed = 0
if keyPressed:
if key == "d":
xxspeed = 10
if key == "a":
xxspeed = -10
if key == "w":
guny = guny - velocity
else:
xxspeed = 0
x = x + xspeed
gunx = gunx + xxspeed
if x > 1500:
x = 0
gunx = 50
if x < 0:
x = 1500
gunx = 1450
image(alien, bossx, 100)
bossx = bossx + bxspeed
bgunx = bgunx + bxspeed
if bossx == 1000:
bxspeed = -10
if bossx == 0:
bxspeed = 10
guny = guny - 50
if guny < 0:
guny=900
bguny = bguny + 10
if bguny > 1000:
bguny=200