Skip to content

Commit

Permalink
- Remove the lv_ prefix from all classes/objects
Browse files Browse the repository at this point in the history
- Fixed a bug in the radius code (The radius code needs some care at all)
  • Loading branch information
Florian R. A. Angermeier committed Jun 23, 2011
1 parent 3b6d93c commit 511b70d
Show file tree
Hide file tree
Showing 12 changed files with 720 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ClientBasic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

from twisted.internet import reactor, protocol

from lv_protocol import lv_protocol

class lv_clientFactory( protocol.ClientFactory ):
protocol = lv_protocol

class lv_client:
def __init__( self ):
reactor.callInThread( self.runInterface )
reactor.connectTCP( raw_input( '\033[1;37mlv_client_basic\033[0m host [127.0.0.1] > ' ), 65000, lv_clientFactory() )
reactor.run()

def runInterface( self ):
playerInput = ''
while( playerInput != 'quit' ):
playerInput = raw_input( '\033[1;37mlv_client_basic\033[0m command > ' )

if( __name__ == '__main__' ):
client = lv_client()
39 changes: 39 additions & 0 deletions Server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

from twisted.internet import reactor

import gameEngine
from gameEngine.ServerFactory import ServerFactory
from gameEngine.World import World

class Server:
def __init__( self ):
# Initializing the simulation
self.world = World( 1 )
def run( self ):
print '\033[32mInfo\033[0m Starting world thread...'
reactor.callInThread( self.world.run )

print '\033[32mInfo\033[0m Starting listening socket...'
reactor.listenTCP( 65000, ServerFactory() )

print '\033[32mInfo\033[0m Starting reactor...'
reactor.run()

if( __name__ == '__main__' ):
Server = Server()
Server.run()
271 changes: 271 additions & 0 deletions gameEngine/Character.py

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions gameEngine/Object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

class Object:
# The base class for in-world objects in La Vida.

def __init__( self, id ):
self.id = id
self.type = 'generic'
self.pos = [ 0, 0, 0 ]
self.isInUse = False
23 changes: 23 additions & 0 deletions gameEngine/Protocol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

from twisted.protocols import basic

class Protocol( basic.LineReceiver ):
def lineReceived( self, line ):
if( line == "stop" ):
self.sendLine("server_stoped")
reactor.stop()
22 changes: 22 additions & 0 deletions gameEngine/ServerFactory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

from twisted.internet import protocol

from gameEngine.Protocol import Protocol

class ServerFactory( protocol.ServerFactory ):
protocol = Protocol
145 changes: 145 additions & 0 deletions gameEngine/World.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

import os
from time import sleep, time
from ConfigParser import ConfigParser

import gameEngine
from gameEngine.Character import Character

import objects
from objects.Bed import Bed
from objects.Cooker import Cooker
from objects.Refrigerator import Refrigerator
from objects.Shower import Shower

class World:
def __init__( self, amountOfCharacters ):


# Basic infrastructure
self.configParser = ConfigParser()

# Reading the game engine cinfiguration
if( os.path.exists( '../config/gameEngine.cfg' ) == True ):
self.configParser.read( open( '../config/gameEngine.cfg' ) )
self.gameEngineConfigExists = True
else:
self.gameEngineConfigExists = False
print '\033[31mError\033[0m No game engine configuration file found. Using default options.'

# Game time
self.startTime = time() # The start time
self.gameYear = 1 # In game year; NOT real year
self.gameMonth = 1 # In game month; NOT real month
self.gameDay = 1 # In game day; NOT real day
self.gameHour = 0 # In game hour; NOT real hour
self.gameMinute = 0 # In game minute; NOT real minute
self.gameSecond = 0 # In game second; NOT real second

if( self.gameEngineConfigExists == True ):
self.ticksPerSecond = self.configParser.get( 'time', 'ticksPerSecond' ) # Ticks per second
self.gameSecondsPerTick = self.configParser.get( 'time', 'gameSecondsPerTick' ) # The amount of game seconds passing each tick
else:
self.ticksPerSecond = 1
self.gameSecondsPerTick = 1

# Physics data
self.physicsGravity = 9.8 # Factor of gravity

# Terrain information
self.typeMap = [] # Type of the ground
self.heightMap = [] # Height of the ground

# Entities in the world
self.characters = [] # List of characters in the world
self.objects = [] # List of objects in the world

for i in range(amountOfCharacters):
self.characters.insert( 0, Character( i, self, 'random' ) )

self.objects.insert( 0, Bed( 0, -7, -7, 0 ) )
self.objects.insert( 1, Cooker( 1, 1, 1, 0 ) )
self.objects.insert( 2, Refrigerator( 2, 5, 5, 0 ) )
self.objects.insert( 3, Shower( 3, 7, 3, 0 ) )

def processTime( self ):
# Process the game time.
self.gameSecond += self.gameSecondsPerTick
if( self.gameSecond >= 60 ):
self.gameMinute += 1
self.gameSecond = 0

if( self.gameMinute >= 60 ):
self.gameHour += 1
self.gameMinute = 0

if( self.gameHour >= 24 ):
self.gameDay += 1
self.gameHour = 0

if( self.gameMonth == 1 or self.gameMonth == 3 or self.gameMonth == 5 or self.gameMonth == 7 or self.gameMonth == 8 or self.gameMonth == 10 or self.gameMonth >= 12 ):
if( self.gameDay == 32 ):
self.gameMonth += 1
self.gameDay = 1
elif( self.gameMonth == 2 ):
if( self.gameYear % 4 == 0 ):
if( self.gameDay == 30 ):
self.gameMonth += 1
self.gameDay = 1
else:
if( self.gameDay == 29 ):
self.gameMonth += 1
self.gameDay = 1
elif( self.gameMonth == 4 or self.gameMonth == 6 or self.gameMonth == 9 or self.gameMonth == 11 ):
if( self.gameDay == 31 ):
self.gameMonth += 1
self.gameDay = 1

if( self.gameMonth >= 13 ):
self.gameYear += 1
self.gameMonth = 1

def processGravity( self ):
# Processes gravity on characters and objects.
for character in self.characters:
if( character.pos[2] > 0):
character.pos[2] -= 1
else:
character.pos[2] = 0
for object in self.objects:
if( object.pos[2] > 0):
object.pos[2] -= 1
else:
object.pos[2] = 0

def run( self ):
while( self.gameDay <= 7 ):
os.system('clear')
self.processTime()
# self.processGravity()
print '\033[32mInfo\033[0m World\tGame date: %i-%i-%i\tGame time: %i:%i:%i' % ( self.gameYear, self.gameMonth, self.gameDay, self.gameHour, self.gameMinute, self.gameSecond )
for character in self.characters:
print '\033[32mInfo\033[0m Character %i, %s' % ( character.id, character.gender )
print '\033[32mInfo\033[0m Pos: %i %i %i\tDestination: %i %i %i' % ( character.pos[0], character.pos[1], character.pos[2], character.destination[0], character.destination[1], character.destination[2] )
print '\033[32mInfo\033[0m Sleep: %i\t\tFood: %i\tWater: %i' % ( character.needs['sleep'], character.needs['food'], character.needs['water'] )
print '\033[32mInfo\033[0m Hygiene: %i\tFun: %i\tSocial: %i' % ( character.needs['hygiene'], character.needs['fun'], character.needs['social'] )
print '\033[32mInfo\033[0m Activity: %s (%i game seconds left)' % ( character.activity, character.activityTimer )
character.decreaseNeeds()
character.processActivity()
sleep( 1 / self.ticksPerSecond )

35 changes: 35 additions & 0 deletions objects/Bed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

import gameEngine
from gameEngine.Object import Object

class Bed( Object ):
def __init__( self, id, x, y, z ):
self.id = id
self.type = 'Bed'
self.pos = [ x, y, z ]
self.isInUse = False

def rest( self, user ):
# The user rests on the bed.
print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) )
user.increaseNeed( 'sleep', 0.008680555 )

def sleep( self, user ):
# The user sleeps on the bed.
print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) )
user.increaseNeed( 'sleep', 0.034722222 )
30 changes: 30 additions & 0 deletions objects/Cooker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

import gameEngine
from gameEngine.Object import Object

class Cooker( Object ):
def __init__( self, id, x, y, z ):
self.id = id
self.type = 'Cooker'
self.pos = [ x, y, z ]
self.isInUse = False

def cook( self, user ):
# The user cooks on the cooker and eats.
print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) )
user.increaseNeed( 'food', 0.37037037 )
35 changes: 35 additions & 0 deletions objects/Refrigerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/python
#*** encoding:utf-8 ***

# This file is part of La Vida
# Copyright (C) 2011 Florian R. A. Angermeier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

import gameEngine
from gameEngine.Object import Object

class Refrigerator( object ):
def __init__( self, id, x, y, z ):
self.id = id
self.type = 'Refrigerator'
self.pos = [ x, y, z ]
self.isInUse = False

def drink( self, user ):
# The user drinks somthing.
print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) )
user.increaseNeed( 'water', 1.388888889 )

def eatSnack( self, user ):
# The user eats a snack.
print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) )
user.increaseNeed( 'food', 0.555555556 )
Loading

0 comments on commit 511b70d

Please sign in to comment.