<commit_before>#!/usr/bin/env ruby
#
#
# A simple game in Chingu, using GameState, GameObject, Paralaxx, has_traits etc
# 
#
require 'rubygems' rescue nil
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), "..", "..", "lib")
require 'chingu'
require 'texplay'     # adds Image#get_pixel
require 'optparse'

include Gosu
include Chingu


class Game < Chingu::Window  
  def initialize
    $debug = false
    ARGV.each do |a|
	if a == "-debug"
	   $debug = true
	end
    end
    super(1000,400,false)
    self.input = { :escape => :exit }
		retrofy
    switch_game_state(Level)
  end
end


#
# GAME STATE: LEVEL
#
class Level < Chingu::GameState
  has_trait :timer
  
  def initialize(options = {})
    super

    @parallax = Parallax.create(:rotation_center => :top_left, :zorder => 0)
    @parallax << { :image => "city2.png", :damping => 2, :zorder => 0}
    @parallax << { :image => "city1.png", :damping => 1, :zorder => 1000}
    @player = Player.create(:x => 30, :y => 10, :zorder=> 500)
    
    @bg1 = Color.new(0xFFCE28FF)
    @bg2 = Color.new(0xFF013E87)
    @text = Text.create("Score:", :size => 20, :x => 30, :y => 10) #initialize score string
    @text1 = Text.create("0", :size => 20, :x => 90, :y => 10 )   #initialize score value to 0
    
    
  end
  
  #
  # This is called each time this GameState is switched/pushed/poped to.
  #
  def setup
    # Remove all lingering game objects
    Enemy.destroy_all
    Bullet.destroy_all
    
    @player.score = 0
    @player.x = 10
    @player.y = 100
    
    @parallax.camera_x = 0
    @total_game_ticks = 10000#100000
    @timer = 100
    @total_ticks = 0
  end

  #
  # The foremost layer in our parallax scroller is the collidable terrain
  #
  def solid_pixel_at?(x, y)
    begin     
      @parallax.layers.last.get_pixel(x, y)[3] != 0
    rescue
      puts "Error in get_pixel(#{x}, #{y})"
    end
  end
  
  def update
    super
    
    # Move the level forward by increasing the parallax-scrollers camera x-coordinate
    @parallax.camera_x += 1
    
    # Remove all objects outside screen
    game_objects.destroy_if { |game_object| game_object.respond_to?("outside_window?") && game_object.outside_window? }

    # Collide bullets with terrain
    Bullet.select { |o| solid_pixel_at?(o.x, o.y)}.each { |o| o.die }
        
    # Collide player with terrain
    push_game_state(GameOver) if solid_pixel_at?(@player.x, @player.y)
    
    # Collide player with enemies and enemy bullets
    @player.each_bounding_circle_collision(Enemy) do |player, enemy|
      enemy.die
      push_game_state(GameOver)
    end
    
    Bullet.each_bounding_circle_collision(Enemy) do |bullet, enemy|
      bullet.die
      if enemy.hit_by(bullet)
        @player.score += 20
            @text1.destroy!       #destroy old score
            @text1 = Text.create(@player.score, :size => 20, :x => 90, :y => 10 )    #update the new score
            
      end
    end
    
    @timer = @timer * 0.9999
    @total_ticks += 1
    if @total_ticks > @timer<commit_msg>Moved score (bottom left)<commit_after>#!/usr/bin/env ruby
#
#
# A simple game in Chingu, using GameState, GameObject, Paralaxx, has_traits etc
# 
#
require 'rubygems' rescue nil
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), "..", "..", "lib")
require 'chingu'
require 'texplay'     # adds Image#get_pixel
require 'optparse'

include Gosu
include Chingu


class Game < Chingu::Window  
  def initialize
    $debug = false
    ARGV.each do |a|
	if a == "-debug"
	   $debug = true
	end
    end
    super(1000,400,false)
    self.input = { :escape => :exit }
		retrofy
    switch_game_state(Level)
  end
end


#
# GAME STATE: LEVEL
#
class Level < Chingu::GameState
  has_trait :timer
  
  def initialize(options = {})
    super

    @parallax = Parallax.create(:rotation_center => :top_left, :zorder => 0)
    @parallax << { :image => "city2.png", :damping => 2, :zorder => 0}
    @parallax << { :image => "city1.png", :damping => 1, :zorder => 1000}

    @player = Player.create(:x => 30, :y => 10, :zorder=> 500)
    
    @bg1 = Color.new(0xFFCE28FF)
    @bg2 = Color.new(0xFF013E87)
    @text = Text.create("Score:", :size => 20, :x => 30, :y => 370, :zorder => 1001) #initialize score string
    @text1 = Text.create("0", :size => 20, :x => 90, :y => 370, :zorder => 1001)   #initialize score value to 0
    
    
  end
  
  #
  # This is called each time this GameState is switched/pushed/poped to.
  #
  def setup
    # Remove all lingering game objects
    Enemy.destroy_all
    Bullet.destroy_all
    
    @player.score = 0
    @player.x = 10
    @player.y = 100
    
    @parallax.camera_x = 0
    @total_game_ticks = 10000#100000
    @timer = 100
    @total_ticks = 0
  end

  #
  # The foremost layer in our parallax scroller is the collidable terrain
  #
  def solid_pixel_at?(x, y)
    begin     
      @parallax.layers.last.get_pixel(x, y)[3] != 0
    rescue
      puts "Error in get_pixel(#{x}, #{y})"
    end
  end
  
  def update
    super
    
    # Move the level forward by increasing the parallax-scrollers camera x-coordinate
    @parallax.camera_x += 1
    
    # Remove all objects outside screen
    game_objects.destroy_if { |game_object| game_object.respond_to?("outside_window?") && game_object.outside_window? }

    # Collide bullets with terrain
    Bullet.select { |o| solid_pixel_at?(o.x, o.y)}.each { |o| o.die }
        
    # Collide player with terrain
    push_game_state(GameOver) if solid_pixel_at?(@player.x, @player.y)
    
    # Collide player with enemies and enemy bullets
    @player.each_bounding_circle_collision(Enemy) do |player, enemy|
      enemy.die
      push_game_state(GameOver)
    end
    
    Bullet.each_bounding_circle_collision(Enemy) do |bullet, enemy|
      bullet.die
      if enemy.hit_by(bullet)
        @player.score += 20
            @text1.destroy!       #destroy old score
            @text1 = Text.create(@player.score, :size => 20, :x => 90, :y => 370, :zorder => 1001 )    #update the new score
            
      end
    end
    
    @timer = @timer * 0.9999
    @total_ticks += 1
    if @total_ticks > @timer
{'fraction_non_alphanumeric': 0.12581699346405228, 'fraction_numerical': 0.03218954248366013, 'mean_word_length': 2.6984894259818732, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6913492', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2156, 'n_words': 556}