Skip to content

Commit

Permalink
Add one game character when hosting a game.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmcalabroso committed Mar 12, 2014
1 parent 08ba138 commit dd2285a
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 11 deletions.
Binary file added assets/img/char_air.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 assets/img/char_earth.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 assets/img/char_fire.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 assets/img/char_water.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion game/connection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import socket

class Connection:
def __init__(self):
self.my_socket = socket.socket()

def host_server(self):
pass

def join_server(self,configs):
pass

def send_message(self,message):
pass

def receive_message(self,message):
def receive_message(self):
pass
Binary file added game/connection.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions game/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def hit_test(self,x,y):
if x > (self.x - (self.width*0.5)) and x < (self.x + (self.width*0.5)):
if y > (self.y - self.height*0.5) and y < (self.y + (self.height*0.5)):
return True
return False

def on_mouse_press(self, x, y, button, modifiers):
if self.active and self.world.state == Resources.states[self.curr_state]:
Expand Down
Binary file modified game/gui.pyc
Binary file not shown.
21 changes: 19 additions & 2 deletions game/manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from gameobject import GameObject
from resources import Resources
from connection import Connection
from game.player import Player

class GameManager(GameObject):

Expand All @@ -16,6 +18,7 @@ def __init__(self,*args,**kwargs):
self.state = Resources.states['TITLE']
self.focus = None
self.set_focus(self.find_widget('text_ip'))
#self.my_connection = Connection()

def switch_to_setup(self,batch):
bg = self.find_widget('my_bg')
Expand All @@ -35,6 +38,7 @@ def switch_to_game(self,batch):
bg = self.find_widget('my_bg')
bg.set_image(Resources.sprites['game_bg'])
self.set_player_data()

self.delete_widgets_by_batch(batch)
self.delete_labels_by_batch(batch)

Expand Down Expand Up @@ -62,10 +66,22 @@ def set_player_data(self):
ip_address = "None"
port_num = text_port.document.text
name = text_name.document.text
x,y = Resources.starting_points['char_air']

my_player = Player(name = "host_player",
actual_name = name,
x = x,
y = y,
img = Resources.sprites['char_air']
)

self.add_game_object(my_player)
self.window.push_handlers(my_player)

print "IP Address:",ip_address
print "Port:",port_num
print "Name:",name
print self.game_objects

def switch_to_end(self):
pass
Expand Down Expand Up @@ -224,5 +240,6 @@ def on_mouse_motion(self,x,y,dx,dy):
self.window.set_mouse_cursor(None)

def update(self,dt):
#game loop
pass
if self.state == Resources.states['GAME']:
for obj in self.get_game_objects():
obj.update(dt)
Binary file modified game/manager.pyc
Binary file not shown.
52 changes: 51 additions & 1 deletion game/player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
from gameobject import GameObject
from pyglet.window import key

class Player(GameObject):
def __init__(self,actual_name,name,*args,**kwargs):
super(Player,self).__init__(name = name,*args,**kwargs)
self.actual_name = actual_name
self.actual_name = actual_name
self.velocity_x = 3
self.velocity_y = 3
self.keys = {}
self.keys['up'] = False
self.keys['down'] = False
self.keys['right'] = False
self.keys['left'] = False

def is_colliding(self,x,y):
if x > (self.x - (self.width*0.5)) and x < (self.x + (self.width*0.5)):
if y > (self.y - self.height*0.5) and y < (self.y + (self.height*0.5)):
return True
return False

def set_velocity(self,velocity_x = 1, velocity_y = 1):
self.velocity_x = velocity_x
self.velocity_y = velocity_y

def on_key_press(self,symbol,modifiers):
if symbol == key.LEFT:
self.keys['left'] = True
elif symbol == key.UP:
self.keys['up'] = True
elif symbol == key.RIGHT:
self.keys['right'] = True
elif symbol == key.DOWN:
self.keys['down'] = True

def on_key_release(self,symbol,modifiers):
if symbol == key.LEFT:
self.keys['left'] = False
elif symbol == key.UP:
self.keys['up'] = False
elif symbol == key.RIGHT:
self.keys['right'] = False
elif symbol == key.DOWN:
self.keys['down'] = False

def update(self,dt):
if self.keys['left']:
self.x -= self.velocity_x
elif self.keys['up']:
self.y += self.velocity_y
elif self.keys['right']:
self.x += self.velocity_x
elif self.keys['down']:
self.y -= self.velocity_y

print "x,y",(self.x,self.y)
Binary file modified game/player.pyc
Binary file not shown.
15 changes: 14 additions & 1 deletion game/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class Resources:
window_height = 600
center_x,center_y = get_center_coordinates(window_width,window_height)

# Starting Points of Characters (x,y)
starting_points = {}

starting_points['char_air'] = (center_x,400)
starting_points['char_earth'] = (center_x,200)
starting_points['char_fire'] = (center_y,100)
starting_points['char_water'] = (center_y,200)

# Object Batches per state #
batches = {}

Expand All @@ -45,4 +53,9 @@ class Resources:
#Backgrounds
sprites['title_bg'] = center_image(image.load(join(res_path,'title_bg.jpg')))
sprites['setup_bg'] = center_image(image.load(join(res_path,'setup_bg.jpg')))
sprites['game_bg'] = center_image(image.load(join(res_path,'game_bg.jpg')))
sprites['game_bg'] = center_image(image.load(join(res_path,'game_bg.jpg')))
#Game Elements
sprites['char_air'] = center_image(image.load(join(res_path,'char_air.png')))
sprites['char_earth'] = center_image(image.load(join(res_path,'char_earth.png')))
sprites['char_fire'] = center_image(image.load(join(res_path,'char_fire.png')))
sprites['char_water'] = center_image(image.load(join(res_path,'char_water.png')))
Binary file modified game/resources.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion push.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from game.gui import TextWidget
from game.gui import UILabel
from game.manager import GameManager
from game.player import Player
from game.resources import Resources

game_window = Window(Resources.window_width, Resources.window_height)
Expand Down
5 changes: 0 additions & 5 deletions server.py

This file was deleted.

0 comments on commit dd2285a

Please sign in to comment.