-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove the lv_ prefix from all classes/objects
- 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
Showing
12 changed files
with
720 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
Oops, something went wrong.