Skip to content

Commit

Permalink
Added Debris Dodge
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditijainnn authored Aug 9, 2024
1 parent 7af1820 commit c12786c
Show file tree
Hide file tree
Showing 100 changed files with 6,417 additions and 0 deletions.
Binary file added Games/Debris_Dodge/Assets/debris dodge.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 Games/Debris_Dodge/Assets/debriss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Games/Debris_Dodge/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in tank_island.gemspec
gemspec
79 changes: 79 additions & 0 deletions Games/Debris_Dodge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# **Debris Dodge**

---

<br>
Give you best Hit!

## **Description 📃**
Tank Island is an open source 2D top down shooter game that was created with Ruby using
[Gosu](http://www.libgosu.org) game development library while writing
[this book](https://leanpub.com/developing-games-with-ruby/).


## **functionalities 🎮**

Top down 2D shooter game that involves blowing up tanks

<br>

## **How to play? 🕹️**

- `W` `A` `S` `D` moves your tank.
- Mouse `left click` shoots.
- `ESC` goes into menu and away from it.
- `R` respawns your tank.
- `T` spawns an enemy tank under mouse cursor.
- `F1` enters debug mode.
- `F2` toggles profiling


<br>

## **Screenshots 📸**

<br><img src="./Assets/debris dodge.png" alt="Image Description">
<br>
<img src="./Assets/debriss.png" alt="Image Description">
<br>





<br>

## Installation

Before installing, make sure you have:

- Ruby installed, preferably through [rbenv](https://github.com/sstephenson/rbenv), not rvm.
- ImageMagick (`gem install rmagick` should work).
- Gosu prerequisites for [Mac](https://github.com/jlnr/gosu/wiki/Getting-Started-on-OS-X),
[Linux](https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux) or
[Windows](https://github.com/jlnr/gosu/wiki/Getting-Started-on-Windows)

To install it, run

$ gem install Debris_Dodge

## Starting the game

There are several ways to start the game.

### Running in 800x600 window mode

$ Debris_Dodge

### Running with custom resolution

$ w=1600 h=1200 Debris_Dodge

### Running full screen with custom resolution

$ fs=1 w=1200 h=800 Debris_Dodge





2 changes: 2 additions & 0 deletions Games/Debris_Dodge/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "bundler/gem_tasks"

82 changes: 82 additions & 0 deletions Games/Debris_Dodge/bin/tank_island
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env ruby

require 'gosu_texture_packer'
require 'perlin_noise'
require 'gosu'

root_dir = File.expand_path(File.join(
File.dirname(File.dirname(__FILE__)), 'lib'))

%w(
game_states/game_state.rb
game_states/play_state.rb
entities/components/component.rb
entities/components/ai/tank_motion_state.rb
entities/game_object.rb
entities/powerups/powerup.rb
entities/box.rb
entities/bullet.rb
entities/camera.rb
entities/components/ai/gun.rb
entities/components/ai/tank_chasing_state.rb
entities/components/ai/tank_fighting_state.rb
entities/components/ai/tank_fleeing_state.rb
entities/components/ai/tank_motion_fsm.rb
entities/components/ai/tank_motion_state.rb
entities/components/ai/tank_navigating_state.rb
entities/components/ai/tank_roaming_state.rb
entities/components/ai/tank_stuck_state.rb
entities/components/ai/vision.rb
entities/components/ai_input.rb
entities/components/box_graphics.rb
entities/components/bullet_graphics.rb
entities/components/bullet_physics.rb
entities/components/bullet_sounds.rb
entities/components/component.rb
entities/components/damage_graphics.rb
entities/components/explosion_graphics.rb
entities/components/explosion_sounds.rb
entities/components/health.rb
entities/components/player_input.rb
entities/components/player_sounds.rb
entities/components/powerup_graphics.rb
entities/components/powerup_sounds.rb
entities/components/tank_graphics.rb
entities/components/tank_health.rb
entities/components/tank_physics.rb
entities/components/tank_sounds.rb
entities/components/tree_graphics.rb
entities/damage.rb
entities/explosion.rb
entities/game_object.rb
entities/hud.rb
entities/map.rb
entities/object_pool.rb
entities/powerups/fire_rate_powerup.rb
entities/powerups/health_powerup.rb
entities/powerups/powerup.rb
entities/powerups/powerup_respawn_queue.rb
entities/powerups/repair_powerup.rb
entities/powerups/tank_speed_powerup.rb
entities/radar.rb
entities/score_display.rb
entities/tank.rb
entities/tree.rb
game_states/demo_state.rb
game_states/menu_state.rb
game_states/pause_state.rb
misc/axis_aligned_bounding_box.rb
misc/game_window.rb
misc/names.rb
misc/quad_tree.rb
misc/stats.rb
misc/stereo_sample.rb
misc/utils.rb
).each do |f|
require File.join(root_dir, f)
end

$debug = false
$window = GameWindow.new
GameState.switch(MenuState.instance)
$window.show
28 changes: 28 additions & 0 deletions Games/Debris_Dodge/lib/entities/box.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Box < GameObject
attr_reader :health, :graphics, :angle

def initialize(object_pool, x, y)
super
@graphics = BoxGraphics.new(self)
@health = Health.new(self, object_pool, 10, true)
@angle = rand(-15..15)
end

def on_collision(object)
return unless object.physics.speed > 1.0
move(*Utils.point_at_distance(@x, @y, object.direction, 2))
@box = nil
end

def box
return @box if @box
w = @graphics.width / 2
h = @graphics.height / 2
# Bounding box adjusted to trim shadows
@box = [x - w + 4, y - h + 8,
x + w , y - h + 8,
x + w , y + h,
x - w + 4, y + h]
@box = Utils.rotate(@angle, @x, @y, *@box)
end
end
26 changes: 26 additions & 0 deletions Games/Debris_Dodge/lib/entities/bullet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Bullet < GameObject
attr_accessor :target_x, :target_y, :source, :speed, :fired_at

def initialize(object_pool, source_x, source_y, target_x, target_y)
super(object_pool, source_x, source_y)
@target_x, @target_y = target_x, target_y
BulletPhysics.new(self, object_pool)
BulletGraphics.new(self)
BulletSounds.play(self, object_pool.camera)
end

def box
[@x, @y]
end

def explode
Explosion.new(object_pool, @x, @y, @source)
mark_for_removal
end

def fire(source, speed)
@source = source
@speed = speed
@fired_at = Gosu.milliseconds
end
end
113 changes: 113 additions & 0 deletions Games/Debris_Dodge/lib/entities/camera.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
class Camera
attr_accessor :x, :y, :zoom
attr_reader :target

def target=(target)
@target = target
@x, @y = target.x, target.y
@zoom = 1
end

def desired_spot
if @target.physics.moving?
Utils.point_at_distance(
@target.x, @target.y,
@target.direction,
@target.physics.speed.ceil * 25)
else
[@target.x, @target.y]
end
end

def mouse_coords
x, y = target_delta_on_screen
mouse_x_on_map = @target.x +
(x + $window.mouse_x - ($window.width / 2)) / @zoom
mouse_y_on_map = @target.y +
(y + $window.mouse_y - ($window.height / 2)) / @zoom
[mouse_x_on_map, mouse_y_on_map].map(&:round)
end

def update
des_x, des_y = desired_spot
shift = Utils.adjust_speed(
@target.physics.speed).floor *
@target.speed_modifier + 1
if @x < des_x
if des_x - @x < shift
@x = des_x
else
@x += shift
end
elsif @x > des_x
if @x - des_x < shift
@x = des_x
else
@x -= shift
end
end
if @y < des_y
if des_y - @y < shift
@y = des_y
else
@y += shift
end
elsif @y > des_y
if @y - des_y < shift
@y = des_y
else
@y -= shift
end
end

zoom_delta = @zoom > 0 ? 0.01 : 1.0
zoom_delta = Utils.adjust_speed(zoom_delta)
if $window.button_down?(Gosu::KbUp)
@zoom -= zoom_delta unless @zoom < 0.7
elsif $window.button_down?(Gosu::KbDown)
@zoom += zoom_delta unless @zoom > 10
else
target_zoom = @target.physics.speed > 1.1 ? 0.75 : 1.0
if @zoom <= (target_zoom - 0.01)
@zoom += zoom_delta / 3
elsif @zoom > (target_zoom + 0.01)
@zoom -= zoom_delta / 3
end
end
end

def to_s
"FPS: #{Gosu.fps}. " <<
"#{@x}:#{@y} @ #{'%.2f' % @zoom}. " <<
'WASD to move, arrows to zoom.'
end

def target_delta_on_screen
[(@x - @target.x) * @zoom, (@y - @target.y) * @zoom]
end

def draw_crosshair
factor = 0.5
x = $window.mouse_x
y = $window.mouse_y
c = crosshair
c.draw(x - c.width * factor / 2,
y - c.height * factor / 2,
1000, factor, factor)
end

def viewport
x0 = @x - ($window.width / 2) / @zoom
x1 = @x + ($window.width / 2) / @zoom
y0 = @y - ($window.height / 2) / @zoom
y1 = @y + ($window.height / 2) / @zoom
[x0, x1, y0, y1]
end

private

def crosshair
@crosshair ||= Gosu::Image.new(
Utils.media_path('c_dot.png'), false)
end
end
Loading

0 comments on commit c12786c

Please sign in to comment.