From df5e6947bae27eaa1ad1ac1d14c8428e505363af Mon Sep 17 00:00:00 2001 From: Andrea Date: Sun, 6 Nov 2011 10:15:18 -0500 Subject: [PATCH 1/3] Fixing collisions, vertical scroll --- lib/vimcity/map.rb | 6 +++--- lib/vimcity/vim_city_game.rb | 6 +++--- vimcity.vim | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/vimcity/map.rb b/lib/vimcity/map.rb index 79055ee..e2cc55e 100644 --- a/lib/vimcity/map.rb +++ b/lib/vimcity/map.rb @@ -5,11 +5,11 @@ class Map include Printer - def initialize(buffer) + def initialize(buffer, width=200, height=70) @buffer = buffer @offset = 1 - @width = 200 - @height = 70 + @width = width + @height = height empty_space= " "*@offset + "."*@width diff --git a/lib/vimcity/vim_city_game.rb b/lib/vimcity/vim_city_game.rb index f1dfda1..38ebb20 100644 --- a/lib/vimcity/vim_city_game.rb +++ b/lib/vimcity/vim_city_game.rb @@ -26,7 +26,7 @@ def initialize @height = @main_window.height @width = @main_window.width - @map = Map.new(@main_buffer) + @map = Map.new(@main_buffer, 20, 300) VIM::evaluate("genutils#MoveCursorToWindow(2)") #oh hey, 2 is the lower panel ./sigh @@ -119,11 +119,11 @@ def update_cursor(x,y) c[1] += y c[1] = 1 if c[1] < 1 - c[1] = @map.height+1 if c[1] >= @map.height+1 + c[1] = @map.height+2-cursor_height if c[1]+cursor_height >= @map.height+2 c[2] += x c[2] = @map.offset if c[2] < @map.offset - c[2] = @map.width-(@map.offset-1) if c[2] >= (@map.width+@map.offset) + c[2] = @map.width-(@map.offset)-cursor_width+2 if c[2]+cursor_width >= (@map.width+@map.offset+1) VIM::evaluate("cursor(#{c[1]},#{c[2]})") diff --git a/vimcity.vim b/vimcity.vim index fa243ba..dd0a1d9 100644 --- a/vimcity.vim +++ b/vimcity.vim @@ -60,6 +60,7 @@ function! s:play() setlocal noswapfile setlocal buftype=nofile setlocal nowrap + setlocal so=999 exec "sp Welcome_to_VimCity" exec "resize 1" From d4db11ca930164fa88d57e24dd5ffb36e88b9b1d Mon Sep 17 00:00:00 2001 From: Andrea Date: Sun, 6 Nov 2011 11:59:11 -0500 Subject: [PATCH 2/3] Implementing city logic --- lib/vimcity/city.rb | 14 ++++++++++++++ lib/vimcity/vim_city_game.rb | 13 +++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/vimcity/city.rb b/lib/vimcity/city.rb index 98dc3ad..8da925c 100644 --- a/lib/vimcity/city.rb +++ b/lib/vimcity/city.rb @@ -5,6 +5,20 @@ class City def initialize(coins=1000, population=100) @coins = coins @population = population + @population_cap = 0 + @money_per_second = 1 + @people_per_second = 1 + @happiness = 1 + end + + def update + @coins+=@money_per_second + if @population < @population_cap + @population+=@people_per_second*@happiness + @population=@population.round + end + @happiness-=0.001 + @happiness = 0.001 if @happiness < 0 end end diff --git a/lib/vimcity/vim_city_game.rb b/lib/vimcity/vim_city_game.rb index 22eda7a..a7af850 100644 --- a/lib/vimcity/vim_city_game.rb +++ b/lib/vimcity/vim_city_game.rb @@ -79,7 +79,8 @@ def start_game elsif input == 'r' VIM::message("receive p") - if @insert_mode && @current_building + if @insert_mode && @current_building + @city.coins+=1000 failure = false @last_chars.each do |row| failure = true if row != "."*@current_building.width @@ -94,6 +95,7 @@ def start_game end update_status_bar + @city.update() wait 80 end end @@ -127,7 +129,6 @@ def init_cursor def update_status_bar VIM::evaluate("genutils#MoveCursorToWindow(1)") - @city.coins +=1 @status_buffer[1] = " "*@width print_to_buffer(@status_buffer, 1, 0, "Money: #{@city.coins}c") print_to_buffer(@status_buffer, 1, 18, "Population: #{@city.population}") @@ -143,12 +144,12 @@ def update_cursor(x,y) print_area_to_buffer(@main_buffer, c[0], c[1], @last_chars) c[0] += y - c[0] = 1 if c[1] < 1 - c[0] = @map.height+2-cursor_height if c[1]+cursor_height >= @map.height+2 + c[0] = 1 if c[0] < 1 + c[0] = @map.height+2-cursor_height if c[0]+cursor_height >= @map.height+2 c[1] += x - c[1] = @map.offset if c[2] < @map.offset - c[1] = @map.width-(@map.offset)-cursor_width+2 if c[2]+cursor_width >= (@map.width+@map.offset+1) + c[1] = @map.offset if c[1] < @map.offset + c[1] = @map.width-(@map.offset)-cursor_width+2 if c[1]+cursor_width >= (@map.width+@map.offset+1) set_cursor_pos(c[0], c[1]) From e9915be8ad683bf8d5c35d403cde5b64528908db Mon Sep 17 00:00:00 2001 From: Andrea Date: Sun, 6 Nov 2011 12:05:24 -0500 Subject: [PATCH 3/3] Fixing indentation in city.rb --- lib/vimcity/city.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vimcity/city.rb b/lib/vimcity/city.rb index 8da925c..faf55ce 100644 --- a/lib/vimcity/city.rb +++ b/lib/vimcity/city.rb @@ -14,7 +14,7 @@ def initialize(coins=1000, population=100) def update @coins+=@money_per_second if @population < @population_cap - @population+=@people_per_second*@happiness + @population+=@people_per_second*@happiness @population=@population.round end @happiness-=0.001