Added all the Jumping mechanics
This commit is contained in:
+49
-35
@@ -51,11 +51,11 @@ const DEFAULT_MAP:&[Tile] = &[
|
|||||||
Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky,
|
Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky,
|
||||||
Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky,
|
Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky, Tile::sky,Tile::sky,Tile::sky,Tile::sky,Tile::sky,
|
||||||
|
|
||||||
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::sand,Tile::grass,Tile::sand,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
||||||
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::sand,Tile::grass,Tile::sand,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
||||||
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::sand,Tile::grass,Tile::sand, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
||||||
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::sand,Tile::grass, Tile::sand,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
||||||
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::sand, Tile::grass,Tile::sand,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock, Tile::rock,Tile::rock,Tile::rock,Tile::rock,Tile::rock,
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -155,8 +155,8 @@ 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 charge_color:u8 = ((self.main_ball.charge.x * 4).abs() + (self.main_ball.charge.y * 4).abs()) as u8;
|
||||||
let arrow_color:Color = Color::RGB(velocity_color,0x00,0x00);
|
let arrow_color:Color = Color::RGB(charge_color,0x00,0x00);
|
||||||
let arrow_outline:Color = Color::RGB(0x00,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();
|
||||||
@@ -169,15 +169,16 @@ impl Game{
|
|||||||
ctx.fill_rect(self.main_ball.shape).expect("Could not fill the rectangle");
|
ctx.fill_rect(self.main_ball.shape).expect("Could not fill the rectangle");
|
||||||
ctx.set_draw_color(main_ball_outline);
|
ctx.set_draw_color(main_ball_outline);
|
||||||
ctx.draw_rect(self.main_ball.shape).expect("Could not ouline the rectangle");
|
ctx.draw_rect(self.main_ball.shape).expect("Could not ouline the rectangle");
|
||||||
let apex:Point = Point::new(center.x + (self.main_ball.velocity.x * DEBUG_FX_SIZE_RATIO) as i32,center.y + (self.main_ball.velocity.y * DEBUG_FX_SIZE_RATIO) as i32);
|
let apex:Point = Point::new(center.x + (self.main_ball.charge.x * DEBUG_FX_SIZE_RATIO) as i32,center.y + (self.main_ball.charge.y * DEBUG_FX_SIZE_RATIO) as i32);
|
||||||
ctx.draw_line(center,apex).expect("Could not render the Debug FX");
|
ctx.draw_line(center,apex).expect("Could not render the Debug FX");
|
||||||
}else{
|
}else{
|
||||||
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 apex:Point = Point::new(center.x + (self.main_ball.charge.x * ARROW_SIZE_RATIO) as i32,center.y + (self.main_ball.charge.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);
|
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.main_ball.grounded{
|
||||||
for i in 0..ARROW_PARTS{
|
for i in 0..ARROW_PARTS{
|
||||||
ctx.set_draw_color(arrow_color);
|
ctx.set_draw_color(arrow_color);
|
||||||
let center = Point::new(center.x + i*offset.x,center.y + i*offset.y);
|
let center = Point::new(center.x + i*offset.x,center.y + i*offset.y);
|
||||||
@@ -186,17 +187,23 @@ impl Game{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
pub fn up(&mut self){
|
pub fn up(&mut self){
|
||||||
self.main_ball.velocity.y -= BALL_SPEED as i32;
|
if self.main_ball.grounded{self.main_ball.charge.y -= BALL_SPEED as i32;}
|
||||||
}
|
}
|
||||||
pub fn down(&mut self){
|
pub fn down(&mut self){
|
||||||
self.main_ball.velocity.y += BALL_SPEED as i32;
|
if self.main_ball.grounded{self.main_ball.charge.y += BALL_SPEED as i32;}
|
||||||
}
|
}
|
||||||
pub fn left(&mut self){
|
pub fn left(&mut self){
|
||||||
self.main_ball.velocity.x -= BALL_SPEED as i32;
|
if self.main_ball.grounded{self.main_ball.charge.x -= BALL_SPEED as i32;}
|
||||||
}
|
}
|
||||||
pub fn right(&mut self){
|
pub fn right(&mut self){
|
||||||
self.main_ball.velocity.x += BALL_SPEED as i32;
|
if self.main_ball.grounded{self.main_ball.charge.x += BALL_SPEED as i32;}
|
||||||
|
}
|
||||||
|
pub fn jump(&mut self){
|
||||||
|
if self.main_ball.grounded{
|
||||||
|
self.main_ball.grounded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn toggle_debug(&mut self){
|
pub fn toggle_debug(&mut self){
|
||||||
self.draw_debug = !self.draw_debug;
|
self.draw_debug = !self.draw_debug;
|
||||||
@@ -208,7 +215,7 @@ impl Game{
|
|||||||
}
|
}
|
||||||
pub fn right_click(&mut self,_mouse_position:Point){
|
pub fn right_click(&mut self,_mouse_position:Point){
|
||||||
// Removes any vectors
|
// Removes any vectors
|
||||||
self.main_ball.velocity = Point::new(0,0);
|
self.main_ball.charge = Point::new(0,0);
|
||||||
}
|
}
|
||||||
pub fn update(&mut self){
|
pub fn update(&mut self){
|
||||||
let bloc = &mut self.main_ball;
|
let bloc = &mut self.main_ball;
|
||||||
@@ -217,49 +224,53 @@ impl Game{
|
|||||||
let width = bloc.shape.width() as i32;
|
let width = bloc.shape.width() as i32;
|
||||||
let height = bloc.shape.height() as i32;
|
let height = bloc.shape.height() as i32;
|
||||||
|
|
||||||
//Window Collision Detection
|
if !bloc.grounded{
|
||||||
|
posx += bloc.charge.x;
|
||||||
|
posy += bloc.charge.y;
|
||||||
|
//gravity
|
||||||
|
bloc.charge.y += 1;
|
||||||
|
|
||||||
if posy + height >= WINDOW_HEIGHT{
|
if posy + height >= WINDOW_HEIGHT{
|
||||||
posy = WINDOW_HEIGHT - height;
|
posy = WINDOW_HEIGHT - height;
|
||||||
bloc.velocity.y = bounce(bloc.velocity.y);
|
//hits the bottom
|
||||||
|
bloc.grounded = true;
|
||||||
|
bloc.charge = Point::new(0,0);
|
||||||
}
|
}
|
||||||
if posy <= 0{
|
if posy <= 0{
|
||||||
posy = 0;
|
posy = 0;
|
||||||
bloc.velocity.y = bounce(bloc.velocity.y);
|
|
||||||
}
|
}
|
||||||
if posx + width >= WINDOW_WIDTH{
|
if posx + width >= WINDOW_WIDTH{
|
||||||
posx = WINDOW_WIDTH - width;
|
posx = WINDOW_WIDTH - width;
|
||||||
bloc.velocity.x = bounce(bloc.velocity.x);
|
bloc.charge.x = ((-bloc.charge.x as f32 / 100.0) * BOUNCE_RATIO as f32) as i32;
|
||||||
}
|
}
|
||||||
if posx <= 0{
|
if posx <= 0{
|
||||||
posx = 0;
|
posx = 0;
|
||||||
bloc.velocity.x = bounce(bloc.velocity.x);
|
bloc.charge.x = -bloc.charge.x;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Uggly way to maintain the bloc in a normal speed
|
//Uggly way to maintain the bloc in a normal speed
|
||||||
if bloc.velocity.x > MAX_SPEED as i32{
|
if bloc.charge.x > MAX_SPEED as i32{
|
||||||
bloc.velocity.x = MAX_SPEED as i32;
|
bloc.charge.x = MAX_SPEED as i32;
|
||||||
}
|
}
|
||||||
if bloc.velocity.x < -MAX_SPEED as i32{
|
if bloc.charge.x < -MAX_SPEED as i32{
|
||||||
bloc.velocity.x = -MAX_SPEED as i32;
|
bloc.charge.x = -MAX_SPEED as i32;
|
||||||
}
|
}
|
||||||
if bloc.velocity.y > MAX_SPEED as i32{
|
if bloc.charge.y > MAX_SPEED as i32{
|
||||||
bloc.velocity.y = MAX_SPEED as i32;
|
bloc.charge.y = MAX_SPEED as i32;
|
||||||
}
|
}
|
||||||
if bloc.velocity.y < -MAX_SPEED as i32{
|
if bloc.charge.y < -MAX_SPEED as i32{
|
||||||
bloc.velocity.y = -MAX_SPEED as i32;
|
bloc.charge.y = -MAX_SPEED as i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
posx += bloc.velocity.x;
|
|
||||||
posy += bloc.velocity.y;
|
|
||||||
|
|
||||||
bloc.shape.set_x(posx);
|
bloc.shape.set_x(posx);
|
||||||
bloc.shape.set_y(posy);
|
bloc.shape.set_y(posy);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn bounce(acceleration:i32)->i32{
|
|
||||||
-(acceleration as f32 / 100.0 * BOUNCE_RATIO as f32) as i32
|
|
||||||
}
|
|
||||||
//https://stackoverflow.com/questions/65723827/sdl2-function-to-draw-a-filled-circle ## Translated to Rust
|
//https://stackoverflow.com/questions/65723827/sdl2-function-to-draw-a-filled-circle ## Translated to Rust
|
||||||
pub fn fill_circle(ctx:&mut sdl2::render::Canvas<sdl2::video::Window>, x:i32, y:i32, radius:i32, color:Color)
|
pub fn fill_circle(ctx:&mut sdl2::render::Canvas<sdl2::video::Window>, x:i32, y:i32, radius:i32, color:Color)
|
||||||
{
|
{
|
||||||
@@ -313,7 +324,8 @@ pub fn draw_circle(ctx:&mut sdl2::render::Canvas<sdl2::video::Window>, centre_x:
|
|||||||
}
|
}
|
||||||
pub struct Entity{
|
pub struct Entity{
|
||||||
shape:Rect,
|
shape:Rect,
|
||||||
velocity:Point,
|
charge:Point,
|
||||||
|
grounded:bool,
|
||||||
}
|
}
|
||||||
fn is_up_pressed(e: &sdl2::EventPump) -> bool {
|
fn is_up_pressed(e: &sdl2::EventPump) -> bool {
|
||||||
e.keyboard_state().is_scancode_pressed(Scancode::W) || e.keyboard_state().is_scancode_pressed(Scancode::Up)
|
e.keyboard_state().is_scancode_pressed(Scancode::W) || e.keyboard_state().is_scancode_pressed(Scancode::Up)
|
||||||
@@ -391,6 +403,7 @@ pub fn main_loop(canvas: &mut sdl2::render::Canvas<sdl2::video::Window>,event_pu
|
|||||||
if space_state == true{
|
if space_state == true{
|
||||||
//KeyDown
|
//KeyDown
|
||||||
space_state = false;
|
space_state = false;
|
||||||
|
game.jump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut mouse_position:Point = check_mouse_left_pressed(event_pump);
|
let mut mouse_position:Point = check_mouse_left_pressed(event_pump);
|
||||||
@@ -443,10 +456,11 @@ pub fn main() {
|
|||||||
|
|
||||||
let main_ball_rectangle = Rect::new(
|
let main_ball_rectangle = Rect::new(
|
||||||
DEFAULT_START_BALL_LOCATION_X,DEFAULT_START_BALL_LOCATION_Y, DEFAULT_BALL_WIDTH as u32, DEFAULT_BALL_WIDTH as u32);
|
DEFAULT_START_BALL_LOCATION_X,DEFAULT_START_BALL_LOCATION_Y, DEFAULT_BALL_WIDTH as u32, DEFAULT_BALL_WIDTH as u32);
|
||||||
let main_ball_velocity = Point::new(0,0);
|
let main_ball_charge = Point::new(0,0);
|
||||||
let main_entity = Entity{
|
let main_entity = Entity{
|
||||||
shape:main_ball_rectangle,
|
shape:main_ball_rectangle,
|
||||||
velocity:main_ball_velocity
|
charge:main_ball_charge,
|
||||||
|
grounded:false,
|
||||||
};
|
};
|
||||||
let mut game = Game{main_ball:main_entity,draw_debug:false,map:Map::new()};
|
let mut game = Game{main_ball:main_entity,draw_debug:false,map:Map::new()};
|
||||||
main_loop(&mut canvas,&mut event_pump,&mut game);
|
main_loop(&mut canvas,&mut event_pump,&mut game);
|
||||||
|
|||||||
Reference in New Issue
Block a user