/* Hurry Curry! - a game about cooking Copyright 2024 metamuffin This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License only. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ use atlas::SpriteRenderer; use game::Game; use hurrycurry_protocol::PacketC; use network::Network; use sdl2::{event::Event, keyboard::Keycode, pixels::Color}; pub mod atlas; pub mod game; pub mod network; fn main() { let sdl_context = sdl2::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); let window = video_subsystem .window("Hurry Curry! Light Client", 1280, 720) .position_centered() .resizable() .build() .map_err(|e| e.to_string()) .unwrap(); let mut canvas = window .into_canvas() .accelerated() .build() .map_err(|e| e.to_string()) .unwrap(); let texture_creator = canvas.texture_creator(); let mut net = Network::connect("ws://127.0.0.1/").unwrap(); let mut game = Game::new(); let mut renderer = SpriteRenderer::init(&texture_creator); 'mainloop: loop { net.poll(); for packet in net.queue_in.drain(..) { match packet { PacketC::Data { data } => { renderer.set_sprite_map(data); } _ => game.packet_in(packet), } } game.render(&mut renderer); canvas.set_draw_color(Color::BLACK); canvas.clear(); renderer.submit(&mut canvas); canvas.present(); for event in sdl_context.event_pump().unwrap().poll_iter() { match event { Event::Quit { .. } | Event::KeyDown { keycode: Option::Some(Keycode::Escape), .. } => break 'mainloop, _ => {} } } } }