Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added AI-Final-master/__pycache__/enemy.cpython-39.pyc
Binary file not shown.
Binary file added AI-Final-master/__pycache__/game.cpython-36.pyc
Binary file not shown.
Binary file added AI-Final-master/__pycache__/game.cpython-39.pyc
Binary file not shown.
Binary file added AI-Final-master/__pycache__/player.cpython-36.pyc
Binary file not shown.
Binary file added AI-Final-master/__pycache__/player.cpython-39.pyc
Binary file not shown.
Binary file added AI-Final-master/character PNGs/characters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AI-Final-master/character PNGs/goblin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions AI-Final-master/enemy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
File for enemy functions (AI functionality for movement and attacks and things)
"""

import pygame
from pygame.locals import *
from pytmx.util_pygame import load_pygame



class Enemy:




def __init__(self, x, y):
self.image = pygame.image.load("character PNGs\\goblin.png")
self.x = x
self.y = y
self.path = [self.x, self.y]
self.walkCount = 0
self.vel = 3
self.hitbox = (self.x + 17, self.y + 2, 31, 57) # NEW
self.health = 1000
self.visible = True

def draw(self,win):
self.move()
if self.visible:
if self.walkCount + 1 >= 33:
self.walkCount = 0

if self.vel > 0:
win.blit(self.walkRight[self.walkCount //3], (self.x, self.y))
self.walkCount += 1
else:
win.blit(self.walkLeft[self.walkCount //3], (self.x, self.y))
self.walkCount += 1


# Drawing the health bar of the enemy.
pygame.draw.rect(win, (255,0,0), (self.hitbox[0], self.hitbox[1] - 20, 50, 10))

# Substract from the health bar width each time enemy is hit
pygame.draw.rect(win, (0,255,0), (self.hitbox[0], self.hitbox[1] - 20, 50 - (5 * (10 - self.health)), 10))

# Creating a hitbox around the character.
self.hitbox = (self.x + 15, self.y + 10, 29, 52)

def hit(self):
if self.health > 0:
self.health -= 1
else:
self.visible = False
print('Enemy hit')

def move(self):
if self.vel > 0:
if self.x + self.vel < self.path[1]:
self.x += self.vel
else:
self.vel = self.vel * -1
self.walkCount = 0
else:
if self.x - self.vel > self.path[0]:
self.x += self.vel
else:
self.vel = self.vel * -1
self.walkCount = 0

# NEW METHOD
def hit(self): # This will display when the enemy is hit
print('hit')

















70 changes: 70 additions & 0 deletions AI-Final-master/game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Contains info to initialize the game (pygame init, screen init, map info/drawing, etc.)
"""
import player
import sys
import pygame
from pygame.locals import *
from pytmx.util_pygame import load_pygame

class Directions:
NORTH = "North"
SOUTH = 'South'
EAST = 'East'
WEST = 'West'
STOP = 'Stop'

LEFT = {NORTH: WEST,
SOUTH: EAST,
EAST: NORTH,
WEST: SOUTH,
STOP: STOP}

RIGHT = dict([(y, x) for x, y in list(LEFT.items())])

REVERSE = {NORTH: SOUTH,
SOUTH: NORTH,
EAST: WEST,
WEST: EAST,
STOP: STOP}

class Game:
def __init__(self):
self.screen = pygame.display.set_mode((640, 640)) # set screen size
pygame.display.set_caption("Untitled Rogue-like Game") # set display caption
self.clock = pygame.time.Clock() # create clock
self.running = True # init running to true, change to false when exit button clicked
self.tmxdata = load_pygame("rooms\\basic_room.tmx") # Load map from tmx file
self.playerX = 320
self.playerY = 500

#game loop
def runGame(self):
print("run game")
while self.running:
#print("running")
self.screen.fill((255,255,255)) # init screen to white
keyPressed = pygame.key.get_pressed()
mousePressed = pygame.mouse.get_pressed()
mouseX, mouseY = pygame.mouse.get_pos()
self.getEvents()
self.drawMap()
#player.Player().draw()
pygame.display.update()


# handle all events in game
def getEvents(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
#print("exit game")
self.running = False

def drawMap(self):
#print("draw map")
for layer in self.tmxdata:
for tiles in layer.tiles():
xPixel = tiles[0] * 16
yPixel = tiles[1] * 16
mapImg = tiles[2]
self.screen.blit(mapImg, (xPixel, yPixel))
172 changes: 172 additions & 0 deletions AI-Final-master/game_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
"""
This file is meant to be used to test various parts of the final game in static, mostly blank world.
The world is created using Tiled and pyTMX.

Features to test here include initial player movement, player attacking, enemy AI movement, and enemy attacking.
"""
import sys
import random
import pygame
import math
from enemy import Enemy
from player import Player
from game import Game
from pygame.locals import *
from pytmx.util_pygame import load_pygame


width, height = 640, 640
#init pygame
pygame.init()
#create screen (width, height)
#Game().runGame() # UNCOMMENT THIS TO RUN WITH GAME CLASS INSTEAD -- CURRENTLY UNECESSARY
screenSize = (width, height)
screen = pygame.display.set_mode(screenSize)
# Window title
pygame.display.set_caption("Untitled Rogue-Like game")
tmxdata = load_pygame("rooms\\basic_room.tmx") # Load map from tmx file
fireBallList = [] # list of fire ball sprites

fireBallTimer = 0.1
# To set window icon:
# icon = pygame.image.load("image.png")
# pygame.display.set_icon(icon)
clock = pygame.time.Clock()
dt = clock.tick(60)/1000 # dt = time since last tick in milliseconds
startTicks = pygame.time.get_ticks()

class fireBall:
def __init__(self, playerX, playerY, mouseX, mouseY):
self.x = playerX
self.y = playerY
self.speed = 2
self.angle = math.atan2(mouseY-playerY, mouseX-playerX)
self.xVel = math.cos(self.angle) * self.speed
self.yVel = math.sin(self.angle) * self.speed
self.fireBallTimer = 0.1

def update(self, dt):
self.x += int(self.xVel)
self.y += int(self.yVel)

# fbTimer = self.fireBallTimer - dt
# if fbTimer <= 0:
# print("SHHOOOOTT HEERRRR")
# #wafbTimer = 0
pygame.draw.circle(screen, (0,0,0), (self.x, self.y), 10)
# fbTimer = 0.1



"""
Consider changing attack buttons to arrow keys instead of mouse
"""
def playerAttack(playerX, playerY, mouseX, mouseY, mousePressed):
if mousePressed:
fireBallList.append(fireBall(playerX, playerY, mouseX, mouseY))
for fb in fireBallList:
#pygame.time.wait(5)
#print("before update")
fb.update(dt)
#print("after update")
if fb.x < 20 or fb.y < 20 or fb.x > 610 or fb.y > 610: #delete orb if it leaves world bounds --
#need to make this so it deltes when it hits an enemy or a wall
fireBallList.pop(fireBallList.index(fb))

"""
Using this for now but there is also a drawMap function in the Game class from game.py
"""
# start draw_map()
def draw_map():
#tmxdata = load_pygame("rooms\\basic_room.tmx") # Load map from tmx file
for layer in tmxdata:
for tiles in layer.tiles():
xPixelPos = tiles[0] * 16 #+ world_offset
yPixelPos = tiles[1] * 16 #+ world_offset
mapImg = tiles[2] #get img to draw from tmxdata
screen.blit(mapImg, (xPixelPos, yPixelPos)) #draw map to screen
# end draw_map()

def redraw_game_window():
win.blit(bg, (0, 0))
win.blit(text, (520, 10))
player.draw(win)
enemy.draw(win)
for fireball in fireballs
fireball.draw(win)
# Refresh the display and show the character
pygame.display.update()


player = Player(250, 250)
enemy = Enemy(450, 300)

# Game loop
running = True
fireballCooldown = 0
fireballs = []
while running:
screen.fill((255,255,255)) # Screen starts white before doing anything else
keyPressed = pygame.key.get_pressed() # get key presses for movement
mousePressed = pygame.mouse.get_pressed()[0]
mouseX, mouseY = pygame.mouse.get_pos()

if fireballCooldown > 0:
fireballCooldown += 1
if fireballCooldown > 3:
fireballCooldown = 0

#event loop -- looks for events like key presses or quit
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False


for fireball in fireballs:
if fireball.y - fireball.radius < enemy.hitbox[1] + enemy.hitbox[3] and fireball.y + fireball.radius > enemy.hitbox[1]:
if fireball.x + fireball.radius > enemy.hitbox[0] and fireball.x - fireball.radius < enemy.hitbox[0] + enemy.hitbox[2]:

enemy.hit()

fireballs.pop(fireballs.index(fireball))
if fireball.x < 750 and fireball.x > 0:
fireball.x += fireball.vel
else:
fireballs.pop(fireballs.index(fireball))



#player movement
playerXY = player.move(playerXpos, playerYpos, keyPressed, tmxdata)
playerXpos = playerXY[0]
playerYpos = playerXY[1]

draw_map() #draws the map to the screen
#draw player and update postion
player.draw((playerXpos, playerYpos), screen)



playerAttack(playerXpos, playerYpos, mouseX, mouseY, mousePressed)

redraw_game_window()



pygame.quit()
















51 changes: 51 additions & 0 deletions AI-Final-master/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
File for player functions (move, attack, etc.)
"""

import pygame
from pygame.locals import *
from pytmx.util_pygame import load_pygame

class Player:
def __init__(self, x, y):
self.image = pygame.image.load("tile PNGs\\blueWizard.png")
self.x = x
self.y = y
self.speed = 10
def draw(self, XYpos, screen):
screen.blit(self.image, XYpos)

def getMapProperties(self, x, y):
xTile = x // 16
yTile = y // 16


wallProp = game.Game().tmxdata.get_tile_properties(xTile, yTile, 0)
stairProp = game.Game().tmxdata.get_tile_properties(xTile, yTile, 1)
#print("got wall props")
if wallProp is None and stairProp is None:
wallProp = {"solid":0, "stairs":0}
stairProp = {"solid":0, "stairs":0}
return (wallProp, stairProp)

def move(self, x, y, keyPressed, tmxdata):
if keyPressed[ord("a")]: # check what key was pressed
westTile = self.getMapProperties(x-5, y+11) #find the tile next to the player and get its properties
if westTile[0]['solid'] == 0: # if not solid keep moving, stop otherwise
x += -self.speed
if keyPressed[ord("d")]:
eastTile = self.getMapProperties(x+24, y+22)
if eastTile[0]['solid'] == 0:
x += self.speed
if keyPressed[ord("w")]:
northTile = self.getMapProperties(x, y)
if northTile[0]['solid'] == 0:
y += -self.speed
if keyPressed[ord("s")]:
southTile = self.getMapProperties(x-2, y+32)
if southTile[0]['solid'] == 0:
y += self.speed
return(x, y)


#def attack(self, dt):
Binary file not shown.
Binary file not shown.
Loading