Added an arrow to see where you shoot
This commit is contained in:
+20
-3
@@ -17,6 +17,9 @@ const BOUNCE_RATIO:f32 = 60.0;
|
|||||||
const DEFAULT_BALL_WIDTH:i32 = 20;
|
const DEFAULT_BALL_WIDTH:i32 = 20;
|
||||||
const DEFAULT_START_BALL_LOCATION_X:i32 = WINDOW_WIDTH / 2 - DEFAULT_BALL_WIDTH / 2;
|
const DEFAULT_START_BALL_LOCATION_X:i32 = WINDOW_WIDTH / 2 - DEFAULT_BALL_WIDTH / 2;
|
||||||
const DEFAULT_START_BALL_LOCATION_Y:i32 = (WINDOW_HEIGHT / 5) * 4 - DEFAULT_BALL_WIDTH / 2;
|
const DEFAULT_START_BALL_LOCATION_Y:i32 = (WINDOW_HEIGHT / 5) * 4 - DEFAULT_BALL_WIDTH / 2;
|
||||||
|
const ARROW_PARTS:i32 = 10;
|
||||||
|
const ARROW_SIZE_RATIO:i32 = 3;
|
||||||
|
const ARROW_WIDTH:i32 = 3;
|
||||||
|
|
||||||
const DEFAULT_MAP_WIDTH:i32 = 40;
|
const DEFAULT_MAP_WIDTH:i32 = 40;
|
||||||
const DEFAULT_MAP_HEIGHT:i32 = 50;
|
const DEFAULT_MAP_HEIGHT:i32 = 50;
|
||||||
@@ -111,7 +114,7 @@ impl Map{
|
|||||||
for y in 0..self.size.y{
|
for y in 0..self.size.y{
|
||||||
let rect = Rect::new(x * width,y * height,width as u32,height as u32);
|
let rect = Rect::new(x * width,y * height,width as u32,height as u32);
|
||||||
let index = x + self.size.x * y;
|
let index = x + self.size.x * y;
|
||||||
let tile_color:Color = Color::RGB(0xFF, 0xFF, 0xFF);
|
let debug_color:Color = Color::RGB(0xFF, 0xFF, 0xFF);
|
||||||
let tile_bg:Color;
|
let tile_bg:Color;
|
||||||
|
|
||||||
match self.grid[index as usize]{
|
match self.grid[index as usize]{
|
||||||
@@ -151,8 +154,8 @@ impl Map{
|
|||||||
ctx.set_draw_color(tile_bg);
|
ctx.set_draw_color(tile_bg);
|
||||||
ctx.fill_rect(rect).expect("Could not render grid");
|
ctx.fill_rect(rect).expect("Could not render grid");
|
||||||
if debug{
|
if debug{
|
||||||
ctx.set_draw_color(tile_color);
|
ctx.set_draw_color(debug_color);
|
||||||
ctx.draw_rect(rect).expect("Could not render grid");
|
ctx.draw_rect(rect).expect("Could not render debug grid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +172,9 @@ impl Game{
|
|||||||
let main_ball_color:Color = Color::RGB(0xFA, 0xFD, 0xF6);
|
let main_ball_color:Color = Color::RGB(0xFA, 0xFD, 0xF6);
|
||||||
let main_ball_outline:Color = Color::RGB(0x17, 0x2A, 0x33);
|
let main_ball_outline:Color = Color::RGB(0x17, 0x2A, 0x33);
|
||||||
let background_color:Color = Color::RGB(0xFF,0xFF,0xFF);
|
let background_color:Color = Color::RGB(0xFF,0xFF,0xFF);
|
||||||
|
let velocity_color:u8 = ((self.main_ball.velocity.x * 4).abs() + (self.main_ball.velocity.y * 4).abs()) as u8;
|
||||||
|
let arrow_color:Color = Color::RGB(velocity_color,0x00,0x00);
|
||||||
|
let arrow_outline:Color = Color::RGB(0x00,0x00,0x00);
|
||||||
ctx.set_draw_color(background_color);
|
ctx.set_draw_color(background_color);
|
||||||
ctx.clear();
|
ctx.clear();
|
||||||
//map
|
//map
|
||||||
@@ -186,6 +192,17 @@ impl Game{
|
|||||||
fill_circle(ctx, center.x, center.y,self.main_ball.shape.width() as i32 / 2, main_ball_color);
|
fill_circle(ctx, center.x, center.y,self.main_ball.shape.width() as i32 / 2, main_ball_color);
|
||||||
draw_circle(ctx,center.x,center.y,self.main_ball.shape.width() as i32 / 2, main_ball_outline);
|
draw_circle(ctx,center.x,center.y,self.main_ball.shape.width() as i32 / 2, main_ball_outline);
|
||||||
draw_circle(ctx,center.x,center.y,self.main_ball.shape.width() as i32 / 2 + 1, main_ball_outline);
|
draw_circle(ctx,center.x,center.y,self.main_ball.shape.width() as i32 / 2 + 1, main_ball_outline);
|
||||||
|
|
||||||
|
let apex:Point = Point::new(center.x + (self.main_ball.velocity.x * ARROW_SIZE_RATIO) as i32,center.y + (self.main_ball.velocity.y * ARROW_SIZE_RATIO) as i32);
|
||||||
|
let offset = Point::new(((apex.x - center.x) as f32 / ARROW_PARTS as f32) as i32,((apex.y -center.y) as f32 / ARROW_PARTS as f32) as i32);
|
||||||
|
if !self.ball_released{
|
||||||
|
for i in 0..ARROW_PARTS{
|
||||||
|
ctx.set_draw_color(arrow_color);
|
||||||
|
let center = Point::new(center.x + i*offset.x,center.y + i*offset.y);
|
||||||
|
fill_circle(ctx, center.x, center.y, ARROW_WIDTH, arrow_color);
|
||||||
|
draw_circle(ctx, center.x, center.y, ARROW_WIDTH + 1, arrow_outline);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn up(&mut self){
|
pub fn up(&mut self){
|
||||||
|
|||||||
Reference in New Issue
Block a user